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
TransposeGatedConv2d
import torch import torch.nn as nn from torch.nn import functional as F from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2d, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest') x = self.gated_conv2d(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_mv_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_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) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.load(in_ptr0 + (64 + r0), None) tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp9 = tl.load(in_ptr0 + (128 + r0), None) tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp14 = tl.load(in_ptr0 + (192 + r0), None) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp3 = tmp0 * tmp2 tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp12 = tmp9 * tmp11 tmp13 = tmp8 + tmp12 tmp17 = tmp14 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = tmp18 * tmp18 tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK]) tmp22 = tl.sum(tmp20, 1)[:, None] tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-12 tmp25 = tmp23 + tmp24 tmp26 = tmp18 / tmp25 tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp18, None) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp25, None) tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp26, None) @triton.jit def triton_per_fused_div_mv_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, 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 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp4 = tmp1 / tmp3 tmp5 = tmp0 * tmp4 tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tl.store(out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_3(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tmp5 = libdevice.sqrt(tmp4) tmp6 = 1e-12 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp8, None) @triton.jit def triton_per_fused_dot_4(in_ptr0, in_ptr1, out_ptr0, 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) tmp1 = tl.load(in_ptr1 + r0, 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) @triton.jit def triton_poi_fused_div_5(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 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 / tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.0 tmp7 = tmp2 > tmp6 tmp8 = 0.2 tmp9 = tmp2 * tmp8 tmp10 = tl.where(tmp7, tmp2, tmp9) tmp11 = tl.sigmoid(tmp5) tmp12 = tmp10 * tmp11 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(in_out_ptr1 + x3, tmp5, 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) = 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, (64,), (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, (64,), (1,)) assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64,), (1,), torch.float32) buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 buf27 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf3, primals_4, primals_2, buf1, buf27, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_div_mv_2[grid(4)](primals_4, buf1, buf3, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf6 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf4, buf6, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf6, buf4, buf7, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_4, buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf0, buf8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 4, 5, 5), (100, 25, 5, 1)) buf11 = empty_strided_cuda((64,), (1,), torch.float32) buf12 = empty_strided_cuda((), (), torch.float32) buf13 = buf12 del buf12 buf36 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf13, primals_8, primals_6, buf11, buf36, 1, 64, XBLOCK=1, num_warps= 2, num_stages=1) buf14 = buf4 del buf4 triton_per_fused_div_mv_2[grid(4)](primals_8, buf11, buf13, buf14, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf16 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf14, buf16, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf17 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf16, buf14, buf17, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf14 buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_8, buf17, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1) buf19 = extern_kernels.convolution(buf0, buf18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 4, 5, 5), (100, 25, 5, 1)) buf10 = buf9 del buf9 buf20 = buf19 del buf19 buf21 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.float32 ) triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6[grid(400)](buf10, buf20, primals_5, primals_9, buf21, 400, XBLOCK=256, num_warps= 4, num_stages=1) del primals_5 del primals_9 buf22 = torch.ops.aten.set_.source_Tensor(primals_2, buf6) assert_size_stride(buf22, (4,), (1,)) del buf1 buf28 = torch.ops.aten.set_.source_Tensor(primals_3, buf27) assert_size_stride(buf28, (64,), (1,)) del primals_3 buf31 = torch.ops.aten.set_.source_Tensor(primals_6, buf16) assert_size_stride(buf31, (4,), (1,)) del buf11 buf37 = torch.ops.aten.set_.source_Tensor(primals_7, buf36) assert_size_stride(buf37, (64,), (1,)) del primals_7 return (buf21, buf8, buf18, primals_2, primals_4, primals_6, primals_8, buf0, buf3, buf6, buf7, buf8, buf10, buf13, buf16, buf17, buf18, buf20) def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2dNew, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, input_0): primals_2 = self.gated_conv2d.conv2d.module.bias primals_5 = self.gated_conv2d.conv2d.module.weight_u primals_3 = self.gated_conv2d.conv2d.module.weight_v primals_1 = self.gated_conv2d.conv2d.module.weight_bar primals_6 = self.gated_conv2d.mask_conv2d.module.bias primals_9 = self.gated_conv2d.mask_conv2d.module.weight_u primals_7 = self.gated_conv2d.mask_conv2d.module.weight_v primals_4 = self.gated_conv2d.mask_conv2d.module.weight_bar primals_8 = 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]
piggy2303/DeepFillv2_Pytorch
TransposeGatedConv2d
false
7,479
[ "MIT" ]
1
dd35299f11704f878ed7a33e14ccd51a9d64baaf
https://github.com/piggy2303/DeepFillv2_Pytorch/tree/dd35299f11704f878ed7a33e14ccd51a9d64baaf
BasePolicy
import torch import torch.nn as nn import torch.nn.functional as F class BasePolicy(nn.Module): """ Base policy network """ def __init__(self, input_dim, out_dim, hidden_dim=64, nonlin=F. leaky_relu, norm_in=False, onehot_dim=0): """ Inputs: input_dim (int): Number of dimensions in input out_dim (int): Number of dimensions in output hidden_dim (int): Number of hidden dimensions nonlin (PyTorch function): Nonlinearity to apply to hidden layers """ super(BasePolicy, self).__init__() if norm_in: self.in_fn = nn.BatchNorm1d(input_dim, affine=False) else: self.in_fn = lambda x: x self.fc1 = nn.Linear(input_dim + onehot_dim, hidden_dim) self.fc2 = nn.Linear(hidden_dim, hidden_dim) self.fc3 = nn.Linear(hidden_dim, out_dim) self.nonlin = nonlin return def forward(self, X): """ Inputs: X (PyTorch Matrix): Batch of observations (optionally a tuple that additionally includes a onehot label) Outputs: out (PyTorch Matrix): Actions """ onehot = None if isinstance(X, tuple): X, onehot = X inp = self.in_fn(X) if onehot is not None: inp = torch.cat((onehot, inp), dim=1) h1 = self.nonlin(self.fc1(inp)) h2 = self.nonlin(self.fc2(h1)) out = self.fc3(h2) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'out_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.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_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) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, 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, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (64, 4), (4, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64), (64, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 64), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) buf2 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch. float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(4096)](buf0, primals_3, buf1, buf2, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 64), (1, 64), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) buf5 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch. float32) triton_poi_fused_leaky_relu_0[grid(4096)](buf3, primals_5, buf4, buf5, 4096, XBLOCK=128, num_warps=4, num_stages=1) del buf3 del primals_5 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf5, (64, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf6) del primals_7 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 64), (64, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 64), (64, 1), 0 ), primals_6, primals_4 class BasePolicyNew(nn.Module): """ Base policy network """ def __init__(self, input_dim, out_dim, hidden_dim=64, nonlin=F. leaky_relu, norm_in=False, onehot_dim=0): """ Inputs: input_dim (int): Number of dimensions in input out_dim (int): Number of dimensions in output hidden_dim (int): Number of hidden dimensions nonlin (PyTorch function): Nonlinearity to apply to hidden layers """ super(BasePolicyNew, self).__init__() if norm_in: self.in_fn = nn.BatchNorm1d(input_dim, affine=False) else: self.in_fn = lambda x: x self.fc1 = nn.Linear(input_dim + onehot_dim, hidden_dim) self.fc2 = nn.Linear(hidden_dim, hidden_dim) self.fc3 = nn.Linear(hidden_dim, out_dim) self.nonlin = nonlin return def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
pohanchi/DL_final_project
BasePolicy
false
7,480
[ "Apache-2.0" ]
1
8ade422f61a2e8bd4256523ebda56e19b189fe91
https://github.com/pohanchi/DL_final_project/tree/8ade422f61a2e8bd4256523ebda56e19b189fe91
ContinuousCritic
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class ContinuousCritic(nn.Module): """ContinuousCritic network :param state_size: the size of the state space :type state_size: int :param hidden1_size: the size of the first hidden network :type hidden1_size: int :param hidden2_size: the size of the second hidden network :type hidden2_size: int :param action_size: the size of the action space :type action_size: int """ def __init__(self, state_size, hidden1_size, hidden2_size, action_size): super(ContinuousCritic, self).__init__() self.fc1 = nn.Linear(state_size, hidden1_size) self.fc2 = nn.Linear(hidden1_size + action_size, hidden2_size) self.fc3 = nn.Linear(hidden2_size, 1) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.0003, 0.0003) def forward(self, state, action): """Build a critic network that maps (state,action) to utility. :param state: the state :type state: :class:`torch.Tensor` :param action: action tensor :type action: :class:`torch.Tensor` :return: utility tensor :rtype: :class:`torch.Tensor` """ xs = F.leaky_relu(self.fc1(state)) x = torch.cat((xs, action), dim=1) x = F.leaky_relu(self.fc2(x)) return self.fc3(x) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'hidden1_size': 4, 'hidden2_size': 4, 'action_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 numpy as np 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_leaky_relu_0(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 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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).to(tl.int1) tmp6 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = 0.01 tmp10 = tmp8 * tmp9 tmp11 = tl.where(tmp5, tmp8, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp17 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tl.where(tmp4, tmp13, tmp17) tl.store(out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, 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, 8), (8, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (1, 4), (4, 1)) assert_size_stride(primals_8, (1,), (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 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(16)](buf0, primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32) triton_poi_fused_cat_1[grid(32)](buf1, buf0, primals_2, primals_4, buf2, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_2 del primals_4 buf3 = buf0 del buf0 extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (8, 4), (1, 8 ), 0), out=buf3) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_leaky_relu_2[grid(16)](buf3, primals_6, buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf3 del primals_6 buf7 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, buf5, reinterpret_tensor(primals_7, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf7) del primals_8 return buf7, primals_3, buf1, buf2, buf4, buf5, primals_7, primals_5 def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class ContinuousCriticNew(nn.Module): """ContinuousCritic network :param state_size: the size of the state space :type state_size: int :param hidden1_size: the size of the first hidden network :type hidden1_size: int :param hidden2_size: the size of the second hidden network :type hidden2_size: int :param action_size: the size of the action space :type action_size: int """ def __init__(self, state_size, hidden1_size, hidden2_size, action_size): super(ContinuousCriticNew, self).__init__() self.fc1 = nn.Linear(state_size, hidden1_size) self.fc2 = nn.Linear(hidden1_size + action_size, hidden2_size) self.fc3 = nn.Linear(hidden2_size, 1) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.0003, 0.0003) def forward(self, input_0, input_1): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_5 = self.fc2.weight primals_6 = self.fc2.bias primals_7 = self.fc3.weight primals_8 = self.fc3.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
pjordan/rlcc
ContinuousCritic
false
7,481
[ "Apache-2.0" ]
1
e84b8b5c14680dbad2efae22756fb40606b2384a
https://github.com/pjordan/rlcc/tree/e84b8b5c14680dbad2efae22756fb40606b2384a
Net
import torch import torch.nn as nn class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(kernel_size=5, in_channels=3, out_channels=3) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = nn.Conv2d(kernel_size=5, in_channels=3, out_channels=3) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.lin1 = nn.Linear(in_features=75, out_features=10) self.lin2 = nn.Linear(in_features=10, out_features=2) def forward(self, x): x = self.conv1(x) x = self.pool1(x) x = self.conv2(x) x = self.pool2(x) x = x.view(-1, 75) x = self.lin1(x) x = self.lin2(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.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 9408 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 3 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_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 2352 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 14 x1 = xindex // 14 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x1), xmask, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x1), 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 + x2, tmp6, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 100 % 3 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_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 300 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) 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, (3, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_2, (3,), (1,)) assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1)) assert_size_stride(primals_4, (3, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_5, (3,), (1,)) assert_size_stride(primals_6, (10, 75), (75, 1)) assert_size_stride(primals_7, (10,), (1,)) assert_size_stride(primals_8, (2, 10), (10, 1)) assert_size_stride(primals_9, (2,), (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, 3, 28, 28), (2352, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(9408)](buf1, primals_2, 9408, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 3, 14, 14), (588, 196, 14, 1), torch. float32) buf3 = empty_strided_cuda((4, 3, 14, 14), (588, 196, 14, 1), torch.int8 ) triton_poi_fused_max_pool2d_with_indices_1[grid(2352)](buf1, buf2, buf3, 2352, 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, 3, 10, 10), (300, 100, 10, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(1200)](buf5, primals_5, 1200, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 3, 5, 5), (75, 25, 5, 1), torch.int8) buf7 = empty_strided_cuda((4, 3, 5, 5), (75, 25, 5, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_3[grid(300)](buf5, buf6, buf7, 300, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf7, (4, 75), ( 75, 1), 0), reinterpret_tensor(primals_6, (75, 10), (1, 75), 0), alpha=1, beta=1, out=buf8) del primals_7 buf9 = empty_strided_cuda((4, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_9, buf8, reinterpret_tensor(primals_8, (10, 2), (1, 10), 0), alpha=1, beta=1, out=buf9) del primals_9 return (buf9, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 75), (75, 1), 0), buf8, primals_8, primals_6) class NetNew(nn.Module): def __init__(self): super(NetNew, self).__init__() self.conv1 = nn.Conv2d(kernel_size=5, in_channels=3, out_channels=3) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2 = nn.Conv2d(kernel_size=5, in_channels=3, out_channels=3) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.lin1 = nn.Linear(in_features=75, out_features=10) self.lin2 = nn.Linear(in_features=10, out_features=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.lin1.weight primals_7 = self.lin1.bias primals_8 = self.lin2.weight primals_9 = self.lin2.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]
pippinhio/image-recognition
Net
false
7,482
[ "MIT" ]
1
89569a0d66ae144d2f6e6f2d73a8577ef8b2272b
https://github.com/pippinhio/image-recognition/tree/89569a0d66ae144d2f6e6f2d73a8577ef8b2272b
AddBroadcastPosEmbed
import torch import torch.nn as nn def tensor_slice(x, begin, size): assert all([(b >= 0) for b in begin]) size = [(l - b if s == -1 else s) for s, b, l in zip(size, begin, x.shape)] assert all([(s >= 0) for s in size]) slices = [slice(b, b + s) for b, s in zip(begin, size)] return x[slices] class AddBroadcastPosEmbed(nn.Module): def __init__(self, shape, embd_dim, dim=-1): super().__init__() assert dim in [-1, 1] self.shape = shape self.n_dim = n_dim = len(shape) self.embd_dim = embd_dim self.dim = dim assert embd_dim % n_dim == 0, f'{embd_dim} % {n_dim} != 0' self.emb = nn.ParameterDict({f'd_{i}': nn.Parameter(torch.randn( shape[i], embd_dim // n_dim) * 0.01 if dim == -1 else torch. randn(embd_dim // n_dim, shape[i]) * 0.01) for i in range(n_dim)}) def forward(self, x, decode_step=None, decode_idx=None): embs = [] for i in range(self.n_dim): e = self.emb[f'd_{i}'] if self.dim == -1: e = e.view(1, *((1,) * i), self.shape[i], *((1,) * (self. n_dim - i - 1)), -1) e = e.expand(1, *self.shape, -1) else: e = e.view(1, -1, *((1,) * i), self.shape[i], *((1,) * ( self.n_dim - i - 1))) e = e.expand(1, -1, *self.shape) embs.append(e) embs = torch.cat(embs, dim=self.dim) if decode_step is not None: embs = tensor_slice(embs, [0, *decode_idx, 0], [x.shape[0], *(( 1,) * self.n_dim), x.shape[-1]]) return x + embs def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'shape': [4, 4], 'embd_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 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_cat_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 x4 = xindex x0 = xindex % 4 x2 = xindex // 16 % 4 x1 = xindex // 4 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = x0 tl.full([1], 0, tl.int64) tmp4 = tl.full([1], 2, tl.int64) tmp5 = tmp1 < tmp4 tmp6 = tl.load(in_ptr1 + (2 * x2 + x0), tmp5 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp1 >= tmp4 tl.full([1], 4, tl.int64) tmp10 = tl.load(in_ptr2 + (2 * x1 + (-2 + x0)), tmp7 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tl.where(tmp5, tmp6, tmp10) tmp12 = tmp0 + tmp11 tl.store(out_ptr0 + x4, tmp12, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 2), (2, 1)) assert_size_stride(primals_2, (4, 2), (2, 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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_cat_0[grid(256)](primals_3, primals_1, primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 del primals_3 return buf0, def tensor_slice(x, begin, size): assert all([(b >= 0) for b in begin]) size = [(l - b if s == -1 else s) for s, b, l in zip(size, begin, x.shape)] assert all([(s >= 0) for s in size]) slices = [slice(b, b + s) for b, s in zip(begin, size)] return x[slices] class AddBroadcastPosEmbedNew(nn.Module): def __init__(self, shape, embd_dim, dim=-1): super().__init__() assert dim in [-1, 1] self.shape = shape self.n_dim = n_dim = len(shape) self.embd_dim = embd_dim self.dim = dim assert embd_dim % n_dim == 0, f'{embd_dim} % {n_dim} != 0' self.emb = nn.ParameterDict({f'd_{i}': nn.Parameter(torch.randn( shape[i], embd_dim // n_dim) * 0.01 if dim == -1 else torch. randn(embd_dim // n_dim, shape[i]) * 0.01) for i in range(n_dim)}) def forward(self, input_0): primals_1 = self.emb.d_0 primals_2 = self.emb.d_1 primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
pointoflight/VideoGPT
AddBroadcastPosEmbed
false
7,483
[ "MIT" ]
1
85f19d8cb0d251238f295f0294e69b9299c13e21
https://github.com/pointoflight/VideoGPT/tree/85f19d8cb0d251238f295f0294e69b9299c13e21
Model
import torch from torch import nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.conv1_7x7_s2 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3 ) self.pool1_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.pool1_norm1 = nn.LocalResponseNorm(2, 1.99999994948e-05, 0.75) self.conv2_3x3_reduce = nn.Conv2d(64, 64, kernel_size=1, stride=1, padding=0) self.conv2_3x3 = nn.Conv2d(64, 192, kernel_size=3, stride=1, padding=1) self.conv2_norm2 = nn.LocalResponseNorm(2, 1.99999994948e-05, 0.75) self.pool2_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_3a_1x1 = nn.Conv2d(192, 64, kernel_size=1, stride=1, padding=0) self.inception_3a_3x3_reduce = nn.Conv2d(192, 96, kernel_size=1, stride=1, padding=0) self.inception_3a_3x3 = nn.Conv2d(96, 128, kernel_size=3, stride=1, padding=1) self.inception_3a_5x5_reduce = nn.Conv2d(192, 16, kernel_size=1, stride=1, padding=0) self.inception_3a_5x5 = nn.Conv2d(16, 32, kernel_size=5, stride=1, padding=2) self.inception_3a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_3a_pool_proj = nn.Conv2d(192, 32, kernel_size=1, stride=1, padding=0) self.inception_3b_1x1 = nn.Conv2d(256, 128, kernel_size=1, stride=1, padding=0) self.inception_3b_3x3_reduce = nn.Conv2d(256, 128, kernel_size=1, stride=1, padding=0) self.inception_3b_3x3 = nn.Conv2d(128, 192, kernel_size=3, stride=1, padding=1) self.inception_3b_5x5_reduce = nn.Conv2d(256, 32, kernel_size=1, stride=1, padding=0) self.inception_3b_5x5 = nn.Conv2d(32, 96, kernel_size=5, stride=1, padding=2) self.inception_3b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_3b_pool_proj = nn.Conv2d(256, 64, kernel_size=1, stride=1, padding=0) self.pool3_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_4a_1x1 = nn.Conv2d(480, 192, kernel_size=1, stride=1, padding=0) self.inception_4a_3x3_reduce = nn.Conv2d(480, 96, kernel_size=1, stride=1, padding=0) self.inception_4a_3x3 = nn.Conv2d(96, 208, kernel_size=3, stride=1, padding=1) self.inception_4a_5x5_reduce = nn.Conv2d(480, 16, kernel_size=1, stride=1, padding=0) self.inception_4a_5x5 = nn.Conv2d(16, 48, kernel_size=5, stride=1, padding=2) self.inception_4a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4a_pool_proj = nn.Conv2d(480, 64, kernel_size=1, stride=1, padding=0) self.inception_4b_1x1 = nn.Conv2d(512, 160, kernel_size=1, stride=1, padding=0) self.inception_4b_3x3_reduce = nn.Conv2d(512, 112, kernel_size=1, stride=1, padding=0) self.inception_4b_3x3 = nn.Conv2d(112, 224, kernel_size=3, stride=1, padding=1) self.inception_4b_5x5_reduce = nn.Conv2d(512, 24, kernel_size=1, stride=1, padding=0) self.inception_4b_5x5 = nn.Conv2d(24, 64, kernel_size=5, stride=1, padding=2) self.inception_4b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4b_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4c_1x1 = nn.Conv2d(512, 128, kernel_size=1, stride=1, padding=0) self.inception_4c_3x3_reduce = nn.Conv2d(512, 128, kernel_size=1, stride=1, padding=0) self.inception_4c_3x3 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) self.inception_4c_5x5_reduce = nn.Conv2d(512, 24, kernel_size=1, stride=1, padding=0) self.inception_4c_5x5 = nn.Conv2d(24, 64, kernel_size=5, stride=1, padding=2) self.inception_4c_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4c_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4d_1x1 = nn.Conv2d(512, 112, kernel_size=1, stride=1, padding=0) self.inception_4d_3x3_reduce = nn.Conv2d(512, 144, kernel_size=1, stride=1, padding=0) self.inception_4d_3x3 = nn.Conv2d(144, 288, kernel_size=3, stride=1, padding=1) self.inception_4d_5x5_reduce = nn.Conv2d(512, 32, kernel_size=1, stride=1, padding=0) self.inception_4d_5x5 = nn.Conv2d(32, 64, kernel_size=5, stride=1, padding=2) self.inception_4d_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4d_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4e_1x1 = nn.Conv2d(528, 256, kernel_size=1, stride=1, padding=0) self.inception_4e_3x3_reduce = nn.Conv2d(528, 160, kernel_size=1, stride=1, padding=0) self.inception_4e_3x3 = nn.Conv2d(160, 320, kernel_size=3, stride=1, padding=1) self.inception_4e_5x5_reduce = nn.Conv2d(528, 32, kernel_size=1, stride=1, padding=0) self.inception_4e_5x5 = nn.Conv2d(32, 128, kernel_size=5, stride=1, padding=2) self.inception_4e_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4e_pool_proj = nn.Conv2d(528, 128, kernel_size=1, stride=1, padding=0) self.pool4_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_5a_1x1 = nn.Conv2d(832, 256, kernel_size=1, stride=1, padding=0) self.inception_5a_3x3_reduce = nn.Conv2d(832, 160, kernel_size=1, stride=1, padding=0) self.inception_5a_3x3 = nn.Conv2d(160, 320, kernel_size=3, stride=1, padding=1) self.inception_5a_5x5_reduce = nn.Conv2d(832, 32, kernel_size=1, stride=1, padding=0) self.inception_5a_5x5 = nn.Conv2d(32, 128, kernel_size=5, stride=1, padding=2) self.inception_5a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_5a_pool_proj = nn.Conv2d(832, 128, kernel_size=1, stride=1, padding=0) self.inception_5b_1x1 = nn.Conv2d(832, 384, kernel_size=1, stride=1, padding=0) self.inception_5b_3x3_reduce = nn.Conv2d(832, 192, kernel_size=1, stride=1, padding=0) self.inception_5b_3x3 = nn.Conv2d(192, 384, kernel_size=3, stride=1, padding=1) self.inception_5b_5x5_reduce = nn.Conv2d(832, 48, kernel_size=1, stride=1, padding=0) self.inception_5b_5x5 = nn.Conv2d(48, 128, kernel_size=5, stride=1, padding=2) self.inception_5b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_5b_pool_proj = nn.Conv2d(832, 128, kernel_size=1, stride=1, padding=0) self.pool5_7x7_s1 = nn.AdaptiveAvgPool2d(1) self.dropout = nn.Dropout(0.2) self.loss3_SLclassifier = nn.Linear(1024, 61) def forward(self, x): x = F.relu(self.conv1_7x7_s2(x)) x = self.pool1_3x3_s2(x) x = self.pool1_norm1(x) x = F.relu(self.conv2_3x3_reduce(x)) x = F.relu(self.conv2_3x3(x)) x = self.conv2_norm2(x) x = self.pool2_3x3_s2(x) x1 = F.relu(self.inception_3a_1x1(x)) x2 = F.relu(self.inception_3a_3x3_reduce(x)) x2 = F.relu(self.inception_3a_3x3(x2)) x3 = F.relu(self.inception_3a_5x5_reduce(x)) x3 = F.relu(self.inception_3a_5x5(x3)) x4 = self.inception_3a_pool(x) x4 = F.relu(self.inception_3a_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_3b_1x1(x)) x2 = F.relu(self.inception_3b_3x3_reduce(x)) x2 = F.relu(self.inception_3b_3x3(x2)) x3 = F.relu(self.inception_3b_5x5_reduce(x)) x3 = F.relu(self.inception_3b_5x5(x3)) x4 = self.inception_3b_pool(x) x4 = F.relu(self.inception_3b_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x = self.pool3_3x3_s2(x) x1 = F.relu(self.inception_4a_1x1(x)) x2 = F.relu(self.inception_4a_3x3_reduce(x)) x2 = F.relu(self.inception_4a_3x3(x2)) x3 = F.relu(self.inception_4a_5x5_reduce(x)) x3 = F.relu(self.inception_4a_5x5(x3)) x4 = self.inception_4a_pool(x) x4 = F.relu(self.inception_4a_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_4b_1x1(x)) x2 = F.relu(self.inception_4b_3x3_reduce(x)) x2 = F.relu(self.inception_4b_3x3(x2)) x3 = F.relu(self.inception_4b_5x5_reduce(x)) x3 = F.relu(self.inception_4b_5x5(x3)) x4 = self.inception_4b_pool(x) x4 = F.relu(self.inception_4b_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_4c_1x1(x)) x2 = F.relu(self.inception_4c_3x3_reduce(x)) x2 = F.relu(self.inception_4c_3x3(x2)) x3 = F.relu(self.inception_4c_5x5_reduce(x)) x3 = F.relu(self.inception_4c_5x5(x3)) x4 = self.inception_4c_pool(x) x4 = F.relu(self.inception_4c_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_4d_1x1(x)) x2 = F.relu(self.inception_4d_3x3_reduce(x)) x2 = F.relu(self.inception_4d_3x3(x2)) x3 = F.relu(self.inception_4d_5x5_reduce(x)) x3 = F.relu(self.inception_4d_5x5(x3)) x4 = self.inception_4d_pool(x) x4 = F.relu(self.inception_4d_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_4e_1x1(x)) x2 = F.relu(self.inception_4e_3x3_reduce(x)) x2 = F.relu(self.inception_4e_3x3(x2)) x3 = F.relu(self.inception_4e_5x5_reduce(x)) x3 = F.relu(self.inception_4e_5x5(x3)) x4 = self.inception_4e_pool(x) x4 = F.relu(self.inception_4e_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x = self.pool4_3x3_s2(x) x1 = F.relu(self.inception_5a_1x1(x)) x2 = F.relu(self.inception_5a_3x3_reduce(x)) x2 = F.relu(self.inception_5a_3x3(x2)) x3 = F.relu(self.inception_5a_5x5_reduce(x)) x3 = F.relu(self.inception_5a_5x5(x3)) x4 = self.inception_5a_pool(x) x4 = F.relu(self.inception_5a_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x1 = F.relu(self.inception_5b_1x1(x)) x2 = F.relu(self.inception_5b_3x3_reduce(x)) x2 = F.relu(self.inception_5b_3x3(x2)) x3 = F.relu(self.inception_5b_5x5_reduce(x)) x3 = F.relu(self.inception_5b_5x5(x3)) x4 = self.inception_5b_pool(x) x4 = F.relu(self.inception_5b_pool_proj(x4)) x = torch.cat((x1, x2, x3, x4), dim=1) x = self.pool5_7x7_s1(x) x = torch.flatten(x, 1) x = self.dropout(x) x = self.loss3_SLclassifier(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._inductor.runtime import triton_helpers 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 192 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) * 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_3(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 % 96 y1 = yindex // 96 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 96 * x2 + 864 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 512 xnumel = 25 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 % 16 y1 = yindex // 16 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 16 * x2 + 400 * y1), tmp0, xmask & ymask) @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) * 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 % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 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 % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 800 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_7(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 19968 xnumel = 9 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 % 96 y1 = yindex // 96 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 96 * x2 + 864 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 768 xnumel = 25 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 % 16 y1 = yindex // 16 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 16 * x2 + 400 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_9(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 25088 xnumel = 9 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 % 112 y1 = yindex // 112 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 112 * x2 + 1008 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_10(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 1536 xnumel = 25 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 % 24 y1 = yindex // 24 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 24 * x2 + 600 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_11(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 % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_12(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 41472 xnumel = 9 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 % 144 y1 = yindex // 144 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 144 * x2 + 1296 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_13(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 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 % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 800 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_14(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 % 160 y1 = yindex // 160 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 160 * x2 + 1440 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_15(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 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 % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 800 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_16(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 % 192 y1 = yindex // 192 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 192 * x2 + 1728 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_17(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 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 % 48 y1 = yindex // 48 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 48 * x2 + 1200 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_relu_18(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 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_max_pool2d_with_indices_19(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) x2 = xindex // 1024 % 16 x1 = xindex // 64 % 16 x0 = xindex % 64 x5 = xindex // 1024 x6 = xindex tmp0 = 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (x0 + 128 * x1 + 4096 * x5), tmp10, other= float('-inf')) tmp12 = 1 + 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (64 + x0 + 128 * x1 + 4096 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (128 + x0 + 128 * x1 + 4096 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 1 + 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (2048 + x0 + 128 * x1 + 4096 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (2112 + x0 + 128 * x1 + 4096 * x5), tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (2176 + x0 + 128 * x1 + 4096 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 2 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (4096 + x0 + 128 * x1 + 4096 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4160 + x0 + 128 * x1 + 4096 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (4224 + x0 + 128 * x1 + 4096 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_constant_pad_nd_20(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 65 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 % 256 y1 = yindex // 256 tmp0 = -1 + x2 tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.load(in_ptr0 + (-1 + x2 + 64 * y3), tmp2 & xmask, eviction_policy='evict_last', other=0.0) tmp4 = tmp3 * tmp3 tmp5 = tl.full(tmp4.shape, 0.0, tmp4.dtype) tmp6 = tl.where(tmp2, tmp4, tmp5) tl.store(out_ptr0 + (y0 + 256 * x2 + 16640 * y1), tmp6, xmask) @triton.jit def triton_poi_fused_avg_pool3d_21(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 % 16384 x1 = xindex // 16384 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16640 * x1), None) tmp1 = tl.load(in_ptr0 + (256 + x0 + 16640 * x1), None) tmp2 = tmp1 + tmp0 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_add_div_mul_pow_22(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 64 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 % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 64 * y3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + (y0 + 256 * x2 + 16384 * y1), xmask, eviction_policy='evict_last') tmp2 = 1.99999994948e-05 tmp3 = tmp1 * tmp2 tmp4 = 1.0 tmp5 = tmp3 + tmp4 tmp6 = 0.75 tmp7 = libdevice.pow(tmp5, tmp6) tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + (x2 + 64 * y3), tmp8, xmask) @triton.jit def triton_poi_fused_convolution_relu_23(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 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_24(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 % 192 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_constant_pad_nd_25(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 193 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 % 256 y1 = yindex // 256 tmp0 = -1 + x2 tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.load(in_ptr0 + (-1 + x2 + 192 * y3), tmp2 & xmask, eviction_policy='evict_last', other=0.0) tmp4 = tl.full([1, 1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = tmp5 * tmp5 tmp7 = tl.full(tmp6.shape, 0.0, tmp6.dtype) tmp8 = tl.where(tmp2, tmp6, tmp7) tl.store(out_ptr0 + (y0 + 256 * x2 + 49408 * y1), tmp8, xmask) @triton.jit def triton_poi_fused_avg_pool3d_26(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 % 49152 x1 = xindex // 49152 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 49408 * x1), None) tmp1 = tl.load(in_ptr0 + (256 + x0 + 49408 * x1), None) tmp2 = tmp1 + tmp0 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_add_div_mul_pow_relu_27(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 192 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 % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 192 * y3), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr1 + (y0 + 256 * x2 + 49152 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.full([1, 1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = 1.99999994948e-05 tmp5 = tmp3 * tmp4 tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = 0.75 tmp9 = libdevice.pow(tmp7, tmp8) tmp10 = tmp2 / tmp9 tl.store(out_ptr0 + (x2 + 192 * y3), tmp10, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_28(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) x2 = xindex // 1536 % 8 x1 = xindex // 192 % 8 x0 = xindex % 192 x5 = xindex // 1536 x6 = xindex tmp0 = 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 16, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (x0 + 384 * x1 + 6144 * x5), tmp10, other= float('-inf')) tmp12 = 1 + 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (192 + x0 + 384 * x1 + 6144 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (384 + x0 + 384 * x1 + 6144 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 1 + 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (3072 + x0 + 384 * x1 + 6144 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (3264 + x0 + 384 * x1 + 6144 * x5), tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (3456 + x0 + 384 * x1 + 6144 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 2 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (6144 + x0 + 384 * x1 + 6144 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (6336 + x0 + 384 * x1 + 6144 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (6528 + x0 + 384 * x1 + 6144 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_29(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 % 96 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_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) x2 = xindex x0 = xindex % 16 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_max_pool2d_with_indices_31(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) x2 = xindex // 1536 % 8 x1 = xindex // 192 % 8 x6 = xindex tmp0 = -1 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-1728 + x6), tmp10, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-1536 + x6), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-1344 + x6), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-192 + x6), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (192 + x6), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (1344 + x6), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (1536 + x6), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (1728 + x6), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_cat_32(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 256 x1 = xindex // 256 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (64 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 192, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (128 * x1 + (-64 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-64 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 224, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (32 * x1 + (-192 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-192 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 256, tl.int64) tmp35 = tl.load(in_ptr6 + (32 * x1 + (-224 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-224 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_convolution_relu_33(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 % 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) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_34(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 % 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) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_35(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) x2 = xindex // 2048 % 8 x1 = xindex // 256 % 8 x6 = xindex tmp0 = -1 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-2304 + x6), tmp10, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-2048 + x6), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-1792 + x6), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-256 + x6), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (256 + x6), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (1792 + x6), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (2048 + x6), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (2304 + x6), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_cat_36(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 480 x1 = xindex // 480 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (128 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 320, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (192 * x1 + (-128 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-128 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 416, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (96 * x1 + (-320 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-320 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 480, tl.int64) tmp35 = tl.load(in_ptr6 + (64 * x1 + (-416 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-416 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_37(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) x2 = xindex // 1920 % 4 x1 = xindex // 480 % 4 x0 = xindex % 480 x5 = xindex // 1920 x6 = xindex tmp0 = 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (x0 + 960 * x1 + 7680 * x5), tmp10, other= float('-inf')) tmp12 = 1 + 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (480 + x0 + 960 * x1 + 7680 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (960 + x0 + 960 * x1 + 7680 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 1 + 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (3840 + x0 + 960 * x1 + 7680 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (4320 + x0 + 960 * x1 + 7680 * x5), tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (4800 + x0 + 960 * x1 + 7680 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 2 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (7680 + x0 + 960 * x1 + 7680 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (8160 + x0 + 960 * x1 + 7680 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (8640 + x0 + 960 * x1 + 7680 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_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) x2 = xindex x0 = xindex % 96 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_39(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 % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_40(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) x2 = xindex // 1920 % 4 x1 = xindex // 480 % 4 x6 = xindex tmp0 = -1 + x2 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 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-2400 + x6), tmp10, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-1920 + x6), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-1440 + x6), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-480 + x6), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (480 + x6), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (1440 + x6), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (1920 + x6), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (2400 + x6), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_cat_41(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 512 x1 = xindex // 512 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 192, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (192 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 400, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (208 * x1 + (-192 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-192 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 448, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (48 * x1 + (-400 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-400 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 512, tl.int64) tmp35 = tl.load(in_ptr6 + (64 * x1 + (-448 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-448 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_convolution_relu_42(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 7168 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 112 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_43(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1536 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 24 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_44(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) x2 = xindex // 2048 % 4 x1 = xindex // 512 % 4 x6 = xindex tmp0 = -1 + x2 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 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-2560 + x6), tmp10, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-2048 + x6), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-1536 + x6), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-512 + x6), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (512 + x6), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (1536 + x6), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (2048 + x6), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (2560 + x6), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_cat_45(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 512 x1 = xindex // 512 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 160, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (160 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 384, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (224 * x1 + (-160 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-160 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 448, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (64 * x1 + (-384 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-384 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 512, tl.int64) tmp35 = tl.load(in_ptr6 + (64 * x1 + (-448 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-448 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_convolution_relu_46(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 % 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) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_cat_47(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 512 x1 = xindex // 512 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (128 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 384, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (256 * x1 + (-128 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-128 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 448, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (64 * x1 + (-384 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-384 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 512, tl.int64) tmp35 = tl.load(in_ptr6 + (64 * x1 + (-448 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-448 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_convolution_relu_48(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 9216 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 144 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_49(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 % 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) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_cat_50(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 33792 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 528 x1 = xindex // 528 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 112, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (112 * 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 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 400, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (288 * x1 + (-112 + x0)), tmp15 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-112 + x0), tmp15 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 464, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (64 * x1 + (-400 + x0)), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-400 + x0), tmp25 & xmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 528, tl.int64) tmp35 = tl.load(in_ptr6 + (64 * x1 + (-464 + x0)), tmp32 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-464 + x0), tmp32 & xmask, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, xmask) @triton.jit def triton_poi_fused_convolution_relu_51(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 % 160 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_max_pool2d_with_indices_52(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 33792 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 2112 % 4 x1 = xindex // 528 % 4 x6 = xindex tmp0 = -1 + x2 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 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-2640 + x6), tmp10 & xmask, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-2112 + x6), tmp16 & xmask, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-1584 + x6), tmp23 & xmask, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-528 + x6), tmp30 & xmask, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33 & xmask, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (528 + x6), tmp36 & xmask, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (1584 + x6), tmp43 & xmask, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (2112 + x6), tmp46 & xmask, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (2640 + x6), tmp49 & xmask, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, xmask) tl.store(out_ptr1 + x6, tmp76, xmask) @triton.jit def triton_poi_fused_cat_53(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 832 x1 = xindex // 832 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (256 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 576, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (320 * x1 + (-256 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-256 + x0), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 704, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (128 * x1 + (-576 + x0)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-576 + x0), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 832, tl.int64) tmp35 = tl.load(in_ptr6 + (128 * x1 + (-704 + x0)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-704 + x0), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_54(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 13312 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 1664 % 2 x1 = xindex // 832 % 2 x0 = xindex % 832 x5 = xindex // 1664 x6 = xindex tmp0 = 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (x0 + 1664 * x1 + 6656 * x5), tmp10 & xmask, other=float('-inf')) tmp12 = 1 + 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (832 + x0 + 1664 * x1 + 6656 * x5), tmp16 & xmask, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (1664 + x0 + 1664 * x1 + 6656 * x5), tmp23 & xmask, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 1 + 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (3328 + x0 + 1664 * x1 + 6656 * x5), tmp30 & xmask, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (4160 + x0 + 1664 * x1 + 6656 * x5), tmp33 & xmask, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (4992 + x0 + 1664 * x1 + 6656 * x5), tmp36 & xmask, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 2 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (6656 + x0 + 1664 * x1 + 6656 * x5), tmp43 & xmask, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (7488 + x0 + 1664 * x1 + 6656 * x5), tmp46 & xmask, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (8320 + x0 + 1664 * x1 + 6656 * x5), tmp49 & xmask, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, xmask) tl.store(out_ptr1 + x6, tmp76, xmask) @triton.jit def triton_poi_fused_convolution_relu_55(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2560 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 160 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_56(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_57(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 13312 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 1664 % 2 x1 = xindex // 832 % 2 x6 = xindex tmp0 = -1 + x2 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 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-2496 + x6), tmp10 & xmask, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-1664 + x6), tmp16 & xmask, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-832 + x6), tmp23 & xmask, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-832 + x6), tmp30 & xmask, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33 & xmask, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (832 + x6), tmp36 & xmask, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (832 + x6), tmp43 & xmask, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (1664 + x6), tmp46 & xmask, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (2496 + x6), tmp49 & xmask, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, xmask) tl.store(out_ptr1 + x6, tmp76, xmask) @triton.jit def triton_poi_fused_cat_58(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 13312 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 832 x1 = xindex // 832 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (256 * 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 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 576, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (320 * x1 + (-256 + x0)), tmp15 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-256 + x0), tmp15 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 704, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (128 * x1 + (-576 + x0)), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-576 + x0), tmp25 & xmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 832, tl.int64) tmp35 = tl.load(in_ptr6 + (128 * x1 + (-704 + x0)), tmp32 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-704 + x0), tmp32 & xmask, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x2, tmp43, xmask) @triton.jit def triton_poi_fused_convolution_relu_59(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 192 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_60(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 768 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 48 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_cat_61(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 // 4 % 1024 x0 = xindex % 4 x2 = xindex // 4096 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 384, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (384 * x0 + 1536 * x2 + x1), tmp4, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x1, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 768, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr2 + (384 * x0 + 1536 * x2 + (-384 + x1)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr3 + (-384 + x1), tmp15, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp8, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp15, tmp19, tmp20) tmp22 = tmp0 >= tmp13 tmp23 = tl.full([1], 896, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr4 + (128 * x0 + 512 * x2 + (-768 + x1)), tmp25, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr5 + (-768 + x1), tmp25, eviction_policy= 'evict_last', other=0.0) tmp28 = tmp26 + tmp27 tmp29 = triton_helpers.maximum(tmp8, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp25, tmp29, tmp30) tmp32 = tmp0 >= tmp23 tl.full([1], 1024, tl.int64) tmp35 = tl.load(in_ptr6 + (128 * x0 + 512 * x2 + (-896 + x1)), tmp32, eviction_policy='evict_last', other=0.0) tmp36 = tl.load(in_ptr7 + (-896 + x1), tmp32, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = triton_helpers.maximum(tmp8, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp25, tmp31, tmp40) tmp42 = tl.where(tmp15, tmp21, tmp41) tmp43 = tl.where(tmp4, tmp11, tmp42) tl.store(out_ptr0 + x3, tmp43, None) @triton.jit def triton_poi_fused_mean_62(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 tmp0 = tl.load(in_ptr0 + 4 * x0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tl.store(out_ptr0 + x0, tmp8, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_63(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 % 128 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_64(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 % 384 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_65(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 5120 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 320 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_66(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 % 256 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_67(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 % 128 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_68(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_69(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 % 256 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_70(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 % 64 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_71(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 % 288 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_72(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 7168 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 112 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_73(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 % 224 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_74(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 % 160 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_75(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 48 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_76(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 13312 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 208 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_77(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 % 192 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_78(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 % 64 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_79(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 % 96 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_80(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 % 192 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_81(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 % 128 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_82(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 % 32 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, 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) = args args.clear() assert_size_stride(primals_1, (64, 3, 7, 7), (147, 49, 7, 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, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (192, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (192,), (1,)) assert_size_stride(primals_8, (64, 192, 1, 1), (192, 1, 1, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (96, 192, 1, 1), (192, 1, 1, 1)) assert_size_stride(primals_11, (96,), (1,)) assert_size_stride(primals_12, (128, 96, 3, 3), (864, 9, 3, 1)) assert_size_stride(primals_13, (128,), (1,)) assert_size_stride(primals_14, (16, 192, 1, 1), (192, 1, 1, 1)) assert_size_stride(primals_15, (16,), (1,)) assert_size_stride(primals_16, (32, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_17, (32,), (1,)) assert_size_stride(primals_18, (32, 192, 1, 1), (192, 1, 1, 1)) assert_size_stride(primals_19, (32,), (1,)) assert_size_stride(primals_20, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_21, (128,), (1,)) assert_size_stride(primals_22, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_23, (128,), (1,)) assert_size_stride(primals_24, (192, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_25, (192,), (1,)) assert_size_stride(primals_26, (32, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_27, (32,), (1,)) assert_size_stride(primals_28, (96, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_29, (96,), (1,)) assert_size_stride(primals_30, (64, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_31, (64,), (1,)) assert_size_stride(primals_32, (192, 480, 1, 1), (480, 1, 1, 1)) assert_size_stride(primals_33, (192,), (1,)) assert_size_stride(primals_34, (96, 480, 1, 1), (480, 1, 1, 1)) assert_size_stride(primals_35, (96,), (1,)) assert_size_stride(primals_36, (208, 96, 3, 3), (864, 9, 3, 1)) assert_size_stride(primals_37, (208,), (1,)) assert_size_stride(primals_38, (16, 480, 1, 1), (480, 1, 1, 1)) assert_size_stride(primals_39, (16,), (1,)) assert_size_stride(primals_40, (48, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_41, (48,), (1,)) assert_size_stride(primals_42, (64, 480, 1, 1), (480, 1, 1, 1)) assert_size_stride(primals_43, (64,), (1,)) assert_size_stride(primals_44, (160, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_45, (160,), (1,)) assert_size_stride(primals_46, (112, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_47, (112,), (1,)) assert_size_stride(primals_48, (224, 112, 3, 3), (1008, 9, 3, 1)) assert_size_stride(primals_49, (224,), (1,)) assert_size_stride(primals_50, (24, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_51, (24,), (1,)) assert_size_stride(primals_52, (64, 24, 5, 5), (600, 25, 5, 1)) assert_size_stride(primals_53, (64,), (1,)) assert_size_stride(primals_54, (64, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_55, (64,), (1,)) assert_size_stride(primals_56, (128, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_57, (128,), (1,)) assert_size_stride(primals_58, (128, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_59, (128,), (1,)) assert_size_stride(primals_60, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_61, (256,), (1,)) assert_size_stride(primals_62, (24, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_63, (24,), (1,)) assert_size_stride(primals_64, (64, 24, 5, 5), (600, 25, 5, 1)) assert_size_stride(primals_65, (64,), (1,)) assert_size_stride(primals_66, (64, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_67, (64,), (1,)) assert_size_stride(primals_68, (112, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_69, (112,), (1,)) assert_size_stride(primals_70, (144, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_71, (144,), (1,)) assert_size_stride(primals_72, (288, 144, 3, 3), (1296, 9, 3, 1)) assert_size_stride(primals_73, (288,), (1,)) assert_size_stride(primals_74, (32, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_75, (32,), (1,)) assert_size_stride(primals_76, (64, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_77, (64,), (1,)) assert_size_stride(primals_78, (64, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_79, (64,), (1,)) assert_size_stride(primals_80, (256, 528, 1, 1), (528, 1, 1, 1)) assert_size_stride(primals_81, (256,), (1,)) assert_size_stride(primals_82, (160, 528, 1, 1), (528, 1, 1, 1)) assert_size_stride(primals_83, (160,), (1,)) assert_size_stride(primals_84, (320, 160, 3, 3), (1440, 9, 3, 1)) assert_size_stride(primals_85, (320,), (1,)) assert_size_stride(primals_86, (32, 528, 1, 1), (528, 1, 1, 1)) assert_size_stride(primals_87, (32,), (1,)) assert_size_stride(primals_88, (128, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_89, (128,), (1,)) assert_size_stride(primals_90, (128, 528, 1, 1), (528, 1, 1, 1)) assert_size_stride(primals_91, (128,), (1,)) assert_size_stride(primals_92, (256, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_93, (256,), (1,)) assert_size_stride(primals_94, (160, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_95, (160,), (1,)) assert_size_stride(primals_96, (320, 160, 3, 3), (1440, 9, 3, 1)) assert_size_stride(primals_97, (320,), (1,)) assert_size_stride(primals_98, (32, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_99, (32,), (1,)) assert_size_stride(primals_100, (128, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_101, (128,), (1,)) assert_size_stride(primals_102, (128, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_103, (128,), (1,)) assert_size_stride(primals_104, (384, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_105, (384,), (1,)) assert_size_stride(primals_106, (192, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_107, (192,), (1,)) assert_size_stride(primals_108, (384, 192, 3, 3), (1728, 9, 3, 1)) assert_size_stride(primals_109, (384,), (1,)) assert_size_stride(primals_110, (48, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_111, (48,), (1,)) assert_size_stride(primals_112, (128, 48, 5, 5), (1200, 25, 5, 1)) assert_size_stride(primals_113, (128,), (1,)) assert_size_stride(primals_114, (128, 832, 1, 1), (832, 1, 1, 1)) assert_size_stride(primals_115, (128,), (1,)) assert_size_stride(primals_116, (61, 1024), (1024, 1)) assert_size_stride(primals_117, (61,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 3, 7, 7), (147, 1, 21, 3), torch.float32 ) get_raw_stream(0) triton_poi_fused_0[grid(192, 49)](primals_1, buf0, 192, 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_3, buf1, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((192, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_2[grid(12288, 9)](primals_6, buf2, 12288, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf3 = empty_strided_cuda((128, 96, 3, 3), (864, 1, 288, 96), torch .float32) triton_poi_fused_3[grid(12288, 9)](primals_12, buf3, 12288, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf4 = empty_strided_cuda((32, 16, 5, 5), (400, 1, 80, 16), torch. float32) triton_poi_fused_4[grid(512, 25)](primals_16, buf4, 512, 25, XBLOCK =32, YBLOCK=32, num_warps=4, num_stages=1) del primals_16 buf5 = empty_strided_cuda((192, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_5[grid(24576, 9)](primals_24, buf5, 24576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_24 buf6 = empty_strided_cuda((96, 32, 5, 5), (800, 1, 160, 32), torch. float32) triton_poi_fused_6[grid(3072, 25)](primals_28, buf6, 3072, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_28 buf7 = empty_strided_cuda((208, 96, 3, 3), (864, 1, 288, 96), torch .float32) triton_poi_fused_7[grid(19968, 9)](primals_36, buf7, 19968, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_36 buf8 = empty_strided_cuda((48, 16, 5, 5), (400, 1, 80, 16), torch. float32) triton_poi_fused_8[grid(768, 25)](primals_40, buf8, 768, 25, XBLOCK =32, YBLOCK=32, num_warps=4, num_stages=1) del primals_40 buf9 = empty_strided_cuda((224, 112, 3, 3), (1008, 1, 336, 112), torch.float32) triton_poi_fused_9[grid(25088, 9)](primals_48, buf9, 25088, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_48 buf10 = empty_strided_cuda((64, 24, 5, 5), (600, 1, 120, 24), torch .float32) triton_poi_fused_10[grid(1536, 25)](primals_52, buf10, 1536, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_52 buf11 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_11[grid(32768, 9)](primals_60, buf11, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_60 buf12 = empty_strided_cuda((64, 24, 5, 5), (600, 1, 120, 24), torch .float32) triton_poi_fused_10[grid(1536, 25)](primals_64, buf12, 1536, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_64 buf13 = empty_strided_cuda((288, 144, 3, 3), (1296, 1, 432, 144), torch.float32) triton_poi_fused_12[grid(41472, 9)](primals_72, buf13, 41472, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_72 buf14 = empty_strided_cuda((64, 32, 5, 5), (800, 1, 160, 32), torch .float32) triton_poi_fused_13[grid(2048, 25)](primals_76, buf14, 2048, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_76 buf15 = empty_strided_cuda((320, 160, 3, 3), (1440, 1, 480, 160), torch.float32) triton_poi_fused_14[grid(51200, 9)](primals_84, buf15, 51200, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_84 buf16 = empty_strided_cuda((128, 32, 5, 5), (800, 1, 160, 32), torch.float32) triton_poi_fused_15[grid(4096, 25)](primals_88, buf16, 4096, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_88 buf17 = empty_strided_cuda((320, 160, 3, 3), (1440, 1, 480, 160), torch.float32) triton_poi_fused_14[grid(51200, 9)](primals_96, buf17, 51200, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_96 buf18 = empty_strided_cuda((128, 32, 5, 5), (800, 1, 160, 32), torch.float32) triton_poi_fused_15[grid(4096, 25)](primals_100, buf18, 4096, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_100 buf19 = empty_strided_cuda((384, 192, 3, 3), (1728, 1, 576, 192), torch.float32) triton_poi_fused_16[grid(73728, 9)](primals_108, buf19, 73728, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_108 buf20 = empty_strided_cuda((128, 48, 5, 5), (1200, 1, 240, 48), torch.float32) triton_poi_fused_17[grid(6144, 25)](primals_112, buf20, 6144, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_112 buf21 = extern_kernels.convolution(buf1, buf0, stride=(2, 2), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf21, (4, 64, 32, 32), (65536, 1, 2048, 64)) buf22 = buf21 del buf21 triton_poi_fused_convolution_relu_18[grid(262144)](buf22, primals_2, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf23 = empty_strided_cuda((4, 64, 16, 16), (16384, 1, 1024, 64), torch.float32) buf24 = empty_strided_cuda((4, 64, 16, 16), (16384, 1, 1024, 64), torch.int8) triton_poi_fused_max_pool2d_with_indices_19[grid(65536)](buf22, buf23, buf24, 65536, XBLOCK=256, num_warps=4, num_stages=1) buf25 = empty_strided_cuda((4, 1, 65, 16, 16), (16640, 16640, 256, 16, 1), torch.float32) triton_poi_fused_constant_pad_nd_20[grid(1024, 65)](buf23, buf25, 1024, 65, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf26 = empty_strided_cuda((4, 1, 64, 16, 16), (16384, 16384, 256, 16, 1), torch.float32) triton_poi_fused_avg_pool3d_21[grid(65536)](buf25, buf26, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf27 = empty_strided_cuda((4, 64, 16, 16), (16384, 1, 1024, 64), torch.float32) triton_poi_fused_add_div_mul_pow_22[grid(1024, 64)](buf23, buf26, buf27, 1024, 64, XBLOCK=64, YBLOCK=8, num_warps=4, num_stages=1) buf28 = extern_kernels.convolution(buf27, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_23[grid(65536)](buf29, primals_5, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf30 = extern_kernels.convolution(buf29, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 192, 16, 16), (49152, 1, 3072, 192)) buf31 = buf30 del buf30 triton_poi_fused_convolution_24[grid(196608)](buf31, primals_7, 196608, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf32 = empty_strided_cuda((4, 1, 193, 16, 16), (49408, 49408, 256, 16, 1), torch.float32) triton_poi_fused_constant_pad_nd_25[grid(1024, 193)](buf31, buf32, 1024, 193, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf33 = empty_strided_cuda((4, 1, 192, 16, 16), (49152, 49152, 256, 16, 1), torch.float32) triton_poi_fused_avg_pool3d_26[grid(196608)](buf32, buf33, 196608, XBLOCK=1024, num_warps=4, num_stages=1) buf34 = empty_strided_cuda((4, 192, 16, 16), (49152, 1, 3072, 192), torch.float32) triton_poi_fused_add_div_mul_pow_relu_27[grid(1024, 192)](buf31, buf33, buf34, 1024, 192, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf35 = empty_strided_cuda((4, 192, 8, 8), (12288, 1, 1536, 192), torch.float32) buf36 = empty_strided_cuda((4, 192, 8, 8), (12288, 1, 1536, 192), torch.int8) triton_poi_fused_max_pool2d_with_indices_28[grid(49152)](buf34, buf35, buf36, 49152, XBLOCK=256, num_warps=4, num_stages=1) buf37 = extern_kernels.convolution(buf35, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf37, (4, 64, 8, 8), (4096, 1, 512, 64)) buf38 = extern_kernels.convolution(buf35, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 96, 8, 8), (6144, 1, 768, 96)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_29[grid(24576)](buf39, primals_11, 24576, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf40 = extern_kernels.convolution(buf39, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf40, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf41 = extern_kernels.convolution(buf35, primals_14, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf41, (4, 16, 8, 8), (1024, 1, 128, 16)) buf42 = buf41 del buf41 triton_poi_fused_convolution_relu_30[grid(4096)](buf42, primals_15, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_15 buf43 = extern_kernels.convolution(buf42, buf4, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf43, (4, 32, 8, 8), (2048, 1, 256, 32)) buf44 = empty_strided_cuda((4, 192, 8, 8), (12288, 1, 1536, 192), torch.float32) buf45 = empty_strided_cuda((4, 192, 8, 8), (12288, 1, 1536, 192), torch.int8) triton_poi_fused_max_pool2d_with_indices_31[grid(49152)](buf35, buf44, buf45, 49152, XBLOCK=256, num_warps=4, num_stages=1) buf46 = extern_kernels.convolution(buf44, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 32, 8, 8), (2048, 1, 256, 32)) buf47 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.float32) triton_poi_fused_cat_32[grid(65536)](buf37, primals_9, buf40, primals_13, buf43, primals_17, buf46, primals_19, buf47, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf48 = extern_kernels.convolution(buf47, primals_20, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf49 = extern_kernels.convolution(buf47, primals_22, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf49, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf50 = buf49 del buf49 triton_poi_fused_convolution_relu_33[grid(32768)](buf50, primals_23, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_23 buf51 = extern_kernels.convolution(buf50, buf5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf51, (4, 192, 8, 8), (12288, 1, 1536, 192)) buf52 = extern_kernels.convolution(buf47, primals_26, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf52, (4, 32, 8, 8), (2048, 1, 256, 32)) buf53 = buf52 del buf52 triton_poi_fused_convolution_relu_34[grid(8192)](buf53, primals_27, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_27 buf54 = extern_kernels.convolution(buf53, buf6, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 96, 8, 8), (6144, 1, 768, 96)) buf55 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.float32) buf56 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.int8) triton_poi_fused_max_pool2d_with_indices_35[grid(65536)](buf47, buf55, buf56, 65536, XBLOCK=256, num_warps=4, num_stages=1) buf57 = extern_kernels.convolution(buf55, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf57, (4, 64, 8, 8), (4096, 1, 512, 64)) buf58 = empty_strided_cuda((4, 480, 8, 8), (30720, 1, 3840, 480), torch.float32) triton_poi_fused_cat_36[grid(122880)](buf48, primals_21, buf51, primals_25, buf54, primals_29, buf57, primals_31, buf58, 122880, XBLOCK=512, num_warps=8, num_stages=1) buf59 = empty_strided_cuda((4, 480, 4, 4), (7680, 1, 1920, 480), torch.float32) buf60 = empty_strided_cuda((4, 480, 4, 4), (7680, 1, 1920, 480), torch.int8) triton_poi_fused_max_pool2d_with_indices_37[grid(30720)](buf58, buf59, buf60, 30720, XBLOCK=256, num_warps=4, num_stages=1) buf61 = extern_kernels.convolution(buf59, primals_32, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 192, 4, 4), (3072, 1, 768, 192)) buf62 = extern_kernels.convolution(buf59, primals_34, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 96, 4, 4), (1536, 1, 384, 96)) buf63 = buf62 del buf62 triton_poi_fused_convolution_relu_38[grid(6144)](buf63, primals_35, 6144, XBLOCK=256, num_warps=4, num_stages=1) del primals_35 buf64 = extern_kernels.convolution(buf63, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 208, 4, 4), (3328, 1, 832, 208)) buf65 = extern_kernels.convolution(buf59, primals_38, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf65, (4, 16, 4, 4), (256, 1, 64, 16)) buf66 = buf65 del buf65 triton_poi_fused_convolution_relu_39[grid(1024)](buf66, primals_39, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_39 buf67 = extern_kernels.convolution(buf66, buf8, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf67, (4, 48, 4, 4), (768, 1, 192, 48)) buf68 = empty_strided_cuda((4, 480, 4, 4), (7680, 1, 1920, 480), torch.float32) buf69 = empty_strided_cuda((4, 480, 4, 4), (7680, 1, 1920, 480), torch.int8) triton_poi_fused_max_pool2d_with_indices_40[grid(30720)](buf59, buf68, buf69, 30720, XBLOCK=256, num_warps=4, num_stages=1) buf70 = extern_kernels.convolution(buf68, primals_42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 64, 4, 4), (1024, 1, 256, 64)) buf71 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) triton_poi_fused_cat_41[grid(32768)](buf61, primals_33, buf64, primals_37, buf67, primals_41, buf70, primals_43, buf71, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf72 = extern_kernels.convolution(buf71, primals_44, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf72, (4, 160, 4, 4), (2560, 1, 640, 160)) buf73 = extern_kernels.convolution(buf71, primals_46, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf73, (4, 112, 4, 4), (1792, 1, 448, 112)) buf74 = buf73 del buf73 triton_poi_fused_convolution_relu_42[grid(7168)](buf74, primals_47, 7168, XBLOCK=256, num_warps=4, num_stages=1) del primals_47 buf75 = extern_kernels.convolution(buf74, buf9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf75, (4, 224, 4, 4), (3584, 1, 896, 224)) buf76 = extern_kernels.convolution(buf71, primals_50, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf76, (4, 24, 4, 4), (384, 1, 96, 24)) buf77 = buf76 del buf76 triton_poi_fused_convolution_relu_43[grid(1536)](buf77, primals_51, 1536, XBLOCK=256, num_warps=4, num_stages=1) del primals_51 buf78 = extern_kernels.convolution(buf77, buf10, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf78, (4, 64, 4, 4), (1024, 1, 256, 64)) buf79 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) buf80 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.int8) triton_poi_fused_max_pool2d_with_indices_44[grid(32768)](buf71, buf79, buf80, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf81 = extern_kernels.convolution(buf79, primals_54, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf81, (4, 64, 4, 4), (1024, 1, 256, 64)) buf82 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) triton_poi_fused_cat_45[grid(32768)](buf72, primals_45, buf75, primals_49, buf78, primals_53, buf81, primals_55, buf82, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf83 = extern_kernels.convolution(buf82, primals_56, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf83, (4, 128, 4, 4), (2048, 1, 512, 128)) buf84 = extern_kernels.convolution(buf82, primals_58, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf84, (4, 128, 4, 4), (2048, 1, 512, 128)) buf85 = buf84 del buf84 triton_poi_fused_convolution_relu_46[grid(8192)](buf85, primals_59, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_59 buf86 = extern_kernels.convolution(buf85, buf11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf86, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf87 = extern_kernels.convolution(buf82, primals_62, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf87, (4, 24, 4, 4), (384, 1, 96, 24)) buf88 = buf87 del buf87 triton_poi_fused_convolution_relu_43[grid(1536)](buf88, primals_63, 1536, XBLOCK=256, num_warps=4, num_stages=1) del primals_63 buf89 = extern_kernels.convolution(buf88, buf12, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf89, (4, 64, 4, 4), (1024, 1, 256, 64)) buf90 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) buf91 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.int8) triton_poi_fused_max_pool2d_with_indices_44[grid(32768)](buf82, buf90, buf91, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf92 = extern_kernels.convolution(buf90, primals_66, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf92, (4, 64, 4, 4), (1024, 1, 256, 64)) buf93 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) triton_poi_fused_cat_47[grid(32768)](buf83, primals_57, buf86, primals_61, buf89, primals_65, buf92, primals_67, buf93, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf94 = extern_kernels.convolution(buf93, primals_68, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf94, (4, 112, 4, 4), (1792, 1, 448, 112)) buf95 = extern_kernels.convolution(buf93, primals_70, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf95, (4, 144, 4, 4), (2304, 1, 576, 144)) buf96 = buf95 del buf95 triton_poi_fused_convolution_relu_48[grid(9216)](buf96, primals_71, 9216, XBLOCK=256, num_warps=4, num_stages=1) del primals_71 buf97 = extern_kernels.convolution(buf96, buf13, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf97, (4, 288, 4, 4), (4608, 1, 1152, 288)) buf98 = extern_kernels.convolution(buf93, primals_74, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf98, (4, 32, 4, 4), (512, 1, 128, 32)) buf99 = buf98 del buf98 triton_poi_fused_convolution_relu_49[grid(2048)](buf99, primals_75, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_75 buf100 = extern_kernels.convolution(buf99, buf14, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf100, (4, 64, 4, 4), (1024, 1, 256, 64)) buf101 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.float32) buf102 = empty_strided_cuda((4, 512, 4, 4), (8192, 1, 2048, 512), torch.int8) triton_poi_fused_max_pool2d_with_indices_44[grid(32768)](buf93, buf101, buf102, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf103 = extern_kernels.convolution(buf101, primals_78, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf103, (4, 64, 4, 4), (1024, 1, 256, 64)) buf104 = empty_strided_cuda((4, 528, 4, 4), (8448, 1, 2112, 528), torch.float32) triton_poi_fused_cat_50[grid(33792)](buf94, primals_69, buf97, primals_73, buf100, primals_77, buf103, primals_79, buf104, 33792, XBLOCK=512, num_warps=4, num_stages=1) buf105 = extern_kernels.convolution(buf104, primals_80, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf105, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf106 = extern_kernels.convolution(buf104, primals_82, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf106, (4, 160, 4, 4), (2560, 1, 640, 160)) buf107 = buf106 del buf106 triton_poi_fused_convolution_relu_51[grid(10240)](buf107, primals_83, 10240, XBLOCK=256, num_warps=4, num_stages=1) del primals_83 buf108 = extern_kernels.convolution(buf107, buf15, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf108, (4, 320, 4, 4), (5120, 1, 1280, 320)) buf109 = extern_kernels.convolution(buf104, primals_86, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf109, (4, 32, 4, 4), (512, 1, 128, 32)) buf110 = buf109 del buf109 triton_poi_fused_convolution_relu_49[grid(2048)](buf110, primals_87, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_87 buf111 = extern_kernels.convolution(buf110, buf16, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf111, (4, 128, 4, 4), (2048, 1, 512, 128)) buf112 = empty_strided_cuda((4, 528, 4, 4), (8448, 1, 2112, 528), torch.float32) buf113 = empty_strided_cuda((4, 528, 4, 4), (8448, 1, 2112, 528), torch.int8) triton_poi_fused_max_pool2d_with_indices_52[grid(33792)](buf104, buf112, buf113, 33792, XBLOCK=512, num_warps=4, num_stages=1) buf114 = extern_kernels.convolution(buf112, primals_90, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf114, (4, 128, 4, 4), (2048, 1, 512, 128)) buf115 = empty_strided_cuda((4, 832, 4, 4), (13312, 1, 3328, 832), torch.float32) triton_poi_fused_cat_53[grid(53248)](buf105, primals_81, buf108, primals_85, buf111, primals_89, buf114, primals_91, buf115, 53248, XBLOCK=256, num_warps=4, num_stages=1) buf116 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.float32) buf117 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.int8) triton_poi_fused_max_pool2d_with_indices_54[grid(13312)](buf115, buf116, buf117, 13312, XBLOCK=128, num_warps=4, num_stages=1) buf118 = extern_kernels.convolution(buf116, primals_92, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf118, (4, 256, 2, 2), (1024, 1, 512, 256)) buf119 = extern_kernels.convolution(buf116, primals_94, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf119, (4, 160, 2, 2), (640, 1, 320, 160)) buf120 = buf119 del buf119 triton_poi_fused_convolution_relu_55[grid(2560)](buf120, primals_95, 2560, XBLOCK=256, num_warps=4, num_stages=1) del primals_95 buf121 = extern_kernels.convolution(buf120, buf17, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf121, (4, 320, 2, 2), (1280, 1, 640, 320)) buf122 = extern_kernels.convolution(buf116, primals_98, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf122, (4, 32, 2, 2), (128, 1, 64, 32)) buf123 = buf122 del buf122 triton_poi_fused_convolution_relu_56[grid(512)](buf123, primals_99, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_99 buf124 = extern_kernels.convolution(buf123, buf18, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf124, (4, 128, 2, 2), (512, 1, 256, 128)) buf125 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.float32) buf126 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.int8) triton_poi_fused_max_pool2d_with_indices_57[grid(13312)](buf116, buf125, buf126, 13312, XBLOCK=128, num_warps=4, num_stages=1) buf127 = extern_kernels.convolution(buf125, primals_102, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf127, (4, 128, 2, 2), (512, 1, 256, 128)) buf128 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.float32) triton_poi_fused_cat_58[grid(13312)](buf118, primals_93, buf121, primals_97, buf124, primals_101, buf127, primals_103, buf128, 13312, XBLOCK=128, num_warps=4, num_stages=1) buf129 = extern_kernels.convolution(buf128, primals_104, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf129, (4, 384, 2, 2), (1536, 1, 768, 384)) buf130 = extern_kernels.convolution(buf128, primals_106, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf130, (4, 192, 2, 2), (768, 1, 384, 192)) buf131 = buf130 del buf130 triton_poi_fused_convolution_relu_59[grid(3072)](buf131, primals_107, 3072, XBLOCK=256, num_warps=4, num_stages=1) del primals_107 buf132 = extern_kernels.convolution(buf131, buf19, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf132, (4, 384, 2, 2), (1536, 1, 768, 384)) buf133 = extern_kernels.convolution(buf128, primals_110, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf133, (4, 48, 2, 2), (192, 1, 96, 48)) buf134 = buf133 del buf133 triton_poi_fused_convolution_relu_60[grid(768)](buf134, primals_111, 768, XBLOCK=128, num_warps=4, num_stages=1) del primals_111 buf135 = extern_kernels.convolution(buf134, buf20, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf135, (4, 128, 2, 2), (512, 1, 256, 128)) buf136 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.float32) buf137 = empty_strided_cuda((4, 832, 2, 2), (3328, 1, 1664, 832), torch.int8) triton_poi_fused_max_pool2d_with_indices_57[grid(13312)](buf128, buf136, buf137, 13312, XBLOCK=128, num_warps=4, num_stages=1) buf138 = extern_kernels.convolution(buf136, primals_114, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf138, (4, 128, 2, 2), (512, 1, 256, 128)) buf139 = empty_strided_cuda((4, 1024, 2, 2), (4096, 4, 2, 1), torch .float32) triton_poi_fused_cat_61[grid(16384)](buf129, primals_105, buf132, primals_109, buf135, primals_113, buf138, primals_115, buf139, 16384, XBLOCK=256, num_warps=4, num_stages=1) buf140 = empty_strided_cuda((4, 1024, 1, 1), (1024, 1, 4096, 4096), torch.float32) triton_poi_fused_mean_62[grid(4096)](buf139, buf140, 4096, XBLOCK= 256, num_warps=4, num_stages=1) del buf139 buf141 = empty_strided_cuda((4, 61), (61, 1), torch.float32) extern_kernels.addmm(primals_117, reinterpret_tensor(buf140, (4, 1024), (1024, 1), 0), reinterpret_tensor(primals_116, (1024, 61 ), (1, 1024), 0), alpha=1, beta=1, out=buf141) del primals_117 buf142 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_63[grid(2048)]( buf138, primals_115, buf142, 2048, XBLOCK=256, num_warps=4, num_stages=1) del buf138 del primals_115 buf143 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_63[grid(2048)]( buf135, primals_113, buf143, 2048, XBLOCK=256, num_warps=4, num_stages=1) del buf135 del primals_113 buf144 = empty_strided_cuda((4, 384, 2, 2), (1536, 1, 768, 384), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_64[grid(6144)]( buf132, primals_109, buf144, 6144, XBLOCK=256, num_warps=4, num_stages=1) del buf132 del primals_109 buf145 = empty_strided_cuda((4, 384, 2, 2), (1536, 1, 768, 384), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_64[grid(6144)]( buf129, primals_105, buf145, 6144, XBLOCK=256, num_warps=4, num_stages=1) del buf129 del primals_105 buf146 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_63[grid(2048)]( buf127, primals_103, buf146, 2048, XBLOCK=256, num_warps=4, num_stages=1) del buf127 del primals_103 buf147 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_63[grid(2048)]( buf124, primals_101, buf147, 2048, XBLOCK=256, num_warps=4, num_stages=1) del buf124 del primals_101 buf148 = empty_strided_cuda((4, 320, 2, 2), (1280, 1, 640, 320), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_65[grid(5120)]( buf121, primals_97, buf148, 5120, XBLOCK=256, num_warps=4, num_stages=1) del buf121 del primals_97 buf149 = empty_strided_cuda((4, 256, 2, 2), (1024, 1, 512, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_66[grid(4096)]( buf118, primals_93, buf149, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf118 del primals_93 buf150 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_67[grid(8192)]( buf114, primals_91, buf150, 8192, XBLOCK=128, num_warps=4, num_stages=1) del buf114 del primals_91 buf151 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_67[grid(8192)]( buf111, primals_89, buf151, 8192, XBLOCK=128, num_warps=4, num_stages=1) del buf111 del primals_89 buf152 = empty_strided_cuda((4, 320, 4, 4), (5120, 1, 1280, 320), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_68[grid(20480)]( buf108, primals_85, buf152, 20480, XBLOCK=256, num_warps=4, num_stages=1) del buf108 del primals_85 buf153 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_69[grid(16384)]( buf105, primals_81, buf153, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf105 del primals_81 buf154 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf103, primals_79, buf154, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf103 del primals_79 buf155 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf100, primals_77, buf155, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf100 del primals_77 buf156 = empty_strided_cuda((4, 288, 4, 4), (4608, 1, 1152, 288), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_71[grid(18432)]( buf97, primals_73, buf156, 18432, XBLOCK=256, num_warps=4, num_stages=1) del buf97 del primals_73 buf157 = empty_strided_cuda((4, 112, 4, 4), (1792, 1, 448, 112), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_72[grid(7168)]( buf94, primals_69, buf157, 7168, XBLOCK=256, num_warps=4, num_stages=1) del buf94 del primals_69 buf158 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf92, primals_67, buf158, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf92 del primals_67 buf159 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf89, primals_65, buf159, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf89 del primals_65 buf160 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_69[grid(16384)]( buf86, primals_61, buf160, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf86 del primals_61 buf161 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_67[grid(8192)]( buf83, primals_57, buf161, 8192, XBLOCK=128, num_warps=4, num_stages=1) del buf83 del primals_57 buf162 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf81, primals_55, buf162, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf81 del primals_55 buf163 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf78, primals_53, buf163, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf78 del primals_53 buf164 = empty_strided_cuda((4, 224, 4, 4), (3584, 1, 896, 224), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_73[grid(14336)]( buf75, primals_49, buf164, 14336, XBLOCK=256, num_warps=4, num_stages=1) del buf75 del primals_49 buf165 = empty_strided_cuda((4, 160, 4, 4), (2560, 1, 640, 160), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_74[grid(10240)]( buf72, primals_45, buf165, 10240, XBLOCK=128, num_warps=4, num_stages=1) del buf72 del primals_45 buf166 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_70[grid(4096)]( buf70, primals_43, buf166, 4096, XBLOCK=256, num_warps=4, num_stages=1) del buf70 del primals_43 buf167 = empty_strided_cuda((4, 48, 4, 4), (768, 1, 192, 48), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_75[grid(3072)]( buf67, primals_41, buf167, 3072, XBLOCK=256, num_warps=4, num_stages=1) del buf67 del primals_41 buf168 = empty_strided_cuda((4, 208, 4, 4), (3328, 1, 832, 208), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_76[grid(13312)]( buf64, primals_37, buf168, 13312, XBLOCK=256, num_warps=4, num_stages=1) del buf64 del primals_37 buf169 = empty_strided_cuda((4, 192, 4, 4), (3072, 1, 768, 192), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_77[grid(12288)]( buf61, primals_33, buf169, 12288, XBLOCK=256, num_warps=4, num_stages=1) del buf61 del primals_33 buf170 = empty_strided_cuda((4, 64, 8, 8), (4096, 1, 512, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_78[grid(16384)]( buf57, primals_31, buf170, 16384, XBLOCK=128, num_warps=4, num_stages=1) del buf57 del primals_31 buf171 = empty_strided_cuda((4, 96, 8, 8), (6144, 1, 768, 96), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_79[grid(24576)]( buf54, primals_29, buf171, 24576, XBLOCK=256, num_warps=4, num_stages=1) del buf54 del primals_29 buf172 = empty_strided_cuda((4, 192, 8, 8), (12288, 1, 1536, 192), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_80[grid(49152)]( buf51, primals_25, buf172, 49152, XBLOCK=512, num_warps=4, num_stages=1) del buf51 del primals_25 buf173 = empty_strided_cuda((4, 128, 8, 8), (8192, 1, 1024, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_81[grid(32768)]( buf48, primals_21, buf173, 32768, XBLOCK=128, num_warps=4, num_stages=1) del buf48 del primals_21 buf174 = empty_strided_cuda((4, 32, 8, 8), (2048, 1, 256, 32), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_82[grid(8192)]( buf46, primals_19, buf174, 8192, XBLOCK=256, num_warps=4, num_stages=1) del buf46 del primals_19 buf175 = empty_strided_cuda((4, 32, 8, 8), (2048, 1, 256, 32), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_82[grid(8192)]( buf43, primals_17, buf175, 8192, XBLOCK=256, num_warps=4, num_stages=1) del buf43 del primals_17 buf176 = empty_strided_cuda((4, 128, 8, 8), (8192, 1, 1024, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_81[grid(32768)]( buf40, primals_13, buf176, 32768, XBLOCK=128, num_warps=4, num_stages=1) del buf40 del primals_13 buf177 = empty_strided_cuda((4, 64, 8, 8), (4096, 1, 512, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_78[grid(16384)]( buf37, primals_9, buf177, 16384, XBLOCK=128, num_warps=4, num_stages=1) del buf37 del primals_9 return (buf141, buf0, buf1, primals_4, buf2, primals_8, primals_10, buf3, primals_14, buf4, primals_18, primals_20, primals_22, buf5, primals_26, buf6, primals_30, primals_32, primals_34, buf7, primals_38, buf8, primals_42, primals_44, primals_46, buf9, primals_50, buf10, primals_54, primals_56, primals_58, buf11, primals_62, buf12, primals_66, primals_68, primals_70, buf13, primals_74, buf14, primals_78, primals_80, primals_82, buf15, primals_86, buf16, primals_90, primals_92, primals_94, buf17, primals_98, buf18, primals_102, primals_104, primals_106, buf19, primals_110, buf20, primals_114, buf22, buf23, buf24, buf25, buf26, buf27, buf29, buf31, buf32, buf33, buf34, buf35, buf36, buf39, buf42, buf44, buf45, buf47, buf50, buf53, buf55, buf56, buf58, buf59, buf60, buf63, buf66, buf68, buf69, buf71, buf74, buf77, buf79, buf80, buf82, buf85, buf88, buf90, buf91, buf93, buf96, buf99, buf101, buf102, buf104, buf107, buf110, buf112, buf113, buf115, buf116, buf117, buf120, buf123, buf125, buf126, buf128, buf131, buf134, buf136, buf137, reinterpret_tensor(buf140, (4, 1024 ), (1024, 1), 0), primals_116, buf142, buf143, buf144, buf145, buf146, buf147, buf148, buf149, buf150, buf151, buf152, buf153, buf154, buf155, buf156, buf157, buf158, buf159, buf160, buf161, buf162, buf163, buf164, buf165, buf166, buf167, buf168, buf169, buf170, buf171, buf172, buf173, buf174, buf175, buf176, buf177) class ModelNew(nn.Module): def __init__(self): super(ModelNew, self).__init__() self.conv1_7x7_s2 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3 ) self.pool1_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.pool1_norm1 = nn.LocalResponseNorm(2, 1.99999994948e-05, 0.75) self.conv2_3x3_reduce = nn.Conv2d(64, 64, kernel_size=1, stride=1, padding=0) self.conv2_3x3 = nn.Conv2d(64, 192, kernel_size=3, stride=1, padding=1) self.conv2_norm2 = nn.LocalResponseNorm(2, 1.99999994948e-05, 0.75) self.pool2_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_3a_1x1 = nn.Conv2d(192, 64, kernel_size=1, stride=1, padding=0) self.inception_3a_3x3_reduce = nn.Conv2d(192, 96, kernel_size=1, stride=1, padding=0) self.inception_3a_3x3 = nn.Conv2d(96, 128, kernel_size=3, stride=1, padding=1) self.inception_3a_5x5_reduce = nn.Conv2d(192, 16, kernel_size=1, stride=1, padding=0) self.inception_3a_5x5 = nn.Conv2d(16, 32, kernel_size=5, stride=1, padding=2) self.inception_3a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_3a_pool_proj = nn.Conv2d(192, 32, kernel_size=1, stride=1, padding=0) self.inception_3b_1x1 = nn.Conv2d(256, 128, kernel_size=1, stride=1, padding=0) self.inception_3b_3x3_reduce = nn.Conv2d(256, 128, kernel_size=1, stride=1, padding=0) self.inception_3b_3x3 = nn.Conv2d(128, 192, kernel_size=3, stride=1, padding=1) self.inception_3b_5x5_reduce = nn.Conv2d(256, 32, kernel_size=1, stride=1, padding=0) self.inception_3b_5x5 = nn.Conv2d(32, 96, kernel_size=5, stride=1, padding=2) self.inception_3b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_3b_pool_proj = nn.Conv2d(256, 64, kernel_size=1, stride=1, padding=0) self.pool3_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_4a_1x1 = nn.Conv2d(480, 192, kernel_size=1, stride=1, padding=0) self.inception_4a_3x3_reduce = nn.Conv2d(480, 96, kernel_size=1, stride=1, padding=0) self.inception_4a_3x3 = nn.Conv2d(96, 208, kernel_size=3, stride=1, padding=1) self.inception_4a_5x5_reduce = nn.Conv2d(480, 16, kernel_size=1, stride=1, padding=0) self.inception_4a_5x5 = nn.Conv2d(16, 48, kernel_size=5, stride=1, padding=2) self.inception_4a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4a_pool_proj = nn.Conv2d(480, 64, kernel_size=1, stride=1, padding=0) self.inception_4b_1x1 = nn.Conv2d(512, 160, kernel_size=1, stride=1, padding=0) self.inception_4b_3x3_reduce = nn.Conv2d(512, 112, kernel_size=1, stride=1, padding=0) self.inception_4b_3x3 = nn.Conv2d(112, 224, kernel_size=3, stride=1, padding=1) self.inception_4b_5x5_reduce = nn.Conv2d(512, 24, kernel_size=1, stride=1, padding=0) self.inception_4b_5x5 = nn.Conv2d(24, 64, kernel_size=5, stride=1, padding=2) self.inception_4b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4b_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4c_1x1 = nn.Conv2d(512, 128, kernel_size=1, stride=1, padding=0) self.inception_4c_3x3_reduce = nn.Conv2d(512, 128, kernel_size=1, stride=1, padding=0) self.inception_4c_3x3 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) self.inception_4c_5x5_reduce = nn.Conv2d(512, 24, kernel_size=1, stride=1, padding=0) self.inception_4c_5x5 = nn.Conv2d(24, 64, kernel_size=5, stride=1, padding=2) self.inception_4c_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4c_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4d_1x1 = nn.Conv2d(512, 112, kernel_size=1, stride=1, padding=0) self.inception_4d_3x3_reduce = nn.Conv2d(512, 144, kernel_size=1, stride=1, padding=0) self.inception_4d_3x3 = nn.Conv2d(144, 288, kernel_size=3, stride=1, padding=1) self.inception_4d_5x5_reduce = nn.Conv2d(512, 32, kernel_size=1, stride=1, padding=0) self.inception_4d_5x5 = nn.Conv2d(32, 64, kernel_size=5, stride=1, padding=2) self.inception_4d_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4d_pool_proj = nn.Conv2d(512, 64, kernel_size=1, stride=1, padding=0) self.inception_4e_1x1 = nn.Conv2d(528, 256, kernel_size=1, stride=1, padding=0) self.inception_4e_3x3_reduce = nn.Conv2d(528, 160, kernel_size=1, stride=1, padding=0) self.inception_4e_3x3 = nn.Conv2d(160, 320, kernel_size=3, stride=1, padding=1) self.inception_4e_5x5_reduce = nn.Conv2d(528, 32, kernel_size=1, stride=1, padding=0) self.inception_4e_5x5 = nn.Conv2d(32, 128, kernel_size=5, stride=1, padding=2) self.inception_4e_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_4e_pool_proj = nn.Conv2d(528, 128, kernel_size=1, stride=1, padding=0) self.pool4_3x3_s2 = nn.MaxPool2d(3, stride=2, ceil_mode=True) self.inception_5a_1x1 = nn.Conv2d(832, 256, kernel_size=1, stride=1, padding=0) self.inception_5a_3x3_reduce = nn.Conv2d(832, 160, kernel_size=1, stride=1, padding=0) self.inception_5a_3x3 = nn.Conv2d(160, 320, kernel_size=3, stride=1, padding=1) self.inception_5a_5x5_reduce = nn.Conv2d(832, 32, kernel_size=1, stride=1, padding=0) self.inception_5a_5x5 = nn.Conv2d(32, 128, kernel_size=5, stride=1, padding=2) self.inception_5a_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_5a_pool_proj = nn.Conv2d(832, 128, kernel_size=1, stride=1, padding=0) self.inception_5b_1x1 = nn.Conv2d(832, 384, kernel_size=1, stride=1, padding=0) self.inception_5b_3x3_reduce = nn.Conv2d(832, 192, kernel_size=1, stride=1, padding=0) self.inception_5b_3x3 = nn.Conv2d(192, 384, kernel_size=3, stride=1, padding=1) self.inception_5b_5x5_reduce = nn.Conv2d(832, 48, kernel_size=1, stride=1, padding=0) self.inception_5b_5x5 = nn.Conv2d(48, 128, kernel_size=5, stride=1, padding=2) self.inception_5b_pool = nn.MaxPool2d(3, stride=1, padding=1, ceil_mode=True) self.inception_5b_pool_proj = nn.Conv2d(832, 128, kernel_size=1, stride=1, padding=0) self.pool5_7x7_s1 = nn.AdaptiveAvgPool2d(1) self.dropout = nn.Dropout(0.2) self.loss3_SLclassifier = nn.Linear(1024, 61) def forward(self, input_0): primals_1 = self.conv1_7x7_s2.weight primals_2 = self.conv1_7x7_s2.bias primals_4 = self.conv2_3x3_reduce.weight primals_5 = self.conv2_3x3_reduce.bias primals_6 = self.conv2_3x3.weight primals_7 = self.conv2_3x3.bias primals_8 = self.inception_3a_1x1.weight primals_9 = self.inception_3a_1x1.bias primals_10 = self.inception_3a_3x3_reduce.weight primals_11 = self.inception_3a_3x3_reduce.bias primals_12 = self.inception_3a_3x3.weight primals_13 = self.inception_3a_3x3.bias primals_14 = self.inception_3a_5x5_reduce.weight primals_15 = self.inception_3a_5x5_reduce.bias primals_16 = self.inception_3a_5x5.weight primals_17 = self.inception_3a_5x5.bias primals_18 = self.inception_3a_pool_proj.weight primals_19 = self.inception_3a_pool_proj.bias primals_20 = self.inception_3b_1x1.weight primals_21 = self.inception_3b_1x1.bias primals_22 = self.inception_3b_3x3_reduce.weight primals_23 = self.inception_3b_3x3_reduce.bias primals_24 = self.inception_3b_3x3.weight primals_25 = self.inception_3b_3x3.bias primals_26 = self.inception_3b_5x5_reduce.weight primals_27 = self.inception_3b_5x5_reduce.bias primals_28 = self.inception_3b_5x5.weight primals_29 = self.inception_3b_5x5.bias primals_30 = self.inception_3b_pool_proj.weight primals_31 = self.inception_3b_pool_proj.bias primals_32 = self.inception_4a_1x1.weight primals_33 = self.inception_4a_1x1.bias primals_34 = self.inception_4a_3x3_reduce.weight primals_35 = self.inception_4a_3x3_reduce.bias primals_36 = self.inception_4a_3x3.weight primals_37 = self.inception_4a_3x3.bias primals_38 = self.inception_4a_5x5_reduce.weight primals_39 = self.inception_4a_5x5_reduce.bias primals_40 = self.inception_4a_5x5.weight primals_41 = self.inception_4a_5x5.bias primals_42 = self.inception_4a_pool_proj.weight primals_43 = self.inception_4a_pool_proj.bias primals_44 = self.inception_4b_1x1.weight primals_45 = self.inception_4b_1x1.bias primals_46 = self.inception_4b_3x3_reduce.weight primals_47 = self.inception_4b_3x3_reduce.bias primals_48 = self.inception_4b_3x3.weight primals_49 = self.inception_4b_3x3.bias primals_50 = self.inception_4b_5x5_reduce.weight primals_51 = self.inception_4b_5x5_reduce.bias primals_52 = self.inception_4b_5x5.weight primals_53 = self.inception_4b_5x5.bias primals_54 = self.inception_4b_pool_proj.weight primals_55 = self.inception_4b_pool_proj.bias primals_56 = self.inception_4c_1x1.weight primals_57 = self.inception_4c_1x1.bias primals_58 = self.inception_4c_3x3_reduce.weight primals_59 = self.inception_4c_3x3_reduce.bias primals_60 = self.inception_4c_3x3.weight primals_61 = self.inception_4c_3x3.bias primals_62 = self.inception_4c_5x5_reduce.weight primals_63 = self.inception_4c_5x5_reduce.bias primals_64 = self.inception_4c_5x5.weight primals_65 = self.inception_4c_5x5.bias primals_66 = self.inception_4c_pool_proj.weight primals_67 = self.inception_4c_pool_proj.bias primals_68 = self.inception_4d_1x1.weight primals_69 = self.inception_4d_1x1.bias primals_70 = self.inception_4d_3x3_reduce.weight primals_71 = self.inception_4d_3x3_reduce.bias primals_72 = self.inception_4d_3x3.weight primals_73 = self.inception_4d_3x3.bias primals_74 = self.inception_4d_5x5_reduce.weight primals_75 = self.inception_4d_5x5_reduce.bias primals_76 = self.inception_4d_5x5.weight primals_77 = self.inception_4d_5x5.bias primals_78 = self.inception_4d_pool_proj.weight primals_79 = self.inception_4d_pool_proj.bias primals_80 = self.inception_4e_1x1.weight primals_81 = self.inception_4e_1x1.bias primals_82 = self.inception_4e_3x3_reduce.weight primals_83 = self.inception_4e_3x3_reduce.bias primals_84 = self.inception_4e_3x3.weight primals_85 = self.inception_4e_3x3.bias primals_86 = self.inception_4e_5x5_reduce.weight primals_87 = self.inception_4e_5x5_reduce.bias primals_88 = self.inception_4e_5x5.weight primals_89 = self.inception_4e_5x5.bias primals_90 = self.inception_4e_pool_proj.weight primals_91 = self.inception_4e_pool_proj.bias primals_92 = self.inception_5a_1x1.weight primals_93 = self.inception_5a_1x1.bias primals_94 = self.inception_5a_3x3_reduce.weight primals_95 = self.inception_5a_3x3_reduce.bias primals_96 = self.inception_5a_3x3.weight primals_97 = self.inception_5a_3x3.bias primals_98 = self.inception_5a_5x5_reduce.weight primals_99 = self.inception_5a_5x5_reduce.bias primals_100 = self.inception_5a_5x5.weight primals_101 = self.inception_5a_5x5.bias primals_102 = self.inception_5a_pool_proj.weight primals_103 = self.inception_5a_pool_proj.bias primals_104 = self.inception_5b_1x1.weight primals_105 = self.inception_5b_1x1.bias primals_106 = self.inception_5b_3x3_reduce.weight primals_107 = self.inception_5b_3x3_reduce.bias primals_108 = self.inception_5b_3x3.weight primals_109 = self.inception_5b_3x3.bias primals_110 = self.inception_5b_5x5_reduce.weight primals_111 = self.inception_5b_5x5_reduce.bias primals_112 = self.inception_5b_5x5.weight primals_113 = self.inception_5b_5x5.bias primals_114 = self.inception_5b_pool_proj.weight primals_115 = self.inception_5b_pool_proj.bias primals_116 = self.loss3_SLclassifier.weight primals_117 = self.loss3_SLclassifier.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]) return output[0]
m-decoster/DeepHand-PyTorch
Model
false
7,484
[ "MIT" ]
1
ece77e04ec261a540b011fd00584bfc6d7337dc5
https://github.com/m-decoster/DeepHand-PyTorch/tree/ece77e04ec261a540b011fd00584bfc6d7337dc5
SamePadConv3d
import torch import torch.nn as nn import torch.nn.functional as F class SamePadConv3d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, bias=True): super().__init__() if isinstance(kernel_size, int): kernel_size = (kernel_size,) * 3 if isinstance(stride, int): stride = (stride,) * 3 total_pad = tuple([(k - s) for k, s in zip(kernel_size, stride)]) pad_input = [] for p in total_pad[::-1]: pad_input.append((p // 2 + p % 2, p // 2)) pad_input = sum(pad_input, tuple()) self.pad_input = pad_input self.conv = nn.Conv3d(in_channels, out_channels, kernel_size, stride=stride, padding=0, bias=bias) def forward(self, x): return self.conv(F.pad(x, self.pad_input)) 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 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_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1372 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 49 % 7 x1 = xindex // 7 % 7 x0 = xindex % 7 x3 = xindex // 343 x7 = xindex tmp0 = -2 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -2 + x1 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = -2 + x0 tmp9 = tmp8 >= tmp1 tmp10 = tmp8 < tmp3 tmp11 = tmp2 & tmp4 tmp12 = tmp11 & tmp6 tmp13 = tmp12 & tmp7 tmp14 = tmp13 & tmp9 tmp15 = tmp14 & tmp10 tmp16 = tl.load(in_ptr0 + (-42 + x0 + 4 * x1 + 16 * x2 + 64 * x3), tmp15 & xmask, other=0.0) tl.store(out_ptr0 + x7, tmp16, 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 x2 = xindex x1 = xindex // 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 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, 4), (256, 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, 7, 7, 7), (343, 49, 7, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(1372)](primals_1, buf0, 1372, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 7, 7, 7), (0, 343, 49, 7, 1), 0), primals_2, stride=(1, 1, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf1, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_2, reinterpret_tensor(buf0, (1, 4, 7, 7, 7), (1372, 343, 49, 7, 1), 0) class SamePadConv3dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, bias=True): super().__init__() if isinstance(kernel_size, int): kernel_size = (kernel_size,) * 3 if isinstance(stride, int): stride = (stride,) * 3 total_pad = tuple([(k - s) for k, s in zip(kernel_size, stride)]) pad_input = [] for p in total_pad[::-1]: pad_input.append((p // 2 + p % 2, p // 2)) pad_input = sum(pad_input, tuple()) self.pad_input = pad_input self.conv = nn.Conv3d(in_channels, out_channels, kernel_size, stride=stride, padding=0, bias=bias) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
pointoflight/VideoGPT
SamePadConv3d
false
7,485
[ "MIT" ]
1
85f19d8cb0d251238f295f0294e69b9299c13e21
https://github.com/pointoflight/VideoGPT/tree/85f19d8cb0d251238f295f0294e69b9299c13e21
SamePadConvTranspose3d
import torch import torch.nn as nn import torch.nn.functional as F class SamePadConvTranspose3d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, bias=True): super().__init__() if isinstance(kernel_size, int): kernel_size = (kernel_size,) * 3 if isinstance(stride, int): stride = (stride,) * 3 total_pad = tuple([(k - s) for k, s in zip(kernel_size, stride)]) pad_input = [] for p in total_pad[::-1]: pad_input.append((p // 2 + p % 2, p // 2)) pad_input = sum(pad_input, tuple()) self.pad_input = pad_input self.convt = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, bias=bias, padding=tuple([(k - 1) for k in kernel_size])) def forward(self, x): return self.convt(F.pad(x, self.pad_input)) 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 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_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1372 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 49 % 7 x1 = xindex // 7 % 7 x0 = xindex % 7 x3 = xindex // 343 x7 = xindex tmp0 = -2 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -2 + x1 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = -2 + x0 tmp9 = tmp8 >= tmp1 tmp10 = tmp8 < tmp3 tmp11 = tmp2 & tmp4 tmp12 = tmp11 & tmp6 tmp13 = tmp12 & tmp7 tmp14 = tmp13 & tmp9 tmp15 = tmp14 & tmp10 tmp16 = tl.load(in_ptr0 + (-42 + x0 + 4 * x1 + 16 * x2 + 64 * x3), tmp15 & xmask, other=0.0) tl.store(out_ptr0 + x7, tmp16, 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 x2 = xindex x1 = xindex // 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 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, 4), (256, 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, 7, 7, 7), (343, 49, 7, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(1372)](primals_1, buf0, 1372, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (1, 4, 7, 7, 7), (0, 343, 49, 7, 1), 0), primals_2, stride=(1, 1, 1), padding=(3, 3, 3), dilation=(1, 1, 1), transposed=True, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf1, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_2, reinterpret_tensor(buf0, (1, 4, 7, 7, 7), (1372, 343, 49, 7, 1), 0) class SamePadConvTranspose3dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, bias=True): super().__init__() if isinstance(kernel_size, int): kernel_size = (kernel_size,) * 3 if isinstance(stride, int): stride = (stride,) * 3 total_pad = tuple([(k - s) for k, s in zip(kernel_size, stride)]) pad_input = [] for p in total_pad[::-1]: pad_input.append((p // 2 + p % 2, p // 2)) pad_input = sum(pad_input, tuple()) self.pad_input = pad_input self.convt = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, bias=bias, padding=tuple([(k - 1) for k in kernel_size])) def forward(self, input_0): primals_2 = self.convt.weight primals_3 = self.convt.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
pointoflight/VideoGPT
SamePadConvTranspose3d
false
7,486
[ "MIT" ]
1
85f19d8cb0d251238f295f0294e69b9299c13e21
https://github.com/pointoflight/VideoGPT/tree/85f19d8cb0d251238f295f0294e69b9299c13e21
Pooler
import torch import torch.nn as nn import torch.nn.functional as F from torch.optim.lr_scheduler import * def linear(x): return x def activation(func_a): """Activation function wrapper """ try: f = eval(func_a) except: f = linear return f class DropoutWrapper(nn.Module): """ This is a dropout wrapper which supports the fix mask dropout """ def __init__(self, dropout_p=0, enable_vbp=True): super(DropoutWrapper, self).__init__() """variational dropout means fix dropout mask ref: https://discuss.pytorch.org/t/dropout-for-rnns/633/11 """ self.enable_variational_dropout = enable_vbp self.dropout_p = dropout_p def forward(self, x): """ :param x: batch * len * input_size """ if self.training is False or self.dropout_p == 0: return x if len(x.size()) == 3: mask = 1.0 / (1 - self.dropout_p) * torch.bernoulli((1 - self. dropout_p) * (x.data.new(x.size(0), x.size(2)).zero_() + 1)) mask.requires_grad = False return mask.unsqueeze(1).expand_as(x) * x else: return F.dropout(x, p=self.dropout_p, training=self.training) class Pooler(nn.Module): def __init__(self, hidden_size, dropout_p=0.1, actf='tanh'): super(Pooler, self).__init__() self.dense = nn.Linear(hidden_size, hidden_size) self.activation = activation(actf) self.dropout = DropoutWrapper(dropout_p=dropout_p) def forward(self, hidden_states): first_token_tensor = hidden_states[:, 0] first_token_tensor = self.dropout(first_token_tensor) pooled_output = self.dense(first_token_tensor) pooled_output = self.activation(pooled_output) return pooled_output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.functional as F from torch.optim.lr_scheduler import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 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), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 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), (16, 4, 1), 0) del buf1 triton_poi_fused_add_1[grid(64)](buf2, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf2, reinterpret_tensor(buf0, (16, 4), (4, 1), 0) def linear(x): return x def activation(func_a): """Activation function wrapper """ try: f = eval(func_a) except: f = linear return f class DropoutWrapper(nn.Module): """ This is a dropout wrapper which supports the fix mask dropout """ def __init__(self, dropout_p=0, enable_vbp=True): super(DropoutWrapper, self).__init__() """variational dropout means fix dropout mask ref: https://discuss.pytorch.org/t/dropout-for-rnns/633/11 """ self.enable_variational_dropout = enable_vbp self.dropout_p = dropout_p def forward(self, x): """ :param x: batch * len * input_size """ if self.training is False or self.dropout_p == 0: return x if len(x.size()) == 3: mask = 1.0 / (1 - self.dropout_p) * torch.bernoulli((1 - self. dropout_p) * (x.data.new(x.size(0), x.size(2)).zero_() + 1)) mask.requires_grad = False return mask.unsqueeze(1).expand_as(x) * x else: return F.dropout(x, p=self.dropout_p, training=self.training) class PoolerNew(nn.Module): def __init__(self, hidden_size, dropout_p=0.1, actf='tanh'): super(PoolerNew, self).__init__() self.dense = nn.Linear(hidden_size, hidden_size) self.activation = activation(actf) self.dropout = DropoutWrapper(dropout_p=dropout_p) def forward(self, input_0): primals_2 = self.dense.weight primals_3 = self.dense.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
praj000/DeepPavlov
Pooler
false
7,487
[ "Apache-2.0" ]
1
3c9e4c989c6f6b89cd187f0ec2e2b7c71d1e3bf3
https://github.com/praj000/DeepPavlov/tree/3c9e4c989c6f6b89cd187f0ec2e2b7c71d1e3bf3
ReconstructionLoss
import torch import torch.nn as nn from functools import reduce import torch.utils.data class BaseModule(nn.Module): """ Implements the basic module. All other modules inherit from this one """ def load_w(self, checkpoint_path): """ Loads a checkpoint into the state_dict. :param checkpoint_path: the checkpoint file to be loaded. """ self.load_state_dict(torch.load(checkpoint_path)) def __repr__(self): """ String representation """ good_old = super(BaseModule, self).__repr__() addition = 'Total number of parameters: {:,}'.format(self.n_parameters) return good_old + '\n' + addition def __call__(self, *args, **kwargs): return super(BaseModule, self).__call__(*args, **kwargs) @property def n_parameters(self): """ Number of parameters of the model. """ n_parameters = 0 for p in self.parameters(): if hasattr(p, 'mask'): n_parameters += torch.sum(p.mask).item() else: n_parameters += reduce(mul, p.shape) return int(n_parameters) class ReconstructionLoss(BaseModule): """ Implements the reconstruction loss. """ def __init__(self): """ Class constructor. """ super(ReconstructionLoss, self).__init__() def forward(self, x, x_r): """ Forward propagation. :param x: the batch of input samples. :param x_r: the batch of reconstructions. :return: the mean reconstruction loss (averaged along the batch axis). """ L = torch.pow(x - x_r, 2) while L.dim() > 1: L = torch.sum(L, dim=-1) return torch.mean(L) 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 from functools import reduce 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_pow_sub_sum_0(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 x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 16 * x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr1 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr1 + (2 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (3 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp24 = tl.load(in_ptr1 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp28 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr1 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp33 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp34 = tl.load(in_ptr1 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp39 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp40 = tl.load(in_ptr1 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp43 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp44 = tl.load(in_ptr1 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp48 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp49 = tl.load(in_ptr1 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp53 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp54 = tl.load(in_ptr1 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp59 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp60 = tl.load(in_ptr1 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp63 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp64 = tl.load(in_ptr1 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp68 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp69 = tl.load(in_ptr1 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp73 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp74 = tl.load(in_ptr1 + (15 + 16 * x0), 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 tmp21 = tmp19 - tmp20 tmp22 = tmp21 * tmp21 tmp25 = tmp23 - tmp24 tmp26 = tmp25 * tmp25 tmp27 = tmp22 + tmp26 tmp30 = tmp28 - tmp29 tmp31 = tmp30 * tmp30 tmp32 = tmp27 + tmp31 tmp35 = tmp33 - tmp34 tmp36 = tmp35 * tmp35 tmp37 = tmp32 + tmp36 tmp38 = tmp18 + tmp37 tmp41 = tmp39 - tmp40 tmp42 = tmp41 * tmp41 tmp45 = tmp43 - tmp44 tmp46 = tmp45 * tmp45 tmp47 = tmp42 + tmp46 tmp50 = tmp48 - tmp49 tmp51 = tmp50 * tmp50 tmp52 = tmp47 + tmp51 tmp55 = tmp53 - tmp54 tmp56 = tmp55 * tmp55 tmp57 = tmp52 + tmp56 tmp58 = tmp38 + tmp57 tmp61 = tmp59 - tmp60 tmp62 = tmp61 * tmp61 tmp65 = tmp63 - tmp64 tmp66 = tmp65 * tmp65 tmp67 = tmp62 + tmp66 tmp70 = tmp68 - tmp69 tmp71 = tmp70 * tmp70 tmp72 = tmp67 + tmp71 tmp75 = tmp73 - tmp74 tmp76 = tmp75 * tmp75 tmp77 = tmp72 + tmp76 tmp78 = tmp58 + tmp77 tl.store(out_ptr0 + x0, tmp78, xmask) @triton.jit def triton_per_fused_mean_sum_1(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 4.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 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, 1), torch.float32) get_raw_stream(0) triton_poi_fused_pow_sub_sum_0[grid(16)](arg0_1, arg1_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_mean_sum_1[grid(1)](buf2, buf0, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf0 return buf2, class BaseModule(nn.Module): """ Implements the basic module. All other modules inherit from this one """ def load_w(self, checkpoint_path): """ Loads a checkpoint into the state_dict. :param checkpoint_path: the checkpoint file to be loaded. """ self.load_state_dict(torch.load(checkpoint_path)) def __repr__(self): """ String representation """ good_old = super(BaseModule, self).__repr__() addition = 'Total number of parameters: {:,}'.format(self.n_parameters) return good_old + '\n' + addition def __call__(self, *args, **kwargs): return super(BaseModule, self).__call__(*args, **kwargs) @property def n_parameters(self): """ Number of parameters of the model. """ n_parameters = 0 for p in self.parameters(): if hasattr(p, 'mask'): n_parameters += torch.sum(p.mask).item() else: n_parameters += reduce(mul, p.shape) return int(n_parameters) class ReconstructionLossNew(BaseModule): """ Implements the reconstruction loss. """ def __init__(self): """ Class constructor. """ super(ReconstructionLossNew, 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]
ppalaupuigdevall/moments-vae
ReconstructionLoss
false
7,488
[ "MIT" ]
1
99384094b5b7213e7669ad492f1b56216045b190
https://github.com/ppalaupuigdevall/moments-vae/tree/99384094b5b7213e7669ad492f1b56216045b190
_DQN
import torch from torch import nn import torch.nn.functional as F class _DQN(nn.Module): def __init__(self, observation_space, action_space): super(_DQN, self).__init__() self.fc1 = nn.Linear(observation_space, 8) self.fc2 = nn.Linear(8, 4) self.fc3 = nn.Linear(4, action_space) def forward(self, x): x = F.leaky_relu(self.fc1(x), negative_slope=0.1) x = F.leaky_relu(self.fc2(x), negative_slope=0.1) return self.fc3(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'observation_space': 4, 'action_space': 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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_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 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 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 8), (8, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(512)](buf0, primals_2, buf1, buf2, 512, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_2 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(256)](buf3, primals_5, buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = buf3 del buf3 extern_kernels.addmm(primals_7, reinterpret_tensor(buf5, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf6) del primals_7 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 8), (8, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 4), (4, 1), 0 ), primals_6, primals_4 class _DQNNew(nn.Module): def __init__(self, observation_space, action_space): super(_DQNNew, self).__init__() self.fc1 = nn.Linear(observation_space, 8) self.fc2 = nn.Linear(8, 4) self.fc3 = nn.Linear(4, action_space) 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]
pouyan9675/DeepFlappyBird
_DQN
false
7,489
[ "MIT" ]
1
3dc727cc7fb2ce9e0e665d26770c08d3e924f6c2
https://github.com/pouyan9675/DeepFlappyBird/tree/3dc727cc7fb2ce9e0e665d26770c08d3e924f6c2
Advantage_estimate
import torch import torch.nn as nn import torch.nn.functional as F class Advantage_estimate(nn.Module): def __init__(self, input_shape, output_shape, device, hidden_shape=128): super(Advantage_estimate, self).__init__() self.device = device self.dropout = nn.Dropout(p=0.01) self.input_shape = input_shape self.hidden_shape = hidden_shape self.output_shape = output_shape self.l1 = nn.Linear(self.input_shape, self.hidden_shape) self.l2 = nn.Linear(self.hidden_shape, self.output_shape) def forward(self, x): x = x x = self.dropout(F.leaky_relu(self.l1(x))) x = self.l2(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_shape': 4, 'output_shape': 4, 'device': 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.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_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) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) 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, (128, 4), (4, 1)) assert_size_stride(primals_3, (128,), (1,)) assert_size_stride(primals_4, (4, 128), (128, 1)) assert_size_stride(primals_5, (4,), (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_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 128), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(8192)](buf0, primals_3, buf1, buf2, 8192, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_3 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 128), (128, 1), 0), primals_4 class Advantage_estimateNew(nn.Module): def __init__(self, input_shape, output_shape, device, hidden_shape=128): super(Advantage_estimateNew, self).__init__() self.device = device self.dropout = nn.Dropout(p=0.01) self.input_shape = input_shape self.hidden_shape = hidden_shape self.output_shape = output_shape self.l1 = nn.Linear(self.input_shape, self.hidden_shape) self.l2 = nn.Linear(self.hidden_shape, self.output_shape) def forward(self, input_0): primals_2 = self.l1.weight primals_3 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pupupue/Deep-RL-atari
Advantage_estimate
false
7,490
[ "MIT" ]
1
9b97157f87826feafcf272761d7eef9693a2b2c4
https://github.com/pupupue/Deep-RL-atari/tree/9b97157f87826feafcf272761d7eef9693a2b2c4
InverseSigmoidTransformer
import torch import torch.nn as nn import torch.utils.data import torch.nn.functional as F from torch.distributions.utils import probs_to_logits class Bijection(nn.Module): """ An invertible transformation. """ def __init__(self): super().__init__() def forward(self, inputs, context): """ :param inputs: [..., D] :param context: [..., H] or None :return: [..., D] outputs and [..., D] log determinant of Jacobian """ raise NotImplementedError('Implement me!') def inverse(self, outputs, context): """ :param outputs: [..., D] :param context: [..., H] or None :return: [..., D] inputs and [..., D] log determinant of Jacobian of inverse transform """ raise NotImplementedError('Implement me!') class InverseSigmoidTransformer(Bijection): """ Maps inputs from R to (0, 1) using a sigmoid. """ def __init__(self): super().__init__() def forward(self, outputs, context=None): inputs = probs_to_logits(outputs, is_binary=True) log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) return inputs, -log_p - log_q def inverse(self, inputs, context=None): log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) outputs = torch.sigmoid(inputs) return outputs, log_p + log_q 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._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.utils.data 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_clamp_log_log1p_neg_softplus_sub_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.1920928955078125e-07 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 0.9999998807907104 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp5 = tl_math.log(tmp4) tmp6 = -tmp4 tmp7 = libdevice.log1p(tmp6) tmp8 = tmp5 - tmp7 tmp9 = -tmp8 tmp10 = 20.0 tmp11 = tmp9 > tmp10 tmp12 = tl_math.exp(tmp9) tmp13 = libdevice.log1p(tmp12) tmp14 = tl.where(tmp11, tmp9, tmp13) tmp15 = -tmp14 tmp16 = -tmp15 tmp17 = tmp8 > tmp10 tmp18 = tl_math.exp(tmp8) tmp19 = libdevice.log1p(tmp18) tmp20 = tl.where(tmp17, tmp8, tmp19) tmp21 = -tmp20 tmp22 = tmp16 - tmp21 tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp22, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_log_log1p_neg_softplus_sub_0[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, buf1 class Bijection(nn.Module): """ An invertible transformation. """ def __init__(self): super().__init__() def forward(self, inputs, context): """ :param inputs: [..., D] :param context: [..., H] or None :return: [..., D] outputs and [..., D] log determinant of Jacobian """ raise NotImplementedError('Implement me!') def inverse(self, outputs, context): """ :param outputs: [..., D] :param context: [..., H] or None :return: [..., D] inputs and [..., D] log determinant of Jacobian of inverse transform """ raise NotImplementedError('Implement me!') class InverseSigmoidTransformerNew(Bijection): """ Maps inputs from R to (0, 1) using a sigmoid. """ def __init__(self): super().__init__() def inverse(self, inputs, context=None): log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) outputs = torch.sigmoid(inputs) return outputs, log_p + log_q def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0], output[1]
probabll/dgm.pt
InverseSigmoidTransformer
false
7,491
[ "MIT" ]
1
95b5b1eb798b87c3d621e7416cc1c423c076c865
https://github.com/probabll/dgm.pt/tree/95b5b1eb798b87c3d621e7416cc1c423c076c865
Value_estimate
import torch import torch.nn as nn import torch.nn.functional as F class Value_estimate(nn.Module): def __init__(self, input_shape, device, output_shape=1, hidden_shape=128): super(Value_estimate, self).__init__() self.device = device self.dropout = nn.Dropout(p=0.01) self.input_shape = input_shape self.hidden_shape = hidden_shape self.output_shape = output_shape self.l1 = nn.Linear(self.input_shape, self.hidden_shape) self.l2 = nn.Linear(self.hidden_shape, self.output_shape) def forward(self, x): x = x x = self.dropout(F.relu(self.l1(x))) x = self.l2(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_shape': 4, 'device': 0}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 % 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) 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, (128, 4), (4, 1)) assert_size_stride(primals_3, (128,), (1,)) assert_size_stride(primals_4, (1, 128), (128, 1)) assert_size_stride(primals_5, (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_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 128), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf0 buf4 = 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_3, buf4, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 1), (1, 128), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4, 1), (16, 4, 1, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 128), (128, 1), 0), primals_4, buf4 class Value_estimateNew(nn.Module): def __init__(self, input_shape, device, output_shape=1, hidden_shape=128): super(Value_estimateNew, self).__init__() self.device = device self.dropout = nn.Dropout(p=0.01) self.input_shape = input_shape self.hidden_shape = hidden_shape self.output_shape = output_shape self.l1 = nn.Linear(self.input_shape, self.hidden_shape) self.l2 = nn.Linear(self.hidden_shape, self.output_shape) def forward(self, input_0): primals_2 = self.l1.weight primals_3 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pupupue/Deep-RL-atari
Value_estimate
false
7,492
[ "MIT" ]
1
9b97157f87826feafcf272761d7eef9693a2b2c4
https://github.com/pupupue/Deep-RL-atari/tree/9b97157f87826feafcf272761d7eef9693a2b2c4
SigmoidTransformer
import torch import torch.nn as nn import torch.utils.data import torch.nn.functional as F from torch.distributions.utils import probs_to_logits class Bijection(nn.Module): """ An invertible transformation. """ def __init__(self): super().__init__() def forward(self, inputs, context): """ :param inputs: [..., D] :param context: [..., H] or None :return: [..., D] outputs and [..., D] log determinant of Jacobian """ raise NotImplementedError('Implement me!') def inverse(self, outputs, context): """ :param outputs: [..., D] :param context: [..., H] or None :return: [..., D] inputs and [..., D] log determinant of Jacobian of inverse transform """ raise NotImplementedError('Implement me!') class SigmoidTransformer(Bijection): """ Maps inputs from R to (0, 1) using a sigmoid. """ def __init__(self): super().__init__() def forward(self, inputs, context=None): log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) outputs = torch.sigmoid(inputs) return outputs, log_p + log_q def inverse(self, outputs, context=None): inputs = probs_to_logits(outputs, is_binary=True) log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) return inputs, -log_p - log_q 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, math as tl_math import torch.nn as nn import torch.utils.data import torch.nn.functional as F from torch.distributions.utils import probs_to_logits 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_neg_sigmoid_softplus_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp2 = -tmp0 tmp3 = 20.0 tmp4 = tmp2 > tmp3 tmp5 = tl_math.exp(tmp2) tmp6 = libdevice.log1p(tmp5) tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = -tmp7 tmp9 = tmp0 > tmp3 tmp10 = tl_math.exp(tmp0) tmp11 = libdevice.log1p(tmp10) tmp12 = tl.where(tmp9, tmp0, tmp11) tmp13 = -tmp12 tmp14 = tmp8 + tmp13 tl.store(out_ptr0 + x0, tmp1, xmask) tl.store(out_ptr1 + x0, tmp14, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_neg_sigmoid_softplus_0[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, buf1 class Bijection(nn.Module): """ An invertible transformation. """ def __init__(self): super().__init__() def forward(self, inputs, context): """ :param inputs: [..., D] :param context: [..., H] or None :return: [..., D] outputs and [..., D] log determinant of Jacobian """ raise NotImplementedError('Implement me!') def inverse(self, outputs, context): """ :param outputs: [..., D] :param context: [..., H] or None :return: [..., D] inputs and [..., D] log determinant of Jacobian of inverse transform """ raise NotImplementedError('Implement me!') class SigmoidTransformerNew(Bijection): """ Maps inputs from R to (0, 1) using a sigmoid. """ def __init__(self): super().__init__() def inverse(self, outputs, context=None): inputs = probs_to_logits(outputs, is_binary=True) log_p, log_q = -F.softplus(-inputs), -F.softplus(inputs) return inputs, -log_p - log_q def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0], output[1]
probabll/dgm.pt
SigmoidTransformer
false
7,493
[ "MIT" ]
1
95b5b1eb798b87c3d621e7416cc1c423c076c865
https://github.com/probabll/dgm.pt/tree/95b5b1eb798b87c3d621e7416cc1c423c076c865
distLinear
import torch import torch.nn as nn from torch.nn.utils.weight_norm import WeightNorm import torch.optim class distLinear(nn.Module): def __init__(self, indim, outdim): super(distLinear, self).__init__() self.L = nn.Linear(indim, outdim, bias=False) self.class_wise_learnable_norm = True if self.class_wise_learnable_norm: WeightNorm.apply(self.L, 'weight', dim=0) if outdim <= 200: self.scale_factor = 2 else: self.scale_factor = 10 def forward(self, x): x_norm = torch.norm(x, p=2, dim=1).unsqueeze(1).expand_as(x) x_normalized = x.div(x_norm + 1e-05) if not self.class_wise_learnable_norm: L_norm = torch.norm(self.L.weight.data, p=2, dim=1).unsqueeze(1 ).expand_as(self.L.weight.data) self.L.weight.data = self.L.weight.data.div(L_norm + 1e-05) cos_dist = self.L(x_normalized) scores = self.scale_factor * cos_dist return scores def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'indim': 4, 'outdim': 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 from torch.nn.utils.weight_norm import WeightNorm import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__weight_norm_interface_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = libdevice.sqrt(tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__weight_norm_interface_1(in_ptr0, in_ptr1, in_ptr2, 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_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_div_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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-05 tmp14 = tmp12 + tmp13 tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x3, tmp15, xmask) @triton.jit def triton_poi_fused_mul_3(in_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 = 2.0 tmp2 = tmp0 * tmp1 tl.store(in_out_ptr0 + x0, 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), (1, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 1), torch.float32) get_raw_stream(0) triton_poi_fused__weight_norm_interface_0[grid(4)](primals_3, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__weight_norm_interface_1[grid(16)](primals_3, primals_2, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_2[grid(256)](primals_1, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_1 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused_mul_3[grid(256)](buf4, 256, XBLOCK=256, num_warps= 4, num_stages=1) return buf4, buf1, primals_2, primals_3, buf0, reinterpret_tensor(buf2, (64, 4), (4, 1), 0) class distLinearNew(nn.Module): def __init__(self, indim, outdim): super(distLinearNew, self).__init__() self.L = nn.Linear(indim, outdim, bias=False) self.class_wise_learnable_norm = True if self.class_wise_learnable_norm: WeightNorm.apply(self.L, 'weight', dim=0) if outdim <= 200: self.scale_factor = 2 else: self.scale_factor = 10 def forward(self, input_0): primals_2 = self.L.weight_g primals_3 = self.L.weight_v primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
prabhat1081/self-supervision-cs221
distLinear
false
7,494
[ "Apache-2.0" ]
1
41912c01dd7bf44d45a27d7c715a8db2ee9bbc28
https://github.com/prabhat1081/self-supervision-cs221/tree/41912c01dd7bf44d45a27d7c715a8db2ee9bbc28
GumbelSoftmaxLayer
import torch import torch.nn as nn from torch.distributions import RelaxedOneHotCategorical import torch.nn.parallel import torch.utils.data import torch.distributions def gumbel_softmax_sample(logits: 'torch.Tensor', temperature: 'float'=1.0, training: 'bool'=True, straight_through: 'bool'=False): size = logits.size() if not training: indexes = logits.argmax(dim=-1) one_hot = torch.zeros_like(logits).view(-1, size[-1]) one_hot.scatter_(1, indexes.view(-1, 1), 1) one_hot = one_hot.view(*size) return one_hot sample = RelaxedOneHotCategorical(logits=logits, temperature=temperature ).rsample() if straight_through: size = sample.size() indexes = sample.argmax(dim=-1) hard_sample = torch.zeros_like(sample).view(-1, size[-1]) hard_sample.scatter_(1, indexes.view(-1, 1), 1) hard_sample = hard_sample.view(*size) sample = sample + (hard_sample - sample).detach() return sample class GumbelSoftmaxLayer(nn.Module): def __init__(self, temperature: 'float'=1.0, trainable_temperature: 'bool'=False, straight_through: 'bool'=False): super(GumbelSoftmaxLayer, self).__init__() self.straight_through = straight_through if not trainable_temperature: self.temperature = temperature else: self.temperature = torch.nn.Parameter(torch.tensor([temperature ]), requires_grad=True) def forward(self, logits: 'torch.Tensor'): return gumbel_softmax_sample(logits, self.temperature, self. training, self.straight_through) 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 from torch.distributions import RelaxedOneHotCategorical import torch.nn.parallel import torch.utils.data import torch.distributions assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_argmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tl.store(out_ptr0 + x0, tmp46, xmask) @triton.jit def triton_poi_fused_scatter_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 x1 = xindex // 4 x0 = xindex % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.store(in_out_ptr0 + x4, tmp5, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) get_raw_stream(0) triton_poi_fused_argmax_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_scatter_1[grid(256)](buf2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 return buf2, def gumbel_softmax_sample(logits: 'torch.Tensor', temperature: 'float'=1.0, training: 'bool'=True, straight_through: 'bool'=False): size = logits.size() if not training: indexes = logits.argmax(dim=-1) one_hot = torch.zeros_like(logits).view(-1, size[-1]) one_hot.scatter_(1, indexes.view(-1, 1), 1) one_hot = one_hot.view(*size) return one_hot sample = RelaxedOneHotCategorical(logits=logits, temperature=temperature ).rsample() if straight_through: size = sample.size() indexes = sample.argmax(dim=-1) hard_sample = torch.zeros_like(sample).view(-1, size[-1]) hard_sample.scatter_(1, indexes.view(-1, 1), 1) hard_sample = hard_sample.view(*size) sample = sample + (hard_sample - sample).detach() return sample class GumbelSoftmaxLayerNew(nn.Module): def __init__(self, temperature: 'float'=1.0, trainable_temperature: 'bool'=False, straight_through: 'bool'=False): super(GumbelSoftmaxLayerNew, self).__init__() self.straight_through = straight_through if not trainable_temperature: self.temperature = temperature else: self.temperature = torch.nn.Parameter(torch.tensor([temperature ]), requires_grad=True) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ptigas/EGG
GumbelSoftmaxLayer
false
7,495
[ "MIT" ]
1
5319cc9de2c17bc72de717737cfbb5be2285c59b
https://github.com/ptigas/EGG/tree/5319cc9de2c17bc72de717737cfbb5be2285c59b
Crop
import torch from typing import cast from torch import nn from torchvision.transforms import functional as F import torch.nn.functional as F import torchvision.transforms.functional as F import torch.autograd class Crop(nn.Module): def __init__(self, *, top: int, left: int, height: int, width: int) ->None: super().__init__() self.top = top self.left = left self.height = height self.width = width def forward(self, image: 'torch.Tensor') ->torch.Tensor: return cast(torch.Tensor, F.crop(image, top=self.top, left=self. left, height=self.height, width=self.width)) def extra_repr(self) ->str: return ', '.join([f'top={self.top}', f'left={self.left}', f'height={self.height}', f'width={self.width}']) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'top': 4, 'left': 4, 'height': 4, 'width': 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 import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 4 x0 = xindex % 4 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (20 + x3), tmp5 & xmask, other=0.0) tl.store(out_ptr0 + x3, 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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class CropNew(nn.Module): def __init__(self, *, top: int, left: int, height: int, width: int) ->None: super().__init__() self.top = top self.left = left self.height = height self.width = width def extra_repr(self) ->str: return ', '.join([f'top={self.top}', f'left={self.left}', f'height={self.height}', f'width={self.width}']) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
pystiche/papers
Crop
false
7,496
[ "BSD-3-Clause" ]
1
0d8179dc51f6eda0b27fa525dc0b86b866bc88e1
https://github.com/pystiche/papers/tree/0d8179dc51f6eda0b27fa525dc0b86b866bc88e1
TonemappedRelativeMSE
import torch def _tonemap(im): """Helper Reinhards tonemapper. Args: im(torch.Tensor): image to tonemap. Returns: (torch.Tensor) tonemaped image. """ im = torch.clamp(im, min=0) return im / (1 + im) class TonemappedRelativeMSE(torch.nn.Module): """Relative mean-squared error on tonemaped images. Args: eps(float): small number to avoid division by 0. """ def __init__(self, eps=0.01): super(TonemappedRelativeMSE, self).__init__() self.eps = eps def forward(self, im, ref): im = _tonemap(im) ref = _tonemap(ref) mse = torch.pow(im - ref, 2) loss = mse / (torch.pow(ref, 2) + self.eps) loss = 0.5 * torch.mean(loss) 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 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_clamp_div_mean_mul_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp6 = tl.load(in_ptr1 + r0, None) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = tmp2 + tmp3 tmp5 = tmp2 / tmp4 tmp7 = triton_helpers.maximum(tmp6, tmp1) tmp8 = tmp7 + tmp3 tmp9 = tmp7 / tmp8 tmp10 = tmp5 - tmp9 tmp11 = tmp10 * tmp10 tmp12 = tmp9 * tmp9 tmp13 = 0.01 tmp14 = tmp12 + tmp13 tmp15 = tmp11 / tmp14 tmp16 = tl.broadcast_to(tmp15, [RBLOCK]) tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0)) tmp19 = 256.0 tmp20 = tmp18 / tmp19 tmp21 = 0.5 tmp22 = tmp20 * tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp22, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_clamp_div_mean_mul_pow_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, def _tonemap(im): """Helper Reinhards tonemapper. Args: im(torch.Tensor): image to tonemap. Returns: (torch.Tensor) tonemaped image. """ im = torch.clamp(im, min=0) return im / (1 + im) class TonemappedRelativeMSENew(torch.nn.Module): """Relative mean-squared error on tonemaped images. Args: eps(float): small number to avoid division by 0. """ def __init__(self, eps=0.01): super(TonemappedRelativeMSENew, self).__init__() 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]
qbhan/pathembed
TonemappedRelativeMSE
false
7,497
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
ReinforcedReceiver
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.parallel import torch.utils.data from torch.distributions import Bernoulli import torch.distributions class ReinforcedReceiver(nn.Module): def __init__(self, n_bits, n_hidden): super(ReinforcedReceiver, self).__init__() self.emb_column = nn.Linear(n_bits, n_hidden) self.fc1 = nn.Linear(2 * n_hidden, 2 * n_hidden) self.fc2 = nn.Linear(2 * n_hidden, n_bits) def forward(self, embedded_message, bits): embedded_bits = self.emb_column(bits.float()) x = torch.cat([embedded_bits, embedded_message], dim=1) x = self.fc1(x) x = F.leaky_relu(x) x = self.fc2(x) probs = x.sigmoid() distr = Bernoulli(probs=probs) entropy = distr.entropy() if self.training: sample = distr.sample() else: sample = (probs > 0.5).float() log_prob = distr.log_prob(sample).sum(dim=1) return sample, log_prob, entropy def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'n_bits': 4, 'n_hidden': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.utils.data import torch.distributions 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 + 8 * x1), tmp0, xmask) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (8, 8), (8, 1)) assert_size_stride(primals_6, (8,), (1,)) assert_size_stride(primals_7, (4, 8), (8, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32) buf0 = reinterpret_tensor(buf2, (4, 4), (8, 1), 0) extern_kernels.addmm(primals_3, primals_1, reinterpret_tensor( primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = reinterpret_tensor(buf2, (4, 4), (8, 1), 4) get_raw_stream(0) triton_poi_fused_cat_0[grid(16)](primals_4, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 8), (8, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (8, 8), (1, 8 ), 0), out=buf3) buf4 = empty_strided_cuda((4, 8), (8, 1), torch.bool) buf5 = empty_strided_cuda((4, 8), (8, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(32)](buf3, primals_6, buf4, buf5, 32, XBLOCK=32, num_warps=1, num_stages=1) del buf3 del primals_6 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_7, (8, 4), (1, 8 ), 0), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_sigmoid_2[grid(16)](buf7, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_8 return buf7, buf7, primals_1, buf2, buf4, buf5, buf7, primals_7, primals_5 class ReinforcedReceiverNew(nn.Module): def __init__(self, n_bits, n_hidden): super(ReinforcedReceiverNew, self).__init__() self.emb_column = nn.Linear(n_bits, n_hidden) self.fc1 = nn.Linear(2 * n_hidden, 2 * n_hidden) self.fc2 = nn.Linear(2 * n_hidden, n_bits) def forward(self, input_0, input_1): primals_1 = self.emb_column.weight primals_3 = self.emb_column.bias primals_5 = self.fc1.weight primals_6 = self.fc1.bias primals_7 = self.fc2.weight primals_8 = self.fc2.bias primals_2 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0], output[1], output[2]
ptigas/EGG
ReinforcedReceiver
false
7,498
[ "MIT" ]
1
5319cc9de2c17bc72de717737cfbb5be2285c59b
https://github.com/ptigas/EGG/tree/5319cc9de2c17bc72de717737cfbb5be2285c59b
Luong_Attention
import torch import torch.nn as nn import torch.nn.functional as F class Luong_Attention(nn.Module): def __init__(self, hidden_size, score='general'): super(Luong_Attention, self).__init__() assert score.lower() in ['concat', 'general', 'dot'] self.score = score.lower() def wn(x): return nn.utils.weight_norm(x) if self.score == 'general': self.attn = wn(nn.Linear(hidden_size, hidden_size)) elif self.score == 'concat': raise Exception('concat disabled for now. results are poor') self.attn = wn(nn.Linear(2 * hidden_size, hidden_size)) self.v = wn(nn.Linear(hidden_size, 1)) def forward(self, hidden_state, encoder_outputs): assert hidden_state.size(1) == encoder_outputs.size(1) assert len(hidden_state.size()) == 3 hidden_state = hidden_state.transpose(1, 0).contiguous() encoder_outputs = encoder_outputs.transpose(1, 0).contiguous() if self.score == 'dot': grid = torch.bmm(hidden_state, encoder_outputs.transpose(2, 1)) elif self.score == 'general': grid = torch.bmm(hidden_state, self.attn(encoder_outputs). transpose(2, 1)) elif self.score == 'concat': cc = self.attn(torch.cat((hidden_state.expand(encoder_outputs. size()), encoder_outputs), 2)) grid = self.v(cc) grid = grid.permute(0, 2, 1) mask = (grid != 0).float() attn_weights = F.softmax(grid, dim=2) * mask normalizer = attn_weights.sum(dim=2).unsqueeze(2) attn_weights /= normalizer return attn_weights def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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__weight_norm_interface_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = libdevice.sqrt(tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__weight_norm_interface_1(in_ptr0, in_ptr1, in_ptr2, 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_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_clone_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 % 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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__to_copy_mul_ne_5(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 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') tmp9 = tl.load(in_ptr1 + x2, xmask) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp10 = 0.0 tmp11 = tmp9 != tmp10 tmp12 = tmp11.to(tl.float32) tmp13 = tmp8 * tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_div_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) 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), (16, 4, 1)) assert_size_stride(primals_3, (4, 1), (1, 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, 1), (1, 1), torch.float32) get_raw_stream(0) triton_poi_fused__weight_norm_interface_0[grid(4)](primals_4, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__weight_norm_interface_1[grid(16)](primals_4, primals_3, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_2[grid(64)](primals_2, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (16, 4), ( 4, 1), 0), reinterpret_tensor(buf1, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 buf4 = empty_strided_cuda((4, 4, 4), (4, 16, 1), torch.float32) triton_poi_fused_clone_3[grid(64)](primals_1, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf4, reinterpret_tensor(buf3, (4, 4, 4), (16, 1, 4), 0), out=buf5) buf6 = reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0) del buf3 triton_poi_fused__softmax_4[grid(64)](buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax__to_copy_mul_ne_5[grid(64)](buf6, buf5, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = buf6 del buf6 triton_poi_fused_div_6[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf7, (4, 4, 4), (16, 1, 4), 0) del buf7 triton_poi_fused_clone_2[grid(64)](buf4, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf4 return buf8, buf1, primals_3, primals_4, buf0, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), buf5, buf9 class Luong_AttentionNew(nn.Module): def __init__(self, hidden_size, score='general'): super(Luong_AttentionNew, self).__init__() assert score.lower() in ['concat', 'general', 'dot'] self.score = score.lower() def wn(x): return nn.utils.weight_norm(x) if self.score == 'general': self.attn = wn(nn.Linear(hidden_size, hidden_size)) elif self.score == 'concat': raise Exception('concat disabled for now. results are poor') self.attn = wn(nn.Linear(2 * hidden_size, hidden_size)) self.v = wn(nn.Linear(hidden_size, 1)) def forward(self, input_0, input_1): primals_5 = self.attn.bias primals_3 = self.attn.weight_g primals_4 = self.attn.weight_v primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
placaille/nmt-comp550
Luong_Attention
false
7,499
[ "MIT" ]
1
5809ca68dbd7e5452361700f905740a783f9451c
https://github.com/placaille/nmt-comp550/tree/5809ca68dbd7e5452361700f905740a783f9451c
TensorPermute
import torch import torch.utils.data class TensorPermute(torch.nn.Module): """ Convert a torch.FloatTensor of shape (NUM_IMAGES x CHANNELS x HEIGHT x WIDTH) to a torch.FloatTensor of shape (CHANNELS x NUM_IMAGES x HEIGHT x WIDTH). """ def forward(self, tensor): return tensor.permute(1, 0, 2, 3).contiguous() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.utils.data 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_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2 + 64 * x1), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class TensorPermuteNew(torch.nn.Module): """ Convert a torch.FloatTensor of shape (NUM_IMAGES x CHANNELS x HEIGHT x WIDTH) to a torch.FloatTensor of shape (CHANNELS x NUM_IMAGES x HEIGHT x WIDTH). """ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
pz-white/pykale
TensorPermute
false
7,500
[ "MIT" ]
1
de40d1e8a88aa824ffbd1e072b02fe92b57b7c69
https://github.com/pz-white/pykale/tree/de40d1e8a88aa824ffbd1e072b02fe92b57b7c69
OptimizedMLP
import torch import torch.optim import torch.jit import torch.nn as nn class OptimizedMLP(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int'): super(OptimizedMLP, self).__init__() self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features=107) self.l1 = nn.Linear(in_features=107, out_features=179) self.l2 = nn.Linear(in_features=179, out_features=179) self.l3 = nn.Linear(in_features=179, out_features=184) self.l4 = nn.Linear(in_features=184, out_features=115) self.l_out = nn.Linear(in_features=115, out_features=num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l1.weight) torch.nn.init.zeros_(self.l1.bias) torch.nn.init.xavier_normal_(self.l2.weight) torch.nn.init.zeros_(self.l2.bias) torch.nn.init.xavier_normal_(self.l3.weight) torch.nn.init.zeros_(self.l3.bias) torch.nn.init.xavier_normal_(self.l4.weight) torch.nn.init.zeros_(self.l4.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, x): x = self.act(self.l_in(x)) x = self.act(self.l1(x)) x = self.act(self.l2(x)) x = self.act(self.l3(x)) x = self.act(self.l4(x)) x = self.l_out(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in_features': 4, 'num_out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.optim import torch.jit 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_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6848 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 1712 x1 = xindex // 1712 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + (x0 + 1728 * x1), tmp7, xmask) @triton.jit def triton_poi_fused_elu_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 6848 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 107 x1 = xindex // 107 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 107 * (x1 % 16) + 1728 * (x1 // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_elu_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 11456 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 2864 x1 = xindex // 2864 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + (x0 + 2880 * x1), tmp7, xmask) @triton.jit def triton_poi_fused_elu_view_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 11456 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 179 x1 = xindex // 179 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 179 * (x1 % 16) + 2880 * (x1 // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_elu_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 11776 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 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_elu_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 7360 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 1840 x1 = xindex // 1840 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + (x0 + 1856 * x1), tmp7, xmask) @triton.jit def triton_poi_fused_elu_view_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 7360 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 115 x1 = xindex // 115 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 115 * (x1 % 16) + 1856 * (x1 // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (107, 4), (4, 1)) assert_size_stride(primals_2, (107,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (179, 107), (107, 1)) assert_size_stride(primals_5, (179,), (1,)) assert_size_stride(primals_6, (179, 179), (179, 1)) assert_size_stride(primals_7, (179,), (1,)) assert_size_stride(primals_8, (184, 179), (179, 1)) assert_size_stride(primals_9, (184,), (1,)) assert_size_stride(primals_10, (115, 184), (184, 1)) assert_size_stride(primals_11, (115,), (1,)) assert_size_stride(primals_12, (4, 115), (115, 1)) assert_size_stride(primals_13, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 107), (107, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 107), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 107), (1728, 428, 107, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(6848)](buf0, buf1, 6848, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 107), (107, 1), torch.float32) triton_poi_fused_elu_view_1[grid(6848)](buf1, buf2, 6848, XBLOCK= 256, num_warps=4, num_stages=1) del buf1 buf3 = empty_strided_cuda((64, 179), (179, 1), torch.float32) extern_kernels.addmm(primals_5, buf2, reinterpret_tensor(primals_4, (107, 179), (1, 107), 0), alpha=1, beta=1, out=buf3) del primals_5 buf4 = empty_strided_cuda((4, 4, 4, 179), (2880, 716, 179, 1), torch.float32) triton_poi_fused_elu_2[grid(11456)](buf3, buf4, 11456, XBLOCK=128, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((64, 179), (179, 1), torch.float32) triton_poi_fused_elu_view_3[grid(11456)](buf4, buf5, 11456, XBLOCK= 256, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((64, 179), (179, 1), torch.float32) extern_kernels.addmm(primals_7, buf5, reinterpret_tensor(primals_6, (179, 179), (1, 179), 0), alpha=1, beta=1, out=buf6) del primals_7 buf7 = buf4 del buf4 triton_poi_fused_elu_2[grid(11456)](buf6, buf7, 11456, XBLOCK=128, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((64, 179), (179, 1), torch.float32) triton_poi_fused_elu_view_3[grid(11456)](buf7, buf8, 11456, XBLOCK= 256, num_warps=4, num_stages=1) del buf7 buf9 = empty_strided_cuda((64, 184), (184, 1), torch.float32) extern_kernels.addmm(primals_9, buf8, reinterpret_tensor(primals_8, (179, 184), (1, 179), 0), alpha=1, beta=1, out=buf9) del primals_9 buf10 = empty_strided_cuda((4, 4, 4, 184), (2944, 736, 184, 1), torch.float32) triton_poi_fused_elu_4[grid(11776)](buf9, buf10, 11776, XBLOCK=128, num_warps=4, num_stages=1) buf11 = empty_strided_cuda((64, 115), (115, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf10, (64, 184 ), (184, 1), 0), reinterpret_tensor(primals_10, (184, 115), (1, 184), 0), alpha=1, beta=1, out=buf11) del primals_11 buf12 = empty_strided_cuda((4, 4, 4, 115), (1856, 460, 115, 1), torch.float32) triton_poi_fused_elu_5[grid(7360)](buf11, buf12, 7360, XBLOCK=256, num_warps=4, num_stages=1) buf13 = empty_strided_cuda((64, 115), (115, 1), torch.float32) triton_poi_fused_elu_view_6[grid(7360)](buf12, buf13, 7360, XBLOCK= 256, num_warps=4, num_stages=1) del buf12 buf14 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_13, buf13, reinterpret_tensor( primals_12, (115, 4), (1, 115), 0), alpha=1, beta=1, out=buf14) del primals_13 return reinterpret_tensor(buf14, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, buf2, buf3, buf5, buf6, buf8, buf9, reinterpret_tensor(buf10, (64, 184), (184, 1), 0 ), buf11, buf13, primals_12, primals_10, primals_8, primals_6, primals_4 class OptimizedMLPNew(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int'): super(OptimizedMLPNew, self).__init__() self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features=107) self.l1 = nn.Linear(in_features=107, out_features=179) self.l2 = nn.Linear(in_features=179, out_features=179) self.l3 = nn.Linear(in_features=179, out_features=184) self.l4 = nn.Linear(in_features=184, out_features=115) self.l_out = nn.Linear(in_features=115, out_features=num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l1.weight) torch.nn.init.zeros_(self.l1.bias) torch.nn.init.xavier_normal_(self.l2.weight) torch.nn.init.zeros_(self.l2.bias) torch.nn.init.xavier_normal_(self.l3.weight) torch.nn.init.zeros_(self.l3.bias) torch.nn.init.xavier_normal_(self.l4.weight) torch.nn.init.zeros_(self.l4.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, input_0): primals_1 = self.l_in.weight primals_2 = self.l_in.bias primals_4 = self.l1.weight primals_5 = self.l1.bias primals_6 = self.l2.weight primals_7 = self.l2.bias primals_8 = self.l3.weight primals_9 = self.l3.bias primals_10 = self.l4.weight primals_11 = self.l4.bias primals_12 = self.l_out.weight primals_13 = self.l_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, primals_10, primals_11, primals_12, primals_13]) return output[0]
plaveczlambert/deep_euler_tests
OptimizedMLP
false
7,501
[ "MIT" ]
1
a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a
https://github.com/plaveczlambert/deep_euler_tests/tree/a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a
Net
import torch from torch import nn class Net(nn.Module): def __init__(self, input_size, output_size, num_emojis, dropout): super().__init__() self.V = torch.nn.Parameter(torch.empty(num_emojis, output_size). uniform_(-0.1, 0.1)) self.dropout = torch.nn.Dropout(p=dropout) if not input_size == output_size: self.is_proj = True self.W = torch.nn.Parameter(torch.empty(input_size, output_size ).uniform_(-0.1, 0.1)) self.tanh = torch.nn.Tanh() else: self.is_proj = False def forward(self, x, emoji_ids): if self.is_proj: proj = torch.mm(x, self.W) x = self.tanh(proj) weights = self.V[emoji_ids] weights = self.dropout(weights) x = torch.sum(torch.mul(weights, x), 1) x = torch.sigmoid(x) return x def project_embeddings(self, embeddings_array): return self.tanh(torch.mm(torch.Tensor(embeddings_array), self.W) ).detach().numpy() def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.ones([4], dtype=torch.int64)] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4, 'num_emojis': 4, 'dropout': 0.5}]
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_index_mul_sigmoid_sum_0(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 x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex % 16 x5 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr2 + (x4 + 64 * x2), xmask) tmp9 = tl.load(in_ptr2 + (16 + x4 + 64 * x2), xmask) tmp12 = tl.load(in_ptr2 + (32 + x4 + 64 * x2), xmask) tmp15 = tl.load(in_ptr2 + (48 + x4 + 64 * x2), xmask) tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask, 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + (x0 + 4 * tmp4), xmask) tmp8 = tmp6 * tmp7 tmp10 = tmp6 * tmp9 tmp11 = tmp8 + tmp10 tmp13 = tmp6 * tmp12 tmp14 = tmp11 + tmp13 tmp16 = tmp6 * tmp15 tmp17 = tmp14 + tmp16 tmp18 = tl.sigmoid(tmp17) tl.store(out_ptr0 + x5, tmp18, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_index_mul_sigmoid_sum_0[grid(64)](primals_2, primals_1, primals_3, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 return buf0, primals_2, primals_3, buf0 class NetNew(nn.Module): def __init__(self, input_size, output_size, num_emojis, dropout): super().__init__() self.V = torch.nn.Parameter(torch.empty(num_emojis, output_size). uniform_(-0.1, 0.1)) self.dropout = torch.nn.Dropout(p=dropout) if not input_size == output_size: self.is_proj = True self.W = torch.nn.Parameter(torch.empty(input_size, output_size ).uniform_(-0.1, 0.1)) self.tanh = torch.nn.Tanh() else: self.is_proj = False def project_embeddings(self, embeddings_array): return self.tanh(torch.mm(torch.Tensor(embeddings_array), self.W) ).detach().numpy() def forward(self, input_0, input_1): primals_1 = self.V primals_3 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
pwiercinski/emoji2vec_pytorch
Net
false
7,502
[ "MIT" ]
1
be7c3297998baa85a9542c0d2183d1dbed0f3adb
https://github.com/pwiercinski/emoji2vec_pytorch/tree/be7c3297998baa85a9542c0d2183d1dbed0f3adb
Rotate
import torch from typing import cast from torch import nn from torchvision.transforms import functional as F import torch.nn.functional as F import torchvision.transforms.functional as F import torch.autograd class Rotate(nn.Module): def __init__(self, angle: 'float') ->None: super().__init__() self.angle = angle def forward(self, image: 'torch.Tensor') ->torch.Tensor: return cast(torch.Tensor, F.rotate(image, self.angle)) def extra_repr(self) ->str: return f'factor={self.angle}' def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'angle': 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.autograd 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_fill_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 48 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 3 x2 = xindex // 12 x1 = xindex // 3 % 4 x4 = xindex tmp0 = x0 tmp1 = tl.full([1], 2, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tl.full([1], 1, tl.int32) tmp4 = tmp0 == tmp3 tmp5 = x2 tmp6 = tmp5.to(tl.float32) tmp7 = 2.0 tmp8 = tmp6 < tmp7 tmp9 = 1.0 tmp10 = tmp6 * tmp9 tmp11 = -1.5 tmp12 = tmp10 + tmp11 tmp13 = 3 + -1 * x2 tmp14 = tmp13.to(tl.float32) tmp15 = tmp14 * tmp9 tmp16 = 1.5 tmp17 = tmp16 - tmp15 tmp18 = tl.where(tmp8, tmp12, tmp17) tmp19 = tl.full([1], 0, tl.int32) tmp20 = tmp0 == tmp19 tmp21 = x1 tmp22 = tmp21.to(tl.float32) tmp23 = tmp22 < tmp7 tmp24 = tmp22 * tmp9 tmp25 = tmp24 + tmp11 tmp26 = 3 + -1 * x1 tmp27 = tmp26.to(tl.float32) tmp28 = tmp27 * tmp9 tmp29 = tmp16 - tmp28 tmp30 = tl.where(tmp23, tmp25, tmp29) tmp31 = float('nan') tmp32 = tl.where(tmp20, tmp30, tmp31) tmp33 = tl.where(tmp4, tmp18, tmp32) tmp34 = tl.where(tmp2, tmp9, tmp33) tl.store(out_ptr0 + x4, tmp34, xmask) @triton.jit def triton_poi_fused_div_lift_fresh_1(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 x2 = xindex tmp0 = x1 + 3 * x0 tmp1 = tl.full([1], 3, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 2, tl.int64) tmp6 = tmp0 < tmp5 tmp7 = -0.06975647062063217 tmp8 = 0.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = 0.9975640773773193 tmp11 = tl.where(tmp4, tmp10, tmp9) tmp12 = tl.full([1], 4, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tl.full([1], 5, tl.int64) tmp15 = tmp0 < tmp14 tmp16 = tl.where(tmp15, tmp10, tmp8) tmp17 = 0.06975647062063217 tmp18 = tl.where(tmp13, tmp17, tmp16) tmp19 = tl.where(tmp2, tmp11, tmp18) tmp20 = x0 tmp21 = tmp20 < tmp3 tmp22 = 2.0 tmp23 = tl.where(tmp21, tmp22, tmp22) tmp24 = tmp19 / tmp23 tl.store(out_ptr0 + x2, tmp24, xmask) @triton.jit def triton_poi_fused_grid_sampler_2d_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x3 = xindex // 16 x4 = xindex tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 2.0 tmp2 = tmp0 * tmp1 tmp3 = 1.5 tmp4 = tmp2 + tmp3 tmp5 = libdevice.nearbyint(tmp4) tmp6 = 0.0 tmp7 = tmp5 >= tmp6 tmp8 = 4.0 tmp9 = tmp5 < tmp8 tmp11 = tmp10 * tmp1 tmp12 = tmp11 + tmp3 tmp13 = libdevice.nearbyint(tmp12) tmp14 = tmp13 >= tmp6 tmp15 = tmp13 < tmp8 tmp16 = tmp14 & tmp15 tmp17 = tmp9 & tmp16 tmp18 = tmp7 & tmp17 tmp19 = tmp13.to(tl.int64) tmp20 = tl.full([1], 0, tl.int64) tmp21 = tl.where(tmp18, tmp19, tmp20) tmp22 = tl.full([XBLOCK], 4, tl.int32) tmp23 = tmp21 + tmp22 tmp24 = tmp21 < 0 tmp25 = tl.where(tmp24, tmp23, tmp21) tl.device_assert((0 <= tmp25) & (tmp25 < 4) | ~xmask, 'index out of bounds: 0 <= tmp25 < 4') tmp27 = tmp5.to(tl.int64) tmp28 = tl.where(tmp18, tmp27, tmp20) tmp29 = tmp28 + tmp22 tmp30 = tmp28 < 0 tmp31 = tl.where(tmp30, tmp29, tmp28) tl.device_assert((0 <= tmp31) & (tmp31 < 4) | ~xmask, 'index out of bounds: 0 <= tmp31 < 4') tmp33 = tl.load(in_ptr1 + (tmp31 + 4 * tmp25 + 16 * x3), xmask, eviction_policy='evict_last') tmp34 = tl.full([1], 1, tl.int64) tmp35 = tl.where(tmp18, tmp34, tmp20) tmp36 = tmp35.to(tl.float32) tmp37 = tmp33 * tmp36 tl.store(out_ptr0 + x4, tmp37, 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((1, 4, 4, 3), (48, 12, 3, 1), torch.float32) get_raw_stream(0) triton_poi_fused_fill_0[grid(48)](buf2, 48, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((1, 3, 2), (6, 2, 1), torch.float32) triton_poi_fused_div_lift_fresh_1[grid(6)](buf3, 6, XBLOCK=8, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((1, 16, 2), (32, 2, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf2, (1, 16, 3), (48, 3, 1), 0), buf3, out=buf4) del buf2 del buf3 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_grid_sampler_2d_2[grid(256)](buf4, arg0_1, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del buf4 return buf5, class RotateNew(nn.Module): def __init__(self, angle: 'float') ->None: super().__init__() self.angle = angle def extra_repr(self) ->str: return f'factor={self.angle}' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
pystiche/papers
Rotate
false
7,503
[ "BSD-3-Clause" ]
1
0d8179dc51f6eda0b27fa525dc0b86b866bc88e1
https://github.com/pystiche/papers/tree/0d8179dc51f6eda0b27fa525dc0b86b866bc88e1
srcEncoder
import torch import torch.nn as nn class srcEncoder(nn.Module): def __init__(self, in_ch, hid_ch): super(srcEncoder, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return self.conv2(self.act(self.conv1(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'hid_ch': 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 @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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = 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,)) 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_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=(1, 1), 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=256, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1 class srcEncoderNew(nn.Module): def __init__(self, in_ch, hid_ch): super(srcEncoderNew, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
qbhan/pathembed
srcEncoder
false
7,504
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
TonemappedMSE
import torch def _tonemap(im): """Helper Reinhards tonemapper. Args: im(torch.Tensor): image to tonemap. Returns: (torch.Tensor) tonemaped image. """ im = torch.clamp(im, min=0) return im / (1 + im) class TonemappedMSE(torch.nn.Module): """Mean-squared error on tonemaped images. Args: eps(float): small number to avoid division by 0. """ def __init__(self, eps=0.01): super(TonemappedMSE, self).__init__() self.eps = eps def forward(self, im, ref): im = _tonemap(im) ref = _tonemap(ref) loss = torch.pow(im - ref, 2) loss = 0.5 * torch.mean(loss) 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 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_clamp_div_mean_mul_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp6 = tl.load(in_ptr1 + r0, None) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = tmp2 + tmp3 tmp5 = tmp2 / tmp4 tmp7 = triton_helpers.maximum(tmp6, tmp1) tmp8 = tmp7 + tmp3 tmp9 = tmp7 / tmp8 tmp10 = tmp5 - tmp9 tmp11 = tmp10 * tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 256.0 tmp16 = tmp14 / tmp15 tmp17 = 0.5 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_clamp_div_mean_mul_pow_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, def _tonemap(im): """Helper Reinhards tonemapper. Args: im(torch.Tensor): image to tonemap. Returns: (torch.Tensor) tonemaped image. """ im = torch.clamp(im, min=0) return im / (1 + im) class TonemappedMSENew(torch.nn.Module): """Mean-squared error on tonemaped images. Args: eps(float): small number to avoid division by 0. """ def __init__(self, eps=0.01): super(TonemappedMSENew, self).__init__() 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]
qbhan/pathembed
TonemappedMSE
false
7,505
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
Residual_Block
import torch import torch.nn as nn class AddCoords(nn.Module): def __init__(self, with_r=False): super().__init__() self.with_r = with_r def forward(self, input_tensor): """ @param input_tensor: shape(batch, channel, x_dim, y_dim) """ batch_size, _, x_dim, y_dim = input_tensor.size() xx_channel = torch.arange(x_dim).repeat(1, y_dim, 1) yy_channel = torch.arange(y_dim).repeat(1, x_dim, 1).transpose(1, 2) xx_channel = xx_channel.float() / (x_dim - 1) yy_channel = yy_channel.float() / (y_dim - 1) xx_channel = xx_channel * 2 - 1 yy_channel = yy_channel * 2 - 1 xx_channel = xx_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3) yy_channel = yy_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3) ret = torch.cat([input_tensor, xx_channel.type_as(input_tensor), yy_channel.type_as(input_tensor)], dim=1) if self.with_r: rr = torch.sqrt(torch.pow(xx_channel.type_as(input_tensor) - 0.5, 2) + torch.pow(yy_channel.type_as(input_tensor) - 0.5, 2)) ret = torch.cat([ret, rr], dim=1) return ret class CoordConv(nn.Module): def __init__(self, in_channels, out_channels, with_r=False, **kwargs): super().__init__() self.addcoords = AddCoords(with_r=with_r) in_size = in_channels + 2 if with_r: in_size += 1 self.conv = nn.Conv2d(in_size, out_channels, **kwargs) def forward(self, x): ret = self.addcoords(x) ret = self.conv(ret) return ret class Residual_Block(nn.Module): def __init__(self): super(Residual_Block, self).__init__() self.conv1 = CoordConv(in_channels=64, out_channels=64, with_r=True, kernel_size=3, stride=1, padding=1, bias=True) self.in1 = nn.InstanceNorm2d(64, affine=True) self.relu = nn.LeakyReLU(0.2, inplace=True) self.conv2 = CoordConv(in_channels=64, out_channels=64, with_r=True, kernel_size=3, stride=1, padding=1, bias=True) self.in2 = nn.InstanceNorm2d(64, affine=True) def forward(self, x): identity_data = x output = self.relu(self.in1(self.conv1(x))) output = self.in2(self.conv2(output)) output = torch.add(output, identity_data) return output def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4288 xnumel = 9 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 % 67 y1 = yindex // 67 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 67 * x2 + 603 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_cat_1(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 // 4096 % 66 x3 = xindex // 270336 x4 = xindex % 4096 x1 = xindex // 64 % 64 x0 = xindex % 64 x5 = xindex % 270336 tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 4096 * x2 + 262144 * x3), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 65, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = x1 tmp11 = tmp10.to(tl.float32) tmp12 = 0.015873015873015872 tmp13 = tmp11 * tmp12 tmp14 = 2.0 tmp15 = tmp13 * tmp14 tmp16 = 1.0 tmp17 = tmp15 - tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp9, tmp17, tmp18) tmp20 = tmp0 >= tmp7 tl.full([1], 66, tl.int64) tmp23 = x0 tmp24 = tmp23.to(tl.float32) tmp25 = tmp24 * tmp12 tmp26 = tmp25 * tmp14 tmp27 = tmp26 - tmp16 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp20, tmp27, tmp28) tmp30 = tl.where(tmp9, tmp19, tmp29) tmp31 = tl.where(tmp4, tmp5, tmp30) tl.store(out_ptr0 + (x5 + 274432 * x3), tmp31, None) @triton.jit def triton_poi_fused__to_copy_add_pow_sqrt_sub_2(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 x2 = xindex // 4096 x3 = xindex % 4096 tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.015873015873015872 tmp3 = tmp1 * tmp2 tmp4 = 2.0 tmp5 = tmp3 * tmp4 tmp6 = 1.0 tmp7 = tmp5 - tmp6 tmp8 = 0.5 tmp9 = tmp7 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = x0 tmp12 = tmp11.to(tl.float32) tmp13 = tmp12 * tmp2 tmp14 = tmp13 * tmp4 tmp15 = tmp14 - tmp6 tmp16 = tmp15 - tmp8 tmp17 = tmp16 * tmp16 tmp18 = tmp10 + tmp17 tmp19 = libdevice.sqrt(tmp18) tl.store(out_ptr0 + (x3 + 274432 * x2), tmp19, None) @triton.jit def triton_poi_fused_cat_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 268 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 % 67 y1 = yindex // 67 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 67 * x2 + 274432 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_convolution_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 % 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_repeat_5(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 % 64, xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_red_fused__native_batch_norm_legit_6(in_out_ptr0, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 256 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (64 * r1 + 262144 * (x0 // 64) + x0 % 64), 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 + x0, tmp2, xmask) tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_7(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 % 256 x1 = xindex // 256 x2 = xindex tmp0 = tl.load(in_ptr0 + (64 * x1 + 262144 * (x0 // 64) + x0 % 64), None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x0, 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') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, None) @triton.jit def triton_poi_fused_cat_8(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 // 4096 % 66 x3 = xindex // 270336 x4 = xindex % 4096 x1 = xindex // 64 % 64 x0 = xindex % 64 x5 = xindex % 270336 tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (64 * ((64 * x3 + x2) // 64 % 4) + 256 * x4 + x2 % 64), tmp4, eviction_policy='evict_last', other=0.0) tmp6 = 0.0 tmp7 = tmp5 > tmp6 tmp8 = 0.2 tmp9 = tmp5 * tmp8 tmp10 = tl.where(tmp7, tmp5, tmp9) tmp11 = tl.full(tmp10.shape, 0.0, tmp10.dtype) tmp12 = tl.where(tmp4, tmp10, tmp11) tmp13 = tmp0 >= tmp3 tmp14 = tl.full([1], 65, tl.int64) tmp15 = tmp0 < tmp14 tmp16 = tmp13 & tmp15 tmp17 = x1 tmp18 = tmp17.to(tl.float32) tmp19 = 0.015873015873015872 tmp20 = tmp18 * tmp19 tmp21 = 2.0 tmp22 = tmp20 * tmp21 tmp23 = 1.0 tmp24 = tmp22 - tmp23 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp16, tmp24, tmp25) tmp27 = tmp0 >= tmp14 tl.full([1], 66, tl.int64) tmp30 = x0 tmp31 = tmp30.to(tl.float32) tmp32 = tmp31 * tmp19 tmp33 = tmp32 * tmp21 tmp34 = tmp33 - tmp23 tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp27, tmp34, tmp35) tmp37 = tl.where(tmp16, tmp26, tmp36) tmp38 = tl.where(tmp4, tmp12, tmp37) tl.store(out_ptr0 + (x5 + 274432 * x3), tmp38, None) @triton.jit def triton_red_fused__native_batch_norm_legit_add_repeat_9(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, out_ptr3, out_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 256 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 tmp0 = tl.load(in_ptr0 + x0 % 64, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) tmp3_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp3_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp3_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp1 = tl.load(in_ptr1 + (64 * r1 + 262144 * (x0 // 64) + x0 % 64), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp3_mean_next, tmp3_m2_next, tmp3_weight_next = (triton_helpers. welford_reduce(tmp2, tmp3_mean, tmp3_m2, tmp3_weight, roffset == 0) ) tmp3_mean = tl.where(rmask & xmask, tmp3_mean_next, tmp3_mean) tmp3_m2 = tl.where(rmask & xmask, tmp3_m2_next, tmp3_m2) tmp3_weight = tl.where(rmask & xmask, tmp3_weight_next, tmp3_weight) tmp3_tmp, tmp4_tmp, tmp5_tmp = triton_helpers.welford(tmp3_mean, tmp3_m2, tmp3_weight, 1) tmp3 = tmp3_tmp[:, None] tmp4 = tmp4_tmp[:, None] tmp5_tmp[:, None] tl.store(out_ptr1 + x0, tmp3, xmask) tmp6 = 4096.0 tmp7 = tmp4 / tmp6 tmp8 = 1e-05 tmp9 = tmp7 + tmp8 tmp10 = libdevice.rsqrt(tmp9) tl.store(out_ptr3 + x0, tmp10, xmask) x2 = xindex % 64 x3 = xindex // 64 tmp15 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp11 = tl.load(in_ptr1 + (x2 + 64 * r1 + 262144 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp17 = tl.load(in_ptr3 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp12 = tmp11 - tmp3 tmp13 = tmp12 * tmp10 tmp14 = tmp13 * tmp0 tmp16 = tmp14 + tmp15 tmp18 = tmp16 + tmp17 tl.store(out_ptr4 + (r1 + 4096 * x0), tmp18, rmask & 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, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_2, (64, 67, 3, 3), (603, 9, 3, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64,), (1,)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (64, 67, 3, 3), (603, 9, 3, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (64,), (1,)) assert_size_stride(primals_9, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 67, 3, 3), (603, 1, 201, 67), torch. float32) get_raw_stream(0) triton_poi_fused_0[grid(4288, 9)](primals_2, buf0, 4288, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((64, 67, 3, 3), (603, 1, 201, 67), torch. float32) triton_poi_fused_0[grid(4288, 9)](primals_6, buf1, 4288, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = empty_strided_cuda((4, 67, 64, 64), (274432, 4096, 64, 1), torch.float32) buf2 = reinterpret_tensor(buf4, (4, 66, 64, 64), (274432, 4096, 64, 1), 0) triton_poi_fused_cat_1[grid(1081344)](primals_1, buf2, 1081344, XBLOCK=512, num_warps=8, num_stages=1) buf3 = reinterpret_tensor(buf4, (4, 1, 64, 64), (274432, 4096, 64, 1), 270336) triton_poi_fused__to_copy_add_pow_sqrt_sub_2[grid(16384)](buf3, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((4, 67, 64, 64), (274432, 1, 4288, 67), torch.float32) triton_poi_fused_cat_3[grid(268, 4096)](buf4, buf5, 268, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf2 del buf3 buf6 = extern_kernels.convolution(buf5, buf0, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf7 = buf6 del buf6 triton_poi_fused_convolution_4[grid(1048576)](buf7, primals_3, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf8 = empty_strided_cuda((256,), (1,), torch.float32) triton_poi_fused_repeat_5[grid(256)](primals_4, buf8, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_4 buf9 = empty_strided_cuda((256,), (1,), torch.float32) triton_poi_fused_repeat_5[grid(256)](primals_5, buf9, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_5 buf10 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf11 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf13 = buf11 del buf11 triton_red_fused__native_batch_norm_legit_6[grid(256)](buf13, buf7, buf10, 256, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf14 = empty_strided_cuda((1, 256, 64, 64), (1048576, 1, 16384, 256), torch.float32) triton_poi_fused__native_batch_norm_legit_7[grid(1048576)](buf7, buf10, buf13, buf8, buf9, buf14, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) buf17 = buf4 del buf4 buf15 = reinterpret_tensor(buf17, (4, 66, 64, 64), (274432, 4096, 64, 1), 0) triton_poi_fused_cat_8[grid(1081344)](buf14, buf15, 1081344, XBLOCK =512, num_warps=8, num_stages=1) buf16 = reinterpret_tensor(buf17, (4, 1, 64, 64), (274432, 4096, 64, 1), 270336) triton_poi_fused__to_copy_add_pow_sqrt_sub_2[grid(16384)](buf16, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf18 = empty_strided_cuda((4, 67, 64, 64), (274432, 1, 4288, 67), torch.float32) triton_poi_fused_cat_3[grid(268, 4096)](buf17, buf18, 268, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf15 del buf16 del buf17 buf19 = extern_kernels.convolution(buf18, buf1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf20 = buf19 del buf19 triton_poi_fused_convolution_4[grid(1048576)](buf20, primals_7, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf21 = empty_strided_cuda((256,), (1,), torch.float32) buf22 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf25 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf26 = reinterpret_tensor(buf14, (4, 64, 64, 64), (262144, 4096, 64, 1), 0) del buf14 triton_red_fused__native_batch_norm_legit_add_repeat_9[grid(256)]( primals_8, buf20, primals_9, primals_1, buf21, buf22, buf25, buf26, 256, 4096, XBLOCK=8, RBLOCK=512, num_warps=16, num_stages=1) del primals_1 del primals_8 del primals_9 return (buf26, buf0, buf1, buf5, buf7, buf8, buf9, buf10, buf13, buf18, buf20, buf21, reinterpret_tensor(buf25, (256,), (1,), 0), reinterpret_tensor(buf22, (1, 256, 1, 1), (256, 1, 1, 1), 0)) class AddCoords(nn.Module): def __init__(self, with_r=False): super().__init__() self.with_r = with_r def forward(self, input_tensor): """ @param input_tensor: shape(batch, channel, x_dim, y_dim) """ batch_size, _, x_dim, y_dim = input_tensor.size() xx_channel = torch.arange(x_dim).repeat(1, y_dim, 1) yy_channel = torch.arange(y_dim).repeat(1, x_dim, 1).transpose(1, 2) xx_channel = xx_channel.float() / (x_dim - 1) yy_channel = yy_channel.float() / (y_dim - 1) xx_channel = xx_channel * 2 - 1 yy_channel = yy_channel * 2 - 1 xx_channel = xx_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3) yy_channel = yy_channel.repeat(batch_size, 1, 1, 1).transpose(2, 3) ret = torch.cat([input_tensor, xx_channel.type_as(input_tensor), yy_channel.type_as(input_tensor)], dim=1) if self.with_r: rr = torch.sqrt(torch.pow(xx_channel.type_as(input_tensor) - 0.5, 2) + torch.pow(yy_channel.type_as(input_tensor) - 0.5, 2)) ret = torch.cat([ret, rr], dim=1) return ret class CoordConv(nn.Module): def __init__(self, in_channels, out_channels, with_r=False, **kwargs): super().__init__() self.addcoords = AddCoords(with_r=with_r) in_size = in_channels + 2 if with_r: in_size += 1 self.conv = nn.Conv2d(in_size, out_channels, **kwargs) def forward(self, x): ret = self.addcoords(x) ret = self.conv(ret) return ret class Residual_BlockNew(nn.Module): def __init__(self): super(Residual_BlockNew, self).__init__() self.conv1 = CoordConv(in_channels=64, out_channels=64, with_r=True, kernel_size=3, stride=1, padding=1, bias=True) self.in1 = nn.InstanceNorm2d(64, affine=True) self.relu = nn.LeakyReLU(0.2, inplace=True) self.conv2 = CoordConv(in_channels=64, out_channels=64, with_r=True, kernel_size=3, stride=1, padding=1, bias=True) self.in2 = nn.InstanceNorm2d(64, affine=True) def forward(self, input_0): primals_2 = self.conv1.conv.weight primals_3 = self.conv1.conv.bias primals_4 = self.in1.weight primals_5 = self.in1.bias primals_6 = self.conv2.conv.weight primals_7 = self.conv2.conv.bias primals_8 = self.in2.weight primals_9 = self.in2.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]
patrickacole/ccsrresnet
Residual_Block
false
7,506
[ "MIT" ]
1
693d6673c26860bc9f7ced187006d8ef0a8386e6
https://github.com/patrickacole/ccsrresnet/tree/693d6673c26860bc9f7ced187006d8ef0a8386e6
InformedSender
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.parallel import torch.utils.data import torch.distributions class InformedSender(nn.Module): def __init__(self, game_size, feat_size, embedding_size, hidden_size, vocab_size=100, temp=1.0): super(InformedSender, self).__init__() self.game_size = game_size self.embedding_size = embedding_size self.hidden_size = hidden_size self.vocab_size = vocab_size self.temp = temp self.lin1 = nn.Linear(feat_size, embedding_size, bias=False) self.conv2 = nn.Conv2d(1, hidden_size, kernel_size=(game_size, 1), stride=(game_size, 1), bias=False) self.conv3 = nn.Conv2d(1, 1, kernel_size=(hidden_size, 1), stride=( hidden_size, 1), bias=False) self.lin4 = nn.Linear(embedding_size, vocab_size, bias=False) def forward(self, x, return_embeddings=False): emb = self.return_embeddings(x) h = self.conv2(emb) h = torch.sigmoid(h) h = h.transpose(1, 2) h = self.conv3(h) h = torch.sigmoid(h) h = h.squeeze(dim=1) h = h.squeeze(dim=1) h = self.lin4(h) h = h.mul(1.0 / self.temp) logits = F.log_softmax(h, dim=1) return logits def return_embeddings(self, x): embs = [] for i in range(self.game_size): h = x[i] if len(h.size()) == 3: h = h.squeeze(dim=-1) h_i = self.lin1(h) h_i = h_i.unsqueeze(dim=1) h_i = h_i.unsqueeze(dim=1) embs.append(h_i) h = torch.cat(embs, dim=2) return h def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'game_size': 4, 'feat_size': 4, 'embedding_size': 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 from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.nn.parallel import torch.utils.data import torch.distributions 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, 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 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 tmp7 = tl.full([1], 2, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (x0 + 4 * x2), tmp9 & xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 3, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr2 + (x0 + 4 * x2), tmp14 & xmask, eviction_policy ='evict_last', other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 4, tl.int64) tmp19 = tl.load(in_ptr3 + (x0 + 4 * x2), tmp16 & xmask, eviction_policy ='evict_last', other=0.0) tmp20 = tl.where(tmp14, tmp15, tmp19) tmp21 = tl.where(tmp9, tmp10, tmp20) tmp22 = tl.where(tmp4, tmp5, tmp21) tl.store(out_ptr0 + x3, tmp22, xmask) @triton.jit def triton_poi_fused_sigmoid_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_sigmoid_2(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) @triton.jit def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 rnumel = 100 RBLOCK: tl.constexpr = 128 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 + 100 * x0), rmask & xmask, other=0.0) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(rmask & xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tmp7 = tmp2 - tmp6 tmp8 = tmp7 * tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp12 = tl.where(rmask & xmask, tmp10, 0) tmp13 = tl.sum(tmp12, 1)[:, None] tmp14 = tl_math.log(tmp13) tmp15 = tmp8 - tmp14 tl.store(out_ptr2 + (r1 + 100 * x0), tmp15, rmask & xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 1, 4, 1), (4, 4, 1, 1)) assert_size_stride(primals_4, (1, 1, 4, 1), (4, 4, 1, 1)) assert_size_stride(primals_5, (100, 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(reinterpret_tensor(primals_1, (4, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 32), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf2) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 48), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf3) del primals_2 buf4 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(64)](buf0, buf1, buf2, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del buf1 del buf2 del buf3 buf5 = extern_kernels.convolution(buf4, primals_3, stride=(4, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 1, 4), (16, 4, 4, 1)) buf6 = buf5 del buf5 triton_poi_fused_sigmoid_1[grid(64)](buf6, 64, XBLOCK=64, num_warps =1, num_stages=1) buf7 = extern_kernels.convolution(reinterpret_tensor(buf6, (4, 1, 4, 4), (16, 4, 4, 1), 0), primals_4, stride=(4, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 1, 1, 4), (4, 4, 4, 1)) buf8 = buf7 del buf7 triton_poi_fused_sigmoid_2[grid(16)](buf8, 16, XBLOCK=16, num_warps =1, num_stages=1) buf9 = empty_strided_cuda((4, 100), (100, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf8, (4, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 100), (1, 4), 0), out=buf9) buf12 = empty_strided_cuda((4, 100), (100, 1), torch.float32) triton_per_fused__log_softmax_3[grid(4)](buf9, buf12, 4, 100, XBLOCK=1, num_warps=2, num_stages=1) del buf9 return buf12, primals_3, primals_4, reinterpret_tensor(primals_1, (4, 4 ), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (4, 1), 16 ), reinterpret_tensor(primals_1, (4, 4), (4, 1), 32 ), reinterpret_tensor(primals_1, (4, 4), (4, 1), 48 ), buf4, buf6, buf8, buf12, primals_5 class InformedSenderNew(nn.Module): def __init__(self, game_size, feat_size, embedding_size, hidden_size, vocab_size=100, temp=1.0): super(InformedSenderNew, self).__init__() self.game_size = game_size self.embedding_size = embedding_size self.hidden_size = hidden_size self.vocab_size = vocab_size self.temp = temp self.lin1 = nn.Linear(feat_size, embedding_size, bias=False) self.conv2 = nn.Conv2d(1, hidden_size, kernel_size=(game_size, 1), stride=(game_size, 1), bias=False) self.conv3 = nn.Conv2d(1, 1, kernel_size=(hidden_size, 1), stride=( hidden_size, 1), bias=False) self.lin4 = nn.Linear(embedding_size, vocab_size, bias=False) def return_embeddings(self, x): embs = [] for i in range(self.game_size): h = x[i] if len(h.size()) == 3: h = h.squeeze(dim=-1) h_i = self.lin1(h) h_i = h_i.unsqueeze(dim=1) h_i = h_i.unsqueeze(dim=1) embs.append(h_i) h = torch.cat(embs, dim=2) return h def forward(self, input_0): primals_2 = self.lin1.weight primals_3 = self.conv2.weight primals_4 = self.conv3.weight primals_5 = self.lin4.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ptigas/EGG
InformedSender
false
7,507
[ "MIT" ]
1
5319cc9de2c17bc72de717737cfbb5be2285c59b
https://github.com/ptigas/EGG/tree/5319cc9de2c17bc72de717737cfbb5be2285c59b
ResBlock
import torch import torch.nn as nn class ResBlock(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlock, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return x + self.act(self.conv2(self.act(self.conv1(x)))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'hid_ch': 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_add_convolution_relu_threshold_backward_1(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 = 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,)) 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_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=(1, 1), 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 = 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_add_convolution_relu_threshold_backward_1[grid(256)]( primals_3, buf2, primals_5, buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 del primals_5 return buf3, primals_1, primals_3, primals_4, buf1, buf4 class ResBlockNew(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlockNew, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
qbhan/pathembed
ResBlock
false
7,508
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
FeatureEncoder
import torch import torch.nn as nn class ResBlock(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlock, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return x + self.act(self.conv2(self.act(self.conv1(x)))) class FeatureEncoder(nn.Module): def __init__(self, in_channel=34, out_channel=64): super(FeatureEncoder, self).__init__() self.conv = nn.Conv2d(in_channels=in_channel, out_channels= out_channel, kernel_size=3, stride=1, padding=1) self.act = nn.ReLU(inplace=True) self.resblock1 = ResBlock(out_channel, out_channel) self.resblock2 = ResBlock(out_channel, out_channel) def forward(self, batch): return self.resblock2(self.resblock1(self.act(self.conv(batch)))) def get_inputs(): return [torch.rand([4, 34, 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 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): 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_add_convolution_relu_threshold_backward_1(in_ptr0, in_ptr1, in_ptr2, 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 + x3, None) tmp2 = tl.load(in_ptr2 + x1, None, 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, None) tl.store(out_ptr1 + x3, tmp8, 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) = args args.clear() assert_size_stride(primals_1, (64, 34, 3, 3), (306, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 34, 64, 64), (139264, 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,)) assert_size_stride(primals_10, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_11, (64,), (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 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf5 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) buf11 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid( 1048576)](buf1, buf4, primals_7, buf5, buf11, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_0[grid(1048576)](buf7, primals_9, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf8 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf9 = buf4 del buf4 buf10 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid( 1048576)](buf5, buf8, primals_11, buf9, buf10, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) del buf8 del primals_11 return (buf9, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, buf1, buf3, buf5, buf7, buf10, buf11) class ResBlock(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlock, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return x + self.act(self.conv2(self.act(self.conv1(x)))) class FeatureEncoderNew(nn.Module): def __init__(self, in_channel=34, out_channel=64): super(FeatureEncoderNew, self).__init__() self.conv = nn.Conv2d(in_channels=in_channel, out_channels= out_channel, kernel_size=3, stride=1, padding=1) self.act = nn.ReLU(inplace=True) self.resblock1 = ResBlock(out_channel, out_channel) self.resblock2 = ResBlock(out_channel, out_channel) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_4 = self.resblock1.conv1.weight primals_5 = self.resblock1.conv1.bias primals_6 = self.resblock1.conv2.weight primals_7 = self.resblock1.conv2.bias primals_8 = self.resblock2.conv1.weight primals_9 = self.resblock2.conv1.bias primals_10 = self.resblock2.conv2.weight primals_11 = self.resblock2.conv2.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]
qbhan/pathembed
FeatureEncoder
false
7,509
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
PredictionHead
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class PredictionHead(nn.Module): """ Simple classification prediction-head block to plug ontop of the 4D output of a CNN. Args: num_classes: the number of different classes that can be predicted. input_shape: the shape that input to this head will have. Expected to be (batch_size, channels, height, width) """ def __init__(self, num_classes, input_shape): super(PredictionHead, self).__init__() self.avgpool = nn.AvgPool2d(input_shape[2]) self.linear = nn.Linear(input_shape[1], num_classes) def forward(self, x): x = self.avgpool(x) x = torch.flatten(x, 1) x = self.linear(x) return F.log_softmax(x, 1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_classes': 4, 'input_shape': [4, 4, 4]}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp8 = tmp7 + tmp6 tmp10 = tmp9 + tmp8 tmp12 = tmp11 + tmp10 tmp14 = tmp13 + tmp12 tmp16 = tmp15 + tmp14 tmp18 = tmp17 + tmp16 tmp20 = tmp19 + tmp18 tmp22 = tmp21 + tmp20 tmp24 = tmp23 + tmp22 tmp26 = tmp25 + tmp24 tmp28 = tmp27 + tmp26 tmp30 = tmp29 + tmp28 tmp31 = 0.0625 tmp32 = tmp30 * tmp31 tl.store(out_ptr0 + x0, tmp32, xmask) @triton.jit def triton_poi_fused__log_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 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = 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 + x2, tmp13, 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, 1, 1), (4, 1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_avg_pool2d_0[grid(16)](primals_1, buf0, 16, XBLOCK =16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha =1, beta=1, out=buf1) del primals_2 del primals_3 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(16)](buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = buf1 del buf1 triton_poi_fused__log_softmax_2[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf2 return buf3, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), buf3 class PredictionHeadNew(nn.Module): """ Simple classification prediction-head block to plug ontop of the 4D output of a CNN. Args: num_classes: the number of different classes that can be predicted. input_shape: the shape that input to this head will have. Expected to be (batch_size, channels, height, width) """ def __init__(self, num_classes, input_shape): super(PredictionHeadNew, self).__init__() self.avgpool = nn.AvgPool2d(input_shape[2]) self.linear = nn.Linear(input_shape[1], num_classes) def forward(self, input_0): primals_2 = self.linear.weight primals_3 = self.linear.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
pz-white/pykale
PredictionHead
false
7,510
[ "MIT" ]
1
de40d1e8a88aa824ffbd1e072b02fe92b57b7c69
https://github.com/pz-white/pykale/tree/de40d1e8a88aa824ffbd1e072b02fe92b57b7c69
LinearDiag
import torch import torch.nn as nn class LinearDiag(nn.Module): def __init__(self, num_features, bias=False): super(LinearDiag, self).__init__() weight = torch.FloatTensor(num_features).fill_(1) self.weight = nn.Parameter(weight, requires_grad=True) if bias: bias = torch.FloatTensor(num_features).fill_(0) self.bias = nn.Parameter(bias, requires_grad=True) else: self.register_parameter('bias', None) def forward(self, X): assert X.dim() == 2 and X.size(1) == self.weight.size(0) out = X * self.weight.expand_as(X) if self.bias is not None: out = out + self.bias.expand_as(out) return out def get_inputs(): return [torch.rand([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 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_mul_0(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 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (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_1, primals_2, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf0, primals_1 class LinearDiagNew(nn.Module): def __init__(self, num_features, bias=False): super(LinearDiagNew, self).__init__() weight = torch.FloatTensor(num_features).fill_(1) self.weight = nn.Parameter(weight, requires_grad=True) if bias: bias = torch.FloatTensor(num_features).fill_(0) self.bias = nn.Parameter(bias, requires_grad=True) else: self.register_parameter('bias', None) def forward(self, input_0): primals_2 = self.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
qianrusun1015/E3BM-1
LinearDiag
false
7,511
[ "Apache-2.0" ]
1
d2c957bdff66fe28a288f1518f224a1e034d543f
https://github.com/qianrusun1015/E3BM-1/tree/d2c957bdff66fe28a288f1518f224a1e034d543f
FeatExemplarAvgBlock
import torch import torch.nn as nn class FeatExemplarAvgBlock(nn.Module): def __init__(self, nFeat): super(FeatExemplarAvgBlock, self).__init__() def forward(self, features_train, labels_train): labels_train_transposed = labels_train.transpose(1, 2) weight_novel = torch.bmm(labels_train_transposed, features_train) weight_novel = weight_novel.div(labels_train_transposed.sum(dim=2, keepdim=True).expand_as(weight_novel)) return weight_novel def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'nFeat': 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_div_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 x2 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(in_out_ptr0 + x3, tmp8, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 1, 4), 0), arg1_1, out=buf0) del arg1_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_div_0[grid(64)](buf1, arg0_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf1, class FeatExemplarAvgBlockNew(nn.Module): def __init__(self, nFeat): super(FeatExemplarAvgBlockNew, 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]
qianrusun1015/E3BM-1
FeatExemplarAvgBlock
false
7,512
[ "Apache-2.0" ]
1
d2c957bdff66fe28a288f1518f224a1e034d543f
https://github.com/qianrusun1015/E3BM-1/tree/d2c957bdff66fe28a288f1518f224a1e034d543f
CONV
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F class CONV(nn.Module): def __init__(self, input_shape, device): super(CONV, self).__init__() self.device = device self.input_shape = input_shape self.poolavg = nn.AvgPool2d(2, 2) self.conv1 = nn.Conv2d(input_shape[0], 32, kernel_size=8, stride=4, padding=0) self.conv2 = nn.Conv2d(32, 64, kernel_size=4, stride=2, padding=0) self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=0) def forward(self, x): x = F.leaky_relu(self.conv1(x)) x = self.poolavg(x) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = x.view(x.shape[0], -1) return x def get_last_layers(self): x = np.zeros(self.input_shape, dtype=np.float32) x = np.expand_dims(x, axis=0) x = torch.from_numpy(x).float() res = self.forward(x) res = [int(x) for x in res[0].shape] return res[0] def get_inputs(): return [torch.rand([4, 4, 128, 128])] def get_init_inputs(): return [[], {'input_shape': [4, 4], 'device': 0}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import numpy as np 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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 123008 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 961 % 32 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) @triton.jit def triton_poi_fused_avg_pool2d_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 28800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 15 x1 = xindex // 15 % 15 x2 = xindex // 225 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 62 * x1 + 961 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 62 * x1 + 961 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (31 + 2 * x0 + 62 * x1 + 961 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (32 + 2 * x0 + 62 * x1 + 961 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp7 = 0.25 tmp8 = tmp6 * tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 9216 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 36 % 64 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_relu_threshold_backward_3(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 // 16 % 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) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, None) tl.store(out_ptr0 + x3, 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, (32, 4, 8, 8), (256, 64, 8, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 128, 128), (65536, 16384, 128, 1)) assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 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,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(4, 4), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 31, 31), (30752, 961, 31, 1)) buf1 = empty_strided_cuda((4, 32, 31, 31), (30752, 961, 31, 1), torch.bool) buf2 = empty_strided_cuda((4, 32, 31, 31), (30752, 961, 31, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(123008)](buf0, primals_2, buf1, buf2, 123008, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del primals_2 buf3 = empty_strided_cuda((4, 32, 15, 15), (7200, 225, 15, 1), torch.float32) triton_poi_fused_avg_pool2d_1[grid(28800)](buf2, buf3, 28800, XBLOCK=128, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 6, 6), (2304, 36, 6, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(9216)](buf5, primals_5, 9216, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 4, 4), (1024, 16, 4, 1)) buf7 = buf6 del buf6 buf8 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_3[grid(4096)](buf7 , primals_7, buf8, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return reinterpret_tensor(buf7, (4, 1024), (1024, 1), 0 ), primals_1, primals_3, primals_4, primals_6, buf1, buf2, buf3, buf5, buf8 class CONVNew(nn.Module): def __init__(self, input_shape, device): super(CONVNew, self).__init__() self.device = device self.input_shape = input_shape self.poolavg = nn.AvgPool2d(2, 2) self.conv1 = nn.Conv2d(input_shape[0], 32, kernel_size=8, stride=4, padding=0) self.conv2 = nn.Conv2d(32, 64, kernel_size=4, stride=2, padding=0) self.conv3 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=0) def get_last_layers(self): x = np.zeros(self.input_shape, dtype=np.float32) x = np.expand_dims(x, axis=0) x = torch.from_numpy(x).float() res = self.forward(x) res = [int(x) for x in res[0].shape] return res[0] 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]
pupupue/Deep-RL-atari
CONV
false
7,513
[ "MIT" ]
1
9b97157f87826feafcf272761d7eef9693a2b2c4
https://github.com/pupupue/Deep-RL-atari/tree/9b97157f87826feafcf272761d7eef9693a2b2c4
Quantization
import torch import torch.utils.data import torch.nn as nn class Quant(torch.autograd.Function): @staticmethod def forward(ctx, input): input = torch.clamp(input, 0, 1) output = (input * 255.0).round() / 255.0 return output @staticmethod def backward(ctx, grad_output): return grad_output class Quantization(nn.Module): def __init__(self): super(Quantization, self).__init__() def forward(self, input): return Quant.apply(input) 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._inductor.runtime.triton_helpers import libdevice import torch.utils.data 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_clamp_div_mul_round_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp5 = 255.0 tmp6 = tmp4 * tmp5 tmp7 = libdevice.nearbyint(tmp6) tmp8 = 0.00392156862745098 tmp9 = tmp7 * tmp8 tl.store(out_ptr0 + x0, tmp9, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_div_mul_round_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class Quant(torch.autograd.Function): @staticmethod def forward(ctx, input): input = torch.clamp(input, 0, 1) output = (input * 255.0).round() / 255.0 return output @staticmethod def backward(ctx, grad_output): return grad_output class QuantizationNew(nn.Module): def __init__(self): super(QuantizationNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
qwopqwop200/Fast-Invertible-Rescaling-Net
Quantization
false
7,514
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
kernelPredictor
import torch import torch.nn as nn class kernelPredictor(nn.Module): def __init__(self, in_ch, hid_ch, pred_kernel_size=21): super(kernelPredictor, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=1) self.conv2 = nn.Conv2d(hid_ch, pred_kernel_size ** 2, kernel_size=1) def forward(self, x): return self.conv2(self.act(self.conv1(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'hid_ch': 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_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_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 1764 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 441 y1 = yindex // 441 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 441 * x2 + 7056 * 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 + 16 * y3), tmp2, 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, 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, (441, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (441,), (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_3, buf0, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 1, 16, 4)) buf2 = buf1 del buf1 triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 441, 4, 4), (7056, 1, 1764, 441)) buf4 = empty_strided_cuda((4, 441, 4, 4), (7056, 16, 4, 1), torch. float32) triton_poi_fused_convolution_2[grid(1764, 16)](buf3, primals_5, buf4, 1764, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del buf3 del primals_5 return buf4, primals_1, buf0, primals_4, buf2 class kernelPredictorNew(nn.Module): def __init__(self, in_ch, hid_ch, pred_kernel_size=21): super(kernelPredictorNew, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=1) self.conv2 = nn.Conv2d(hid_ch, pred_kernel_size ** 2, kernel_size=1) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
qbhan/pathembed
kernelPredictor
false
7,515
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
GatedFusion
import torch import torch.nn as nn class GatedFusion(nn.Module): """ Reference: - ACL2020, Document-Level Event Role Filler Extraction using Multi-Granularity Contextualized Encoding """ def __init__(self, n_in): super().__init__() self.n_in = n_in self.hidden2scalar1 = nn.Linear(self.n_in, 1) self.hidden2scalar2 = nn.Linear(self.n_in, 1) def forward(self, hidden1, hidden2): gate_alpha = torch.sigmoid(self.hidden2scalar1(hidden1) + self. hidden2scalar2(hidden2)) out = gate_alpha * hidden1 + (1 - gate_alpha) * hidden2 return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_in': 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_add_mul_rsub_sigmoid_0(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 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp10 = tl.load(in_ptr4 + x2, xmask) tmp14 = tl.load(in_ptr5 + x2, xmask) tmp3 = tmp0 + tmp2 tmp7 = tmp4 + tmp6 tmp8 = tmp3 + tmp7 tmp9 = tl.sigmoid(tmp8) tmp11 = tmp9 * tmp10 tmp12 = 1.0 tmp13 = tmp12 - tmp9 tmp15 = tmp13 * tmp14 tmp16 = tmp11 + tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_add_rsub_sigmoid_sigmoid_backward_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr1 + x0, xmask) tmp5 = tl.load(in_ptr2 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp7 = tmp4 + tmp6 tmp8 = tmp3 + tmp7 tmp9 = tl.sigmoid(tmp8) tmp10 = 1.0 tmp11 = tmp10 - tmp9 tmp12 = tmp9 * tmp11 tl.store(in_out_ptr0 + x0, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 4), (4, 1)) assert_size_stride(primals_5, (1,), (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 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 1), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_rsub_sigmoid_0[grid(256)](buf0, primals_2, buf1, primals_5, primals_3, primals_6, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 triton_poi_fused_add_rsub_sigmoid_sigmoid_backward_1[grid(64)](buf3, primals_2, buf1, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 del primals_2 del primals_5 return buf2, primals_3, primals_6, buf3 class GatedFusionNew(nn.Module): """ Reference: - ACL2020, Document-Level Event Role Filler Extraction using Multi-Granularity Contextualized Encoding """ def __init__(self, n_in): super().__init__() self.n_in = n_in self.hidden2scalar1 = nn.Linear(self.n_in, 1) self.hidden2scalar2 = nn.Linear(self.n_in, 1) def forward(self, input_0, input_1): primals_1 = self.hidden2scalar1.weight primals_2 = self.hidden2scalar1.bias primals_4 = self.hidden2scalar2.weight primals_5 = self.hidden2scalar2.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]
qinyan-li/DocEE
GatedFusion
false
7,516
[ "MIT" ]
1
e8d2202a44907df5f12f9a67180d849a54421ab7
https://github.com/qinyan-li/DocEE/tree/e8d2202a44907df5f12f9a67180d849a54421ab7
Attention
import torch import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): """ Applies an attention mechanism on the output features from the decoder. 「A Structured Self-Attentive Sentence Embedding」 Paper https://arxiv.org/abs/1703.03130 .. math:: \\begin{array}{ll} x = encoder outputs*decoder output \\\\ attn score = exp(x_i) / sum_j exp(x_j) \\\\ output = \\tanh(w * (attn score * encoder outputs) + b * output) \\end{array} Args: decoder_hidden_size (int): The number of expected features in the output Inputs: decoder_output, encoder_outputs - **decoder_output** (batch, output_len, dimensions): tensor containing the output features from the decoder. - **encoder_outputs** (batch, input_len, dimensions): tensor containing features of the encoded input sequence. Returns: output - **output** (batch, output_len, dimensions): tensor containing the attended output features from the decoder. Examples:: >>> attention = Attention(hidden_size) >>> output = attention(decoder_output, encoder_outputs) """ def __init__(self, decoder_hidden_size): super(Attention, self).__init__() self.w = nn.Linear(decoder_hidden_size * 2, decoder_hidden_size) def forward(self, decoder_output, encoder_outputs): batch_size = decoder_output.size(0) input_size = encoder_outputs.size(1) hidden_size = decoder_output.size(2) attn_score = torch.bmm(decoder_output, encoder_outputs.transpose(1, 2)) attn_distribution = F.softmax(attn_score.view(-1, input_size), dim=1 ).view(batch_size, -1, input_size) context = torch.bmm(attn_distribution, encoder_outputs) combined = torch.cat((context, decoder_output), dim=2) output = torch.tanh(self.w(combined.view(-1, 2 * hidden_size))).view( batch_size, -1, hidden_size) return output def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'decoder_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 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 = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_tanh_tanh_backward_3(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 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) tmp4 = tmp3 * tmp3 tmp5 = 1.0 tmp6 = tmp5 - tmp4 tl.store(in_out_ptr0 + x2, tmp3, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(primals_1, reinterpret_tensor(primals_2, (4, 4, 4), (16, 1, 4), 0), out=buf0) buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0) del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 extern_kernels.bmm(reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0), primals_2, out=buf3) del primals_2 buf4 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf3, primals_1, buf4, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0) del buf3 extern_kernels.mm(reinterpret_tensor(buf4, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf5) del primals_3 buf6 = buf5 del buf5 buf7 = buf2 del buf2 triton_poi_fused_tanh_tanh_backward_3[grid(64)](buf6, primals_4, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_4 return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf4, (16, 8), (8, 1), 0), buf7 class AttentionNew(nn.Module): """ Applies an attention mechanism on the output features from the decoder. 「A Structured Self-Attentive Sentence Embedding」 Paper https://arxiv.org/abs/1703.03130 .. math:: \\begin{array}{ll} x = encoder outputs*decoder output \\\\ attn score = exp(x_i) / sum_j exp(x_j) \\\\ output = \\tanh(w * (attn score * encoder outputs) + b * output) \\end{array} Args: decoder_hidden_size (int): The number of expected features in the output Inputs: decoder_output, encoder_outputs - **decoder_output** (batch, output_len, dimensions): tensor containing the output features from the decoder. - **encoder_outputs** (batch, input_len, dimensions): tensor containing features of the encoded input sequence. Returns: output - **output** (batch, output_len, dimensions): tensor containing the attended output features from the decoder. Examples:: >>> attention = Attention(hidden_size) >>> output = attention(decoder_output, encoder_outputs) """ def __init__(self, decoder_hidden_size): super(AttentionNew, self).__init__() self.w = nn.Linear(decoder_hidden_size * 2, decoder_hidden_size) def forward(self, input_0, input_1): primals_3 = self.w.weight primals_4 = self.w.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
qute012/Korean-Speech-Recognition
Attention
false
7,517
[ "Apache-2.0" ]
1
0e037fd03df1ad6bf1084ee748781cdf4d428940
https://github.com/qute012/Korean-Speech-Recognition/tree/0e037fd03df1ad6bf1084ee748781cdf4d428940
L1
import torch import torch.utils.data import torch.nn as nn class L1(nn.Module): def __init__(self, eps=1e-06): super(L1, self).__init__() self.eps = eps def forward(self, x, target): diff = x - target return torch.mean(torch.sum(torch.sqrt(diff * diff + self.eps), (1, 2, 3))) 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 libdevice import torch.utils.data import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_mul_sqrt_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, 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 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = 1e-06 tmp5 = tmp3 + tmp4 tmp6 = libdevice.sqrt(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_per_fused_mean_1(in_out_ptr0, in_ptr0, 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) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.sum(tmp1, 1)[:, None] tmp4 = 4.0 tmp5 = tmp3 / tmp4 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, 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,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_add_mul_sqrt_sub_sum_0[grid(4)](arg0_1, arg1_1, buf0, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_mean_1[grid(1)](buf2, buf0, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf0 return buf2, class L1New(nn.Module): def __init__(self, eps=1e-06): super(L1New, self).__init__() 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]
qwopqwop200/Fast-Invertible-Rescaling-Net
L1
false
7,518
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
FullyConnected2
import torch import torch.nn as nn class FullyConnected2(nn.Module): def __init__(self, hidden_size, output_size): super(FullyConnected2, self).__init__() self.lrelu = nn.LeakyReLU(0.1) self.linear_layer = nn.Linear(hidden_size, hidden_size, bias=True) self.linear_layer_1 = nn.Linear(hidden_size, output_size, bias=False) def forward(self, input): out = self.lrelu(self.linear_layer(input)) return self.linear_layer_1(out) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(256)](buf0, primals_2, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf3 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf3) return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 4), (4, 1), 0), primals_4 class FullyConnected2New(nn.Module): def __init__(self, hidden_size, output_size): super(FullyConnected2New, self).__init__() self.lrelu = nn.LeakyReLU(0.1) self.linear_layer = nn.Linear(hidden_size, hidden_size, bias=True) self.linear_layer_1 = nn.Linear(hidden_size, output_size, bias=False) def forward(self, input_0): primals_1 = self.linear_layer.weight primals_2 = self.linear_layer.bias primals_4 = self.linear_layer_1.weight primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
qweas120/Active_VLN
FullyConnected2
false
7,519
[ "MIT" ]
1
d5dabd5fe6127bcfec023b90f14a4ba5ac671f9b
https://github.com/qweas120/Active_VLN/tree/d5dabd5fe6127bcfec023b90f14a4ba5ac671f9b
FullyConnected
import torch import torch.nn as nn class FullyConnected(nn.Module): def __init__(self, hidden_size, output_size): super(FullyConnected, self).__init__() self.lrelu = nn.LeakyReLU(0.1) self.linear_layer = nn.Linear(hidden_size, output_size, bias=False) def forward(self, input): out = self.lrelu(self.linear_layer(input)) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_leaky_relu_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.1 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(256)](buf0, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 return buf2, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf1 class FullyConnectedNew(nn.Module): def __init__(self, hidden_size, output_size): super(FullyConnectedNew, self).__init__() self.lrelu = nn.LeakyReLU(0.1) self.linear_layer = nn.Linear(hidden_size, output_size, bias=False) def forward(self, input_0): primals_1 = self.linear_layer.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
qweas120/Active_VLN
FullyConnected
false
7,520
[ "MIT" ]
1
d5dabd5fe6127bcfec023b90f14a4ba5ac671f9b
https://github.com/qweas120/Active_VLN/tree/d5dabd5fe6127bcfec023b90f14a4ba5ac671f9b
PA
import torch import torch.utils.data import torch.nn as nn class PA(nn.Module): def __init__(self, nf): super(PA, self).__init__() self.conv = nn.Conv2d(nf, nf, 1) self.sigmoid = nn.Sigmoid() def forward(self, x): y = self.conv(x) y = self.sigmoid(y) out = torch.mul(x, y) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'nf': 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.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_mul_sigmoid_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3 = 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)) 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 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_mul_sigmoid_0[grid(256)](buf1, primals_2, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf2, primals_1, primals_3, buf1 class PANew(nn.Module): def __init__(self, nf): super(PANew, self).__init__() self.conv = nn.Conv2d(nf, nf, 1) self.sigmoid = nn.Sigmoid() 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]
qwopqwop200/Fast-Invertible-Rescaling-Net
PA
false
7,521
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
TextureLoss
import torch import torch.utils.data import torch.nn as nn import torch.nn.functional as F def gram_matrix(input): a, b, c, d = input.size() features = input.view(a, b, c * d) G = torch.bmm(features, torch.transpose(features, 1, 2)) return G.div(b * c * d) class TextureLoss(nn.Module): def __init__(self): super(TextureLoss, self).__init__() def forward(self, x, x1): x = gram_matrix(x) x1 = gram_matrix(x1) loss = F.mse_loss(x, x1) 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 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.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_div_mse_loss_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) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 0.015625 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp5 = tmp2 - tmp4 tmp6 = tmp5 * tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 64.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(arg0_1, (4, 16, 4), (64, 1, 16), 0), out=buf0) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(arg1_1, (4, 16, 4), (64, 1, 16), 0), out=buf1) del arg1_1 buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 get_raw_stream(0) triton_per_fused_div_mse_loss_0[grid(1)](buf3, buf0, buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 return buf3, def gram_matrix(input): a, b, c, d = input.size() features = input.view(a, b, c * d) G = torch.bmm(features, torch.transpose(features, 1, 2)) return G.div(b * c * d) class TextureLossNew(nn.Module): def __init__(self): super(TextureLossNew, 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]
qwopqwop200/Fast-Invertible-Rescaling-Net
TextureLoss
false
7,522
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
Conv2dMtl
from torch.nn import Module import math import torch import torch.nn.functional as F from torch.nn.parameter import Parameter from torch.nn.modules.module import Module from torch.nn.modules.utils import _pair class _ConvNdMtl(Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias): super(_ConvNdMtl, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups if transposed: self.weight = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(in_channels, out_channels // groups, 1, 1)) else: self.weight = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(out_channels, in_channels // groups, 1, 1)) self.weight.requires_grad = False if bias: self.bias = Parameter(torch.Tensor(out_channels)) self.bias.requires_grad = False self.mtl_bias = Parameter(torch.zeros(out_channels)) else: self.register_parameter('bias', None) self.register_parameter('mtl_bias', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels for k in self.kernel_size: n *= k stdv = 1.0 / math.sqrt(n) self.weight.data.uniform_(-stdv, stdv) self.mtl_weight.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) self.mtl_bias.data.uniform_(0, 0) def extra_repr(self): s = ( '{in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is None: s += ', bias=False' return s.format(**self.__dict__) class Conv2dMtl(_ConvNdMtl): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(Conv2dMtl, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias) def forward(self, input): new_mtl_weight = self.mtl_weight.expand(self.weight.shape) new_weight = self.weight.mul(new_mtl_weight) if self.bias is not None: new_bias = self.bias + self.mtl_bias else: new_bias = None return F.conv2d(input, new_weight, new_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.nn import Module import math from torch.nn.parameter import Parameter from torch.nn.modules.module import Module 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 @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_add_convolution_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, 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, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (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_mul_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_add_convolution_1[grid(4)](primals_3, primals_4, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 del primals_4 buf2 = extern_kernels.convolution(primals_5, buf0, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_2[grid(16)](buf3, buf1, 16, XBLOCK =16, num_warps=1, num_stages=1) del buf1 return buf3, primals_2, primals_5, buf0 class _ConvNdMtl(Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias): super(_ConvNdMtl, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups if transposed: self.weight = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(in_channels, out_channels // groups, 1, 1)) else: self.weight = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(out_channels, in_channels // groups, 1, 1)) self.weight.requires_grad = False if bias: self.bias = Parameter(torch.Tensor(out_channels)) self.bias.requires_grad = False self.mtl_bias = Parameter(torch.zeros(out_channels)) else: self.register_parameter('bias', None) self.register_parameter('mtl_bias', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels for k in self.kernel_size: n *= k stdv = 1.0 / math.sqrt(n) self.weight.data.uniform_(-stdv, stdv) self.mtl_weight.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) self.mtl_bias.data.uniform_(0, 0) def extra_repr(self): s = ( '{in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is None: s += ', bias=False' return s.format(**self.__dict__) class Conv2dMtlNew(_ConvNdMtl): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(Conv2dMtlNew, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias) def forward(self, input_0): primals_2 = self.weight primals_1 = self.mtl_weight primals_3 = self.bias primals_4 = self.mtl_bias primals_5 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
qianrusun1015/E3BM-1
Conv2dMtl
false
7,523
[ "Apache-2.0" ]
1
d2c957bdff66fe28a288f1518f224a1e034d543f
https://github.com/qianrusun1015/E3BM-1/tree/d2c957bdff66fe28a288f1518f224a1e034d543f
L2
import torch import torch.utils.data import torch.nn as nn class L2(nn.Module): def __init__(self): super(L2, self).__init__() def forward(self, x, target): return torch.mean(torch.sum((x - target) ** 2, (1, 2, 3))) 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.utils.data 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_pow_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, 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 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_per_fused_mean_1(in_out_ptr0, in_ptr0, 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) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.sum(tmp1, 1)[:, None] tmp4 = 4.0 tmp5 = tmp3 / tmp4 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, 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,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_pow_sub_sum_0[grid(4)](arg0_1, arg1_1, buf0, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_mean_1[grid(1)](buf2, buf0, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf0 return buf2, class L2New(nn.Module): def __init__(self): super(L2New, 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]
qwopqwop200/Fast-Invertible-Rescaling-Net
L2
false
7,524
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
NoiseInjection
import torch import torch.nn as nn import torch.nn.parallel class NoiseInjection(nn.Module): def __init__(self, channel): super().__init__() self.weight = nn.Parameter(0.01 * torch.randn(1, channel, 1, 1)) def forward(self, feat, noise=None): if noise is None: noise = torch.randn(feat.shape[0], 1, feat.shape[2], feat.shape [3], dtype=feat.dtype, device=feat.device) return feat + self.weight * noise def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channel': 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 import torch.nn as nn import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_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], dtype=torch. float32, 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 NoiseInjectionNew(nn.Module): def __init__(self, channel): super().__init__() self.weight = nn.Parameter(0.01 * torch.randn(1, channel, 1, 1)) def forward(self, input_0): primals_2 = self.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
rakshithShetty/SemanticAdversary
NoiseInjection
false
7,526
[ "MIT" ]
1
e6d50f00af6f7d847cba4210613afea4be773254
https://github.com/rakshithShetty/SemanticAdversary/tree/e6d50f00af6f7d847cba4210613afea4be773254
GaussianSmoothing
import math import torch import torch.nn as nn import torch.nn.parallel class GaussianSmoothing(nn.Module): """ Apply gaussian smoothing on a 1d, 2d or 3d tensor. Filtering is performed seperately for each channel in the input using a depthwise convolution. Arguments: channels (int, sequence): Number of channels of the input tensors. Output will have this number of channels as well. kernel_size (int, sequence): Size of the gaussian kernel. sigma (float, sequence): Standard deviation of the gaussian kernel. dim (int, optional): The number of dimensions of the data. Default value is 2 (spatial). """ def __init__(self, channels=3, kernel_size=3, sigma=3, dim=2): super(GaussianSmoothing, self).__init__() x_coord = torch.arange(kernel_size) x_grid = x_coord.repeat(kernel_size).view(kernel_size, kernel_size) y_grid = x_grid.t() xy_grid = torch.stack([x_grid, y_grid], dim=-1).float() mean = (kernel_size - 1) / 2.0 variance = sigma ** 2.0 gaussian_kernel = 1.0 / (2.0 * math.pi * variance) * torch.exp(- torch.sum((xy_grid - mean) ** 2.0, dim=-1) / (2 * variance)) gaussian_kernel = gaussian_kernel / torch.sum(gaussian_kernel) gaussian_kernel = gaussian_kernel.view(1, 1, kernel_size, kernel_size) gaussian_kernel = gaussian_kernel.repeat(channels, 1, 1, 1) self.gaussian_filter = nn.Conv2d(in_channels=channels, out_channels =channels, kernel_size=kernel_size, groups=channels, bias=False, padding=(kernel_size - 1) // 2) self.gaussian_filter.weight.data = gaussian_kernel self.gaussian_filter.weight.requires_grad = False def forward(self, input): """ Apply gaussian filter to input. Arguments: input (torch.Tensor): Input to apply gaussian filter on. Returns: filtered (torch.Tensor): Filtered output. """ return self.gaussian_filter(input) 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 import math import torch.nn as nn import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(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_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 y0 = yindex % 3 y1 = yindex // 3 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 3 * x2 + 12288 * y1), ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4096 * y3), tmp0, ymask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (3, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(arg1_1, (4, 3, 64, 64), (12288, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(12, 4096)](arg1_1, buf0, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del arg1_1 buf1 = extern_kernels.convolution(buf0, arg0_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=3, bias=None) assert_size_stride(buf1, (4, 3, 64, 64), (12288, 1, 192, 3)) del arg0_1 buf2 = reinterpret_tensor(buf0, (4, 3, 64, 64), (12288, 4096, 64, 1), 0 ) del buf0 triton_poi_fused_convolution_1[grid(12, 4096)](buf1, buf2, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del buf1 return buf2, class GaussianSmoothingNew(nn.Module): """ Apply gaussian smoothing on a 1d, 2d or 3d tensor. Filtering is performed seperately for each channel in the input using a depthwise convolution. Arguments: channels (int, sequence): Number of channels of the input tensors. Output will have this number of channels as well. kernel_size (int, sequence): Size of the gaussian kernel. sigma (float, sequence): Standard deviation of the gaussian kernel. dim (int, optional): The number of dimensions of the data. Default value is 2 (spatial). """ def __init__(self, channels=3, kernel_size=3, sigma=3, dim=2): super(GaussianSmoothingNew, self).__init__() x_coord = torch.arange(kernel_size) x_grid = x_coord.repeat(kernel_size).view(kernel_size, kernel_size) y_grid = x_grid.t() xy_grid = torch.stack([x_grid, y_grid], dim=-1).float() mean = (kernel_size - 1) / 2.0 variance = sigma ** 2.0 gaussian_kernel = 1.0 / (2.0 * math.pi * variance) * torch.exp(- torch.sum((xy_grid - mean) ** 2.0, dim=-1) / (2 * variance)) gaussian_kernel = gaussian_kernel / torch.sum(gaussian_kernel) gaussian_kernel = gaussian_kernel.view(1, 1, kernel_size, kernel_size) gaussian_kernel = gaussian_kernel.repeat(channels, 1, 1, 1) self.gaussian_filter = nn.Conv2d(in_channels=channels, out_channels =channels, kernel_size=kernel_size, groups=channels, bias=False, padding=(kernel_size - 1) // 2) self.gaussian_filter.weight.data = gaussian_kernel self.gaussian_filter.weight.requires_grad = False def forward(self, input_0): arg0_1 = self.gaussian_filter.weight arg1_1 = input_0 output = call([arg0_1, arg1_1]) return output[0]
rakshithShetty/SemanticAdversary
GaussianSmoothing
false
7,528
[ "MIT" ]
1
e6d50f00af6f7d847cba4210613afea4be773254
https://github.com/rakshithShetty/SemanticAdversary/tree/e6d50f00af6f7d847cba4210613afea4be773254
TransformerEncoderLayer
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.parallel import torch.utils.data import torch.distributions class TransformerEncoderLayer(nn.Module): def __init__(self, embed_dim, num_heads, hidden_size, dropout=0.0, attention_dropout=0.0, activation_dropout=0.0): super().__init__() self.embed_dim = embed_dim self.self_attn = torch.nn.MultiheadAttention(embed_dim=self. embed_dim, num_heads=num_heads, dropout=attention_dropout) self.self_attn_layer_norm = torch.nn.LayerNorm(self.embed_dim) self.dropout = dropout self.activation_dropout = activation_dropout self.normalize_before = True self.fc1 = torch.nn.Linear(self.embed_dim, hidden_size) self.fc2 = torch.nn.Linear(hidden_size, self.embed_dim) self.layer_norm = torch.nn.LayerNorm(self.embed_dim) self.init_parameters() def forward(self, x, key_padding_mask=None, attn_mask=None): residual = x x = self.self_attn_layer_norm(x) x, _att = self.self_attn(query=x, key=x, value=x, key_padding_mask= key_padding_mask, attn_mask=attn_mask) x = F.dropout(x, p=self.dropout, training=self.training) x = residual + x residual = x x = self.layer_norm(x) x = F.relu(self.fc1(x)) x = F.dropout(x, p=self.activation_dropout, training=self.training) x = self.fc2(x) x = F.dropout(x, p=self.dropout, training=self.training) x = residual + x return x def init_parameters(self): nn.init.xavier_uniform_(self.fc1.weight) nn.init.constant_(self.fc1.bias, 0.0) nn.init.xavier_uniform_(self.fc2.weight) nn.init.constant_(self.fc2.bias, 0.0) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'embed_dim': 4, 'num_heads': 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 from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.nn.parallel import torch.utils.data import torch.distributions assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-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_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__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 = 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_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tmp27 / tmp15 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_9(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_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_out_ptr0 + 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, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (12, 4), (4, 1)) assert_size_stride(primals_5, (12,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (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,)) assert_size_stride(primals_12, (4, 4), (4, 1)) assert_size_stride(primals_13, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(4)](primals_1, buf0, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(16)](primals_1, buf0, buf1, primals_2, primals_3, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 del primals_3 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf3) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 4), buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 16), alpha= 1, beta=1, out=buf4) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 8), buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 32), alpha= 1, beta=1, out=buf5) buf6 = reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 16), 0) del buf3 triton_poi_fused_mul_2[grid(16)](buf6, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf6, reinterpret_tensor(buf4, (4, 1, 4), (1, 1, 4), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = buf7 del buf7 triton_poi_fused__softmax_4[grid(64)](buf8, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf8 buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf9, reinterpret_tensor(buf5, (4, 4, 1), (1, 4, 1), 0), out=buf10) buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_clone_5[grid(4, 4)](buf10, buf11, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf12 = reinterpret_tensor(buf10, (4, 4), (4, 1), 0) del buf10 extern_kernels.addmm(primals_7, reinterpret_tensor(buf11, (4, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_7 buf13 = buf1 del buf1 buf14 = buf0 del buf0 triton_poi_fused_add_native_layer_norm_6[grid(4)](primals_1, buf12, buf13, buf14, 4, XBLOCK=4, num_warps=1, num_stages=1) buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_7[grid(16)](primals_1, buf12, buf13, buf14, primals_8, primals_9, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf13 del buf14 del primals_9 buf16 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf15, reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf16) buf17 = buf16 del buf16 triton_poi_fused_relu_8[grid(16)](buf17, primals_11, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_11 buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf17, reinterpret_tensor(primals_12, (4, 4), (1, 4), 0), out=buf18) buf19 = buf18 del buf18 triton_poi_fused_add_9[grid(16)](buf19, primals_1, buf12, primals_13, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_13 return (buf19, primals_1, primals_8, buf2, buf9, reinterpret_tensor( buf11, (4, 4), (4, 1), 0), buf12, buf15, buf17, primals_12, primals_10, primals_6, reinterpret_tensor(buf5, (4, 1, 4), (1, 1, 4 ), 0), reinterpret_tensor(buf6, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf4, (4, 4, 1), (1, 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (4, 1), 32), reinterpret_tensor(primals_4, (4, 4), (4, 1), 16), reinterpret_tensor(primals_4, (4, 4), (4, 1), 0)) class TransformerEncoderLayerNew(nn.Module): def __init__(self, embed_dim, num_heads, hidden_size, dropout=0.0, attention_dropout=0.0, activation_dropout=0.0): super().__init__() self.embed_dim = embed_dim self.self_attn = torch.nn.MultiheadAttention(embed_dim=self. embed_dim, num_heads=num_heads, dropout=attention_dropout) self.self_attn_layer_norm = torch.nn.LayerNorm(self.embed_dim) self.dropout = dropout self.activation_dropout = activation_dropout self.normalize_before = True self.fc1 = torch.nn.Linear(self.embed_dim, hidden_size) self.fc2 = torch.nn.Linear(hidden_size, self.embed_dim) self.layer_norm = torch.nn.LayerNorm(self.embed_dim) self.init_parameters() def init_parameters(self): nn.init.xavier_uniform_(self.fc1.weight) nn.init.constant_(self.fc1.bias, 0.0) nn.init.xavier_uniform_(self.fc2.weight) nn.init.constant_(self.fc2.bias, 0.0) def forward(self, input_0): primals_4 = self.self_attn.in_proj_weight primals_5 = self.self_attn.in_proj_bias primals_1 = self.self_attn.out_proj.weight primals_2 = self.self_attn.out_proj.bias primals_3 = self.self_attn_layer_norm.weight primals_7 = self.self_attn_layer_norm.bias primals_6 = self.fc1.weight primals_8 = self.fc1.bias primals_10 = self.fc2.weight primals_9 = self.fc2.bias primals_11 = self.layer_norm.weight primals_13 = self.layer_norm.bias primals_12 = 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]
ptigas/EGG
TransformerEncoderLayer
false
7,529
[ "MIT" ]
1
5319cc9de2c17bc72de717737cfbb5be2285c59b
https://github.com/ptigas/EGG/tree/5319cc9de2c17bc72de717737cfbb5be2285c59b
FocalLoss
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.nn.functional as F def focal_loss(input_values, gamma): """Computes the focal loss""" p = torch.exp(-input_values) loss = (1 - p) ** gamma * input_values return loss.mean() class FocalLoss(nn.Module): def __init__(self, weight=None, gamma=0.0): super(FocalLoss, self).__init__() assert gamma >= 0 self.gamma = gamma self.weight = weight def forward(self, input, target): return focal_loss(F.cross_entropy(input, target, reduction='none', weight=self.weight), self.gamma) 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.nn.parallel import torch.optim import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 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_exp_mean_mul_neg_pow_rsub_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) tmp2 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp5 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp8 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp13 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp16 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp20 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp24 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp1 = tl_math.exp(tmp0) tmp3 = tl_math.exp(tmp2) tmp4 = tmp1 + tmp3 tmp6 = tl_math.exp(tmp5) tmp7 = tmp4 + tmp6 tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp11 = tl_math.log(tmp10) tmp12 = tmp0 - tmp11 tmp14 = tmp12 * tmp13 tmp15 = tmp2 - tmp11 tmp17 = tmp15 * tmp16 tmp18 = tmp14 + tmp17 tmp19 = tmp5 - tmp11 tmp21 = tmp19 * tmp20 tmp22 = tmp18 + tmp21 tmp23 = tmp8 - tmp11 tmp25 = tmp23 * tmp24 tmp26 = tmp22 + tmp25 tmp27 = -tmp26 tmp28 = -tmp27 tmp29 = tl_math.exp(tmp28) tmp30 = 1.0 tmp30 - tmp29 tmp32 = tmp30 * tmp27 tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK]) tmp35 = tl.sum(tmp33, 1)[:, None] tmp36 = 64.0 tmp37 = tmp35 / tmp36 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp37, 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_exp_mean_mul_neg_pow_rsub_sum_1[grid(1)]( buf3, buf0, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del buf0 return buf3, def focal_loss(input_values, gamma): """Computes the focal loss""" p = torch.exp(-input_values) loss = (1 - p) ** gamma * input_values return loss.mean() class FocalLossNew(nn.Module): def __init__(self, weight=None, gamma=0.0): super(FocalLossNew, self).__init__() assert gamma >= 0 self.gamma = gamma self.weight = weight def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
raman32/LDAM-DRW
FocalLoss
false
7,530
[ "MIT" ]
1
7ce2251c01b94c7259108a1e188457f0b720651d
https://github.com/raman32/LDAM-DRW/tree/7ce2251c01b94c7259108a1e188457f0b720651d
F_conv
import torch import warnings import torch.nn as nn import torch.nn.functional as F class F_conv(nn.Module): """ResNet transformation, not itself reversible, just used below""" def __init__(self, in_channels, channels, channels_hidden=None, stride= None, kernel_size=3, leaky_slope=0.1, batch_norm=False): super(F_conv, self).__init__() if stride: warnings.warn( "Stride doesn't do anything, the argument should be removed", DeprecationWarning) if not channels_hidden: channels_hidden = channels pad = kernel_size // 2 self.leaky_slope = leaky_slope self.conv1 = nn.Conv2d(in_channels, channels_hidden, kernel_size= kernel_size, padding=pad, bias=not batch_norm) self.conv2 = nn.Conv2d(channels_hidden, channels_hidden, kernel_size=kernel_size, padding=pad, bias=not batch_norm) self.conv3 = nn.Conv2d(channels_hidden, channels, kernel_size= kernel_size, padding=pad, bias=not batch_norm) if batch_norm: self.bn1 = nn.BatchNorm2d(channels_hidden) self.bn1.weight.data.fill_(1) self.bn2 = nn.BatchNorm2d(channels_hidden) self.bn2.weight.data.fill_(1) self.bn3 = nn.BatchNorm2d(channels) self.bn3.weight.data.fill_(1) self.batch_norm = batch_norm def forward(self, x): out = self.conv1(x) if self.batch_norm: out = self.bn1(out) out = F.leaky_relu(out, self.leaky_slope) out = self.conv2(out) if self.batch_norm: out = self.bn2(out) out = F.leaky_relu(out, self.leaky_slope) out = self.conv3(out) if self.batch_norm: out = self.bn3(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, '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 warnings 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 = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) @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, primals_6, primals_7) = 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, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf0, primals_2, buf1, buf2, 256, XBLOCK=128, 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, 4, 4, 4), (64, 16, 4, 1)) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf5 = buf0 del buf0 triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf3, primals_5, buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf3 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, 4, 4, 4), (64, 16, 4, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_1[grid(256)](buf7, primals_7, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return (buf7, primals_1, primals_3, primals_4, primals_6, buf1, buf2, buf4, buf5) class F_convNew(nn.Module): """ResNet transformation, not itself reversible, just used below""" def __init__(self, in_channels, channels, channels_hidden=None, stride= None, kernel_size=3, leaky_slope=0.1, batch_norm=False): super(F_convNew, self).__init__() if stride: warnings.warn( "Stride doesn't do anything, the argument should be removed", DeprecationWarning) if not channels_hidden: channels_hidden = channels pad = kernel_size // 2 self.leaky_slope = leaky_slope self.conv1 = nn.Conv2d(in_channels, channels_hidden, kernel_size= kernel_size, padding=pad, bias=not batch_norm) self.conv2 = nn.Conv2d(channels_hidden, channels_hidden, kernel_size=kernel_size, padding=pad, bias=not batch_norm) self.conv3 = nn.Conv2d(channels_hidden, channels, kernel_size= kernel_size, padding=pad, bias=not batch_norm) if batch_norm: self.bn1 = nn.BatchNorm2d(channels_hidden) self.bn1.weight.data.fill_(1) self.bn2 = nn.BatchNorm2d(channels_hidden) self.bn2.weight.data.fill_(1) self.bn3 = nn.BatchNorm2d(channels) self.bn3.weight.data.fill_(1) self.batch_norm = batch_norm 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]
ramonpeter/LaSeR
F_conv
false
7,531
[ "MIT" ]
1
28daa6876256501ed0d3e84a4ddfedc7892bd528
https://github.com/ramonpeter/LaSeR/tree/28daa6876256501ed0d3e84a4ddfedc7892bd528
Critic
import torch class Critic(torch.nn.Module): def __init__(self, critic_lr, critic_epochs): super(Critic, self).__init__() self.initialize_network() self.optimizer = torch.optim.Adam(lr=critic_lr, params=self. parameters()) self.loss = torch.nn.MSELoss() self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self def initialize_network(self): self.fc1 = torch.nn.Linear(1024, 64) self.fc2 = torch.nn.Linear(64, 64) self.fc3 = torch.nn.Linear(64, 1) self.relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.conv1 = torch.nn.Conv2d(3, 32, kernel_size=4, stride=2) self.conv2 = torch.nn.Conv2d(32, 64, kernel_size=4, stride=2) self.conv3 = torch.nn.Conv2d(64, 128, kernel_size=4, stride=2) self.conv4 = torch.nn.Conv2d(128, 256, kernel_size=4, stride=2) def forward(self, x): out = torch.Tensor(x) out = self.conv1(out) out = self.relu(out) out = self.conv2(out) out = self.relu(out) out = self.conv3(out) out = self.relu(out) out = self.conv4(out) out = self.relu(out) out = out.reshape(-1, 1024) out = self.fc1(out) out = self.tanh(out) out = self.fc2(out) out = self.tanh(out) out = self.fc3(out) out = self.relu(out) return out def optimize(self, states, rewards, epochs, batch_sz): n_samples = rewards.shape[0] num_batch = int(n_samples // batch_sz) for i in tqdm(range(epochs)): for b in range(num_batch): s = states[b * batch_sz:(b + 1) * batch_sz] r = rewards[b * batch_sz:(b + 1) * batch_sz] p = self.forward(s) loss = self.loss(p, r) self.optimizer.zero_grad() loss.backward() self.optimizer.step() s = states[num_batch * batch_sz:] r = rewards[num_batch * batch_sz:] p = self.forward(s) loss = self.loss(p, r) self.optimizer.zero_grad() loss.backward() self.optimizer.step() def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {'critic_lr': 4, 'critic_epochs': 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 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 = 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_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 96 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 % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 48 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_2(in_ptr0, 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 y3 = yindex y0 = yindex % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 512 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, 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 y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 64 * x2 + 1024 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_4(in_ptr0, 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 y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 128 * x2 + 2048 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 123008 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 50176 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_7(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) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, 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 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_8(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 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 x1 = xindex y0 = yindex y2 = yindex % 4 y3 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x1 + 256 * y0), xmask & ymask, eviction_policy='evict_last') 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 + (x1 + 256 * y0), tmp4, xmask & ymask) tl.store(out_ptr1 + (y2 + 4 * x1 + 1024 * y3), tmp7, xmask & ymask) @triton.jit def triton_poi_fused_tanh_9(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 % 64 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_leaky_relu_10(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = 0.0 tmp5 = tmp3 > tmp4 tmp6 = 0.01 tmp7 = tmp3 * tmp6 tmp8 = tl.where(tmp5, tmp3, tmp7) tl.store(out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr1 + x0, tmp8, 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, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_2, (32, 3, 4, 4), (48, 16, 4, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (256, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (64, 1024), (1024, 1)) assert_size_stride(primals_11, (64,), (1,)) assert_size_stride(primals_12, (64, 64), (64, 1)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (1, 64), (64, 1)) assert_size_stride(primals_15, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) get_raw_stream(0) triton_poi_fused_0[grid(12, 4096)](primals_1, buf0, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((32, 3, 4, 4), (48, 1, 12, 3), torch.float32) triton_poi_fused_1[grid(96, 16)](primals_2, buf1, 96, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 32, 4, 4), (512, 1, 128, 32), torch. float32) triton_poi_fused_2[grid(2048, 16)](primals_4, buf2, 2048, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((128, 64, 4, 4), (1024, 1, 256, 64), torch.float32) triton_poi_fused_3[grid(8192, 16)](primals_6, buf3, 8192, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = empty_strided_cuda((256, 128, 4, 4), (2048, 1, 512, 128), torch.float32) triton_poi_fused_4[grid(32768, 16)](primals_8, buf4, 32768, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf5 = extern_kernels.convolution(buf0, buf1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 32, 31, 31), (30752, 1, 992, 32)) buf6 = empty_strided_cuda((4, 32, 31, 31), (30752, 1, 992, 32), torch.bool) buf7 = empty_strided_cuda((4, 32, 31, 31), (30752, 1, 992, 32), torch.float32) triton_poi_fused_convolution_leaky_relu_5[grid(123008)](buf5, primals_3, buf6, buf7, 123008, XBLOCK=1024, num_warps=4, num_stages=1) del buf5 del primals_3 buf8 = extern_kernels.convolution(buf7, buf2, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 14, 14), (12544, 1, 896, 64)) buf9 = empty_strided_cuda((4, 64, 14, 14), (12544, 1, 896, 64), torch.bool) buf10 = empty_strided_cuda((4, 64, 14, 14), (12544, 1, 896, 64), torch.float32) triton_poi_fused_convolution_leaky_relu_6[grid(50176)](buf8, primals_5, buf9, buf10, 50176, XBLOCK=512, num_warps=4, num_stages=1) del buf8 del primals_5 buf11 = extern_kernels.convolution(buf10, buf3, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 128, 6, 6), (4608, 1, 768, 128)) buf12 = empty_strided_cuda((4, 128, 6, 6), (4608, 1, 768, 128), torch.bool) buf13 = empty_strided_cuda((4, 128, 6, 6), (4608, 1, 768, 128), torch.float32) triton_poi_fused_convolution_leaky_relu_7[grid(18432)](buf11, primals_7, buf12, buf13, 18432, XBLOCK=256, num_warps=4, num_stages=1) del buf11 del primals_7 buf14 = extern_kernels.convolution(buf13, buf4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 2, 2), (1024, 1, 512, 256)) buf15 = empty_strided_cuda((4, 256, 2, 2), (1024, 1, 512, 256), torch.bool) buf16 = empty_strided_cuda((4, 256, 2, 2), (1024, 4, 2, 1), torch. float32) triton_poi_fused_convolution_leaky_relu_8[grid(16, 256)](buf14, primals_9, buf15, buf16, 16, 256, XBLOCK=256, YBLOCK=1, num_warps=4, num_stages=1) del buf14 del primals_9 buf17 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf16, (4, 1024), (1024, 1), 0 ), reinterpret_tensor(primals_10, (1024, 64), (1, 1024), 0), out=buf17) buf18 = buf17 del buf17 triton_poi_fused_tanh_9[grid(256)](buf18, primals_11, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_11 buf19 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf18, reinterpret_tensor(primals_12, (64, 64), ( 1, 64), 0), out=buf19) buf20 = buf19 del buf19 triton_poi_fused_tanh_9[grid(256)](buf20, primals_13, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_13 buf21 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.mm(buf20, reinterpret_tensor(primals_14, (64, 1), (1, 64), 0), out=buf21) buf22 = empty_strided_cuda((4, 1), (1, 1), torch.bool) buf23 = empty_strided_cuda((4, 1), (1, 1), torch.float32) triton_poi_fused_leaky_relu_10[grid(4)](buf21, primals_15, buf22, buf23, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf21 del primals_15 return (buf23, buf0, buf1, buf2, buf3, buf4, buf6, buf7, buf9, buf10, buf12, buf13, buf15, reinterpret_tensor(buf16, (4, 1024), (1024, 1), 0), buf18, buf20, buf22, primals_14, primals_12, primals_10) class CriticNew(torch.nn.Module): def __init__(self, critic_lr, critic_epochs): super(CriticNew, self).__init__() self.initialize_network() self.optimizer = torch.optim.Adam(lr=critic_lr, params=self. parameters()) self.loss = torch.nn.MSELoss() self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self def initialize_network(self): self.fc1 = torch.nn.Linear(1024, 64) self.fc2 = torch.nn.Linear(64, 64) self.fc3 = torch.nn.Linear(64, 1) self.relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.conv1 = torch.nn.Conv2d(3, 32, kernel_size=4, stride=2) self.conv2 = torch.nn.Conv2d(32, 64, kernel_size=4, stride=2) self.conv3 = torch.nn.Conv2d(64, 128, kernel_size=4, stride=2) self.conv4 = torch.nn.Conv2d(128, 256, kernel_size=4, stride=2) def optimize(self, states, rewards, epochs, batch_sz): n_samples = rewards.shape[0] num_batch = int(n_samples // batch_sz) for i in tqdm(range(epochs)): for b in range(num_batch): s = states[b * batch_sz:(b + 1) * batch_sz] r = rewards[b * batch_sz:(b + 1) * batch_sz] p = self.forward(s) loss = self.loss(p, r) self.optimizer.zero_grad() loss.backward() self.optimizer.step() s = states[num_batch * batch_sz:] r = rewards[num_batch * batch_sz:] p = self.forward(s) loss = self.loss(p, r) self.optimizer.zero_grad() loss.backward() self.optimizer.step() def forward(self, input_0): primals_10 = self.fc1.weight primals_5 = self.fc1.bias primals_12 = self.fc2.weight primals_11 = self.fc2.bias primals_14 = self.fc3.weight primals_15 = self.fc3.bias primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_13 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.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]) return output[0]
Gregory-Eales/Proximal-Policy-Optimization
Critic
false
7,532
[ "Apache-2.0" ]
1
134f930bd1436c34e79af9344fe70f75e11c8a30
https://github.com/Gregory-Eales/Proximal-Policy-Optimization/tree/134f930bd1436c34e79af9344fe70f75e11c8a30
scaleCompositor
import torch import torch.nn as nn class ResBlock(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlock, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return x + self.act(self.conv2(self.act(self.conv1(x)))) class scaleCompositor(nn.Module): def __init__(self, in_ch, hid_ch): super(scaleCompositor, self).__init__() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=1) self.conv2 = nn.Conv2d(hid_ch, 1, kernel_size=1) self.resblock1 = ResBlock(hid_ch, hid_ch) self.resblock2 = ResBlock(hid_ch, hid_ch) self.act = nn.Sigmoid() self.downsample = nn.MaxPool2d(2) self.upsample = nn.Upsample(scale_factor=2, mode='nearest') def forward(self, f, c): x = torch.cat((f, c), dim=1) UDf = self.upsample(self.downsample(f)) scale = self.conv2(self.resblock2(self.resblock1(self.conv1(x)))) scale = self.act(scale) return f - torch.matmul(scale, UDf) + torch.matmul(scale, c) def get_inputs(): return [torch.rand([4, 1, 4, 4]), torch.rand([4, 3, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'hid_ch': 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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 4 x0 = xindex % 16 x2 = xindex // 64 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 4, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 48 * x2), tmp6 & xmask, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_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_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_3(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) @triton.jit def triton_poi_fused_convolution_sigmoid_4(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp3, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_max_pool2d_with_indices_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 x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (2 * tmp8 + 8 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tmp11 = triton_helpers.maximum(tmp10, tmp9) tmp12 = tl.load(in_ptr0 + (4 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp14 = tl.load(in_ptr0 + (5 + 2 * tmp8 + 8 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x4, tmp15, xmask) @triton.jit def triton_poi_fused_clone_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 48 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_add_sub_7(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 48 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_out_ptr0 + x3, xmask) tmp2 = tmp0 - tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, 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, 1, 4, 4), (16, 16, 4, 1)) assert_size_stride(primals_2, (4, 3, 4, 4), (48, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_6, (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, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_14, (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) get_raw_stream(0) triton_poi_fused_cat_0[grid(256)](primals_1, primals_2, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) buf1 = 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(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_4 buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_relu_2[grid(256)](buf4, primals_6, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_6 buf5 = extern_kernels.convolution(buf4, primals_7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1)) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf20 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_3[grid(256)]( buf2, buf5, primals_8, buf6, buf20, 256, XBLOCK=128, num_warps= 4, num_stages=1) del primals_8 buf7 = extern_kernels.convolution(buf6, primals_9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1)) buf8 = buf7 del buf7 triton_poi_fused_convolution_relu_2[grid(256)](buf8, primals_10, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_10 buf9 = extern_kernels.convolution(buf8, primals_11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 4, 4, 4), (64, 16, 4, 1)) buf10 = buf5 del buf5 buf19 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_3[grid(256)]( buf6, buf9, primals_12, buf10, buf19, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf9 del primals_12 buf11 = extern_kernels.convolution(buf10, primals_13, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 1, 4, 4), (16, 16, 4, 1)) buf12 = buf11 del buf11 buf14 = empty_strided_cuda((4, 1, 4, 4), (16, 1, 4, 1), torch.float32) triton_poi_fused_convolution_sigmoid_4[grid(64)](buf12, primals_14, buf14, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_14 buf13 = empty_strided_cuda((4, 1, 4, 4), (16, 1, 4, 1), torch.float32) triton_poi_fused__unsafe_index_max_pool2d_with_indices_5[grid(64)]( primals_1, buf13, 64, XBLOCK=64, num_warps=1, num_stages=1) buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf14, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf13, (4, 4, 4), (16, 4, 1), 0), out=buf15) buf16 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) triton_poi_fused_clone_6[grid(192)](buf14, buf16, 192, XBLOCK=256, num_warps=4, num_stages=1) del buf14 buf17 = empty_strided_cuda((12, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf16, (12, 4, 4), (16, 4, 1), 0), reinterpret_tensor(primals_2, (12, 4, 4), (16, 4, 1), 0), out=buf17) del buf16 buf18 = reinterpret_tensor(buf17, (4, 3, 4, 4), (48, 16, 4, 1), 0) del buf17 triton_poi_fused_add_sub_7[grid(192)](buf18, primals_1, buf15, 192, XBLOCK=256, num_warps=4, num_stages=1) del buf15 del primals_1 return (buf18, primals_3, primals_5, primals_7, primals_9, primals_11, primals_13, buf0, buf2, buf4, buf6, buf8, buf10, buf12, reinterpret_tensor(primals_2, (12, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf13, (4, 4, 4), (16, 1, 4), 0), buf19, buf20) class ResBlock(nn.Module): def __init__(self, in_ch, hid_ch): super(ResBlock, self).__init__() self.act = nn.ReLU() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=3, padding=1) self.conv2 = nn.Conv2d(hid_ch, hid_ch, kernel_size=3, padding=1) def forward(self, x): return x + self.act(self.conv2(self.act(self.conv1(x)))) class scaleCompositorNew(nn.Module): def __init__(self, in_ch, hid_ch): super(scaleCompositorNew, self).__init__() self.conv1 = nn.Conv2d(in_ch, hid_ch, kernel_size=1) self.conv2 = nn.Conv2d(hid_ch, 1, kernel_size=1) self.resblock1 = ResBlock(hid_ch, hid_ch) self.resblock2 = ResBlock(hid_ch, hid_ch) self.act = nn.Sigmoid() self.downsample = nn.MaxPool2d(2) self.upsample = nn.Upsample(scale_factor=2, mode='nearest') def forward(self, input_0, input_1): primals_3 = self.conv1.weight primals_4 = self.conv1.bias primals_13 = self.conv2.weight primals_14 = self.conv2.bias primals_5 = self.resblock1.conv1.weight primals_6 = self.resblock1.conv1.bias primals_7 = self.resblock1.conv2.weight primals_8 = self.resblock1.conv2.bias primals_9 = self.resblock2.conv1.weight primals_10 = self.resblock2.conv1.bias primals_11 = self.resblock2.conv2.weight primals_12 = self.resblock2.conv2.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]
qbhan/pathembed
scaleCompositor
false
7,533
[ "MIT" ]
1
c21823529840593bf606e10696f5879e5adb51b2
https://github.com/qbhan/pathembed/tree/c21823529840593bf606e10696f5879e5adb51b2
NormedLinear
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.nn.functional as F from torch.nn import Parameter class NormedLinear(nn.Module): def __init__(self, in_features, out_features): super(NormedLinear, self).__init__() self.weight = Parameter(torch.Tensor(in_features, out_features)) self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0) def forward(self, x): out = F.normalize(x, dim=1).mm(F.normalize(self.weight, dim=0)) return out def get_inputs(): return [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 from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused_div_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 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (12 + 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 tl.store(out_ptr0 + x2, tmp15, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_1[grid(16)](primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, buf1, out=buf2) del buf1 return buf2, primals_2, reinterpret_tensor(buf0, (4, 4), (1, 4), 0) class NormedLinearNew(nn.Module): def __init__(self, in_features, out_features): super(NormedLinearNew, self).__init__() self.weight = Parameter(torch.Tensor(in_features, out_features)) self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0) def forward(self, input_0): primals_1 = self.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
raman32/LDAM-DRW
NormedLinear
false
7,534
[ "MIT" ]
1
7ce2251c01b94c7259108a1e188457f0b720651d
https://github.com/raman32/LDAM-DRW/tree/7ce2251c01b94c7259108a1e188457f0b720651d
ParagraphPlanSelectionAttention
import torch import torch.nn as nn import torch.nn.functional as F import torch.cuda import torch.distributed def aeq(*args): """ Assert all arguments have the same value """ arguments = (arg for arg in args) first = next(arguments) assert all(arg == first for arg in arguments ), 'Not all arguments have the same value: ' + str(args) def sequence_mask(lengths, max_len=None): """ Creates a boolean mask from sequence lengths. """ batch_size = lengths.numel() max_len = max_len or lengths.max() return torch.arange(0, max_len, device=lengths.device).type_as(lengths ).repeat(batch_size, 1).lt(lengths.unsqueeze(1)) class ParagraphPlanSelectionAttention(nn.Module): def __init__(self, dim): super(ParagraphPlanSelectionAttention, self).__init__() self.dim = dim def score(self, h_t, h_s): src_batch, _src_len, src_dim = h_s.size() tgt_batch, tgt_len, tgt_dim = h_t.size() aeq(src_batch, tgt_batch) aeq(src_dim, tgt_dim) aeq(src_dim, self.dim) h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim) h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim) h_s_ = h_s.transpose(1, 2) return torch.bmm(h_t, h_s_) def forward(self, source, memory_bank, memory_lengths=None): """ Args :param source (FloatTensor): query vectors ``(batch, tgt_len, dim)`` :param memory_bank (FloatTensor): source vectors ``(batch, src_len, dim)`` :param memory_lengths (LongTensor): the source context lengths ``(batch,)`` :return: """ batch, source_l, dim = memory_bank.size() batch_, target_l, dim_ = source.size() aeq(batch, batch_) aeq(dim, dim_) aeq(self.dim, dim) align = self.score(source, memory_bank) if memory_lengths is not None: mask = sequence_mask(memory_lengths, max_len=align.size(-1)) mask = mask.unsqueeze(1) align.masked_fill_(~mask, -float('inf')) align_vectors = F.log_softmax(align.view(batch * target_l, source_l ), -1) align_vectors = align_vectors.view(batch, target_l, source_l) return align_vectors def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.cuda import torch.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__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') 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 = 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 + x2, tmp13, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), ( 16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0) del buf0 triton_poi_fused__log_softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 return reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0), def aeq(*args): """ Assert all arguments have the same value """ arguments = (arg for arg in args) first = next(arguments) assert all(arg == first for arg in arguments ), 'Not all arguments have the same value: ' + str(args) def sequence_mask(lengths, max_len=None): """ Creates a boolean mask from sequence lengths. """ batch_size = lengths.numel() max_len = max_len or lengths.max() return torch.arange(0, max_len, device=lengths.device).type_as(lengths ).repeat(batch_size, 1).lt(lengths.unsqueeze(1)) class ParagraphPlanSelectionAttentionNew(nn.Module): def __init__(self, dim): super(ParagraphPlanSelectionAttentionNew, self).__init__() self.dim = dim def score(self, h_t, h_s): src_batch, _src_len, src_dim = h_s.size() tgt_batch, tgt_len, tgt_dim = h_t.size() aeq(src_batch, tgt_batch) aeq(src_dim, tgt_dim) aeq(src_dim, self.dim) h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim) h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim) h_s_ = h_s.transpose(1, 2) return torch.bmm(h_t, h_s_) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
ratishsp/data2text-seq-plan-py
ParagraphPlanSelectionAttention
false
7,535
[ "MIT" ]
1
16b5242903371280cae8d23ad5a2472d539ea744
https://github.com/ratishsp/data2text-seq-plan-py/tree/16b5242903371280cae8d23ad5a2472d539ea744
GlobalAttentionContext
import torch import torch.nn as nn import torch.nn.functional as F import torch.cuda import torch.distributed def aeq(*args): """ Assert all arguments have the same value """ arguments = (arg for arg in args) first = next(arguments) assert all(arg == first for arg in arguments ), 'Not all arguments have the same value: ' + str(args) def sequence_mask(lengths, max_len=None): """ Creates a boolean mask from sequence lengths. """ batch_size = lengths.numel() max_len = max_len or lengths.max() return torch.arange(0, max_len, device=lengths.device).type_as(lengths ).repeat(batch_size, 1).lt(lengths.unsqueeze(1)) class GlobalAttentionContext(nn.Module): """ Global attention takes a matrix and a query vector. It then computes a parameterized convex combination of the matrix based on the input query. Constructs a unit mapping a query `q` of size `dim` and a source matrix `H` of size `n x dim`, to an output of size `dim`. .. mermaid:: graph BT A[Query] subgraph RNN C[H 1] D[H 2] E[H N] end F[Attn] G[Output] A --> F C --> F D --> F E --> F C -.-> G D -.-> G E -.-> G F --> G All models compute the output as :math:`c = \\sum_{j=1}^{\\text{SeqLength}} a_j H_j` where :math:`a_j` is the softmax of a score function. Then then apply a projection layer to [q, c]. However they differ on how they compute the attention score. * Luong Attention (dot, general): * dot: :math:`\\text{score}(H_j,q) = H_j^T q` * general: :math:`\\text{score}(H_j, q) = H_j^T W_a q` * Bahdanau Attention (mlp): * :math:`\\text{score}(H_j, q) = v_a^T \\text{tanh}(W_a q + U_a h_j)` Args: dim (int): dimensionality of query and key coverage (bool): use coverage term attn_type (str): type of attention to use, options [dot,general,mlp] attn_func (str): attention function to use, options [softmax,sparsemax] """ def __init__(self, dim, coverage=False, attn_type='dot', attn_func= 'softmax'): super(GlobalAttentionContext, self).__init__() self.dim = dim assert attn_type in ['dot', 'general', 'mlp' ], 'Please select a valid attention type (got {:s}).'.format( attn_type) self.attn_type = attn_type assert attn_func in ['softmax', 'sparsemax' ], 'Please select a valid attention function.' self.attn_func = attn_func self.source = nn.Parameter(torch.Tensor(1, dim)) if self.attn_type == 'general': self.linear_in = nn.Linear(dim, dim, bias=False) elif self.attn_type == 'mlp': self.linear_context = nn.Linear(dim, dim, bias=False) self.linear_query = nn.Linear(dim, dim, bias=True) self.v = nn.Linear(dim, 1, bias=False) if coverage: self.linear_cover = nn.Linear(1, dim, bias=False) def score(self, h_t, h_s): """ Args: h_t (FloatTensor): sequence of queries ``(batch, tgt_len, dim)`` h_s (FloatTensor): sequence of sources ``(batch, src_len, dim`` Returns: FloatTensor: raw attention scores (unnormalized) for each src index ``(batch, tgt_len, src_len)`` """ src_batch, src_len, src_dim = h_s.size() tgt_batch, tgt_len, tgt_dim = h_t.size() aeq(src_batch, tgt_batch) aeq(src_dim, tgt_dim) aeq(self.dim, src_dim) if self.attn_type in ['general', 'dot']: if self.attn_type == 'general': h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim) h_t_ = self.linear_in(h_t_) h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim) h_s_ = h_s.transpose(1, 2) return torch.bmm(h_t, h_s_) else: dim = self.dim wq = self.linear_query(h_t.view(-1, dim)) wq = wq.view(tgt_batch, tgt_len, 1, dim) wq = wq.expand(tgt_batch, tgt_len, src_len, dim) uh = self.linear_context(h_s.contiguous().view(-1, dim)) uh = uh.view(src_batch, 1, src_len, dim) uh = uh.expand(src_batch, tgt_len, src_len, dim) wquh = torch.tanh(wq + uh) return self.v(wquh.view(-1, dim)).view(tgt_batch, tgt_len, src_len) def forward(self, memory_bank, memory_lengths=None, coverage=None): """ Args: source (FloatTensor): query vectors ``(batch, tgt_len, dim)`` memory_bank (FloatTensor): source vectors ``(batch, src_len, dim)`` memory_lengths (LongTensor): the source context lengths ``(batch,)`` coverage (FloatTensor): None (not supported yet) Returns: (FloatTensor, FloatTensor): * Computed vector ``(tgt_len, batch, dim)`` * Attention distribtutions for each query ``(tgt_len, batch, src_len)`` """ batch, source_l, dim = memory_bank.size() source = self.source source = source.expand(batch, -1) source = source.unsqueeze(1) batch_, target_l, dim_ = source.size() aeq(batch, batch_) aeq(dim, dim_) aeq(self.dim, dim) if coverage is not None: batch_, source_l_ = coverage.size() aeq(batch, batch_) aeq(source_l, source_l_) if coverage is not None: cover = coverage.view(-1).unsqueeze(1) memory_bank += self.linear_cover(cover).view_as(memory_bank) memory_bank = torch.tanh(memory_bank) align = self.score(source, memory_bank) if memory_lengths is not None: mask = sequence_mask(memory_lengths, max_len=align.size(-1)) mask = mask.unsqueeze(1) align.masked_fill_(~mask, -float('inf')) if self.attn_func == 'softmax': align_vectors = F.softmax(align.view(batch * target_l, source_l ), -1) else: align_vectors = sparsemax(align.view(batch * target_l, source_l ), -1) align_vectors = align_vectors.view(batch, target_l, source_l) c = torch.bmm(align_vectors, memory_bank) c = c.mean(dim=1) batch_, dim_ = c.size() aeq(batch, batch_) aeq(dim, dim_) return c def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.cuda import torch.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__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_mean_2(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) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (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, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_2, (4, 1, 4), (0, 0, 1), 0), reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_1[grid(16)](buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (4, 1, 4), (4, 4, 1), 0) del buf1 extern_kernels.bmm(reinterpret_tensor(buf2, (4, 1, 4), (4, 0, 1), 0 ), primals_1, out=buf3) del buf2 buf4 = reinterpret_tensor(buf3, (4, 4), (4, 1), 0) del buf3 triton_poi_fused_mean_2[grid(16)](buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf4, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), buf0 def aeq(*args): """ Assert all arguments have the same value """ arguments = (arg for arg in args) first = next(arguments) assert all(arg == first for arg in arguments ), 'Not all arguments have the same value: ' + str(args) def sequence_mask(lengths, max_len=None): """ Creates a boolean mask from sequence lengths. """ batch_size = lengths.numel() max_len = max_len or lengths.max() return torch.arange(0, max_len, device=lengths.device).type_as(lengths ).repeat(batch_size, 1).lt(lengths.unsqueeze(1)) class GlobalAttentionContextNew(nn.Module): """ Global attention takes a matrix and a query vector. It then computes a parameterized convex combination of the matrix based on the input query. Constructs a unit mapping a query `q` of size `dim` and a source matrix `H` of size `n x dim`, to an output of size `dim`. .. mermaid:: graph BT A[Query] subgraph RNN C[H 1] D[H 2] E[H N] end F[Attn] G[Output] A --> F C --> F D --> F E --> F C -.-> G D -.-> G E -.-> G F --> G All models compute the output as :math:`c = \\sum_{j=1}^{\\text{SeqLength}} a_j H_j` where :math:`a_j` is the softmax of a score function. Then then apply a projection layer to [q, c]. However they differ on how they compute the attention score. * Luong Attention (dot, general): * dot: :math:`\\text{score}(H_j,q) = H_j^T q` * general: :math:`\\text{score}(H_j, q) = H_j^T W_a q` * Bahdanau Attention (mlp): * :math:`\\text{score}(H_j, q) = v_a^T \\text{tanh}(W_a q + U_a h_j)` Args: dim (int): dimensionality of query and key coverage (bool): use coverage term attn_type (str): type of attention to use, options [dot,general,mlp] attn_func (str): attention function to use, options [softmax,sparsemax] """ def __init__(self, dim, coverage=False, attn_type='dot', attn_func= 'softmax'): super(GlobalAttentionContextNew, self).__init__() self.dim = dim assert attn_type in ['dot', 'general', 'mlp' ], 'Please select a valid attention type (got {:s}).'.format( attn_type) self.attn_type = attn_type assert attn_func in ['softmax', 'sparsemax' ], 'Please select a valid attention function.' self.attn_func = attn_func self.source = nn.Parameter(torch.Tensor(1, dim)) if self.attn_type == 'general': self.linear_in = nn.Linear(dim, dim, bias=False) elif self.attn_type == 'mlp': self.linear_context = nn.Linear(dim, dim, bias=False) self.linear_query = nn.Linear(dim, dim, bias=True) self.v = nn.Linear(dim, 1, bias=False) if coverage: self.linear_cover = nn.Linear(1, dim, bias=False) def score(self, h_t, h_s): """ Args: h_t (FloatTensor): sequence of queries ``(batch, tgt_len, dim)`` h_s (FloatTensor): sequence of sources ``(batch, src_len, dim`` Returns: FloatTensor: raw attention scores (unnormalized) for each src index ``(batch, tgt_len, src_len)`` """ src_batch, src_len, src_dim = h_s.size() tgt_batch, tgt_len, tgt_dim = h_t.size() aeq(src_batch, tgt_batch) aeq(src_dim, tgt_dim) aeq(self.dim, src_dim) if self.attn_type in ['general', 'dot']: if self.attn_type == 'general': h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim) h_t_ = self.linear_in(h_t_) h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim) h_s_ = h_s.transpose(1, 2) return torch.bmm(h_t, h_s_) else: dim = self.dim wq = self.linear_query(h_t.view(-1, dim)) wq = wq.view(tgt_batch, tgt_len, 1, dim) wq = wq.expand(tgt_batch, tgt_len, src_len, dim) uh = self.linear_context(h_s.contiguous().view(-1, dim)) uh = uh.view(src_batch, 1, src_len, dim) uh = uh.expand(src_batch, tgt_len, src_len, dim) wquh = torch.tanh(wq + uh) return self.v(wquh.view(-1, dim)).view(tgt_batch, tgt_len, src_len) def forward(self, input_0): primals_2 = self.source primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
ratishsp/data2text-seq-plan-py
GlobalAttentionContext
false
7,537
[ "MIT" ]
1
16b5242903371280cae8d23ad5a2472d539ea744
https://github.com/ratishsp/data2text-seq-plan-py/tree/16b5242903371280cae8d23ad5a2472d539ea744
CCX_loss
import torch import torch.utils.data import torch.nn as nn class CCX_loss(nn.Module): def __init__(self, eps=1e-06, h=0.5): super(CCX_loss, self).__init__() self.eps = eps self.h = h def forward(self, x, y): N, C, _H, _W = x.size() y_mu = y.mean(3).mean(2).mean(0).reshape(1, -1, 1, 1) x_centered = x - y_mu y_centered = y - y_mu x_normalized = x_centered / torch.norm(x_centered, p=2, dim=1, keepdim=True) y_normalized = y_centered / torch.norm(y_centered, p=2, dim=1, keepdim=True) x_normalized = x_normalized.reshape(N, C, -1) y_normalized = y_normalized.reshape(N, C, -1) cosine_sim = torch.bmm(x_normalized.transpose(1, 2), y_normalized) d = 1 - cosine_sim d_min, _ = torch.min(d, dim=2, keepdim=True) d_tilde = d / (d_min + self.eps) w = torch.exp((1 - d_tilde) / self.h) ccx_ij = w / torch.sum(w, dim=2, keepdim=True) ccx = torch.mean(torch.max(ccx_ij, dim=1)[0], dim=1) ccx_loss = torch.mean(-torch.log(ccx + self.eps)) return ccx_loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.utils.data 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_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp28 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp32 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp11 = tmp9 + tmp10 tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp16 = tmp15 / tmp7 tmp17 = tmp8 + tmp16 tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp24 / tmp7 tmp26 = tmp17 + tmp25 tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tmp33 = tmp31 + tmp32 tmp34 = tmp33 / tmp7 tmp35 = tmp26 + tmp34 tmp36 = tmp35 / tmp7 tl.store(out_ptr0 + x0, tmp36, xmask) @triton.jit def triton_poi_fused_sub_1(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 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + (4 + x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (8 + x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (12 + x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr2 + x3, xmask) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tmp12 = tmp11 - tmp9 tl.store(out_ptr0 + x3, tmp10, xmask) tl.store(out_ptr1 + x3, tmp12, xmask) @triton.jit def triton_poi_fused_div_linalg_vector_norm_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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp0 / tmp12 tl.store(out_ptr0 + x3, tmp13, xmask) @triton.jit def triton_per_fused_add_div_exp_min_rsub_sum_3(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, float('inf')) tmp6 = triton_helpers.min2(tmp5, 1)[:, None] tmp7 = 1e-06 tmp8 = tmp6 + tmp7 tmp9 = tmp2 / tmp8 tmp10 = tmp1 - tmp9 tmp11 = 2.0 tmp12 = tmp10 * tmp11 tmp13 = tl_math.exp(tmp12) tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tl.store(out_ptr0 + x0, tmp6, xmask) tl.store(out_ptr1 + x0, tmp17, xmask) @triton.jit def triton_per_fused_add_div_exp_max_rsub_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 16 x1 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 256 * x1), xmask, other=0.0) tmp3 = tl.load(in_ptr1 + (r2 + 16 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tl.load(in_ptr2 + (r2 + 16 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = 1e-06 tmp5 = tmp3 + tmp4 tmp6 = tmp2 / tmp5 tmp7 = tmp1 - tmp6 tmp8 = 2.0 tmp9 = tmp7 * tmp8 tmp10 = tl_math.exp(tmp9) tmp12 = tmp10 / tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, float('-inf')) tmp16 = triton_helpers.max2(tmp15, 1)[:, None] tl.store(out_ptr0 + x3, tmp16, xmask) @triton.jit def triton_per_fused_mean_5(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 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] tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_per_fused_add_log_mean_neg_6(in_out_ptr0, in_ptr0, 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) tmp1 = 16.0 tmp2 = tmp0 / tmp1 tmp3 = 1e-06 tmp4 = tmp2 + tmp3 tmp5 = tl_math.log(tmp4) tmp6 = -tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 4.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 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, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_0[grid(16)](arg1_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_sub_1[grid(256)](arg0_1, buf0, arg1_1, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del buf0 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_linalg_vector_norm_2[grid(256)](buf1, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) buf4 = buf1 del buf1 triton_poi_fused_div_linalg_vector_norm_2[grid(256)](buf2, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 buf5 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (4, 16, 4), (64, 1, 16), 0), reinterpret_tensor(buf4, (4, 4, 16), (64, 16, 1), 0), out=buf5) del buf3 del buf4 buf6 = empty_strided_cuda((4, 16, 1), (16, 1, 64), torch.float32) buf8 = empty_strided_cuda((4, 16, 1), (16, 1, 64), torch.float32) triton_per_fused_add_div_exp_min_rsub_sum_3[grid(64)](buf5, buf6, buf8, 64, 16, XBLOCK=8, num_warps=2, num_stages=1) buf9 = empty_strided_cuda((4, 16), (16, 1), torch.float32) triton_per_fused_add_div_exp_max_rsub_4[grid(64)](buf5, buf6, buf8, buf9, 64, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf5 del buf6 del buf8 buf11 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_mean_5[grid(4)](buf9, buf11, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf9 buf12 = empty_strided_cuda((), (), torch.float32) buf13 = buf12 del buf12 triton_per_fused_add_log_mean_neg_6[grid(1)](buf13, buf11, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf11 return buf13, class CCX_lossNew(nn.Module): def __init__(self, eps=1e-06, h=0.5): super(CCX_lossNew, self).__init__() self.eps = eps self.h = h def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
qwopqwop200/Fast-Invertible-Rescaling-Net
CCX_loss
false
7,538
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
DepthConv2dv2
import torch import numpy as np import torch.nn as nn from torch.autograd import Variable class tLN(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLN, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3] std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) / inp.shape[3] + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) class CausalConv2d(torch.nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=(1, 1 ), dilation=(1, 1), groups=1, bias=True): _pad = int(np.log2((kernel_size[1] - 1) / 2)) padding_2 = int(2 ** (np.log2(dilation[1]) + _pad)) self.__padding = (kernel_size[0] - 1) * dilation[0], padding_2 super(CausalConv2d, self).__init__(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=self.__padding, dilation=dilation, groups=groups, bias=bias) def forward(self, input): result = super(CausalConv2d, self).forward(input) if self.__padding[0] != 0: return result[:, :, :-self.__padding[0]] return result class DepthConv2dv2(nn.Module): def __init__(self, input_channel, hidden_channel, kernel, dilation=(1, 1), stride=(1, 1), padding=(0, 0), causal=False): super(DepthConv2dv2, self).__init__() self.padding = padding if causal: self.conv1d = CausalConv2d(input_channel, hidden_channel, kernel, stride=stride, dilation=dilation) else: self.conv1d = nn.Conv2d(input_channel, hidden_channel, kernel, stride=stride, padding=self.padding, dilation=dilation) self.nonlinearity1 = nn.PReLU() self.reg1 = tLN(hidden_channel) def forward(self, input): output = self.reg1(self.nonlinearity1(self.conv1d(input))) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channel': 4, 'hidden_channel': 4, 'kernel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn 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 @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_0( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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') tmp5 = tl.load(in_ptr1 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp18 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp7 = tmp6 * tmp2 tmp8 = tl.where(tmp4, tmp2, tmp7) tmp9 = 1.0 tmp10 = tmp8 * tmp9 tmp11 = tmp8 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp12 * tmp9 tmp14 = 1e-08 tmp15 = tmp13 + tmp14 tmp16 = libdevice.sqrt(tmp15) tmp17 = tmp11 / tmp16 tmp19 = tmp17 * tmp18 tmp21 = tmp19 + tmp20 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp21, 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,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1,), (1,)) assert_size_stride(primals_5, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(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 buf2 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_0[ grid(16)](buf1, primals_2, primals_4, primals_5, primals_6, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 del primals_6 return buf2, primals_1, primals_3, primals_4, primals_5, buf1 class tLN(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLN, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3] std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) / inp.shape[3] + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) class CausalConv2d(torch.nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=(1, 1 ), dilation=(1, 1), groups=1, bias=True): _pad = int(np.log2((kernel_size[1] - 1) / 2)) padding_2 = int(2 ** (np.log2(dilation[1]) + _pad)) self.__padding = (kernel_size[0] - 1) * dilation[0], padding_2 super(CausalConv2d, self).__init__(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=self.__padding, dilation=dilation, groups=groups, bias=bias) def forward(self, input): result = super(CausalConv2d, self).forward(input) if self.__padding[0] != 0: return result[:, :, :-self.__padding[0]] return result class DepthConv2dv2New(nn.Module): def __init__(self, input_channel, hidden_channel, kernel, dilation=(1, 1), stride=(1, 1), padding=(0, 0), causal=False): super(DepthConv2dv2New, self).__init__() self.padding = padding if causal: self.conv1d = CausalConv2d(input_channel, hidden_channel, kernel, stride=stride, dilation=dilation) else: self.conv1d = nn.Conv2d(input_channel, hidden_channel, kernel, stride=stride, padding=self.padding, dilation=dilation) self.nonlinearity1 = nn.PReLU() self.reg1 = tLN(hidden_channel) def forward(self, input_0): primals_1 = self.conv1d.weight primals_2 = self.conv1d.bias primals_4 = self.nonlinearity1.weight primals_5 = self.reg1.gain primals_6 = self.reg1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
rbodo/pytorch-OpCounter
DepthConv2dv2
false
7,539
[ "MIT" ]
1
1857cbb5f9e53343fb349af84efdfde2554a2691
https://github.com/rbodo/pytorch-OpCounter/tree/1857cbb5f9e53343fb349af84efdfde2554a2691
tLN
import torch import torch.nn as nn from torch.autograd import Variable class tLN(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLN, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3] std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) / inp.shape[3] + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dimension': 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 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 @triton.jit def triton_poi_fused_add_div_mul_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x5 = xindex // 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + 4 * x5, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x5), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x5), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x5), xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp29 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 0.25 tmp9 = tmp7 * tmp8 tmp10 = tmp0 - tmp9 tmp11 = tmp1 - tmp9 tmp12 = tmp11 * tmp11 tmp13 = tmp2 - tmp9 tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp16 = tmp4 - tmp9 tmp17 = tmp16 * tmp16 tmp18 = tmp15 + tmp17 tmp19 = tmp6 - tmp9 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp21 * tmp8 tmp23 = 1e-08 tmp24 = tmp22 + tmp23 tmp25 = libdevice.sqrt(tmp24) tmp26 = tmp10 / tmp25 tmp28 = tmp26 * tmp27 tmp30 = tmp28 + tmp29 tl.store(out_ptr0 + x4, tmp30, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 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) get_raw_stream(0) triton_poi_fused_add_div_mul_sub_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class tLNNew(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLNNew, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, input_0): primals_2 = self.gain primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
rbodo/pytorch-OpCounter
tLN
false
7,540
[ "MIT" ]
1
1857cbb5f9e53343fb349af84efdfde2554a2691
https://github.com/rbodo/pytorch-OpCounter/tree/1857cbb5f9e53343fb349af84efdfde2554a2691
LearnedKernel
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class LearnedKernel(nn.Module): def __init__(self, args: 'Namespace'): super(LearnedKernel, self).__init__() self.A = nn.Linear(args.ffn_hidden_size, args.ffn_hidden_size) def forward(self, encodings: 'torch.Tensor'): return (self.A(encodings[:, 1, :].squeeze(1)) * encodings[:, 0, :]. squeeze(1)).sum(dim=1, keepdim=True) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'args': _mock_config(ffn_hidden_size=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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 + (16 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_mul_sum_1(in_ptr0, in_ptr1, in_ptr2, 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 % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp7 = tl.load(in_ptr2 + (4 + x0 + 64 * x1), xmask) tmp10 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr2 + (8 + x0 + 64 * x1), xmask) tmp15 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr2 + (12 + x0 + 64 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp5 + tmp1 tmp8 = tmp6 * tmp7 tmp9 = tmp4 + tmp8 tmp11 = tmp10 + tmp1 tmp13 = tmp11 * tmp12 tmp14 = tmp9 + tmp13 tmp16 = tmp15 + tmp1 tmp18 = tmp16 * tmp17 tmp19 = tmp14 + tmp18 tl.store(out_ptr0 + x2, tmp19, 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), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 1, 4), (4, 4, 1), torch.float32) triton_poi_fused_add_mul_sum_1[grid(16)](buf1, primals_3, primals_1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf1 del primals_3 return buf2, reinterpret_tensor(buf0, (16, 4), (4, 1), 0 ), reinterpret_tensor(primals_1, (4, 4, 4), (64, 4, 1), 0) class LearnedKernelNew(nn.Module): def __init__(self, args: 'Namespace'): super(LearnedKernelNew, self).__init__() self.A = nn.Linear(args.ffn_hidden_size, args.ffn_hidden_size) def forward(self, input_0): primals_2 = self.A.weight primals_3 = self.A.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AayushGrover/ViscaNet
LearnedKernel
false
7,541
[ "MIT" ]
1
41786e10b84f2264b638567bdce1c189c1b66b00
https://github.com/AayushGrover/ViscaNet/tree/41786e10b84f2264b638567bdce1c189c1b66b00
ProteinResNetPooler
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class ProteinResNetPooler(nn.Module): def __init__(self, config): super().__init__() self.attention_weights = nn.Linear(config.hidden_size, 1) self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() def forward(self, hidden_states, mask=None): attention_scores = self.attention_weights(hidden_states) if mask is not None: attention_scores += -10000.0 * (1 - mask) attention_weights = torch.softmax(attention_scores, -1) weighted_mean_embedding = torch.matmul(hidden_states.transpose(1, 2 ), attention_weights).squeeze(2) pooled_output = self.dense(weighted_mean_embedding) pooled_output = self.activation(pooled_output) return pooled_output def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(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.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 x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 - tmp0 tmp2 = tl_math.exp(tmp1) tmp3 = tmp2 / tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_1 del primals_2 buf2 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(16)](buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_3, (4, 4, 4), (16, 1, 4), 0), buf2, out=buf3) buf4 = reinterpret_tensor(buf2, (4, 4), (4, 1), 0) del buf2 extern_kernels.mm(reinterpret_tensor(buf3, (4, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_tanh_1[grid(16)](buf5, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return buf5, primals_3, buf1, reinterpret_tensor(buf3, (4, 4), (4, 1), 0 ), buf5, primals_4 class ProteinResNetPoolerNew(nn.Module): def __init__(self, config): super().__init__() self.attention_weights = nn.Linear(config.hidden_size, 1) self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() def forward(self, input_0): primals_1 = self.attention_weights.weight primals_2 = self.attention_weights.bias primals_4 = self.dense.weight primals_5 = self.dense.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
rdedhia/tape
ProteinResNetPooler
false
7,542
[ "BSD-3-Clause" ]
1
421feeb589e4469fb18e297d233d12c1e682338a
https://github.com/rdedhia/tape/tree/421feeb589e4469fb18e297d233d12c1e682338a
Scale
import torch from torch import nn class Scale(nn.Module): def __init__(self, num_features): super().__init__() self.num_features = num_features self.scale = nn.Parameter(torch.zeros(num_features)) self.register_buffer('saved_mean', torch.zeros(num_features)) self.register_buffer('saved_var', torch.ones(num_features)) def forward(self, x): with torch.no_grad(): self.saved_mean = x.mean(dim=0) self.saved_var = x.var(dim=0) return self.scale * x def extra_repr(self): return 'num_features={}'.format(self.num_features) def get_inputs(): return [torch.rand([4, 4, 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 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_mean_var_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + (64 + x0), xmask) tmp3 = tl.load(in_ptr0 + (128 + x0), xmask) tmp5 = tl.load(in_ptr0 + (192 + x0), 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 = 3.0 tmp21 = tmp19 / tmp20 tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp21, xmask) @triton.jit def triton_poi_fused_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) 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, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_var_0[grid(64)](primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_1[grid(256)](primals_2, primals_1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf2, buf0, buf1, primals_1 class ScaleNew(nn.Module): def __init__(self, num_features): super().__init__() self.num_features = num_features self.scale = nn.Parameter(torch.zeros(num_features)) self.register_buffer('saved_mean', torch.zeros(num_features)) self.register_buffer('saved_var', torch.ones(num_features)) def extra_repr(self): return 'num_features={}'.format(self.num_features) def forward(self, input_0): primals_2 = self.scale primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
rgflowopen/rg-flow
Scale
false
7,543
[ "MIT" ]
1
f1ebb56e3e51bb26ecc2f10fe61eb34cae18398b
https://github.com/rgflowopen/rg-flow/tree/f1ebb56e3e51bb26ecc2f10fe61eb34cae18398b
Swish
import torch from torch import nn class Swish(nn.Module): def __init__(self, num_features): super().__init__() self.num_features = num_features self.scale = nn.Parameter(torch.ones(num_features)) def forward(self, x): return x * torch.sigmoid(self.scale * x) def extra_repr(self): return 'num_features={}'.format(self.num_features) def get_inputs(): return [torch.rand([4, 4, 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 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_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp0 tmp3 = tl.sigmoid(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (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_mul_sigmoid_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf0, primals_1, primals_2 class SwishNew(nn.Module): def __init__(self, num_features): super().__init__() self.num_features = num_features self.scale = nn.Parameter(torch.ones(num_features)) def extra_repr(self): return 'num_features={}'.format(self.num_features) def forward(self, input_0): primals_1 = self.scale primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
rgflowopen/rg-flow
Swish
false
7,544
[ "MIT" ]
1
f1ebb56e3e51bb26ecc2f10fe61eb34cae18398b
https://github.com/rgflowopen/rg-flow/tree/f1ebb56e3e51bb26ecc2f10fe61eb34cae18398b
PADB
import torch import torch.utils.data import torch.nn as nn class PA(nn.Module): def __init__(self, nf): super(PA, self).__init__() self.conv = nn.Conv2d(nf, nf, 1) self.sigmoid = nn.Sigmoid() def forward(self, x): y = self.conv(x) y = self.sigmoid(y) out = torch.mul(x, y) return out class PADB(nn.Module): def __init__(self, in_channels, out_channels, c_weight=1): super(PADB, self).__init__() self.in_channels = in_channels self.out_channels = out_channels self.dc = int(in_channels * c_weight) self.c_weight = c_weight expand_dim = in_channels if c_weight > 1: expand_dim = self.dc self.expandconv = nn.Conv2d(in_channels, expand_dim, 3, padding=1) self.c1_d = nn.Conv2d(expand_dim, self.dc, 1) self.c1_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c2_d = nn.Conv2d(expand_dim, self.dc, 1) self.c2_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c3_d = nn.Conv2d(expand_dim, self.dc, 1) self.c3_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c4 = nn.Conv2d(expand_dim, self.dc, 3, padding=1) self.act = nn.LeakyReLU(0.2) self.c5 = nn.Conv2d(self.dc * 4, out_channels, 1) self.PA = PA(out_channels) def forward(self, input): if self.c_weight > 1: input = self.act(self.expandconv(input)) distilled_c1 = self.act(self.c1_d(input)) r_c1 = self.c1_r(input) r_c1 = self.act(r_c1 + input) distilled_c2 = self.act(self.c2_d(r_c1)) r_c2 = self.c2_r(r_c1) r_c2 = self.act(r_c2 + r_c1) distilled_c3 = self.act(self.c3_d(r_c2)) r_c3 = self.c3_r(r_c2) r_c3 = self.act(r_c3 + r_c2) r_c4 = self.act(self.c4(r_c3)) out_cat = torch.cat([distilled_c1, distilled_c2, distilled_c3, r_c4 ], dim=1) out = self.PA(self.c5(out_cat)) 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.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, 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 tl.store(out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_leaky_relu_1(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 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp7 = 0.2 tmp8 = tmp4 * tmp7 tmp9 = tl.where(tmp6, tmp4, tmp8) tl.store(out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr1 + x3, tmp9, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 16 x0 = xindex % 16 x2 = xindex // 256 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 ).to(tl.int1) tmp6 = tl.load(in_ptr1 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp7 = tl.load(in_ptr2 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = 0.2 tmp10 = tmp8 * tmp9 tmp11 = tl.where(tmp5, tmp8, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tmp15 = tl.full([1], 8, tl.int64) tmp16 = tmp0 < tmp15 tmp17 = tmp14 & tmp16 tmp18 = tl.load(in_ptr3 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp17 & xmask, other=0.0).to(tl.int1) tmp19 = tl.load(in_ptr4 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp17 & xmask, other=0.0) tmp20 = tl.load(in_ptr5 + (-4 + x1), tmp17 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tmp19 + tmp20 tmp22 = tmp21 * tmp9 tmp23 = tl.where(tmp18, tmp21, tmp22) tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp17, tmp23, tmp24) tmp26 = tmp0 >= tmp15 tmp27 = tl.full([1], 12, tl.int64) tmp28 = tmp0 < tmp27 tmp29 = tmp26 & tmp28 tmp30 = tl.load(in_ptr6 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp29 & xmask, other=0.0).to(tl.int1) tmp31 = tl.load(in_ptr7 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp29 & xmask, other=0.0) tmp32 = tl.load(in_ptr8 + (-8 + x1), tmp29 & xmask, eviction_policy= 'evict_last', other=0.0) tmp33 = tmp31 + tmp32 tmp34 = tmp33 * tmp9 tmp35 = tl.where(tmp30, tmp33, tmp34) tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype) tmp37 = tl.where(tmp29, tmp35, tmp36) tmp38 = tmp0 >= tmp27 tl.full([1], 16, tl.int64) tmp41 = tl.load(in_ptr9 + (x0 + 16 * (-12 + x1) + 64 * x2), tmp38 & xmask, other=0.0).to(tl.int1) tmp42 = tl.load(in_ptr10 + (x0 + 16 * (-12 + x1) + 64 * x2), tmp38 & xmask, other=0.0) tmp43 = tl.load(in_ptr11 + (-12 + x1), tmp38 & xmask, eviction_policy= 'evict_last', other=0.0) tmp44 = tmp42 + tmp43 tmp45 = tmp44 * tmp9 tmp46 = tl.where(tmp41, tmp44, tmp45) tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype) tmp48 = tl.where(tmp38, tmp46, tmp47) tmp49 = tl.where(tmp29, tmp37, tmp48) tmp50 = tl.where(tmp17, tmp25, tmp49) tmp51 = tl.where(tmp4, tmp13, tmp50) tl.store(out_ptr0 + x3, tmp51, xmask) @triton.jit def triton_poi_fused_convolution_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_convolution_mul_sigmoid_4(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp5, 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) = 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, 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, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_13, (4,), (1,)) assert_size_stride(primals_14, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_15, (4,), (1,)) assert_size_stride(primals_16, (4, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_17, (4,), (1,)) assert_size_stride(primals_18, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_19, (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.bool) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf0, primals_2, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_leaky_relu_1[grid(256)](buf2, primals_5, primals_3, buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf5 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1)) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf5, primals_7, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf7 = extern_kernels.convolution(buf4, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1)) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf9 = buf2 del buf2 triton_poi_fused_add_convolution_leaky_relu_1[grid(256)](buf7, primals_9, buf4, buf8, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf10 = extern_kernels.convolution(buf9, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 4, 4, 4), (64, 16, 4, 1)) buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf10, primals_11, buf11, 256, XBLOCK=256, num_warps=4, num_stages=1) buf12 = extern_kernels.convolution(buf9, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 4, 4, 4), (64, 16, 4, 1)) buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf14 = buf7 del buf7 triton_poi_fused_add_convolution_leaky_relu_1[grid(256)](buf12, primals_13, buf9, buf13, buf14, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf12 del primals_13 buf15 = extern_kernels.convolution(buf14, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 4, 4, 4), (64, 16, 4, 1)) buf16 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf15, primals_15, buf16, 256, XBLOCK=256, num_warps=4, num_stages=1) buf17 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch. float32) triton_poi_fused_cat_2[grid(1024)](buf1, buf0, primals_2, buf6, buf5, primals_7, buf11, buf10, primals_11, buf16, buf15, primals_15, buf17, 1024, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf10 del buf15 del primals_11 del primals_15 del primals_2 del primals_7 buf18 = extern_kernels.convolution(buf17, primals_16, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 4, 4, 4), (64, 16, 4, 1)) buf19 = buf18 del buf18 triton_poi_fused_convolution_3[grid(256)](buf19, primals_17, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_17 buf20 = extern_kernels.convolution(buf19, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 4, 4, 4), (64, 16, 4, 1)) buf21 = buf20 del buf20 buf22 = buf5 del buf5 triton_poi_fused_convolution_mul_sigmoid_4[grid(256)](buf21, primals_19, buf19, buf22, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_19 return (buf22, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, buf1, buf3, buf4, buf6, buf8, buf9, buf11, buf13, buf14, buf16, buf17, buf19, buf21) class PA(nn.Module): def __init__(self, nf): super(PA, self).__init__() self.conv = nn.Conv2d(nf, nf, 1) self.sigmoid = nn.Sigmoid() def forward(self, x): y = self.conv(x) y = self.sigmoid(y) out = torch.mul(x, y) return out class PADBNew(nn.Module): def __init__(self, in_channels, out_channels, c_weight=1): super(PADBNew, self).__init__() self.in_channels = in_channels self.out_channels = out_channels self.dc = int(in_channels * c_weight) self.c_weight = c_weight expand_dim = in_channels if c_weight > 1: expand_dim = self.dc self.expandconv = nn.Conv2d(in_channels, expand_dim, 3, padding=1) self.c1_d = nn.Conv2d(expand_dim, self.dc, 1) self.c1_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c2_d = nn.Conv2d(expand_dim, self.dc, 1) self.c2_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c3_d = nn.Conv2d(expand_dim, self.dc, 1) self.c3_r = nn.Conv2d(expand_dim, expand_dim, 3, padding=1) self.c4 = nn.Conv2d(expand_dim, self.dc, 3, padding=1) self.act = nn.LeakyReLU(0.2) self.c5 = nn.Conv2d(self.dc * 4, out_channels, 1) self.PA = PA(out_channels) def forward(self, input_0): primals_1 = self.c1_d.weight primals_2 = self.c1_d.bias primals_4 = self.c1_r.weight primals_5 = self.c1_r.bias primals_6 = self.c2_d.weight primals_7 = self.c2_d.bias primals_8 = self.c2_r.weight primals_9 = self.c2_r.bias primals_10 = self.c3_d.weight primals_11 = self.c3_d.bias primals_12 = self.c3_r.weight primals_13 = self.c3_r.bias primals_14 = self.c4.weight primals_15 = self.c4.bias primals_16 = self.c5.weight primals_17 = self.c5.bias primals_18 = self.PA.conv.weight primals_19 = self.PA.conv.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]) return output[0]
qwopqwop200/Fast-Invertible-Rescaling-Net
PADB
false
7,545
[ "MIT" ]
1
871733f2eee7929d6b37c4d1d6a27347b39b67a9
https://github.com/qwopqwop200/Fast-Invertible-Rescaling-Net/tree/871733f2eee7929d6b37c4d1d6a27347b39b67a9
tLNv2
import torch import torch.nn as nn from torch.autograd import Variable def my_mean(x): f = x.shape[-1] mean = x[..., 0] for i in range(1, f): mean += x[..., i] return mean[..., None] / f class tLNv2(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLNv2, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = my_mean(inp) std = torch.sqrt(my_mean((inp - mean) ** 2) + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dimension': 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 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 @triton.jit def triton_poi_fused_add_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 tmp4 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + x2, xmask) tmp0 = x0 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tmp1 == tmp1 tmp6 = tmp4 + tmp5 tmp7 = tl.where(tmp3, tmp6, tmp4) tmp8 = tl.full([1], 2, tl.int32) tmp9 = tmp8 == tmp1 tmp11 = tl.where(tmp9, tmp6, tmp10) tmp12 = tmp7 + tmp11 tmp13 = tl.where(tmp3, tmp12, tmp7) tmp14 = tl.full([1], 3, tl.int32) tmp15 = tmp14 == tmp1 tmp17 = tl.where(tmp15, tmp6, tmp16) tmp18 = tl.where(tmp15, tmp12, tmp17) tmp19 = tmp13 + tmp18 tmp21 = tl.where(tmp2, tmp6, tmp20) tmp22 = tl.where(tmp2, tmp12, tmp21) tmp23 = tl.where(tmp2, tmp19, tmp22) tl.store(out_ptr0 + x2, tmp23, xmask) @triton.jit def triton_poi_fused_add_div_pow_sub_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 % 4 x1 = xindex // 4 x2 = xindex tmp4 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp24 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp30 = tl.load(in_ptr0 + x2, xmask) tmp0 = x0 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tmp1 == tmp1 tmp5 = 0.25 tmp6 = tmp4 * tmp5 tmp7 = tmp4 - tmp6 tmp8 = tmp7 * tmp7 tmp10 = tmp9 - tmp6 tmp11 = tmp10 * tmp10 tmp12 = tmp8 + tmp11 tmp13 = tl.where(tmp3, tmp12, tmp8) tmp14 = tl.full([1], 2, tl.int32) tmp15 = tmp14 == tmp1 tmp17 = tmp16 - tmp6 tmp18 = tmp17 * tmp17 tmp19 = tl.where(tmp15, tmp12, tmp18) tmp20 = tmp13 + tmp19 tmp21 = tl.where(tmp3, tmp20, tmp13) tmp22 = tl.full([1], 3, tl.int32) tmp23 = tmp22 == tmp1 tmp25 = tmp24 - tmp6 tmp26 = tmp25 * tmp25 tmp27 = tl.where(tmp23, tmp12, tmp26) tmp28 = tl.where(tmp23, tmp20, tmp27) tmp29 = tmp21 + tmp28 tmp31 = tmp30 - tmp6 tmp32 = tmp31 * tmp31 tmp33 = tl.where(tmp2, tmp12, tmp32) tmp34 = tl.where(tmp2, tmp20, tmp33) tmp35 = tl.where(tmp2, tmp29, tmp34) tl.store(out_ptr0 + x2, tmp35, xmask) @triton.jit def triton_poi_fused_add_div_sqrt_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 tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp3 = 1e-08 tmp4 = tmp2 + tmp3 tmp5 = libdevice.sqrt(tmp4) tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 x5 = xindex // 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + 4 * x5, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last') tmp2 = 0.25 tmp3 = tmp1 * tmp2 tmp4 = tmp0 - tmp3 tmp6 = tmp4 / tmp5 tmp8 = tmp6 * tmp7 tmp10 = tmp8 + tmp9 tl.store(out_ptr0 + x4, tmp10, xmask) tl.store(out_ptr1 + x4, tmp0, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 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) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_pow_sub_1[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_add_div_sqrt_2[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf1 del buf1 triton_poi_fused_add_div_mul_sub_3[grid(256)](buf0, buf2, primals_2, primals_3, buf3, primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 del primals_3 return buf3, buf0, buf2 def my_mean(x): f = x.shape[-1] mean = x[..., 0] for i in range(1, f): mean += x[..., i] return mean[..., None] / f class tLNv2New(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLNv2New, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, input_0): primals_2 = self.gain primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
rbodo/pytorch-OpCounter
tLNv2
false
7,546
[ "MIT" ]
1
1857cbb5f9e53343fb349af84efdfde2554a2691
https://github.com/rbodo/pytorch-OpCounter/tree/1857cbb5f9e53343fb349af84efdfde2554a2691
Net1
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel import torch.optim class Net1(nn.Module): def __init__(self): super(Net1, self).__init__() self.conv1 = nn.Conv2d(1, 32, 3, 1) self.conv2 = nn.Conv2d(32, 64, 3, 1) def forward(self, x): x = self.conv1(x) x = F.relu(x) x = self.conv2(x) x = F.relu(x) x = F.max_pool2d(x, 2) x = torch.flatten(x, 1) 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 import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 492032 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3844 % 32 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_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 // 3600 % 64 x0 = xindex % 3600 x4 = xindex // 3600 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, 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 + (x0 + 3616 * x4), tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 230400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 30 x1 = xindex // 30 % 30 x2 = xindex // 900 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (60 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (61 + 2 * x0 + 120 * x1 + 3616 * x2), 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 + x3, tmp15, xmask) tl.store(out_ptr1 + x3, tmp16, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (32, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (64, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_5, (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, 62, 62), (123008, 3844, 62, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(492032)](buf1, primals_2, 492032, XBLOCK=1024, num_warps=4, num_stages=1) 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, 64, 60, 60), (230400, 3600, 60, 1)) buf3 = empty_strided_cuda((4, 64, 60, 60), (231424, 3616, 60, 1), torch.float32) triton_poi_fused_convolution_relu_1[grid(921600)](buf2, primals_5, buf3, 921600, XBLOCK=1024, num_warps=4, num_stages=1) del buf2 del primals_5 buf4 = empty_strided_cuda((4, 64, 30, 30), (57600, 900, 30, 1), torch.int8) buf5 = empty_strided_cuda((4, 64, 30, 30), (57600, 900, 30, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_2[grid(230400)](buf3, buf4, buf5, 230400, XBLOCK=512, num_warps=8, num_stages=1) return reinterpret_tensor(buf5, (4, 57600), (57600, 1), 0 ), primals_1, primals_3, primals_4, buf1, buf3, buf4 class Net1New(nn.Module): def __init__(self): super(Net1New, self).__init__() self.conv1 = nn.Conv2d(1, 32, 3, 1) self.conv2 = nn.Conv2d(32, 64, 3, 1) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ringier-data/deep-learning-containers
Net1
false
7,547
[ "Apache-2.0" ]
1
e939ceee48a426f9ae4e0b50317dc2fa8845a312
https://github.com/ringier-data/deep-learning-containers/tree/e939ceee48a426f9ae4e0b50317dc2fa8845a312
F_fully_convolutional
import torch import torch.nn as nn import torch.nn.functional as F class F_fully_convolutional(nn.Module): def __init__(self, in_channels, out_channels, internal_size=256, kernel_size=3, leaky_slope=0.02): super().__init__() pad = kernel_size // 2 self.leaky_slope = leaky_slope self.conv1 = nn.Conv2d(in_channels, internal_size, kernel_size= kernel_size, padding=pad) self.conv2 = nn.Conv2d(in_channels + internal_size, internal_size, kernel_size=kernel_size, padding=pad) self.conv3 = nn.Conv2d(in_channels + 2 * internal_size, out_channels, kernel_size=1, padding=0) def forward(self, x): x1 = F.leaky_relu(self.conv1(x), self.leaky_slope) x2 = F.leaky_relu(self.conv2(torch.cat([x, x1], 1)), self.leaky_slope) return self.conv3(torch.cat([x, x1, x2], 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 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_0(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 % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 4 * x2 + 36 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_1(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_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 % 260 y1 = yindex // 260 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 260 * x2 + 2340 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_leaky_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) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16640 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 260 x1 = xindex // 260 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], 260, tl.int64) tmp9 = tl.load(in_ptr1 + (256 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0).to(tl.int1) tmp10 = tl.load(in_ptr2 + (256 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tl.load(in_ptr3 + (-4 + x0), tmp6 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp10 + tmp11 tmp13 = 0.02 tmp14 = tmp12 * tmp13 tmp15 = tl.where(tmp9, tmp12, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp6, tmp15, tmp16) tmp18 = tl.where(tmp4, tmp5, tmp17) tl.store(out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 33024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 516 x1 = xindex // 516 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 tmp7 = tl.full([1], 260, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (256 * x1 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0).to(tl.int1) tmp11 = tl.load(in_ptr2 + (256 * x1 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp12 = tl.load(in_ptr3 + (-4 + x0), tmp9 & xmask, eviction_policy= 'evict_last', other=0.0) tmp13 = tmp11 + tmp12 tmp14 = 0.02 tmp15 = tmp13 * tmp14 tmp16 = tl.where(tmp10, tmp13, tmp15) tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp9, tmp16, tmp17) tmp19 = tmp0 >= tmp7 tl.full([1], 516, tl.int64) tmp22 = tl.load(in_ptr4 + (256 * x1 + (-260 + x0)), tmp19 & xmask, eviction_policy='evict_last', other=0.0).to(tl.int1) tmp23 = tl.load(in_ptr5 + (256 * x1 + (-260 + x0)), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tl.load(in_ptr6 + (-260 + x0), tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tmp23 + tmp24 tmp26 = tmp25 * tmp14 tmp27 = tl.where(tmp22, tmp25, tmp26) tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp19, tmp27, tmp28) tmp30 = tl.where(tmp9, tmp18, tmp29) tmp31 = tl.where(tmp4, tmp5, tmp30) tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_convolution_6(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask) tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask) 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, 3, 3), (36, 9, 3, 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, 260, 3, 3), (2340, 9, 3, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (4, 516, 1, 1), (516, 1, 1, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((256, 4, 3, 3), (36, 1, 12, 4), torch.float32 ) get_raw_stream(0) triton_poi_fused_0[grid(1024, 9)](primals_1, buf0, 1024, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_1[grid(16, 16)](primals_3, buf1, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((256, 260, 3, 3), (2340, 1, 780, 260), torch.float32) triton_poi_fused_2[grid(66560, 9)](primals_4, buf2, 66560, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf3 = 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(buf3, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf4 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_leaky_relu_3[grid(16384)](buf3, primals_2, buf4, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((4, 260, 4, 4), (4160, 1, 1040, 260), torch.float32) triton_poi_fused_cat_4[grid(16640)](buf1, buf4, buf3, primals_2, buf5, 16640, XBLOCK=256, num_warps=4, num_stages=1) buf6 = extern_kernels.convolution(buf5, buf2, 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 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_leaky_relu_3[grid(16384)](buf6, primals_5, buf7, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 516, 4, 4), (8256, 1, 2064, 516), torch.float32) triton_poi_fused_cat_5[grid(33024)](buf1, buf4, buf3, primals_2, buf7, buf6, primals_5, buf8, 33024, XBLOCK=512, num_warps=4, num_stages=1) del buf3 del buf6 del primals_2 del primals_5 buf9 = extern_kernels.convolution(buf8, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 4, 4, 4), (64, 1, 16, 4)) buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_convolution_6[grid(16, 16)](buf9, primals_7, buf10, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del buf9 del primals_7 return buf10, buf0, buf1, buf2, primals_6, buf4, buf5, buf7, buf8 class F_fully_convolutionalNew(nn.Module): def __init__(self, in_channels, out_channels, internal_size=256, kernel_size=3, leaky_slope=0.02): super().__init__() pad = kernel_size // 2 self.leaky_slope = leaky_slope self.conv1 = nn.Conv2d(in_channels, internal_size, kernel_size= kernel_size, padding=pad) self.conv2 = nn.Conv2d(in_channels + internal_size, internal_size, kernel_size=kernel_size, padding=pad) self.conv3 = nn.Conv2d(in_channels + 2 * internal_size, out_channels, kernel_size=1, padding=0) 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]
ramonpeter/LaSeR
F_fully_convolutional
false
7,548
[ "MIT" ]
1
28daa6876256501ed0d3e84a4ddfedc7892bd528
https://github.com/ramonpeter/LaSeR/tree/28daa6876256501ed0d3e84a4ddfedc7892bd528
DepthConv2d
import torch import numpy as np import torch.nn as nn from torch.autograd import Variable class tLN(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLN, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3] std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) / inp.shape[3] + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) class CausalConv2d(torch.nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=(1, 1 ), dilation=(1, 1), groups=1, bias=True): _pad = int(np.log2((kernel_size[1] - 1) / 2)) padding_2 = int(2 ** (np.log2(dilation[1]) + _pad)) self.__padding = (kernel_size[0] - 1) * dilation[0], padding_2 super(CausalConv2d, self).__init__(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=self.__padding, dilation=dilation, groups=groups, bias=bias) def forward(self, input): result = super(CausalConv2d, self).forward(input) if self.__padding[0] != 0: return result[:, :, :-self.__padding[0]] return result class DepthConv2d(nn.Module): def __init__(self, input_channel, hidden_channel, kernel, dilation=(1, 1), stride=(1, 1), padding=(0, 0), causal=False): super(DepthConv2d, self).__init__() self.padding = padding self.linear = nn.Conv2d(input_channel, hidden_channel, (1, 1)) if causal: self.conv1d = CausalConv2d(hidden_channel, hidden_channel, kernel, stride=stride, dilation=dilation) else: self.conv1d = nn.Conv2d(hidden_channel, hidden_channel, kernel, stride=stride, padding=self.padding, dilation=dilation) self.BN = nn.Conv2d(hidden_channel, input_channel, (1, 1)) self.nonlinearity1 = nn.PReLU() self.nonlinearity2 = nn.PReLU() self.reg1 = tLN(hidden_channel) self.reg2 = tLN(hidden_channel) def forward(self, input): output = self.reg1(self.nonlinearity1(self.linear(input))) output = self.reg2(self.nonlinearity2(self.conv1d(output))) output = self.BN(output) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channel': 4, 'hidden_channel': 4, 'kernel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn 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 @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) @triton.jit def triton_poi_fused__prelu_kernel_div_pow_sub_sum_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp5 = tmp4 * tmp0 tmp6 = tl.where(tmp2, tmp0, tmp5) tmp8 = tmp7 > tmp1 tmp9 = tmp4 * tmp7 tmp10 = tl.where(tmp8, tmp7, tmp9) tmp11 = tmp6 + tmp10 tmp13 = tmp12 > tmp1 tmp14 = tmp4 * tmp12 tmp15 = tl.where(tmp13, tmp12, tmp14) tmp16 = tmp11 + tmp15 tmp18 = tmp17 > tmp1 tmp19 = tmp4 * tmp17 tmp20 = tl.where(tmp18, tmp17, tmp19) tmp21 = tmp16 + tmp20 tmp22 = 0.25 tmp23 = tmp21 * tmp22 tmp24 = tmp6 - tmp23 tmp25 = tmp24 * tmp24 tmp26 = tmp10 - tmp23 tmp27 = tmp26 * tmp26 tmp28 = tmp25 + tmp27 tmp29 = tmp15 - tmp23 tmp30 = tmp29 * tmp29 tmp31 = tmp28 + tmp30 tmp32 = tmp20 - tmp23 tmp33 = tmp32 * tmp32 tmp34 = tmp31 + tmp33 tmp35 = tmp34 * tmp22 tl.store(out_ptr0 + x0, tmp23, xmask) tl.store(out_ptr1 + x0, tmp35, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_div_mul_sub_2(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 x4 = xindex x5 = xindex // 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp3 = tl.load(in_ptr1 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x2, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr5 + x2, xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp5 = tmp4 * tmp0 tmp6 = tl.where(tmp2, tmp0, tmp5) tmp8 = tmp6 - tmp7 tmp10 = 1e-08 tmp11 = tmp9 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp8 / tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tl.store(out_ptr0 + x4, tmp17, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_3( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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') tmp5 = tl.load(in_ptr1 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp18 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp7 = tmp6 * tmp2 tmp8 = tl.where(tmp4, tmp2, tmp7) tmp9 = 1.0 tmp10 = tmp8 * tmp9 tmp11 = tmp8 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp12 * tmp9 tmp14 = 1e-08 tmp15 = tmp13 + tmp14 tmp16 = libdevice.sqrt(tmp15) tmp17 = tmp11 / tmp16 tmp19 = tmp17 * tmp18 tmp21 = tmp19 + tmp20 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp21, xmask) @triton.jit def triton_poi_fused_convolution_4(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, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 4, 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, (1,), (1,)) assert_size_stride(primals_5, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_7, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_11, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_12, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_13, (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 = 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((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__prelu_kernel_div_pow_sub_sum_1[grid(64)](buf1, primals_4, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_div_mul_sub_2[grid(256)](buf1, primals_4, buf2, buf3, primals_5, primals_6, buf4, 256, XBLOCK= 128, num_warps=4, num_stages=1) del buf2 del buf3 del primals_6 buf5 = extern_kernels.convolution(buf4, primals_7, 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 buf7 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_div_mul_pow_sqrt_sub_sum_3[ grid(16)](buf6, primals_8, primals_9, primals_10, primals_11, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_11 del primals_8 buf8 = extern_kernels.convolution(buf7, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_4[grid(16)](buf9, primals_13, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_13 return (buf9, primals_1, primals_3, primals_4, primals_5, primals_7, primals_9, primals_10, primals_12, buf1, buf4, buf6, buf7) class tLN(nn.Module): def __init__(self, dimension, eps=1e-08, trainable=True): super(tLN, self).__init__() self.eps = eps if trainable: self.gain = nn.Parameter(torch.ones(1, dimension, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, dimension, 1, 1)) else: self.gain = Variable(torch.ones(1, dimension, 1, 1), requires_grad=False) self.bias = Variable(torch.zeros(1, dimension, 1, 1), requires_grad=False) def forward(self, inp): inp.size(0) mean = torch.sum(inp, 3, keepdim=True) / inp.shape[3] std = torch.sqrt(torch.sum((inp - mean) ** 2, 3, keepdim=True) / inp.shape[3] + self.eps) x = (inp - mean.expand_as(inp)) / std.expand_as(inp) return x * self.gain.expand_as(x).type(x.type()) + self.bias.expand_as( x).type(x.type()) class CausalConv2d(torch.nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=(1, 1 ), dilation=(1, 1), groups=1, bias=True): _pad = int(np.log2((kernel_size[1] - 1) / 2)) padding_2 = int(2 ** (np.log2(dilation[1]) + _pad)) self.__padding = (kernel_size[0] - 1) * dilation[0], padding_2 super(CausalConv2d, self).__init__(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=self.__padding, dilation=dilation, groups=groups, bias=bias) def forward(self, input): result = super(CausalConv2d, self).forward(input) if self.__padding[0] != 0: return result[:, :, :-self.__padding[0]] return result class DepthConv2dNew(nn.Module): def __init__(self, input_channel, hidden_channel, kernel, dilation=(1, 1), stride=(1, 1), padding=(0, 0), causal=False): super(DepthConv2dNew, self).__init__() self.padding = padding self.linear = nn.Conv2d(input_channel, hidden_channel, (1, 1)) if causal: self.conv1d = CausalConv2d(hidden_channel, hidden_channel, kernel, stride=stride, dilation=dilation) else: self.conv1d = nn.Conv2d(hidden_channel, hidden_channel, kernel, stride=stride, padding=self.padding, dilation=dilation) self.BN = nn.Conv2d(hidden_channel, input_channel, (1, 1)) self.nonlinearity1 = nn.PReLU() self.nonlinearity2 = nn.PReLU() self.reg1 = tLN(hidden_channel) self.reg2 = tLN(hidden_channel) def forward(self, input_0): primals_1 = self.linear.weight primals_2 = self.linear.bias primals_3 = self.conv1d.weight primals_8 = self.conv1d.bias primals_12 = self.BN.weight primals_13 = self.BN.bias primals_4 = self.nonlinearity1.weight primals_9 = self.nonlinearity2.weight primals_5 = self.reg1.gain primals_6 = self.reg1.bias primals_10 = self.reg2.gain primals_11 = self.reg2.bias primals_7 = 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]
rbodo/pytorch-OpCounter
DepthConv2d
false
7,549
[ "MIT" ]
1
1857cbb5f9e53343fb349af84efdfde2554a2691
https://github.com/rbodo/pytorch-OpCounter/tree/1857cbb5f9e53343fb349af84efdfde2554a2691
PrimaryCapsules
import torch import torch.nn as nn def squash(s, dim=-1): """ "Squashing" non-linearity that shrunks short vectors to almost zero length and long vectors to a length slightly below 1 Eq. (1): v_j = ||s_j||^2 / (1 + ||s_j||^2) * s_j / ||s_j|| Args: s: Vector before activation dim: Dimension along which to calculate the norm Returns: Squashed vector """ squared_norm = torch.sum(s ** 2, dim=dim, keepdim=True) return squared_norm / (1 + squared_norm) * s / (torch.sqrt(squared_norm ) + 1e-08) class PrimaryCapsules(nn.Module): def __init__(self, in_channels, out_channels, dim_caps, kernel_size=9, stride=2, padding=0): """ Initialize the layer. Args: in_channels: Number of input channels. out_channels: Number of output channels. dim_caps: Dimensionality, i.e. length, of the output capsule vector. """ super(PrimaryCapsules, self).__init__() self.dim_caps = dim_caps self._caps_channel = int(out_channels / dim_caps) self.conv = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride, padding=padding) def forward(self, x): out = self.conv(x) out = out.view(out.size(0), self._caps_channel, out.size(2), out. size(3), self.dim_caps) out = out.view(out.size(0), -1, self.dim_caps) return squash(out) def get_inputs(): return [torch.rand([4, 4, 64, 64])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'dim_caps': 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 @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 12544 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 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_div_mul_pow_sqrt_sum_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 12544 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 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + x2, xmask) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = 1.0 tmp12 = tmp10 + tmp11 tmp13 = tmp10 / tmp12 tmp15 = tmp13 * tmp14 tmp16 = libdevice.sqrt(tmp10) tmp17 = 1e-08 tmp18 = tmp16 + tmp17 tmp19 = tmp15 / tmp18 tl.store(out_ptr0 + x2, tmp19, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 9, 9), (324, 81, 9, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 64, 64), (16384, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 28, 28), (3136, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(12544)](buf1, primals_2, 12544, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 784, 4), (3136, 4, 1), torch.float32) triton_poi_fused_add_div_mul_pow_sqrt_sum_1[grid(12544)](buf1, buf2, 12544, XBLOCK=256, num_warps=4, num_stages=1) return buf2, primals_1, primals_3, buf1 def squash(s, dim=-1): """ "Squashing" non-linearity that shrunks short vectors to almost zero length and long vectors to a length slightly below 1 Eq. (1): v_j = ||s_j||^2 / (1 + ||s_j||^2) * s_j / ||s_j|| Args: s: Vector before activation dim: Dimension along which to calculate the norm Returns: Squashed vector """ squared_norm = torch.sum(s ** 2, dim=dim, keepdim=True) return squared_norm / (1 + squared_norm) * s / (torch.sqrt(squared_norm ) + 1e-08) class PrimaryCapsulesNew(nn.Module): def __init__(self, in_channels, out_channels, dim_caps, kernel_size=9, stride=2, padding=0): """ Initialize the layer. Args: in_channels: Number of input channels. out_channels: Number of output channels. dim_caps: Dimensionality, i.e. length, of the output capsule vector. """ super(PrimaryCapsulesNew, self).__init__() self.dim_caps = dim_caps self._caps_channel = int(out_channels / dim_caps) self.conv = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride, padding=padding) 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]
richardsun-voyager/capsule-network
PrimaryCapsules
false
7,550
[ "MIT" ]
1
349cec1caa9ab95ff4b3333c33d04b1bdb442f67
https://github.com/richardsun-voyager/capsule-network/tree/349cec1caa9ab95ff4b3333c33d04b1bdb442f67
ChannelAttentionModule
import torch import torch.nn as nn import torch.nn.functional as F class ChannelAttentionModule(nn.Module): def __init__(self): super(ChannelAttentionModule, self).__init__() self.beta = nn.Parameter(torch.zeros(1), requires_grad=True) def forward(self, A): batchsize, num_channels, height, width = A.shape N = height * width A1 = A.view((batchsize, num_channels, N)) X = F.softmax(torch.bmm(A1, A1.permute(0, 2, 1)), dim=-1) XA1 = torch.bmm(X.permute(0, 2, 1), A1).view((batchsize, num_channels, height, width)) E = self.beta * XA1 + A return E def initialize_weights(self): nn.init.constant_(self.beta.data, 0.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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_add_mul_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 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp3 = tmp1 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + x0, tmp5, 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), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_1, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(primals_1, (4, 16, 4), (64, 1, 16), 0), out=buf0) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 buf3 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(primals_1, (4, 4, 16), (64, 16, 1), 0), out=buf3) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_2[grid(256)](primals_2, buf3, primals_1, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf4, buf3 class ChannelAttentionModuleNew(nn.Module): def __init__(self): super(ChannelAttentionModuleNew, self).__init__() self.beta = nn.Parameter(torch.zeros(1), requires_grad=True) def initialize_weights(self): nn.init.constant_(self.beta.data, 0.0) def forward(self, input_0): primals_2 = self.beta primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
ChannelAttentionModule
false
7,551
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
Concat2d
import torch import torch.nn as nn import torch.nn.functional as F class Concat2d(nn.Module): def __init__(self): super(Concat2d, self).__init__() def forward(self, x_down, x_enc): if x_down.shape[-1] > x_enc.shape[-1]: p = (x_down.shape[-1] - x_enc.shape[-1]) // 2 if (x_down.shape[-1] - x_enc.shape[-1]) % 2 != 0: p += 1 x_enc = F.pad(x_enc, (p, p, p, p)) start = [(x_enc.shape[-2] - x_down.shape[-2]) // 2, (x_enc.shape[-1 ] - x_down.shape[-1]) // 2] length = [x_down.shape[-2], x_down.shape[-1]] crop = torch.narrow(torch.narrow(x_enc, dim=2, start=start[0], length=length[0]), dim=3, start=start[1], length=length[1]) cat = torch.cat(tensors=(x_down, crop), dim=1) return cat 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 8 x0 = xindex % 16 x2 = xindex // 128 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, 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, 8, 4, 4), (128, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](arg0_1, arg1_1, buf0, 512, XBLOCK =256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class Concat2dNew(nn.Module): def __init__(self): super(Concat2dNew, 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]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
Concat2d
false
7,552
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
ResBlock
import torch import torch.nn as nn from torch.nn import functional as F class ResBlock(nn.Module): """Residual block with bilinear upsampling/downsampling. Args: in_channels (int): Channel number of the input. out_channels (int): Channel number of the output. mode (str): Upsampling/downsampling mode. Options: down | up. Default: down. """ def __init__(self, in_channels, out_channels, mode='down'): super(ResBlock, self).__init__() self.conv1 = nn.Conv2d(in_channels, in_channels, 3, 1, 1) self.conv2 = nn.Conv2d(in_channels, out_channels, 3, 1, 1) self.skip = nn.Conv2d(in_channels, out_channels, 1, bias=False) if mode == 'down': self.scale_factor = 0.5 elif mode == 'up': self.scale_factor = 2 def forward(self, x): out = F.leaky_relu_(self.conv1(x), negative_slope=0.2) out = F.interpolate(out, scale_factor=self.scale_factor, mode= 'bilinear', align_corners=False) out = F.leaky_relu_(self.conv2(out), negative_slope=0.2) x = F.interpolate(x, scale_factor=self.scale_factor, mode= 'bilinear', align_corners=False) skip = self.skip(x) out = out + skip 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 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__to_copy_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2 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 = 2.0 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tl.store(out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_poi_fused_add_clamp_1(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2 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 = 2.0 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = tl.full([1], 1, tl.int64) tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 3, tl.int64) tmp13 = triton_helpers.minimum(tmp11, tmp12) tl.store(out_ptr0 + x0, tmp13, xmask) @triton.jit def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2 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 = 2.0 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 - tmp10 tmp12 = triton_helpers.maximum(tmp11, tmp7) tmp13 = 1.0 tmp14 = triton_helpers.minimum(tmp12, tmp13) tl.store(out_ptr0 + x0, tmp14, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_leaky_relu_mul_sub_3( in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, 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 x5 = xindex // 4 x2 = xindex // 4 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last') tmp48 = tl.load(in_ptr7 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 4 * tmp4 + 16 * x5), xmask, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = 0.0 tmp13 = tmp11 > tmp12 tmp14 = 0.2 tmp15 = tmp11 * tmp14 tmp16 = tl.where(tmp13, tmp11, tmp15) tmp18 = tmp17 + tmp1 tmp19 = tmp17 < 0 tmp20 = tl.where(tmp19, tmp18, tmp17) tmp21 = tl.load(in_ptr2 + (tmp20 + 4 * tmp4 + 16 * x5), xmask, eviction_policy='evict_last') tmp22 = tmp21 + tmp10 tmp23 = tmp22 > tmp12 tmp24 = tmp22 * tmp14 tmp25 = tl.where(tmp23, tmp22, tmp24) tmp26 = tmp25 - tmp16 tmp28 = tmp26 * tmp27 tmp29 = tmp16 + tmp28 tmp31 = tmp30 + tmp1 tmp32 = tmp30 < 0 tmp33 = tl.where(tmp32, tmp31, tmp30) tmp34 = tl.load(in_ptr2 + (tmp8 + 4 * tmp33 + 16 * x5), xmask, eviction_policy='evict_last') tmp35 = tmp34 + tmp10 tmp36 = tmp35 > tmp12 tmp37 = tmp35 * tmp14 tmp38 = tl.where(tmp36, tmp35, tmp37) tmp39 = tl.load(in_ptr2 + (tmp20 + 4 * tmp33 + 16 * x5), xmask, eviction_policy='evict_last') tmp40 = tmp39 + tmp10 tmp41 = tmp40 > tmp12 tmp42 = tmp40 * tmp14 tmp43 = tl.where(tmp41, tmp40, tmp42) tmp44 = tmp43 - tmp38 tmp45 = tmp44 * tmp27 tmp46 = tmp38 + tmp45 tmp47 = tmp46 - tmp29 tmp49 = tmp47 * tmp48 tmp50 = tmp29 + tmp49 tmp51 = tl.load(in_ptr8 + (tmp8 + 4 * tmp4 + 16 * x5), xmask, eviction_policy='evict_last') tmp52 = tl.load(in_ptr8 + (tmp20 + 4 * tmp4 + 16 * x5), xmask, eviction_policy='evict_last') tmp53 = tmp52 - tmp51 tmp54 = tmp53 * tmp27 tmp55 = tmp51 + tmp54 tmp56 = tl.load(in_ptr8 + (tmp8 + 4 * tmp33 + 16 * x5), xmask, eviction_policy='evict_last') tmp57 = tl.load(in_ptr8 + (tmp20 + 4 * tmp33 + 16 * x5), xmask, eviction_policy='evict_last') tmp58 = tmp57 - tmp56 tmp59 = tmp58 * tmp27 tmp60 = tmp56 + tmp59 tmp61 = tmp60 - tmp55 tmp62 = tmp61 * tmp48 tmp63 = tmp55 + tmp62 tl.store(in_out_ptr0 + x4, tmp50, xmask) tl.store(in_out_ptr1 + x4, tmp63, xmask) @triton.jit def triton_poi_fused_add_convolution_leaky_relu_leaky_relu_backward_4( in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_out_ptr0 + x3, xmask) tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp9 = tmp7 + tmp8 tmp10 = tmp7 > tmp3 tl.store(in_out_ptr0 + x3, tmp9, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_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 = tmp7 > tmp3 tl.store(out_ptr0 + x3, tmp8, 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, 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = empty_strided_cuda((2, 1), (1, 1), torch.int64) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(2)](buf1, 2, XBLOCK=2, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((2, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_1[grid(2)](buf2, 2, XBLOCK=2, num_warps= 1, num_stages=1) buf3 = empty_strided_cuda((2,), (1,), torch.int64) triton_poi_fused__to_copy_0[grid(2)](buf3, 2, XBLOCK=2, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((2,), (1,), torch.int64) triton_poi_fused_add_clamp_1[grid(2)](buf4, 2, XBLOCK=2, num_warps= 1, num_stages=1) buf5 = empty_strided_cuda((2,), (1,), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(2)](buf5, 2, XBLOCK=2, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((2, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(2)](buf7, 2, XBLOCK=2, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) buf9 = buf8 del buf8 buf11 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) buf12 = buf11 del buf11 triton_poi_fused__unsafe_index_add_convolution_leaky_relu_mul_sub_3[ grid(64)](buf9, buf12, buf1, buf3, buf0, primals_2, buf4, buf5, buf2, buf7, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf10 = extern_kernels.convolution(buf9, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 4, 2, 2), (16, 4, 2, 1)) buf13 = extern_kernels.convolution(buf12, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (4, 4, 2, 2), (16, 4, 2, 1)) buf14 = buf13 del buf13 buf15 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool) triton_poi_fused_add_convolution_leaky_relu_leaky_relu_backward_4[grid (64)](buf14, buf10, primals_5, buf15, 64, XBLOCK=64, num_warps= 1, num_stages=1) del buf10 del primals_5 buf16 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_5[grid(256) ](buf0, primals_2, buf16, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 return (buf14, primals_1, primals_3, primals_4, primals_6, buf1, buf2, buf3, buf4, buf5, buf7, buf9, buf12, buf15, buf16) class ResBlockNew(nn.Module): """Residual block with bilinear upsampling/downsampling. Args: in_channels (int): Channel number of the input. out_channels (int): Channel number of the output. mode (str): Upsampling/downsampling mode. Options: down | up. Default: down. """ def __init__(self, in_channels, out_channels, mode='down'): super(ResBlockNew, self).__init__() self.conv1 = nn.Conv2d(in_channels, in_channels, 3, 1, 1) self.conv2 = nn.Conv2d(in_channels, out_channels, 3, 1, 1) self.skip = nn.Conv2d(in_channels, out_channels, 1, bias=False) if mode == 'down': self.scale_factor = 0.5 elif mode == 'up': self.scale_factor = 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.skip.weight primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
rawandahmad698/GFPGAN
ResBlock
false
7,553
[ "BSD-3-Clause" ]
1
4700bf1a94ec9c36746f660db19f4f03e0eed9b0
https://github.com/rawandahmad698/GFPGAN/tree/4700bf1a94ec9c36746f660db19f4f03e0eed9b0
CapsuleLoss
import torch import torch.nn as nn import torch.nn.functional as F class MarginLoss(nn.Module): def __init__(self, size_average=False, loss_lambda=0.5): """ Margin loss for digit existence Eq. (4): L_k = T_k * max(0, m+ - ||v_k||)^2 + lambda * (1 - T_k) * max(0, ||v_k|| - m-)^2 Args: size_average: should the losses be averaged (True) or summed (False) over observations for each minibatch. loss_lambda: parameter for down-weighting the loss for missing digits """ super(MarginLoss, self).__init__() self.size_average = size_average self.m_plus = 0.9 self.m_minus = 0.1 self.loss_lambda = loss_lambda def forward(self, inputs, labels): L_k = labels * F.relu(self.m_plus - inputs) ** 2 + self.loss_lambda * ( 1 - labels) * F.relu(inputs - self.m_minus) ** 2 L_k = L_k.sum(dim=1) if self.size_average: return L_k.mean() else: return L_k.sum() class CapsuleLoss(nn.Module): def __init__(self, loss_lambda=0.5, recon_loss_scale=0.0005, size_average=False): """ Combined margin loss and reconstruction loss. Margin loss see above. Sum squared error (SSE) was used as a reconstruction loss. Args: recon_loss_scale: param for scaling down the the reconstruction loss size_average: if True, reconstruction loss becomes MSE instead of SSE """ super(CapsuleLoss, self).__init__() self.size_average = size_average self.margin_loss = MarginLoss(size_average=size_average, loss_lambda=loss_lambda) self.reconstruction_loss = nn.MSELoss(size_average=size_average) self.recon_loss_scale = recon_loss_scale def forward(self, inputs, labels, images, reconstructions): margin_loss = self.margin_loss(inputs, labels) reconstruction_loss = self.reconstruction_loss(reconstructions, images) caps_loss = margin_loss + self.recon_loss_scale * reconstruction_loss return caps_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 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_per_fused_add_mul_pow_relu_rsub_sub_sum_0(in_ptr0, in_ptr1, out_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) tmp18 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp19 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp32 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp33 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp46 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp47 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp2 = 0.9 tmp3 = tmp2 - tmp1 tmp4 = tl.full([1, 1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = tmp5 * tmp5 tmp7 = tmp0 * tmp6 tmp8 = 1.0 tmp9 = tmp8 - tmp0 tmp10 = 0.5 tmp11 = tmp9 * tmp10 tmp12 = 0.1 tmp13 = tmp1 - tmp12 tmp14 = triton_helpers.maximum(tmp4, tmp13) tmp15 = tmp14 * tmp14 tmp16 = tmp11 * tmp15 tmp17 = tmp7 + tmp16 tmp20 = tmp2 - tmp19 tmp21 = triton_helpers.maximum(tmp4, tmp20) tmp22 = tmp21 * tmp21 tmp23 = tmp18 * tmp22 tmp24 = tmp8 - tmp18 tmp25 = tmp24 * tmp10 tmp26 = tmp19 - tmp12 tmp27 = triton_helpers.maximum(tmp4, tmp26) tmp28 = tmp27 * tmp27 tmp29 = tmp25 * tmp28 tmp30 = tmp23 + tmp29 tmp31 = tmp17 + tmp30 tmp34 = tmp2 - tmp33 tmp35 = triton_helpers.maximum(tmp4, tmp34) tmp36 = tmp35 * tmp35 tmp37 = tmp32 * tmp36 tmp38 = tmp8 - tmp32 tmp39 = tmp38 * tmp10 tmp40 = tmp33 - tmp12 tmp41 = triton_helpers.maximum(tmp4, tmp40) tmp42 = tmp41 * tmp41 tmp43 = tmp39 * tmp42 tmp44 = tmp37 + tmp43 tmp45 = tmp31 + tmp44 tmp48 = tmp2 - tmp47 tmp49 = triton_helpers.maximum(tmp4, tmp48) tmp50 = tmp49 * tmp49 tmp51 = tmp46 * tmp50 tmp52 = tmp8 - tmp46 tmp53 = tmp52 * tmp10 tmp54 = tmp47 - tmp12 tmp55 = triton_helpers.maximum(tmp4, tmp54) tmp56 = tmp55 * tmp55 tmp57 = tmp53 * tmp56 tmp58 = tmp51 + tmp57 tmp59 = tmp45 + tmp58 tmp60 = tl.broadcast_to(tmp59, [XBLOCK, RBLOCK]) tmp62 = tl.sum(tmp60, 1)[:, None] tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp62, None) @triton.jit def triton_per_fused_add_mse_loss_mul_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 = 0.0005 tmp10 = tmp6 * tmp9 tmp11 = tmp8 + tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp11, 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) buf1 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_add_mul_pow_relu_rsub_sub_sum_0[grid(1)](arg1_1, arg0_1, buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf3 = buf1 del buf1 triton_per_fused_add_mse_loss_mul_1[grid(1)](buf3, arg3_1, arg2_1, 1, 256, num_warps=2, num_stages=1) del arg2_1 del arg3_1 return buf3, class MarginLoss(nn.Module): def __init__(self, size_average=False, loss_lambda=0.5): """ Margin loss for digit existence Eq. (4): L_k = T_k * max(0, m+ - ||v_k||)^2 + lambda * (1 - T_k) * max(0, ||v_k|| - m-)^2 Args: size_average: should the losses be averaged (True) or summed (False) over observations for each minibatch. loss_lambda: parameter for down-weighting the loss for missing digits """ super(MarginLoss, self).__init__() self.size_average = size_average self.m_plus = 0.9 self.m_minus = 0.1 self.loss_lambda = loss_lambda def forward(self, inputs, labels): L_k = labels * F.relu(self.m_plus - inputs) ** 2 + self.loss_lambda * ( 1 - labels) * F.relu(inputs - self.m_minus) ** 2 L_k = L_k.sum(dim=1) if self.size_average: return L_k.mean() else: return L_k.sum() class CapsuleLossNew(nn.Module): def __init__(self, loss_lambda=0.5, recon_loss_scale=0.0005, size_average=False): """ Combined margin loss and reconstruction loss. Margin loss see above. Sum squared error (SSE) was used as a reconstruction loss. Args: recon_loss_scale: param for scaling down the the reconstruction loss size_average: if True, reconstruction loss becomes MSE instead of SSE """ super(CapsuleLossNew, self).__init__() self.size_average = size_average self.margin_loss = MarginLoss(size_average=size_average, loss_lambda=loss_lambda) self.reconstruction_loss = nn.MSELoss(size_average=size_average) self.recon_loss_scale = recon_loss_scale 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]
richardsun-voyager/capsule-network
CapsuleLoss
false
7,554
[ "MIT" ]
1
349cec1caa9ab95ff4b3333c33d04b1bdb442f67
https://github.com/richardsun-voyager/capsule-network/tree/349cec1caa9ab95ff4b3333c33d04b1bdb442f67
GAT
import math import torch import torch.nn as nn import torch.nn.functional as F def attention(query, key, value, mask=None, dropout=None, return_scores=False): """Compute 'Scaled Dot Product Attention'""" d_k = query.size(-1) scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k) if mask is not None: scores = scores.masked_fill(mask == 0, -1000000000.0) p_attn = F.softmax(scores, dim=-1) if dropout is not None: p_attn = dropout(p_attn) scores = dropout(scores) if return_scores: return torch.matmul(p_attn, value), p_attn, scores else: return torch.matmul(p_attn, value), p_attn class GraphAttentionLayer(nn.Module): """ Simple GAT layer, similar to https://arxiv.org/abs/1710.10903 """ def __init__(self, in_features, out_features, dropout, alpha, concat=True): super(GraphAttentionLayer, self).__init__() self.dropout = dropout self.in_features = in_features self.out_features = out_features self.alpha = alpha self.concat = concat self.W = nn.Parameter(torch.zeros(size=(in_features, out_features))) nn.init.xavier_uniform_(self.W.data, gain=1.414) self.a = nn.Parameter(torch.zeros(size=(2 * out_features, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) self.leakyrelu = nn.LeakyReLU(self.alpha) def forward(self, input, adj): h = torch.matmul(input, self.W) B, N = h.size()[0], h.size()[1] a_input = torch.cat([h.repeat(1, 1, N).view(B, N * N, -1), h.repeat (1, N, 1)], dim=2).view(B, N, -1, 2 * self.out_features) e = self.leakyrelu(torch.matmul(a_input, self.a).squeeze(3)) zero_vec = -9000000000000000.0 * torch.ones_like(e) attention = torch.where(adj > 0, e, zero_vec) attention = F.softmax(attention, dim=2) h_prime = torch.matmul(attention, h) if self.concat: return F.elu(h_prime) else: return h_prime def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' class GAT(nn.Module): def __init__(self, nfeat, nhid, nclass, dropout, alpha, nheads, nlayers=2): """Dense version of GAT.""" super(GAT, self).__init__() self.dropout = dropout self.nlayers = nlayers self.nheads = nheads self.attentions = [GraphAttentionLayer(nfeat, nhid, dropout=dropout, alpha=alpha, concat=True) for _ in range(nheads)] for i, attention in enumerate(self.attentions): self.add_module('attention_{}'.format(i), attention) if self.nlayers > 2: for i in range(self.nlayers - 2): for j in range(self.nheads): self.add_module('attention_{}_{}'.format(i + 1, j), GraphAttentionLayer(nhid * nheads, nhid, dropout= dropout, alpha=alpha, concat=True)) self.out_att = GraphAttentionLayer(nhid * nheads, nclass, dropout= dropout, alpha=alpha, concat=False) def forward(self, x, adj): x = F.dropout(x, self.dropout, training=self.training) input = x x = torch.cat([att(x, adj) for att in self.attentions], dim=2) if self.nlayers > 2: for i in range(self.nlayers - 2): temp = [] x = F.dropout(x, self.dropout, training=self.training) cur_input = x for j in range(self.nheads): temp.append(self.__getattr__('attention_{}_{}'.format(i + 1, j))(x, adj)) x = torch.cat(temp, dim=2) + cur_input x = F.dropout(x, self.dropout, training=self.training) x = F.elu(self.out_att(x, adj)) return x + input def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'nfeat': 4, 'nhid': 4, 'nclass': 4, 'dropout': 0.5, 'alpha': 4, 'nheads': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math import torch.nn as nn 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, 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 % 16 x2 = xindex // 128 x3 = 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 * ((4 * x1 + x0) // 16 % 4) + 16 * ((4 * x1 + 64 * x2 + x0) // 64 % 4) + (4 * x1 + x0) % 16 % 4), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr0 + (4 * (x1 % 4) + 16 * x2 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused__softmax_leaky_relu_mul_where_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, 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').to(tl .int1) tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl .int1) tmp2 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp9 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp10 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp16 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp17 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp23 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp24 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp40 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last').to( tl.int1) tmp41 = tl.load(in_ptr4 + 4 * x0, xmask, eviction_policy='evict_last') tmp45 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp46 = tl.load(in_ptr4 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp51 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp52 = tl.load(in_ptr4 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp57 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp58 = tl.load(in_ptr4 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp74 = tl.load(in_ptr5 + 4 * x0, xmask, eviction_policy='evict_last').to( tl.int1) tmp75 = tl.load(in_ptr6 + 4 * x0, xmask, eviction_policy='evict_last') tmp79 = tl.load(in_ptr5 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp80 = tl.load(in_ptr6 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp85 = tl.load(in_ptr5 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp86 = tl.load(in_ptr6 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp91 = tl.load(in_ptr5 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp92 = tl.load(in_ptr6 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp108 = tl.load(in_ptr7 + 4 * x0, xmask, eviction_policy='evict_last').to( tl.int1) tmp109 = tl.load(in_ptr8 + 4 * x0, xmask, eviction_policy='evict_last') tmp113 = tl.load(in_ptr7 + (1 + 4 * x0), xmask, eviction_policy= 'evict_last').to(tl.int1) tmp114 = tl.load(in_ptr8 + (1 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp119 = tl.load(in_ptr7 + (2 + 4 * x0), xmask, eviction_policy= 'evict_last').to(tl.int1) tmp120 = tl.load(in_ptr8 + (2 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp125 = tl.load(in_ptr7 + (3 + 4 * x0), xmask, eviction_policy= 'evict_last').to(tl.int1) tmp126 = tl.load(in_ptr8 + (3 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp3 = 4.0 tmp4 = tmp2 * tmp3 tmp5 = tl.where(tmp1, tmp2, tmp4) tmp6 = -8999999815811072.0 tmp7 = tl.where(tmp0, tmp5, tmp6) tmp11 = tmp10 * tmp3 tmp12 = tl.where(tmp9, tmp10, tmp11) tmp13 = tl.where(tmp8, tmp12, tmp6) tmp14 = triton_helpers.maximum(tmp7, tmp13) tmp18 = tmp17 * tmp3 tmp19 = tl.where(tmp16, tmp17, tmp18) tmp20 = tl.where(tmp15, tmp19, tmp6) tmp21 = triton_helpers.maximum(tmp14, tmp20) tmp25 = tmp24 * tmp3 tmp26 = tl.where(tmp23, tmp24, tmp25) tmp27 = tl.where(tmp22, tmp26, tmp6) tmp28 = triton_helpers.maximum(tmp21, tmp27) tmp29 = tmp7 - tmp28 tmp30 = tl_math.exp(tmp29) tmp31 = tmp13 - tmp28 tmp32 = tl_math.exp(tmp31) tmp33 = tmp30 + tmp32 tmp34 = tmp20 - tmp28 tmp35 = tl_math.exp(tmp34) tmp36 = tmp33 + tmp35 tmp37 = tmp27 - tmp28 tmp38 = tl_math.exp(tmp37) tmp39 = tmp36 + tmp38 tmp42 = tmp41 * tmp3 tmp43 = tl.where(tmp40, tmp41, tmp42) tmp44 = tl.where(tmp0, tmp43, tmp6) tmp47 = tmp46 * tmp3 tmp48 = tl.where(tmp45, tmp46, tmp47) tmp49 = tl.where(tmp8, tmp48, tmp6) tmp50 = triton_helpers.maximum(tmp44, tmp49) tmp53 = tmp52 * tmp3 tmp54 = tl.where(tmp51, tmp52, tmp53) tmp55 = tl.where(tmp15, tmp54, tmp6) tmp56 = triton_helpers.maximum(tmp50, tmp55) tmp59 = tmp58 * tmp3 tmp60 = tl.where(tmp57, tmp58, tmp59) tmp61 = tl.where(tmp22, tmp60, tmp6) tmp62 = triton_helpers.maximum(tmp56, tmp61) tmp63 = tmp44 - tmp62 tmp64 = tl_math.exp(tmp63) tmp65 = tmp49 - tmp62 tmp66 = tl_math.exp(tmp65) tmp67 = tmp64 + tmp66 tmp68 = tmp55 - tmp62 tmp69 = tl_math.exp(tmp68) tmp70 = tmp67 + tmp69 tmp71 = tmp61 - tmp62 tmp72 = tl_math.exp(tmp71) tmp73 = tmp70 + tmp72 tmp76 = tmp75 * tmp3 tmp77 = tl.where(tmp74, tmp75, tmp76) tmp78 = tl.where(tmp0, tmp77, tmp6) tmp81 = tmp80 * tmp3 tmp82 = tl.where(tmp79, tmp80, tmp81) tmp83 = tl.where(tmp8, tmp82, tmp6) tmp84 = triton_helpers.maximum(tmp78, tmp83) tmp87 = tmp86 * tmp3 tmp88 = tl.where(tmp85, tmp86, tmp87) tmp89 = tl.where(tmp15, tmp88, tmp6) tmp90 = triton_helpers.maximum(tmp84, tmp89) tmp93 = tmp92 * tmp3 tmp94 = tl.where(tmp91, tmp92, tmp93) tmp95 = tl.where(tmp22, tmp94, tmp6) tmp96 = triton_helpers.maximum(tmp90, tmp95) tmp97 = tmp78 - tmp96 tmp98 = tl_math.exp(tmp97) tmp99 = tmp83 - tmp96 tmp100 = tl_math.exp(tmp99) tmp101 = tmp98 + tmp100 tmp102 = tmp89 - tmp96 tmp103 = tl_math.exp(tmp102) tmp104 = tmp101 + tmp103 tmp105 = tmp95 - tmp96 tmp106 = tl_math.exp(tmp105) tmp107 = tmp104 + tmp106 tmp110 = tmp109 * tmp3 tmp111 = tl.where(tmp108, tmp109, tmp110) tmp112 = tl.where(tmp0, tmp111, tmp6) tmp115 = tmp114 * tmp3 tmp116 = tl.where(tmp113, tmp114, tmp115) tmp117 = tl.where(tmp8, tmp116, tmp6) tmp118 = triton_helpers.maximum(tmp112, tmp117) tmp121 = tmp120 * tmp3 tmp122 = tl.where(tmp119, tmp120, tmp121) tmp123 = tl.where(tmp15, tmp122, tmp6) tmp124 = triton_helpers.maximum(tmp118, tmp123) tmp127 = tmp126 * tmp3 tmp128 = tl.where(tmp125, tmp126, tmp127) tmp129 = tl.where(tmp22, tmp128, tmp6) tmp130 = triton_helpers.maximum(tmp124, tmp129) tmp131 = tmp112 - tmp130 tmp132 = tl_math.exp(tmp131) tmp133 = tmp117 - tmp130 tmp134 = tl_math.exp(tmp133) tmp135 = tmp132 + tmp134 tmp136 = tmp123 - tmp130 tmp137 = tl_math.exp(tmp136) tmp138 = tmp135 + tmp137 tmp139 = tmp129 - tmp130 tmp140 = tl_math.exp(tmp139) tmp141 = tmp138 + tmp140 tl.store(out_ptr0 + x0, tmp28, xmask) tl.store(out_ptr1 + x0, tmp39, xmask) tl.store(out_ptr2 + x0, tmp62, xmask) tl.store(out_ptr3 + x0, tmp73, xmask) tl.store(out_ptr4 + x0, tmp96, xmask) tl.store(out_ptr5 + x0, tmp107, xmask) tl.store(out_ptr6 + x0, tmp130, xmask) tl.store(out_ptr7 + x0, tmp141, xmask) @triton.jit def triton_poi_fused__softmax_leaky_relu_mul_where_3(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, in_ptr12, 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).to(tl.int1) tmp1 = tl.load(in_ptr1 + x2, xmask).to(tl.int1) tmp2 = tl.load(in_out_ptr0 + x2, xmask) tmp8 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr4 + x2, xmask).to(tl.int1) tmp14 = tl.load(in_out_ptr1 + x2, xmask) tmp18 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr7 + x2, xmask).to(tl.int1) tmp24 = tl.load(in_out_ptr2 + x2, xmask) tmp28 = tl.load(in_ptr8 + x1, xmask, eviction_policy='evict_last') tmp31 = tl.load(in_ptr9 + x1, xmask, eviction_policy='evict_last') tmp33 = tl.load(in_ptr10 + x2, xmask).to(tl.int1) tmp34 = tl.load(in_out_ptr3 + x2, xmask) tmp38 = tl.load(in_ptr11 + x1, xmask, eviction_policy='evict_last') tmp41 = tl.load(in_ptr12 + x1, xmask, eviction_policy='evict_last') tmp3 = 4.0 tmp4 = tmp2 * tmp3 tmp5 = tl.where(tmp1, tmp2, tmp4) tmp6 = -8999999815811072.0 tmp7 = tl.where(tmp0, tmp5, tmp6) tmp9 = tmp7 - tmp8 tmp10 = tl_math.exp(tmp9) tmp12 = tmp10 / tmp11 tmp15 = tmp14 * tmp3 tmp16 = tl.where(tmp13, tmp14, tmp15) tmp17 = tl.where(tmp0, tmp16, tmp6) tmp19 = tmp17 - tmp18 tmp20 = tl_math.exp(tmp19) tmp22 = tmp20 / tmp21 tmp25 = tmp24 * tmp3 tmp26 = tl.where(tmp23, tmp24, tmp25) tmp27 = tl.where(tmp0, tmp26, tmp6) tmp29 = tmp27 - tmp28 tmp30 = tl_math.exp(tmp29) tmp32 = tmp30 / tmp31 tmp35 = tmp34 * tmp3 tmp36 = tl.where(tmp33, tmp34, tmp35) tmp37 = tl.where(tmp0, tmp36, tmp6) tmp39 = tmp37 - tmp38 tmp40 = tl_math.exp(tmp39) tmp42 = tmp40 / tmp41 tl.store(in_out_ptr0 + x2, tmp12, xmask) tl.store(in_out_ptr1 + x2, tmp22, xmask) tl.store(in_out_ptr2 + x2, tmp32, xmask) tl.store(in_out_ptr3 + x2, tmp42, xmask) @triton.jit def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 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 = 0.0 tmp7 = tmp5 > tmp6 tmp8 = 1.0 tmp9 = tmp5 * tmp8 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp8 tmp12 = tl.where(tmp7, tmp9, tmp11) tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp4, tmp12, tmp13) tmp15 = tmp0 >= tmp3 tmp16 = tl.full([1], 8, tl.int64) tmp17 = tmp0 < tmp16 tmp18 = tmp15 & tmp17 tmp19 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp18 & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tmp19 > tmp6 tmp21 = tmp19 * tmp8 tmp22 = libdevice.expm1(tmp21) tmp23 = tmp22 * tmp8 tmp24 = tl.where(tmp20, tmp21, tmp23) tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp18, tmp24, tmp25) tmp27 = tmp0 >= tmp16 tmp28 = tl.full([1], 12, tl.int64) tmp29 = tmp0 < tmp28 tmp30 = tmp27 & tmp29 tmp31 = tl.load(in_ptr2 + (4 * x1 + (-8 + x0)), tmp30 & xmask, eviction_policy='evict_last', other=0.0) tmp32 = tmp31 > tmp6 tmp33 = tmp31 * tmp8 tmp34 = libdevice.expm1(tmp33) tmp35 = tmp34 * tmp8 tmp36 = tl.where(tmp32, tmp33, tmp35) tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp30, tmp36, tmp37) tmp39 = tmp0 >= tmp28 tl.full([1], 16, tl.int64) tmp42 = tl.load(in_ptr3 + (4 * x1 + (-12 + x0)), tmp39 & xmask, eviction_policy='evict_last', other=0.0) tmp43 = tmp42 > tmp6 tmp44 = tmp42 * tmp8 tmp45 = libdevice.expm1(tmp44) tmp46 = tmp45 * tmp8 tmp47 = tl.where(tmp43, tmp44, tmp46) tmp48 = tl.full(tmp47.shape, 0.0, tmp47.dtype) tmp49 = tl.where(tmp39, tmp47, tmp48) tmp50 = tl.where(tmp30, tmp38, tmp49) tmp51 = tl.where(tmp18, tmp26, tmp50) tmp52 = tl.where(tmp4, tmp14, tmp51) tl.store(out_ptr0 + x2, tmp52, xmask) @triton.jit def triton_poi_fused__softmax_leaky_relu_mul_where_5(in_ptr0, in_ptr1, in_ptr2, 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').to(tl .int1) tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl .int1) tmp2 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp9 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp10 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp16 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp17 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp23 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp24 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp3 = 4.0 tmp4 = tmp2 * tmp3 tmp5 = tl.where(tmp1, tmp2, tmp4) tmp6 = -8999999815811072.0 tmp7 = tl.where(tmp0, tmp5, tmp6) tmp11 = tmp10 * tmp3 tmp12 = tl.where(tmp9, tmp10, tmp11) tmp13 = tl.where(tmp8, tmp12, tmp6) tmp14 = triton_helpers.maximum(tmp7, tmp13) tmp18 = tmp17 * tmp3 tmp19 = tl.where(tmp16, tmp17, tmp18) tmp20 = tl.where(tmp15, tmp19, tmp6) tmp21 = triton_helpers.maximum(tmp14, tmp20) tmp25 = tmp24 * tmp3 tmp26 = tl.where(tmp23, tmp24, tmp25) tmp27 = tl.where(tmp22, tmp26, tmp6) tmp28 = triton_helpers.maximum(tmp21, tmp27) tmp29 = tmp7 - tmp28 tmp30 = tl_math.exp(tmp29) tmp31 = tmp13 - tmp28 tmp32 = tl_math.exp(tmp31) tmp33 = tmp30 + tmp32 tmp34 = tmp20 - tmp28 tmp35 = tl_math.exp(tmp34) tmp36 = tmp33 + tmp35 tmp37 = tmp27 - tmp28 tmp38 = tl_math.exp(tmp37) tmp39 = tmp36 + tmp38 tl.store(out_ptr0 + x0, tmp28, xmask) tl.store(out_ptr1 + x0, tmp39, xmask) @triton.jit def triton_poi_fused__softmax_leaky_relu_mul_where_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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).to(tl.int1) tmp1 = tl.load(in_ptr1 + x2, xmask).to(tl.int1) tmp2 = tl.load(in_out_ptr0 + x2, xmask) tmp8 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp3 = 4.0 tmp4 = tmp2 * tmp3 tmp5 = tl.where(tmp1, tmp2, tmp4) tmp6 = -8999999815811072.0 tmp7 = tl.where(tmp0, tmp5, tmp6) tmp9 = tmp7 - tmp8 tmp10 = tl_math.exp(tmp9) tmp12 = tmp10 / tmp11 tl.store(in_out_ptr0 + x2, tmp12, xmask) @triton.jit def triton_poi_fused_add_elu_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 x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp8 = tl.load(in_ptr1 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tmp9 = tmp7 + tmp8 tl.store(out_ptr0 + x0, 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, primals_12 ) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (8, 1), (1, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (8, 1), (1, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (8, 1), (1, 1)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (8, 1), (1, 1)) assert_size_stride(primals_11, (16, 4), (4, 1)) assert_size_stride(primals_12, (8, 1), (1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](buf0, buf1, 512, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 8), (8, 1), 0), primals_3, out=buf2) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](primals_4, buf4, 64, XBLOCK =64, num_warps=1, num_stages=1) del primals_4 buf9 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_5, out=buf9) del primals_5 buf10 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) triton_poi_fused_cat_0[grid(512)](buf9, buf10, 512, XBLOCK=128, num_warps=4, num_stages=1) buf11 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf10, (64, 8), (8, 1), 0), primals_6, out=buf11) buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf11, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_7, out=buf17) del primals_7 buf18 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) triton_poi_fused_cat_0[grid(512)](buf17, buf18, 512, XBLOCK=128, num_warps=4, num_stages=1) buf19 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf18, (64, 8), (8, 1), 0), primals_8, out=buf19) buf20 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf19, buf20, 64, XBLOCK=64, num_warps=1, num_stages=1) buf25 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_9, out=buf25) del primals_9 buf26 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) triton_poi_fused_cat_0[grid(512)](buf25, buf26, 512, XBLOCK=128, num_warps=4, num_stages=1) buf27 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf26, (64, 8), (8, 1), 0), primals_10, out=buf27) buf28 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf27, buf28, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf6 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf13 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf21 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf22 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf29 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf30 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_leaky_relu_mul_where_2[grid(16)](buf4, buf3, buf2, buf12, buf11, buf20, buf19, buf28, buf27, buf5, buf6, buf13, buf14, buf21, buf22, buf29, buf30, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0) del buf2 buf15 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0) del buf11 buf23 = reinterpret_tensor(buf19, (4, 4, 4), (16, 4, 1), 0) del buf19 buf31 = reinterpret_tensor(buf27, (4, 4, 4), (16, 4, 1), 0) del buf27 triton_poi_fused__softmax_leaky_relu_mul_where_3[grid(64)](buf7, buf15, buf23, buf31, buf4, buf3, buf5, buf6, buf12, buf13, buf14, buf20, buf21, buf22, buf28, buf29, buf30, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf13 del buf14 del buf21 del buf22 del buf29 del buf30 buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf7, reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), out=buf8) buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf15, reinterpret_tensor(buf9, (4, 4, 4), (16, 4, 1), 0), out=buf16) buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf23, reinterpret_tensor(buf17, (4, 4, 4), (16, 4, 1), 0), out=buf24) buf32 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf31, reinterpret_tensor(buf25, (4, 4, 4), (16, 4, 1), 0), out=buf32) buf33 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_cat_4[grid(256)](buf8, buf16, buf24, buf32, buf33, 256, XBLOCK=128, num_warps=4, num_stages=1) buf34 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf33, (16, 16), (16, 1), 0), primals_11, out=buf34) buf35 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) triton_poi_fused_cat_0[grid(512)](buf34, buf35, 512, XBLOCK=128, num_warps=4, num_stages=1) buf36 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf35, (64, 8), (8, 1), 0), primals_12, out=buf36) buf37 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf36, buf37, 64, XBLOCK=64, num_warps=1, num_stages=1) buf38 = buf6 del buf6 buf39 = buf5 del buf5 triton_poi_fused__softmax_leaky_relu_mul_where_5[grid(16)](buf4, buf37, buf36, buf38, buf39, 16, XBLOCK=16, num_warps=1, num_stages=1) buf40 = reinterpret_tensor(buf36, (4, 4, 4), (16, 4, 1), 0) del buf36 triton_poi_fused__softmax_leaky_relu_mul_where_6[grid(64)](buf40, buf4, buf37, buf38, buf39, 64, XBLOCK=64, num_warps=1, num_stages=1 ) del buf38 del buf39 buf41 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf40, reinterpret_tensor(buf34, (4, 4, 4), (16, 4, 1), 0), out=buf41) buf42 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_elu_7[grid(64)](buf41, primals_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1) return (buf42, buf3, buf4, buf7, buf8, buf12, buf15, buf16, buf20, buf23, buf24, buf28, buf31, buf32, buf37, buf40, buf41, reinterpret_tensor(buf34, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf35, (8, 64), (1, 8), 0), reinterpret_tensor( primals_12, (1, 8), (1, 1), 0), reinterpret_tensor(buf33, (16, 16), (1, 16), 0), reinterpret_tensor(primals_11, (4, 16), (1, 4), 0), reinterpret_tensor(buf25, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf26, (8, 64), (1, 8), 0), reinterpret_tensor( primals_10, (1, 8), (1, 1), 0), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), reinterpret_tensor(buf17, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf18, (8, 64), (1, 8), 0), reinterpret_tensor(primals_8, (1, 8), (1, 1), 0), reinterpret_tensor(buf9, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf10, (8, 64), (1, 8), 0), reinterpret_tensor( primals_6, (1, 8), (1, 1), 0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf1, (8, 64), (1, 8), 0), reinterpret_tensor(primals_3, (1, 8), (1, 1), 0)) def attention(query, key, value, mask=None, dropout=None, return_scores=False): """Compute 'Scaled Dot Product Attention'""" d_k = query.size(-1) scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k) if mask is not None: scores = scores.masked_fill(mask == 0, -1000000000.0) p_attn = F.softmax(scores, dim=-1) if dropout is not None: p_attn = dropout(p_attn) scores = dropout(scores) if return_scores: return torch.matmul(p_attn, value), p_attn, scores else: return torch.matmul(p_attn, value), p_attn class GraphAttentionLayer(nn.Module): """ Simple GAT layer, similar to https://arxiv.org/abs/1710.10903 """ def __init__(self, in_features, out_features, dropout, alpha, concat=True): super(GraphAttentionLayer, self).__init__() self.dropout = dropout self.in_features = in_features self.out_features = out_features self.alpha = alpha self.concat = concat self.W = nn.Parameter(torch.zeros(size=(in_features, out_features))) nn.init.xavier_uniform_(self.W.data, gain=1.414) self.a = nn.Parameter(torch.zeros(size=(2 * out_features, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) self.leakyrelu = nn.LeakyReLU(self.alpha) def forward(self, input, adj): h = torch.matmul(input, self.W) B, N = h.size()[0], h.size()[1] a_input = torch.cat([h.repeat(1, 1, N).view(B, N * N, -1), h.repeat (1, N, 1)], dim=2).view(B, N, -1, 2 * self.out_features) e = self.leakyrelu(torch.matmul(a_input, self.a).squeeze(3)) zero_vec = -9000000000000000.0 * torch.ones_like(e) attention = torch.where(adj > 0, e, zero_vec) attention = F.softmax(attention, dim=2) h_prime = torch.matmul(attention, h) if self.concat: return F.elu(h_prime) else: return h_prime def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' class GATNew(nn.Module): def __init__(self, nfeat, nhid, nclass, dropout, alpha, nheads, nlayers=2): """Dense version of GAT.""" super(GATNew, self).__init__() self.dropout = dropout self.nlayers = nlayers self.nheads = nheads self.attentions = [GraphAttentionLayer(nfeat, nhid, dropout=dropout, alpha=alpha, concat=True) for _ in range(nheads)] for i, attention in enumerate(self.attentions): self.add_module('attention_{}'.format(i), attention) if self.nlayers > 2: for i in range(self.nlayers - 2): for j in range(self.nheads): self.add_module('attention_{}_{}'.format(i + 1, j), GraphAttentionLayer(nhid * nheads, nhid, dropout= dropout, alpha=alpha, concat=True)) self.out_att = GraphAttentionLayer(nhid * nheads, nclass, dropout= dropout, alpha=alpha, concat=False) def forward(self, input_0, input_1): primals_2 = self.attention_0.W primals_3 = self.attention_0.a primals_5 = self.attention_1.W primals_6 = self.attention_1.a primals_7 = self.attention_2.W primals_8 = self.attention_2.a primals_9 = self.attention_3.W primals_10 = self.attention_3.a primals_11 = self.out_att.W primals_12 = self.out_att.a primals_1 = input_0 primals_4 = 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]) return output[0]
qinyan-li/DocEE
GAT
false
7,555
[ "MIT" ]
1
e8d2202a44907df5f12f9a67180d849a54421ab7
https://github.com/qinyan-li/DocEE/tree/e8d2202a44907df5f12f9a67180d849a54421ab7
ResBlock
import torch from torch import nn import torch.nn.functional as F class LinearAndMultiply(nn.Module): def __init__(self, input_size, output_size, use_multiply=True, linear_block=nn.Linear): super().__init__() self._activation = nn.CELU() self._linear = linear_block(input_size, output_size) self._use_multiply = use_multiply if self._use_multiply: self._to_multiplier = linear_block(output_size, output_size) def forward(self, x, *extra): x = self._activation(self._linear(x, *extra)) if not self._use_multiply: return x return x * torch.tanh(self._to_multiplier(x, *extra)) class ResBlock(nn.Module): def __init__(self, input_size, output_size, use_multiply=True, linear_block=nn.Linear, use_norm=True): super().__init__() self._linear_block = LinearAndMultiply(input_size, output_size, use_multiply=False, linear_block=linear_block) self._mul_block = LinearAndMultiply(output_size, output_size, use_multiply=use_multiply, linear_block=linear_block) self._use_norm = use_norm if self._use_norm: self._norm = nn.LayerNorm(output_size) self._pad_size = output_size - input_size assert self._pad_size >= 0 def forward(self, x, *extra): padded_input = F.pad(x, (0, self._pad_size)) x = self._mul_block(self._linear_block(x, *extra), *extra) x = padded_input + x if self._use_norm: x = self._norm(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_celu_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 = libdevice.expm1(tmp0) tmp4 = tl.where(tmp2, tmp0, tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_add_mul_tanh_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 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask) tmp3 = libdevice.tanh(tmp2) tmp4 = tmp1 * tmp3 tmp5 = tmp0 + tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_native_layer_norm_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-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_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) 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, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_celu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_celu_0[grid(256)](buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) 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((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_tanh_1[grid(256)](primals_1, buf3, buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_native_layer_norm_2[grid(64)](buf5, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_3[grid(256)](buf5, buf6, buf7, primals_8, primals_9, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf6 del buf7 del primals_9 return buf8, primals_8, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0 ), buf2, buf3, buf4, buf5, primals_6, primals_4 class LinearAndMultiply(nn.Module): def __init__(self, input_size, output_size, use_multiply=True, linear_block=nn.Linear): super().__init__() self._activation = nn.CELU() self._linear = linear_block(input_size, output_size) self._use_multiply = use_multiply if self._use_multiply: self._to_multiplier = linear_block(output_size, output_size) def forward(self, x, *extra): x = self._activation(self._linear(x, *extra)) if not self._use_multiply: return x return x * torch.tanh(self._to_multiplier(x, *extra)) class ResBlockNew(nn.Module): def __init__(self, input_size, output_size, use_multiply=True, linear_block=nn.Linear, use_norm=True): super().__init__() self._linear_block = LinearAndMultiply(input_size, output_size, use_multiply=False, linear_block=linear_block) self._mul_block = LinearAndMultiply(output_size, output_size, use_multiply=use_multiply, linear_block=linear_block) self._use_norm = use_norm if self._use_norm: self._norm = nn.LayerNorm(output_size) self._pad_size = output_size - input_size assert self._pad_size >= 0 def forward(self, input_0): primals_2 = self._linear_block._linear.weight primals_3 = self._linear_block._linear.bias primals_4 = self._mul_block._linear.weight primals_5 = self._mul_block._linear.bias primals_6 = self._mul_block._to_multiplier.weight primals_7 = self._mul_block._to_multiplier.bias primals_8 = self._norm.weight primals_9 = self._norm.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]
rgreenblatt/path
ResBlock
false
7,556
[ "MIT" ]
1
2057618ee3a6067c230c1c1c40856d2c9f5006b0
https://github.com/rgreenblatt/path/tree/2057618ee3a6067c230c1c1c40856d2c9f5006b0
SAM
import torch import torch.nn as nn class SAM(nn.Module): def __init__(self, channels_in): super(SAM, self).__init__() self.channels_in = channels_in self.avg_pool = nn.AvgPool3d(kernel_size=(self.channels_in, 1, 1)) self.max_pool = nn.MaxPool3d(kernel_size=(self.channels_in, 1, 1)) self.conv1 = nn.Conv2d(in_channels=2, out_channels=1, kernel_size=7, stride=1, padding=3) def forward(self, x, save_attention=False): spat_att = torch.cat(tensors=(self.avg_pool(x), self.max_pool(x)), dim=1) spat_att = torch.sigmoid(self.conv1(spat_att)) if save_attention: torch.save(spat_att, f'tmp/cbam-attention_spatial_{spat_att.shape[-2]}-{spat_att.shape[-1]}.pt' ) return spat_att def initialize_weights(self): nn.init.normal_(self.conv1.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.conv1.bias.data, 0.0) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels_in': 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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 2 x0 = xindex % 16 x2 = xindex // 32 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2 + 64 * x1), tmp4 & xmask, other=0.0) tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2 + 64 * x1), tmp4 & xmask, other=0.0) tmp7 = tmp6 + tmp5 tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2 + 64 * x1), tmp4 & xmask, other=0.0) tmp9 = tmp8 + tmp7 tmp10 = tl.load(in_ptr0 + (48 + x0 + 64 * x2 + 64 * x1), tmp4 & xmask, other=0.0) tmp11 = tmp10 + tmp9 tmp12 = 0.25 tmp13 = tmp11 * tmp12 tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp4, tmp13, tmp14) tmp16 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp19 = tl.load(in_ptr1 + (x0 + 16 * x2), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tl.where(tmp4, tmp15, tmp19) tl.store(out_ptr0 + x3, tmp20, xmask) @triton.jit def triton_poi_fused_convolution_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_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, (1, 2, 7, 7), (98, 49, 7, 1)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.max_pool3d_with_indices.default(primals_1, [4, 1, 1], [4, 1, 1]) buf1 = buf0[0] del buf0 buf3 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_1, buf1, buf3, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_1 buf4 = extern_kernels.convolution(buf3, primals_2, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 1, 4, 4), (16, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_sigmoid_1[grid(64)](buf5, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf5, primals_2, buf3, buf5 class SAMNew(nn.Module): def __init__(self, channels_in): super(SAMNew, self).__init__() self.channels_in = channels_in self.avg_pool = nn.AvgPool3d(kernel_size=(self.channels_in, 1, 1)) self.max_pool = nn.MaxPool3d(kernel_size=(self.channels_in, 1, 1)) self.conv1 = nn.Conv2d(in_channels=2, out_channels=1, kernel_size=7, stride=1, padding=3) def initialize_weights(self): nn.init.normal_(self.conv1.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.conv1.bias.data, 0.0) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
SAM
false
7,557
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
Affine
import torch import torch.nn as nn import torch.nn.parallel import torch.utils.data class Affine(nn.Module): def __init__(self, dim): super().__init__() self.alpha = nn.Parameter(torch.ones((1, 1, dim))) self.beta = nn.Parameter(torch.zeros((1, 1, dim))) def forward(self, x): return torch.addcmul(self.beta, self.alpha, x) 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 import torch.nn as nn import torch.nn.parallel 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_addcmul_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x2, xmask) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp5 = tmp3 * tmp4 tmp6 = tmp0 + tmp5 tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (1, 1, 4), (4, 4, 1)) assert_size_stride(primals_2, (1, 1, 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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_addcmul_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, primals_3 class AffineNew(nn.Module): def __init__(self, dim): super().__init__() self.alpha = nn.Parameter(torch.ones((1, 1, dim))) self.beta = nn.Parameter(torch.zeros((1, 1, dim))) def forward(self, input_0): primals_1 = self.alpha primals_2 = self.beta primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
rioyokotalab/pytorch-image-models
Affine
false
7,558
[ "Apache-2.0" ]
1
87d8d3c14b64bb6a76402f363a1e1ee1829bca93
https://github.com/rioyokotalab/pytorch-image-models/tree/87d8d3c14b64bb6a76402f363a1e1ee1829bca93
PositionalAttentionModule
import torch import torch.nn as nn import torch.nn.functional as F class PositionalAttentionModule(nn.Module): def __init__(self, in_channels): super(PositionalAttentionModule, self).__init__() self.in_channels = in_channels self.conv_B = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.conv_C = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.conv_D = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.alpha = nn.Parameter(torch.zeros(1), requires_grad=True) def forward(self, A): batchsize, num_channels, height, width = A.shape N = height * width B = self.conv_B(A).view((batchsize, num_channels, N)) C = self.conv_C(A).view((batchsize, num_channels, N)) D = self.conv_D(A).view((batchsize, num_channels, N)) S = F.softmax(torch.bmm(C.permute(0, 2, 1), B), dim=-1) DS = torch.bmm(D, S.permute(0, 2, 1)).view((batchsize, num_channels, height, width)) E = self.alpha * DS + A return E def initialize_weights(self): for layer in [self.conv_B, self.conv_C, self.conv_D]: nn.init.normal_(layer.weight.data, mean=0.0, std=0.02) nn.init.constant_(layer.bias.data, 0.0) nn.init.constant_(self.alpha.data, 0.0) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_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) @triton.jit def triton_per_fused__softmax_1(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tmp6 / tmp10 tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask) @triton.jit def triton_poi_fused_add_mul_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 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp3 = tmp1 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + x0, tmp5, 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) 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, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(256)](buf1, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(primals_1, 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 = extern_kernels.convolution(primals_1, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_0[grid(256)](buf4, primals_7, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf5 = buf2 del buf2 triton_poi_fused_convolution_0[grid(256)](buf5, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf5, (4, 16, 4), (64, 1, 16), 0), reinterpret_tensor(buf1, (4, 4, 16), (64, 16, 1), 0), out=buf6) buf9 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) triton_per_fused__softmax_1[grid(64)](buf6, buf9, 64, 16, XBLOCK=8, num_warps=2, num_stages=1) del buf6 buf10 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(buf9, (4, 16, 16), (256, 1, 16), 0), out =buf10) buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_2[grid(256)](primals_8, buf10, primals_1, buf11, 256, XBLOCK=128, num_warps=4, num_stages=1) return (buf11, primals_1, primals_2, primals_4, primals_6, primals_8, buf9, buf10, reinterpret_tensor(buf4, (4, 16, 4), (64, 1, 16), 0), reinterpret_tensor(buf5, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(buf1, (4, 16, 4), (64, 1, 16), 0)) class PositionalAttentionModuleNew(nn.Module): def __init__(self, in_channels): super(PositionalAttentionModuleNew, self).__init__() self.in_channels = in_channels self.conv_B = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.conv_C = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.conv_D = nn.Conv2d(in_channels=self.in_channels, out_channels= self.in_channels, kernel_size=1, stride=1, padding=0) self.alpha = nn.Parameter(torch.zeros(1), requires_grad=True) def initialize_weights(self): for layer in [self.conv_B, self.conv_C, self.conv_D]: nn.init.normal_(layer.weight.data, mean=0.0, std=0.02) nn.init.constant_(layer.bias.data, 0.0) nn.init.constant_(self.alpha.data, 0.0) def forward(self, input_0): primals_8 = self.alpha primals_2 = self.conv_B.weight primals_3 = self.conv_B.bias primals_4 = self.conv_C.weight primals_5 = self.conv_C.bias primals_6 = self.conv_D.weight primals_7 = self.conv_D.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
PositionalAttentionModule
false
7,559
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
UpConcat2d
import torch import torch.nn as nn import torch.nn.functional as F class UpConcat2d(nn.Module): def __init__(self, in_channels_conv, out_channels_conv, scale_factor=2): super(UpConcat2d, self).__init__() self.in_channels_conv = in_channels_conv self.out_channels_conv = out_channels_conv self.scale_factor = scale_factor self.up = nn.ConvTranspose2d(in_channels=self.in_channels_conv, out_channels=self.out_channels_conv, kernel_size=2, stride=2, padding=0) if scale_factor == 4: self.up2 = nn.ConvTranspose2d(in_channels=self. out_channels_conv, out_channels=self.out_channels_conv, kernel_size=2, stride=2, padding=0) def forward(self, x_down, x_enc): up = F.relu(self.up(x_down)) if self.scale_factor == 4: up = F.relu(self.up2(up)) if up.shape[-1] > x_enc.shape[-1]: p = (up.shape[-1] - x_enc.shape[-1]) // 2 if (up.shape[-1] - x_enc.shape[-1]) % 2 != 0: p += 1 x_enc = F.pad(x_enc, (p, p, p, p)) start = [(x_enc.shape[-2] - up.shape[-2]) // 2, (x_enc.shape[-1] - up.shape[-1]) // 2] length = [up.shape[-2], up.shape[-1]] crop = torch.narrow(torch.narrow(x_enc, dim=2, start=start[0], length=length[0]), dim=3, start=start[1], length=length[1]) cat = torch.cat(tensors=(up, crop), dim=1) return cat def initialize_weights(self): nn.init.normal_(self.up.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.up.bias.data, 0.0) if self.scale_factor == 4: nn.init.normal_(self.up2.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.up2.bias.data, 0.0) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels_conv': 4, 'out_channels_conv': 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_cat_0(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) x2 = xindex // 64 % 8 x3 = xindex // 512 x4 = xindex % 64 x1 = xindex // 8 % 8 x0 = xindex % 8 x7 = xindex tmp0 = x2 tmp1 = tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 64 * x2 + 256 * x3), tmp4, other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp15 = -2 + x1 tmp16 = tmp15 >= tmp1 tmp17 = tmp15 < tmp3 tmp18 = -2 + x0 tmp19 = tmp18 >= tmp1 tmp20 = tmp18 < tmp3 tmp21 = tmp16 & tmp17 tmp22 = tmp21 & tmp19 tmp23 = tmp22 & tmp20 tmp24 = tmp23 & tmp12 tmp25 = tl.load(in_ptr2 + (-10 + x0 + 4 * x1 + 16 * (-4 + x2) + 64 * x3 ), tmp24, other=0.0) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp12, tmp25, tmp26) tmp28 = tl.where(tmp4, tmp11, tmp27) tl.store(out_ptr0 + x7, tmp28, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 2, 2), (16, 4, 2, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 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=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 8, 8), (256, 64, 8, 1)) buf1 = empty_strided_cuda((4, 8, 8, 8), (512, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(2048)](buf0, primals_2, primals_4, buf1, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_1[grid(1024)](buf0 , primals_2, buf2, 1024, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_2 return buf1, primals_1, primals_3, buf2 class UpConcat2dNew(nn.Module): def __init__(self, in_channels_conv, out_channels_conv, scale_factor=2): super(UpConcat2dNew, self).__init__() self.in_channels_conv = in_channels_conv self.out_channels_conv = out_channels_conv self.scale_factor = scale_factor self.up = nn.ConvTranspose2d(in_channels=self.in_channels_conv, out_channels=self.out_channels_conv, kernel_size=2, stride=2, padding=0) if scale_factor == 4: self.up2 = nn.ConvTranspose2d(in_channels=self. out_channels_conv, out_channels=self.out_channels_conv, kernel_size=2, stride=2, padding=0) def initialize_weights(self): nn.init.normal_(self.up.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.up.bias.data, 0.0) if self.scale_factor == 4: nn.init.normal_(self.up2.weight.data, mean=0.0, std=0.02) nn.init.constant_(self.up2.bias.data, 0.0) def forward(self, input_0, input_1): primals_1 = self.up.weight primals_2 = self.up.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
UpConcat2d
false
7,560
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
DiscShiftLoss
import torch import torch.nn as nn class DiscShiftLoss(nn.Module): """Disc shift loss. Args: loss_weight (float, optional): Loss weight. Defaults to 1.0. """ def __init__(self, loss_weight=0.1): super(DiscShiftLoss, self).__init__() self.loss_weight = loss_weight def forward(self, x): """Forward function. Args: x (Tensor): Tensor with shape (n, c, h, w) Returns: Tensor: Loss. """ loss = torch.mean(x ** 2) return loss * self.loss_weight 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_per_fused_mean_mul_pow_0(in_out_ptr0, in_ptr0, 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 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = triton_helpers.promote_to_tensor(tl.sum(tmp2, 0)) tmp5 = 256.0 tmp6 = tmp4 / tmp5 tmp7 = 0.1 tmp8 = tmp6 * tmp7 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp8, None) 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((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_mul_pow_0[grid(1)](buf1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 return buf1, class DiscShiftLossNew(nn.Module): """Disc shift loss. Args: loss_weight (float, optional): Loss weight. Defaults to 1.0. """ def __init__(self, loss_weight=0.1): super(DiscShiftLossNew, self).__init__() self.loss_weight = loss_weight def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
rivergold/mmediting
DiscShiftLoss
false
7,561
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
Attention
import torch from torch import nn class Attention(nn.Module): def __init__(self, heads, dim, hidden_dim): super().__init__() self.dim = dim self.hdim = hidden_dim self.heads = heads self.to_q = nn.Linear(dim, hidden_dim * heads) self.to_k = nn.Linear(dim, hidden_dim * heads) self.to_v = nn.Linear(dim, hidden_dim * heads) self.project = nn.Linear(heads * hidden_dim, dim) def forward(self, x): B, T, _ = x.shape Q = self.to_q(x).view(B, self.heads, T, self.hdim) K = self.to_k(x).view(B, self.heads, T, self.hdim) V = self.to_v(x).view(B, self.heads, T, self.hdim) weights = torch.softmax(Q.permute(0, 1, 3, 2) @ K / self.hdim ** 0.5, dim=-1) out = weights @ V.permute(0, 1, 3, 2) out = self.project(out.view(B, T, self.heads * self.hdim)) return out def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'heads': 4, '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._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_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x2, tmp17, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (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, 4), (16, 4, 1)) assert_size_stride(primals_2, (16, 4), (4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (16, 4), (4, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (4, 16), (16, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_6 del primals_7 buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 1, 4), 0), out=buf6) buf7 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf6, (16, 16), (16, 1), 0), reinterpret_tensor(primals_8, (16, 4), (1, 16), 0), alpha=1, beta=1, out=buf7) del primals_9 return reinterpret_tensor(buf7, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0 ), buf5, reinterpret_tensor(buf6, (16, 16), (16, 1), 0 ), primals_8, reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf1, (16, 4, 4), (16, 1, 4), 0) class AttentionNew(nn.Module): def __init__(self, heads, dim, hidden_dim): super().__init__() self.dim = dim self.hdim = hidden_dim self.heads = heads self.to_q = nn.Linear(dim, hidden_dim * heads) self.to_k = nn.Linear(dim, hidden_dim * heads) self.to_v = nn.Linear(dim, hidden_dim * heads) self.project = nn.Linear(heads * hidden_dim, dim) def forward(self, input_0): primals_2 = self.to_q.weight primals_3 = self.to_q.bias primals_4 = self.to_k.weight primals_5 = self.to_k.bias primals_6 = self.to_v.weight primals_7 = self.to_v.bias primals_8 = self.project.weight primals_9 = self.project.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]
rish-16/audio-tf-pytorch
Attention
false
7,562
[ "MIT" ]
1
397a6e9f1a97cce774202d392eb9706f0483405c
https://github.com/rish-16/audio-tf-pytorch/tree/397a6e9f1a97cce774202d392eb9706f0483405c
CharbonnierCompLoss
import functools import torch import torch.nn as nn from torch.nn import functional as F def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def charbonnier_loss(pred, target, eps=1e-12): """Charbonnier loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated Charbonnier loss. """ return torch.sqrt((pred - target) ** 2 + eps) class CharbonnierCompLoss(nn.Module): """Charbonnier composition loss. Args: loss_weight (float): Loss weight for L1 loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. eps (float): A value used to control the curvature near zero. Default: 1e-12. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False, eps=1e-12): super(CharbonnierCompLoss, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise self.eps = eps def forward(self, pred_alpha, fg, bg, ori_merged, weight=None, **kwargs): """ Args: pred_alpha (Tensor): of shape (N, 1, H, W). Predicted alpha matte. fg (Tensor): of shape (N, 3, H, W). Tensor of foreground object. bg (Tensor): of shape (N, 3, H, W). Tensor of background object. ori_merged (Tensor): of shape (N, 3, H, W). Tensor of origin merged image before normalized by ImageNet mean and std. weight (Tensor, optional): of shape (N, 1, H, W). It is an indicating matrix: weight[trimap == 128] = 1. Default: None. """ pred_merged = pred_alpha * fg + (1.0 - pred_alpha) * bg if weight is not None: weight = weight.expand(-1, 3, -1, -1) return self.loss_weight * charbonnier_loss(pred_merged, ori_merged, weight, eps=self.eps, reduction=self.reduction, sample_wise= self.sample_wise) 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 from torch._inductor.runtime.triton_helpers import libdevice import functools import torch.nn as nn from torch.nn import 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_per_fused_add_mean_mul_pow_rsub_sqrt_sub_0(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) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp5 = tl.load(in_ptr2 + r0, None) tmp8 = tl.load(in_ptr3 + r0, None) tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp9 = tmp7 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = 1e-12 tmp12 = tmp10 + tmp11 tmp13 = libdevice.sqrt(tmp12) tmp14 = tl.broadcast_to(tmp13, [RBLOCK]) tmp16 = triton_helpers.promote_to_tensor(tl.sum(tmp14, 0)) tmp17 = 256.0 tmp18 = tmp16 / tmp17 tmp19 = tmp18 * tmp3 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp19, 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) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_mul_pow_rsub_sqrt_sub_0[grid(1)](buf1, arg0_1, arg1_1, arg2_1, arg3_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 return buf1, def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def charbonnier_loss(pred, target, eps=1e-12): """Charbonnier loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated Charbonnier loss. """ return torch.sqrt((pred - target) ** 2 + eps) class CharbonnierCompLossNew(nn.Module): """Charbonnier composition loss. Args: loss_weight (float): Loss weight for L1 loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. eps (float): A value used to control the curvature near zero. Default: 1e-12. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False, eps=1e-12): super(CharbonnierCompLossNew, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise self.eps = eps 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]
rivergold/mmediting
CharbonnierCompLoss
false
7,563
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
sAG
import torch import torch.nn as nn class sAG(nn.Module): def __init__(self, num_channels_in_enc, num_channels_in_dec): super(sAG, self).__init__() self.num_channels_in_enc = num_channels_in_enc self.num_channels_in_dec = num_channels_in_dec self.ch_max_pool_enc = nn.MaxPool3d(kernel_size=(self. num_channels_in_enc, 1, 1)) self.ch_avg_pool_enc = nn.AvgPool3d(kernel_size=(self. num_channels_in_enc, 1, 1)) self.conv1_enc = nn.Conv2d(in_channels=self.num_channels_in_enc, out_channels=1, kernel_size=1, stride=1, padding=0) self.conv2_enc = nn.Conv2d(in_channels=3, out_channels=1, kernel_size=7, stride=1, padding=3) self.ch_max_pool_dec = nn.MaxPool3d(kernel_size=(self. num_channels_in_dec, 1, 1)) self.ch_avg_pool_dec = nn.AvgPool3d(kernel_size=(self. num_channels_in_dec, 1, 1)) self.conv1_dec = nn.Conv2d(in_channels=self.num_channels_in_dec, out_channels=1, kernel_size=1, stride=1, padding=0) self.conv2_dec = nn.Conv2d(in_channels=3, out_channels=1, kernel_size=7, stride=1, padding=3) def forward(self, enc, dec): enc = torch.cat(tensors=(self.ch_max_pool_enc(enc), self. ch_avg_pool_enc(enc), self.conv1_enc(enc)), dim=1) enc = self.conv2_enc(enc) dec = torch.cat(tensors=(self.ch_max_pool_dec(dec), self. ch_avg_pool_dec(dec), self.conv1_dec(dec)), dim=1) dec = self.conv2_dec(dec) out = torch.sigmoid(enc + dec) return out def initialize_weights(self): for layer in [self.conv1_enc, self.conv1_dec, self.conv2_enc, self. conv2_dec]: nn.init.normal_(layer.weight.data, mean=0.0, std=0.02) nn.init.constant_(layer.bias.data, 0.0) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_channels_in_enc': 4, 'num_channels_in_dec': 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_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 3 x0 = xindex % 16 x2 = xindex // 48 x3 = xindex tmp25 = tl.load(in_ptr3 + 0) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 2, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (x0 + 64 * x2 + 64 * (-1 + x1)), tmp9 & xmask, other=0.0) tmp11 = tl.load(in_ptr1 + (16 + x0 + 64 * x2 + 64 * (-1 + x1)), tmp9 & xmask, other=0.0) tmp12 = tmp11 + tmp10 tmp13 = tl.load(in_ptr1 + (32 + x0 + 64 * x2 + 64 * (-1 + x1)), tmp9 & xmask, other=0.0) tmp14 = tmp13 + tmp12 tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x2 + 64 * (-1 + x1)), tmp9 & xmask, other=0.0) tmp16 = tmp15 + tmp14 tmp17 = 0.25 tmp18 = tmp16 * tmp17 tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp9, tmp18, tmp19) tmp21 = tmp0 >= tmp7 tl.full([1], 3, tl.int64) tmp24 = tl.load(in_ptr2 + (x0 + 16 * x2), tmp21 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tmp24 + tmp26 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp21, tmp27, tmp28) tmp30 = tl.where(tmp9, tmp20, tmp29) tmp31 = tl.where(tmp4, tmp5, tmp30) tl.store(out_ptr0 + x3, tmp31, xmask) @triton.jit def triton_poi_fused_add_convolution_sigmoid_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_out_ptr0 + x0, xmask) tmp5 = tl.load(in_ptr2 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp7 = tmp4 + tmp6 tmp8 = tmp3 + tmp7 tmp9 = tl.sigmoid(tmp8) tl.store(in_out_ptr0 + x0, 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) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (1, 3, 7, 7), (147, 49, 7, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_7, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_8, (1,), (1,)) assert_size_stride(primals_9, (1, 3, 7, 7), (147, 49, 7, 1)) assert_size_stride(primals_10, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.max_pool3d_with_indices.default(primals_1, [4, 1, 1], [4, 1, 1]) buf1 = buf0[0] del buf0 buf3 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 1, 4, 4), (16, 16, 4, 1)) buf4 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(192)](buf1, primals_1, buf3, primals_3, buf4, 192, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del buf3 del primals_3 buf5 = extern_kernels.convolution(buf4, primals_4, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 1, 4, 4), (16, 16, 4, 1)) buf6 = torch.ops.aten.max_pool3d_with_indices.default(primals_6, [4, 1, 1], [4, 1, 1]) buf7 = buf6[0] del buf6 buf9 = extern_kernels.convolution(primals_6, primals_7, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 1, 4, 4), (16, 16, 4, 1)) buf10 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) triton_poi_fused_cat_0[grid(192)](buf7, primals_6, buf9, primals_8, buf10, 192, XBLOCK=256, num_warps=4, num_stages=1) del buf7 del buf9 del primals_8 buf11 = extern_kernels.convolution(buf10, primals_9, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 1, 4, 4), (16, 16, 4, 1)) buf12 = buf11 del buf11 triton_poi_fused_add_convolution_sigmoid_1[grid(64)](buf12, buf5, primals_5, primals_10, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf5 del primals_10 del primals_5 return (buf12, primals_1, primals_2, primals_4, primals_6, primals_7, primals_9, buf4, buf10, buf12) class sAGNew(nn.Module): def __init__(self, num_channels_in_enc, num_channels_in_dec): super(sAGNew, self).__init__() self.num_channels_in_enc = num_channels_in_enc self.num_channels_in_dec = num_channels_in_dec self.ch_max_pool_enc = nn.MaxPool3d(kernel_size=(self. num_channels_in_enc, 1, 1)) self.ch_avg_pool_enc = nn.AvgPool3d(kernel_size=(self. num_channels_in_enc, 1, 1)) self.conv1_enc = nn.Conv2d(in_channels=self.num_channels_in_enc, out_channels=1, kernel_size=1, stride=1, padding=0) self.conv2_enc = nn.Conv2d(in_channels=3, out_channels=1, kernel_size=7, stride=1, padding=3) self.ch_max_pool_dec = nn.MaxPool3d(kernel_size=(self. num_channels_in_dec, 1, 1)) self.ch_avg_pool_dec = nn.AvgPool3d(kernel_size=(self. num_channels_in_dec, 1, 1)) self.conv1_dec = nn.Conv2d(in_channels=self.num_channels_in_dec, out_channels=1, kernel_size=1, stride=1, padding=0) self.conv2_dec = nn.Conv2d(in_channels=3, out_channels=1, kernel_size=7, stride=1, padding=3) def initialize_weights(self): for layer in [self.conv1_enc, self.conv1_dec, self.conv2_enc, self. conv2_dec]: nn.init.normal_(layer.weight.data, mean=0.0, std=0.02) nn.init.constant_(layer.bias.data, 0.0) def forward(self, input_0, input_1): primals_2 = self.conv1_enc.weight primals_3 = self.conv1_enc.bias primals_4 = self.conv2_enc.weight primals_5 = self.conv2_enc.bias primals_7 = self.conv1_dec.weight primals_8 = self.conv1_dec.bias primals_9 = self.conv2_dec.weight primals_10 = self.conv2_dec.bias primals_1 = 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]) return output[0]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
sAG
false
7,564
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
L1CompositionLoss
import functools import torch import torch.nn as nn from torch.nn import functional as F def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def l1_loss(pred, target): """L1 loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated L1 loss. """ return F.l1_loss(pred, target, reduction='none') class L1CompositionLoss(nn.Module): """L1 composition loss. Args: loss_weight (float): Loss weight for L1 loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False): super(L1CompositionLoss, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise def forward(self, pred_alpha, fg, bg, ori_merged, weight=None, **kwargs): """ Args: pred_alpha (Tensor): of shape (N, 1, H, W). Predicted alpha matte. fg (Tensor): of shape (N, 3, H, W). Tensor of foreground object. bg (Tensor): of shape (N, 3, H, W). Tensor of background object. ori_merged (Tensor): of shape (N, 3, H, W). Tensor of origin merged image before normalized by ImageNet mean and std. weight (Tensor, optional): of shape (N, 1, H, W). It is an indicating matrix: weight[trimap == 128] = 1. Default: None. """ pred_merged = pred_alpha * fg + (1.0 - pred_alpha) * bg if weight is not None: weight = weight.expand(-1, 3, -1, -1) return self.loss_weight * l1_loss(pred_merged, ori_merged, weight, reduction=self.reduction, sample_wise=self.sample_wise) 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 from torch._inductor.runtime.triton_helpers import math as tl_math import functools import torch.nn as nn from torch.nn import 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_per_fused_abs_add_mean_mul_rsub_sub_0(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) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp5 = tl.load(in_ptr2 + r0, None) tmp8 = tl.load(in_ptr3 + r0, None) tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp9 = tmp7 - tmp8 tmp10 = tl_math.abs(tmp9) tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = tmp15 * tmp3 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp16, 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) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_mean_mul_rsub_sub_0[grid(1)](buf1, arg0_1, arg1_1, arg2_1, arg3_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 return buf1, def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def l1_loss(pred, target): """L1 loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated L1 loss. """ return F.l1_loss(pred, target, reduction='none') class L1CompositionLossNew(nn.Module): """L1 composition loss. Args: loss_weight (float): Loss weight for L1 loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False): super(L1CompositionLossNew, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise 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]
rivergold/mmediting
L1CompositionLoss
false
7,565
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
DeepSupervisionModule
import torch import torch.nn as nn class DeepSupervisionModule(nn.Module): def __init__(self, up_sampling_factors=(2, 2, 2)): super(DeepSupervisionModule, self).__init__() self.up = nn.UpsamplingBilinear2d(scale_factor=2) self.up_sampling_factors = up_sampling_factors def forward(self, dec4, dec3, dec2, dec1): out = self.up(dec4) if self.up_sampling_factors[0] == 4: out = self.up(out) start = [(out.shape[-2] - dec3.shape[-2]) // 2, (out.shape[-1] - dec3.shape[-1]) // 2] length = [dec3.shape[-2], dec3.shape[-1]] out = torch.narrow(torch.narrow(out, dim=2, start=start[0], length= length[0]), dim=3, start=start[1], length=length[1]) out = self.up(torch.cat(tensors=(dec3, out), dim=1)) if self.up_sampling_factors[1] == 4: out = self.up(out) start = [(out.shape[-2] - dec2.shape[-2]) // 2, (out.shape[-1] - dec2.shape[-1]) // 2] length = [dec2.shape[-2], dec2.shape[-1]] out = torch.narrow(torch.narrow(out, dim=2, start=start[0], length= length[0]), dim=3, start=start[1], length=length[1]) out = self.up(torch.cat(tensors=(dec2, out), dim=1)) if self.up_sampling_factors[2] == 4: out = self.up(out) start = [(out.shape[-2] - dec1.shape[-2]) // 2, (out.shape[-1] - dec1.shape[-1]) // 2] length = [dec1.shape[-2], dec1.shape[-1]] out = torch.narrow(torch.narrow(out, dim=2, start=start[0], length= length[0]), dim=3, start=start[1], length=length[1]) out = torch.cat(tensors=(dec1, out), dim=1) return out 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 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 = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.42857142857142855 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), xmask, eviction_policy='evict_last') tmp17 = tmp15 + tmp7 tmp18 = triton_helpers.minimum(tmp17, tmp9) tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), xmask, eviction_policy='evict_last') tmp20 = tmp19 - tmp16 tmp21 = tmp15.to(tl.float32) tmp22 = tmp14 - tmp21 tmp23 = triton_helpers.maximum(tmp22, tmp4) tmp24 = 1.0 tmp25 = triton_helpers.minimum(tmp23, tmp24) tmp26 = tmp20 * tmp25 tmp27 = tmp16 + tmp26 tmp28 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), xmask, eviction_policy='evict_last') tmp29 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), xmask, eviction_policy='evict_last') tmp30 = tmp29 - tmp28 tmp31 = tmp30 * tmp25 tmp32 = tmp28 + tmp31 tmp33 = tmp27 - tmp32 tmp34 = tmp6.to(tl.float32) tmp35 = tmp5 - tmp34 tmp36 = triton_helpers.maximum(tmp35, tmp4) tmp37 = triton_helpers.minimum(tmp36, tmp24) tmp38 = tmp33 * tmp37 tmp39 = tmp32 + tmp38 tl.store(in_out_ptr0 + x4, tmp39, xmask) @triton.jit def triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_1( in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, 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 x2 = xindex // 64 % 8 x3 = xindex // 512 x5 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.42857142857142855 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 = tmp15 + tmp7 tmp17 = triton_helpers.minimum(tmp16, tmp9) tmp18 = x2 tl.full([1], 0, tl.int64) tmp21 = tl.full([1], 4, tl.int64) tmp22 = tmp18 < tmp21 tmp23 = tl.load(in_ptr0 + (tmp17 + 4 * tmp10 + 16 * x2 + 64 * x3), tmp22, eviction_policy='evict_last', other=0.0) tmp24 = tmp18 >= tmp21 tl.full([1], 8, tl.int64) tmp27 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 256 * x3), tmp24, eviction_policy='evict_last', other=0.0) tmp28 = tl.where(tmp22, tmp23, tmp27) tmp29 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2 + 64 * x3), tmp22, eviction_policy='evict_last', other=0.0) tmp30 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 256 * x3), tmp24, eviction_policy='evict_last', other=0.0) tmp31 = tl.where(tmp22, tmp29, tmp30) tmp32 = tmp28 - tmp31 tmp33 = tmp15.to(tl.float32) tmp34 = tmp14 - tmp33 tmp35 = triton_helpers.maximum(tmp34, tmp4) tmp36 = 1.0 tmp37 = triton_helpers.minimum(tmp35, tmp36) tmp38 = tmp32 * tmp37 tmp39 = tmp31 + tmp38 tmp40 = tl.load(in_ptr0 + (tmp17 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22, eviction_policy='evict_last', other=0.0) tmp41 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 256 * x3), tmp24, eviction_policy='evict_last', other=0.0) tmp42 = tl.where(tmp22, tmp40, tmp41) tmp43 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22, eviction_policy='evict_last', other=0.0) tmp44 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 256 * x3), tmp24, eviction_policy='evict_last', other=0.0) tmp45 = tl.where(tmp22, tmp43, tmp44) tmp46 = tmp42 - tmp45 tmp47 = tmp46 * tmp37 tmp48 = tmp45 + tmp47 tl.store(in_out_ptr0 + x5, tmp39, None) tl.store(in_out_ptr1 + x5, tmp48, None) @triton.jit def triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_2( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 % 12 x3 = xindex // 768 x6 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.42857142857142855 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 = tmp15 + tmp7 tmp17 = triton_helpers.minimum(tmp16, tmp9) tmp18 = x2 tl.full([1], 0, tl.int64) tmp21 = tl.full([1], 4, tl.int64) tmp22 = tmp18 < tmp21 tmp23 = tl.load(in_ptr0 + (tmp17 + 4 * tmp10 + 16 * x2 + 64 * x3), tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tmp18 >= tmp21 tl.full([1], 12, tl.int64) tmp27 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tl.load(in_ptr2 + (18 + tmp17 + 8 * tmp10 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp29 = tmp28 - tmp27 tmp30 = tl.broadcast_to(2 + tmp10, [XBLOCK]) tmp31 = tmp30.to(tl.float32) tmp32 = tmp31 * tmp2 tmp33 = triton_helpers.maximum(tmp32, tmp4) tmp34 = tmp33.to(tl.int32) tmp35 = tmp34.to(tl.float32) tmp36 = tmp33 - tmp35 tmp37 = triton_helpers.maximum(tmp36, tmp4) tmp38 = 1.0 tmp39 = triton_helpers.minimum(tmp37, tmp38) tmp40 = tmp29 * tmp39 tmp41 = tmp27 + tmp40 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp24, tmp41, tmp42) tmp44 = tl.where(tmp22, tmp23, tmp43) tmp45 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2 + 64 * x3), tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp46 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp47 = tl.load(in_ptr2 + (18 + tmp15 + 8 * tmp10 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp48 = tmp47 - tmp46 tmp49 = tmp48 * tmp39 tmp50 = tmp46 + tmp49 tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype) tmp52 = tl.where(tmp24, tmp50, tmp51) tmp53 = tl.where(tmp22, tmp45, tmp52) tmp54 = tl.load(in_ptr0 + (tmp17 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp55 = tl.load(in_ptr1 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp56 = tl.load(in_ptr2 + (18 + tmp17 + 8 * tmp6 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp57 = tmp56 - tmp55 tmp58 = tl.broadcast_to(2 + tmp6, [XBLOCK]) tmp59 = tmp58.to(tl.float32) tmp60 = tmp59 * tmp2 tmp61 = triton_helpers.maximum(tmp60, tmp4) tmp62 = tmp61.to(tl.int32) tmp63 = tmp62.to(tl.float32) tmp64 = tmp61 - tmp63 tmp65 = triton_helpers.maximum(tmp64, tmp4) tmp66 = triton_helpers.minimum(tmp65, tmp38) tmp67 = tmp57 * tmp66 tmp68 = tmp55 + tmp67 tmp69 = tl.full(tmp68.shape, 0.0, tmp68.dtype) tmp70 = tl.where(tmp24, tmp68, tmp69) tmp71 = tl.where(tmp22, tmp54, tmp70) tmp72 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2 + 64 * x3), tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp73 = tl.load(in_ptr1 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp74 = tl.load(in_ptr2 + (18 + tmp15 + 8 * tmp6 + 64 * (-4 + x2) + 512 * x3), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp75 = tmp74 - tmp73 tmp76 = tmp75 * tmp66 tmp77 = tmp73 + tmp76 tmp78 = tl.full(tmp77.shape, 0.0, tmp77.dtype) tmp79 = tl.where(tmp24, tmp77, tmp78) tmp80 = tl.where(tmp22, tmp72, tmp79) tmp81 = tmp44 - tmp53 tmp82 = tmp15.to(tl.float32) tmp83 = tmp14 - tmp82 tmp84 = triton_helpers.maximum(tmp83, tmp4) tmp85 = triton_helpers.minimum(tmp84, tmp38) tmp86 = tmp81 * tmp85 tmp87 = tmp53 + tmp86 tmp88 = tmp71 - tmp80 tmp89 = tmp88 * tmp85 tmp90 = tmp80 + tmp89 tmp91 = tmp87 - tmp90 tmp92 = tmp6.to(tl.float32) tmp93 = tmp5 - tmp92 tmp94 = triton_helpers.maximum(tmp93, tmp4) tmp95 = triton_helpers.minimum(tmp94, tmp38) tmp96 = tmp91 * tmp95 tl.store(out_ptr1 + x6, tmp71, xmask) tl.store(out_ptr2 + x6, tmp80, xmask) tl.store(in_out_ptr0 + x6, tmp96, xmask) @triton.jit def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 % 16 x3 = xindex // 256 x4 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x6 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 64 * x3), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 16, tl.int64) tmp9 = tl.load(in_ptr1 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3), tmp6 & xmask, other=0.0) tmp10 = tl.load(in_ptr2 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3 ), tmp6 & xmask, other=0.0) tmp11 = tmp10 - tmp9 tmp12 = 2 + x0 tmp13 = tmp12.to(tl.float32) tmp14 = 0.42857142857142855 tmp15 = tmp13 * tmp14 tmp16 = 0.0 tmp17 = triton_helpers.maximum(tmp15, tmp16) tmp18 = tmp17.to(tl.int32) tmp19 = tmp18.to(tl.float32) tmp20 = tmp17 - tmp19 tmp21 = triton_helpers.maximum(tmp20, tmp16) tmp22 = 1.0 tmp23 = triton_helpers.minimum(tmp21, tmp22) tmp24 = tmp11 * tmp23 tmp25 = tmp9 + tmp24 tmp26 = tl.load(in_ptr3 + (18 + x0 + 8 * x1 + 64 * (-4 + x2) + 768 * x3 ), tmp6 & xmask, other=0.0) tmp27 = tmp25 + tmp26 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp6, tmp27, tmp28) tmp30 = tl.where(tmp4, tmp5, tmp29) tl.store(out_ptr0 + x6, tmp30, xmask) 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((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid (1024)](buf1, arg0_1, 1024, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((4, 8, 8, 8), (512, 64, 8, 1), torch.float32) buf3 = buf2 del buf2 buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 8, 8, 8), (512, 64, 8, 1), torch.float32) buf6 = buf5 del buf5 triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_1[ grid(2048)](buf4, buf6, arg1_1, buf1, 2048, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 buf7 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch.float32 ) buf9 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch.float32 ) buf10 = empty_strided_cuda((4, 12, 8, 8), (768, 64, 8, 1), torch. float32) buf11 = buf7 del buf7 triton_poi_fused__to_copy__unsafe_index_add_arange_cat_clamp_mul_sub_2[ grid(3072)](buf11, arg2_1, buf6, buf4, buf9, buf10, 3072, XBLOCK=128, num_warps=4, num_stages=1) del arg2_1 del buf4 del buf6 buf12 = reinterpret_tensor(buf1, (4, 16, 4, 4), (256, 16, 4, 1), 0) del buf1 triton_poi_fused_cat_3[grid(1024)](arg3_1, buf10, buf9, buf11, buf12, 1024, XBLOCK=256, num_warps=4, num_stages=1) del arg3_1 del buf10 del buf11 del buf9 return buf12, class DeepSupervisionModuleNew(nn.Module): def __init__(self, up_sampling_factors=(2, 2, 2)): super(DeepSupervisionModuleNew, self).__init__() self.up = nn.UpsamplingBilinear2d(scale_factor=2) self.up_sampling_factors = up_sampling_factors 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]
rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets
DeepSupervisionModule
false
7,566
[ "MIT" ]
1
75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
https://github.com/rinkwitz/Thesis_Semantic_Image_Segmentation_on_Satellite_Imagery_using_UNets/tree/75d3a4a536f6ef81fe0efd4f5fbba32b627a7472
Attention
import math import torch import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): def __init__(self, embed_dim, hidden_dim=None, out_dim=None, n_head=1, score_function='dot_product', dropout=0): """ Attention Mechanism :param embed_dim: :param hidden_dim: :param out_dim: :param n_head: num of head (Multi-Head Attention) :param score_function: scaled_dot_product / mlp (concat) / bi_linear (general dot) :return (?, q_len, out_dim,) """ super(Attention, self).__init__() if hidden_dim is None: hidden_dim = embed_dim // n_head if out_dim is None: out_dim = embed_dim self.embed_dim = embed_dim self.hidden_dim = hidden_dim self.n_head = n_head self.score_function = score_function self.w_k = nn.Linear(embed_dim, n_head * hidden_dim) self.w_q = nn.Linear(embed_dim, n_head * hidden_dim) self.proj = nn.Linear(n_head * hidden_dim, out_dim) self.dropout = nn.Dropout(dropout) if score_function == 'mlp': self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2)) elif self.score_function == 'bi_linear': self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim)) else: self.register_parameter('weight', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_dim) if self.weight is not None: self.weight.data.uniform_(-stdv, stdv) def forward(self, k, q): if len(q.shape) == 2: q = torch.unsqueeze(q, dim=1) if len(k.shape) == 2: k = torch.unsqueeze(k, dim=1) mb_size = k.shape[0] k_len = k.shape[1] q_len = q.shape[1] kx = self.w_k(k).view(mb_size, k_len, self.n_head, self.hidden_dim) kx = kx.permute(2, 0, 1, 3).contiguous().view(-1, k_len, self. hidden_dim) qx = self.w_q(q).view(mb_size, q_len, self.n_head, self.hidden_dim) qx = qx.permute(2, 0, 1, 3).contiguous().view(-1, q_len, self. hidden_dim) if self.score_function == 'dot_product': kt = kx.permute(0, 2, 1) score = torch.bmm(qx, kt) elif self.score_function == 'scaled_dot_product': kt = kx.permute(0, 2, 1) qkt = torch.bmm(qx, kt) score = torch.div(qkt, math.sqrt(self.hidden_dim)) elif self.score_function == 'mlp': kxx = torch.unsqueeze(kx, dim=1).expand(-1, q_len, -1, -1) qxx = torch.unsqueeze(qx, dim=2).expand(-1, -1, k_len, -1) kq = torch.cat((kxx, qxx), dim=-1) score = F.tanh(torch.matmul(kq, self.weight)) elif self.score_function == 'bi_linear': qw = torch.matmul(qx, self.weight) kt = kx.permute(0, 2, 1) score = torch.bmm(qw, kt) else: raise RuntimeError('invalid score_function') score = F.softmax(score, dim=-1) output = torch.bmm(score, kx) output = torch.cat(torch.split(output, mb_size, dim=0), dim=-1) output = self.proj(output) output = self.dropout(output) return output, score def get_inputs(): return [torch.rand([4, 4, 1, 4]), torch.rand([4, 4, 1, 4])] def get_init_inputs(): return [[], {'embed_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 4), (16, 4, 4, 1)) assert_size_stride(primals_2, (4, 4, 1, 4), (16, 4, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_3 del primals_4 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_5 del primals_6 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0), out=buf2) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = buf2 del buf2 triton_poi_fused__softmax_1[grid(64)](buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf3 del buf3 extern_kernels.bmm(buf4, reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), out=buf5) buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_8, reinterpret_tensor(buf5, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf6) del primals_8 return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0 ), buf4, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0 ), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0 ), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0 ), buf4, reinterpret_tensor(buf5, (16, 4), (4, 1), 0 ), primals_7, reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0) class AttentionNew(nn.Module): def __init__(self, embed_dim, hidden_dim=None, out_dim=None, n_head=1, score_function='dot_product', dropout=0): """ Attention Mechanism :param embed_dim: :param hidden_dim: :param out_dim: :param n_head: num of head (Multi-Head Attention) :param score_function: scaled_dot_product / mlp (concat) / bi_linear (general dot) :return (?, q_len, out_dim,) """ super(AttentionNew, self).__init__() if hidden_dim is None: hidden_dim = embed_dim // n_head if out_dim is None: out_dim = embed_dim self.embed_dim = embed_dim self.hidden_dim = hidden_dim self.n_head = n_head self.score_function = score_function self.w_k = nn.Linear(embed_dim, n_head * hidden_dim) self.w_q = nn.Linear(embed_dim, n_head * hidden_dim) self.proj = nn.Linear(n_head * hidden_dim, out_dim) self.dropout = nn.Dropout(dropout) if score_function == 'mlp': self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2)) elif self.score_function == 'bi_linear': self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim)) else: self.register_parameter('weight', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_dim) if self.weight is not None: self.weight.data.uniform_(-stdv, stdv) def forward(self, input_0, input_1): primals_3 = self.w_k.weight primals_4 = self.w_k.bias primals_5 = self.w_q.weight primals_6 = self.w_q.bias primals_7 = self.proj.weight primals_8 = self.proj.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0], output[1]
rmarcacini/LC-ABSA
Attention
false
7,567
[ "MIT" ]
1
90ae7f41b3766761005caf015292926127fe3949
https://github.com/rmarcacini/LC-ABSA/tree/90ae7f41b3766761005caf015292926127fe3949
Conv
import torch import torch.utils.data from torch import nn class Conv(nn.Module): """ 2d卷积 先batchnorm再ReLU,默认有ReLU但是没有BN 默认小核 """ def __init__(self, inp_dim, out_dim, kernel_size=3, stride=1, bn=False, relu=True): super(Conv, self).__init__() self.inp_dim = inp_dim self.conv = nn.Conv2d(inp_dim, out_dim, kernel_size, stride, padding=(kernel_size - 1) // 2, bias=True) self.relu = None self.bn = None if relu: self.relu = nn.ReLU() if bn: self.bn = nn.BatchNorm2d(out_dim) def forward(self, x): assert x.size()[1] == self.inp_dim, '{} {}'.format(x.size()[1], self.inp_dim) x = self.conv(x) if self.bn is not None: x = self.bn(x) if self.relu is not None: x = self.relu(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'inp_dim': 4, 'out_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.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 @triton.jit def triton_poi_fused_convolution_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 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) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (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 = 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, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(256)](buf1, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf2 class ConvNew(nn.Module): """ 2d卷积 先batchnorm再ReLU,默认有ReLU但是没有BN 默认小核 """ def __init__(self, inp_dim, out_dim, kernel_size=3, stride=1, bn=False, relu=True): super(ConvNew, self).__init__() self.inp_dim = inp_dim self.conv = nn.Conv2d(inp_dim, out_dim, kernel_size, stride, padding=(kernel_size - 1) // 2, bias=True) self.relu = None self.bn = None if relu: self.relu = nn.ReLU() if bn: self.bn = nn.BatchNorm2d(out_dim) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
rm-rf-me/Study-stacked-hourglass
Conv
false
7,568
[ "BSD-3-Clause" ]
1
48441f0dd5ae3397470c70db0f50ab5576b9d2f2
https://github.com/rm-rf-me/Study-stacked-hourglass/tree/48441f0dd5ae3397470c70db0f50ab5576b9d2f2
LandmarkHead
import torch import torch.nn as nn from itertools import product as product class LandmarkHead(nn.Module): def __init__(self, inchannels=512, num_anchors=3): super(LandmarkHead, self).__init__() self.conv1x1 = nn.Conv2d(inchannels, num_anchors * 8, kernel_size=( 1, 1), stride=1, padding=0) def forward(self, x): out = self.conv1x1(x) out = out.permute(0, 2, 3, 1).contiguous() return out.view(out.shape[0], -1, 8) def get_inputs(): return [torch.rand([4, 512, 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 from itertools import product as product 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): 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] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), None, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 512 * x2 + 2097152 * y1), tmp0, None) @triton.jit def triton_poi_fused_clone_view_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) x4 = xindex x0 = xindex % 24 tmp0 = tl.load(in_out_ptr0 + x4, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x4, tmp2, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (24, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_2, (24,), (1,)) assert_size_stride(primals_3, (4, 512, 64, 64), (2097152, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 512, 64, 64), (2097152, 1, 32768, 512 ), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(2048, 4096)](primals_3, buf0, 2048, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_3 buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 24, 64, 64), (98304, 1, 1536, 24)) buf2 = reinterpret_tensor(buf1, (4, 64, 64, 24), (98304, 1536, 24, 1), 0) del buf1 buf3 = reinterpret_tensor(buf2, (4, 12288, 8), (98304, 8, 1), 0) del buf2 triton_poi_fused_clone_view_1[grid(393216)](buf3, primals_2, 393216, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 return buf3, primals_1, buf0 class LandmarkHeadNew(nn.Module): def __init__(self, inchannels=512, num_anchors=3): super(LandmarkHeadNew, self).__init__() self.conv1x1 = nn.Conv2d(inchannels, num_anchors * 8, kernel_size=( 1, 1), stride=1, padding=0) def forward(self, input_0): primals_1 = self.conv1x1.weight primals_2 = self.conv1x1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
qw85639229/Car_License_SVM
LandmarkHead
false
7,569
[ "MIT" ]
1
c5b0062e84e5000c7940b1d90cc7c63e52afed21
https://github.com/qw85639229/Car_License_SVM/tree/c5b0062e84e5000c7940b1d90cc7c63e52afed21
Attention
import torch import torch.nn.functional as F class Attention(torch.nn.Module): def __init__(self, features, attn_dim): super(Attention, self).__init__() self.to_q = torch.nn.Linear(features, attn_dim) self.to_k = torch.nn.Linear(features, attn_dim) self.to_v = torch.nn.Linear(features, attn_dim) self.project = torch.nn.Linear(attn_dim, features) def forward(self, x): Q = self.to_q(x) K = self.to_k(x) V = self.to_v(x) dots = torch.bmm(Q, K.permute(0, 2, 1)) attn = F.softmax(dots, 0) out = torch.bmm(attn, V) out = self.project(out) return out def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'features': 4, 'attn_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = 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), (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,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf2) del primals_6 del primals_7 buf3 = 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(buf1, (4, 4, 4), (16, 1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf3 del buf3 triton_poi_fused__softmax_1[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = buf4 del buf4 extern_kernels.bmm(buf5, reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0), out=buf6) buf7 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf6, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf7) del primals_9 return reinterpret_tensor(buf7, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_3, (16, 4), (4, 1), 0 ), buf5, reinterpret_tensor(buf6, (16, 4), (4, 1), 0 ), primals_8, reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) class AttentionNew(torch.nn.Module): def __init__(self, features, attn_dim): super(AttentionNew, self).__init__() self.to_q = torch.nn.Linear(features, attn_dim) self.to_k = torch.nn.Linear(features, attn_dim) self.to_v = torch.nn.Linear(features, attn_dim) self.project = torch.nn.Linear(attn_dim, features) def forward(self, input_0): primals_1 = self.to_q.weight primals_2 = self.to_q.bias primals_4 = self.to_k.weight primals_5 = self.to_k.bias primals_6 = self.to_v.weight primals_7 = self.to_v.bias primals_8 = self.project.weight primals_9 = self.project.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]
rish-16/pytorch-graphdl
Attention
false
7,570
[ "MIT" ]
1
631da8cbf24e67fab2122c507e1935d4acf26e41
https://github.com/rish-16/pytorch-graphdl/tree/631da8cbf24e67fab2122c507e1935d4acf26e41
DQN
import torch import torch.nn as nn import torch.nn.functional as F class DQN(nn.Module): """ Deep Q-Network: Actor (Policy) Model. (function approximator for the Q-table) """ def __init__(self, state_size, action_size, seed, fc1_unit=64, fc2_unit=64 ): """ Initialize parameters and build model. Params ======= state_size (int): Dimension of each state action_size (int): Dimension of each action seed (int): Random seed fc1_unit (int): Number of neurons in first hidden layer fc2_unit (int): Number of neurons in second hidden layer """ super(DQN, self).__init__() self.seed = torch.manual_seed(seed) self.conv1 = nn.Conv2d(1, 32, 8, stride=4, padding=1) self.conv2 = nn.Conv2d(32, 64, 4, stride=2) self.conv3 = nn.Conv2d(64, 128, 3) self.fc1 = nn.Linear(1 * 128 * 19 * 8, 512) self.fc2 = nn.Linear(512, action_size) def forward(self, state): """ mapping a state to action-values. --- args: state: state tensor (grayscale img) returns: q_values: array of length 6. It corresponds to the action-values for each action given the input state q_values=[Q(state, a_1), Q(state, a_2), ..., Q(state, a_6)] """ x = state.clone() x = x.view(-1, 1, 185, 95) x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = x.view(-1, 128 * 19 * 8) x = F.relu(self.fc1(x)) return self.fc2(x) def get_inputs(): return [torch.rand([4, 1, 185, 95])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4, 'seed': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_0(in_ptr0, 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 y3 = yindex y0 = yindex % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 512 * y1), tmp0, xmask) @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) * 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_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 128 xnumel = 1035 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 % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 1035 * y3), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (y0 + 32 * x2 + 33120 * y1), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 53760 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl. constexpr): ynumel = 512 xnumel = 152 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 % 128 y1 = yindex // 128 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 128 * x2 + 19456 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 152 * y3), tmp4, xmask & ymask) tl.store(out_ptr1 + (y0 + 128 * x2 + 19456 * y1), tmp6, xmask & ymask) @triton.jit def triton_poi_fused_relu_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 % 512 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) = args args.clear() assert_size_stride(primals_1, (4, 1, 185, 95), (17575, 17575, 95, 1)) assert_size_stride(primals_2, (32, 1, 8, 8), (64, 64, 8, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 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, (512, 19456), (19456, 1)) assert_size_stride(primals_9, (512,), (1,)) assert_size_stride(primals_10, (4, 512), (512, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 32, 4, 4), (512, 1, 128, 32), torch. float32) get_raw_stream(0) triton_poi_fused_0[grid(2048, 16)](primals_4, buf0, 2048, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf1 = empty_strided_cuda((128, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_1[grid(8192, 9)](primals_6, buf1, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf2 = extern_kernels.convolution(primals_1, primals_2, stride=(4, 4), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 32, 45, 23), (33120, 1035, 23, 1)) buf3 = empty_strided_cuda((4, 32, 45, 23), (33120, 1, 736, 32), torch.float32) triton_poi_fused_convolution_relu_2[grid(128, 1035)](buf2, primals_3, buf3, 128, 1035, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf2 del primals_3 buf4 = extern_kernels.convolution(buf3, buf0, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 21, 10), (13440, 1, 640, 64)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_3[grid(53760)](buf5, primals_5, 53760, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf6 = extern_kernels.convolution(buf5, buf1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 19, 8), (19456, 1, 1024, 128)) buf7 = empty_strided_cuda((4, 128, 19, 8), (19456, 152, 8, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 19, 8), (19456, 1, 1024, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_4[grid(512, 152)]( buf6, primals_7, buf7, buf11, 512, 152, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf6 del primals_7 buf8 = empty_strided_cuda((4, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (4, 19456), (19456, 1), 0), reinterpret_tensor(primals_8, (19456, 512), (1, 19456), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_5[grid(2048)](buf9, primals_9, 2048, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_11, buf9, reinterpret_tensor( primals_10, (512, 4), (1, 512), 0), alpha=1, beta=1, out=buf10) del primals_11 return (buf10, primals_2, buf0, buf1, primals_1, buf3, buf5, reinterpret_tensor(buf7, (4, 19456), (19456, 1), 0), buf9, primals_10, primals_8, buf11) class DQNNew(nn.Module): """ Deep Q-Network: Actor (Policy) Model. (function approximator for the Q-table) """ def __init__(self, state_size, action_size, seed, fc1_unit=64, fc2_unit=64 ): """ Initialize parameters and build model. Params ======= state_size (int): Dimension of each state action_size (int): Dimension of each action seed (int): Random seed fc1_unit (int): Number of neurons in first hidden layer fc2_unit (int): Number of neurons in second hidden layer """ super(DQNNew, self).__init__() self.seed = torch.manual_seed(seed) self.conv1 = nn.Conv2d(1, 32, 8, stride=4, padding=1) self.conv2 = nn.Conv2d(32, 64, 4, stride=2) self.conv3 = nn.Conv2d(64, 128, 3) self.fc1 = nn.Linear(1 * 128 * 19 * 8, 512) self.fc2 = nn.Linear(512, action_size) 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_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.fc1.weight primals_9 = self.fc1.bias primals_10 = self.fc2.weight primals_11 = 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, primals_10, primals_11]) return output[0]
qarchli/dqn-on-space-invaders
DQN
false
7,571
[ "MIT" ]
1
148f1a7b65b2f47dab736b08cc7d6b7de1725a00
https://github.com/qarchli/dqn-on-space-invaders/tree/148f1a7b65b2f47dab736b08cc7d6b7de1725a00
HeatmapLoss
import torch import torch.utils.data class HeatmapLoss(torch.nn.Module): """ loss for detection heatmap """ def __init__(self): super(HeatmapLoss, self).__init__() def forward(self, pred, gt): l = (pred - gt) ** 2 l = l.mean(dim=3).mean(dim=2).mean(dim=1) return l 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.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_mean_pow_sub_0(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 x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 16 * x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr1 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr1 + (2 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (3 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp26 = tl.load(in_ptr1 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp31 = tl.load(in_ptr1 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp35 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp36 = tl.load(in_ptr1 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp42 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp43 = tl.load(in_ptr1 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp46 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp47 = tl.load(in_ptr1 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp51 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp52 = tl.load(in_ptr1 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp56 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp57 = tl.load(in_ptr1 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp63 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp64 = tl.load(in_ptr1 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp67 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp68 = tl.load(in_ptr1 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp72 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp73 = tl.load(in_ptr1 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp77 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp78 = tl.load(in_ptr1 + (15 + 16 * x0), 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 = 4.0 tmp20 = tmp18 / tmp19 tmp23 = tmp21 - tmp22 tmp24 = tmp23 * tmp23 tmp27 = tmp25 - tmp26 tmp28 = tmp27 * tmp27 tmp29 = tmp24 + tmp28 tmp32 = tmp30 - tmp31 tmp33 = tmp32 * tmp32 tmp34 = tmp29 + tmp33 tmp37 = tmp35 - tmp36 tmp38 = tmp37 * tmp37 tmp39 = tmp34 + tmp38 tmp40 = tmp39 / tmp19 tmp41 = tmp20 + tmp40 tmp44 = tmp42 - tmp43 tmp45 = tmp44 * tmp44 tmp48 = tmp46 - tmp47 tmp49 = tmp48 * tmp48 tmp50 = tmp45 + tmp49 tmp53 = tmp51 - tmp52 tmp54 = tmp53 * tmp53 tmp55 = tmp50 + tmp54 tmp58 = tmp56 - tmp57 tmp59 = tmp58 * tmp58 tmp60 = tmp55 + tmp59 tmp61 = tmp60 / tmp19 tmp62 = tmp41 + tmp61 tmp65 = tmp63 - tmp64 tmp66 = tmp65 * tmp65 tmp69 = tmp67 - tmp68 tmp70 = tmp69 * tmp69 tmp71 = tmp66 + tmp70 tmp74 = tmp72 - tmp73 tmp75 = tmp74 * tmp74 tmp76 = tmp71 + tmp75 tmp79 = tmp77 - tmp78 tmp80 = tmp79 * tmp79 tmp81 = tmp76 + tmp80 tmp82 = tmp81 / tmp19 tmp83 = tmp62 + tmp82 tmp84 = tmp83 / tmp19 tl.store(out_ptr0 + x0, tmp84, xmask) @triton.jit def triton_poi_fused_mean_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 + 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 tl.store(out_ptr0 + x0, tmp8, 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, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_pow_sub_0[grid(16)](arg0_1, arg1_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_mean_1[grid(4)](buf0, buf1, 4, XBLOCK=4, num_warps =1, num_stages=1) del buf0 return buf1, class HeatmapLossNew(torch.nn.Module): """ loss for detection heatmap """ def __init__(self): super(HeatmapLossNew, 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]
rm-rf-me/Study-stacked-hourglass
HeatmapLoss
false
7,572
[ "BSD-3-Clause" ]
1
48441f0dd5ae3397470c70db0f50ab5576b9d2f2
https://github.com/rm-rf-me/Study-stacked-hourglass/tree/48441f0dd5ae3397470c70db0f50ab5576b9d2f2
MSECompositionLoss
import functools import torch import torch.nn as nn from torch.nn import functional as F def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def mse_loss(pred, target): """MSE loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated MSE loss. """ return F.mse_loss(pred, target, reduction='none') class MSECompositionLoss(nn.Module): """MSE (L2) composition loss. Args: loss_weight (float): Loss weight for MSE loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False): super(MSECompositionLoss, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise def forward(self, pred_alpha, fg, bg, ori_merged, weight=None, **kwargs): """ Args: pred_alpha (Tensor): of shape (N, 1, H, W). Predicted alpha matte. fg (Tensor): of shape (N, 3, H, W). Tensor of foreground object. bg (Tensor): of shape (N, 3, H, W). Tensor of background object. ori_merged (Tensor): of shape (N, 3, H, W). Tensor of origin merged image before normalized by ImageNet mean and std. weight (Tensor, optional): of shape (N, 1, H, W). It is an indicating matrix: weight[trimap == 128] = 1. Default: None. """ pred_merged = pred_alpha * fg + (1.0 - pred_alpha) * bg if weight is not None: weight = weight.expand(-1, 3, -1, -1) return self.loss_weight * mse_loss(pred_merged, ori_merged, weight, reduction=self.reduction, sample_wise=self.sample_wise) 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 functools import torch.nn as nn from torch.nn import 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_per_fused_add_mean_mse_loss_mul_rsub_0(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) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp5 = tl.load(in_ptr2 + r0, None) tmp8 = tl.load(in_ptr3 + r0, None) tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp9 = tmp7 - 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 = tmp15 * tmp3 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp16, 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) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_mse_loss_mul_rsub_0[grid(1)](buf1, arg0_1, arg1_1, arg2_1, arg3_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 return buf1, def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Returns: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() else: return loss.sum() def mask_reduce_loss(loss, weight=None, reduction='mean', sample_wise=False): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. Default: None. reduction (str): Same as built-in losses of PyTorch. Options are "none", "mean" and "sum". Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. Returns: Tensor: Processed loss values. """ if weight is not None: assert weight.dim() == loss.dim() assert weight.size(1) == 1 or weight.size(1) == loss.size(1) loss = loss * weight if weight is None or reduction == 'sum': loss = reduce_loss(loss, reduction) elif reduction == 'mean': if weight.size(1) == 1: weight = weight.expand_as(loss) eps = 1e-12 if sample_wise: weight = weight.sum(dim=[1, 2, 3], keepdim=True) loss = (loss / (weight + eps)).sum() / weight.size(0) else: loss = loss.sum() / (weight.sum() + eps) return loss def masked_loss(loss_func): """Create a masked version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> import torch >>> @masked_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.5000) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, reduction='sum') tensor(3.) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', sample_wise= False, **kwargs): loss = loss_func(pred, target, **kwargs) loss = mask_reduce_loss(loss, weight, reduction, sample_wise) return loss return wrapper @masked_loss def mse_loss(pred, target): """MSE loss. Args: pred (Tensor): Prediction Tensor with shape (n, c, h, w). target ([type]): Target Tensor with shape (n, c, h, w). Returns: Tensor: Calculated MSE loss. """ return F.mse_loss(pred, target, reduction='none') class MSECompositionLossNew(nn.Module): """MSE (L2) composition loss. Args: loss_weight (float): Loss weight for MSE loss. Default: 1.0. reduction (str): Specifies the reduction to apply to the output. Supported choices are 'none' | 'mean' | 'sum'. Default: 'mean'. sample_wise (bool): Whether calculate the loss sample-wise. This argument only takes effect when `reduction` is 'mean' and `weight` (argument of `forward()`) is not None. It will first reduces loss with 'mean' per-sample, and then it means over all the samples. Default: False. """ def __init__(self, loss_weight=1.0, reduction='mean', sample_wise=False): super(MSECompositionLossNew, self).__init__() if reduction not in ['none', 'mean', 'sum']: raise ValueError( f'Unsupported reduction mode: {reduction}. Supported ones are: {_reduction_modes}' ) self.loss_weight = loss_weight self.reduction = reduction self.sample_wise = sample_wise 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]
rivergold/mmediting
MSECompositionLoss
false
7,573
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
Entmax15
from torch.autograd import Function import torch import torch.nn as nn def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _entmax_threshold_and_support(X, dim=-1, k=None): """Core computation for 1.5-entmax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: Xsrt, _ = torch.sort(X, dim=dim, descending=True) else: Xsrt, _ = torch.topk(X, k=k, dim=dim) rho = _make_ix_like(Xsrt, dim) mean = Xsrt.cumsum(dim) / rho mean_sq = (Xsrt ** 2).cumsum(dim) / rho ss = rho * (mean_sq - mean ** 2) delta = (1 - ss) / rho delta_nz = torch.clamp(delta, 0) tau = mean - torch.sqrt(delta_nz) support_size = (tau <= Xsrt).sum(dim).unsqueeze(dim) tau_star = tau.gather(dim, support_size - 1) if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): X_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _entmax_threshold_and_support(X_, dim=-1, k=2 * k) _roll_last(tau_star, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau_star, support_size def entmax15(X, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return Entmax15Function.apply(X, dim, k) class Entmax15Function(Function): @classmethod def forward(cls, ctx, X, dim=0, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val X = X / 2 tau_star, _ = _entmax_threshold_and_support(X, dim=dim, k=k) Y = torch.clamp(X - tau_star, min=0) ** 2 ctx.save_for_backward(Y) return Y @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y.sqrt() dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None class Entmax15(nn.Module): def __init__(self, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Entmax15, self).__init__() def forward(self, X): return entmax15(X, dim=self.dim, k=self.k) 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._inductor.runtime.triton_helpers import libdevice from torch.autograd import Function 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_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_div_max_pow_sort_sub_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 4 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 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x0), 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 = 0.5 tmp10 = tmp8 * tmp9 tmp11 = r1 tmp12 = tmp11.to(tl.int16) tmp13 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp14 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15, _tmp16 = triton_helpers.sort_with_index(tmp13, tmp14, None, 1, stable=False, descending=True) tmp17 = tmp15 * tmp15 tmp18 = tmp17.to(tl.float32) tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK]) tmp20, = tl.associative_scan((tmp19,), 1, _triton_helper_fn_add0) tmp21 = tmp15.to(tl.float32) tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp23, = tl.associative_scan((tmp22,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (r1 + 4 * x0), tmp10, xmask) tl.store(out_ptr1 + (r1 + 4 * x0), tmp15, xmask) tl.store(out_ptr2 + (r1 + 4 * x0), tmp20, xmask) tl.store(out_ptr3 + (r1 + 4 * x0), tmp23, xmask) @triton.jit def triton_poi_fused_clamp_div_le_mul_pow_rsub_sqrt_sub_sum_1(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 x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp30 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp34 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp37 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp47 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp51 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp54 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp64 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 / tmp1 tmp4 = tmp3 / tmp1 tmp5 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp1 * tmp6 tmp8 = tmp1 - tmp7 tmp9 = tmp8 / tmp1 tmp10 = 0.0 tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp2 - tmp12 tmp15 = tmp13 <= tmp14 tmp16 = tmp15.to(tl.int64) tmp18 = 2.0 tmp19 = tmp17 / tmp18 tmp21 = tmp20 / tmp18 tmp22 = tmp19 * tmp19 tmp23 = tmp21 - tmp22 tmp24 = tmp18 * tmp23 tmp25 = tmp1 - tmp24 tmp26 = tmp25 / tmp18 tmp27 = triton_helpers.maximum(tmp26, tmp10) tmp28 = libdevice.sqrt(tmp27) tmp29 = tmp19 - tmp28 tmp31 = tmp29 <= tmp30 tmp32 = tmp31.to(tl.int64) tmp33 = tmp16 + tmp32 tmp35 = 3.0 tmp36 = tmp34 / tmp35 tmp38 = tmp37 / tmp35 tmp39 = tmp36 * tmp36 tmp40 = tmp38 - tmp39 tmp41 = tmp35 * tmp40 tmp42 = tmp1 - tmp41 tmp43 = tmp42 / tmp35 tmp44 = triton_helpers.maximum(tmp43, tmp10) tmp45 = libdevice.sqrt(tmp44) tmp46 = tmp36 - tmp45 tmp48 = tmp46 <= tmp47 tmp49 = tmp48.to(tl.int64) tmp50 = tmp33 + tmp49 tmp52 = 4.0 tmp53 = tmp51 / tmp52 tmp55 = tmp54 / tmp52 tmp56 = tmp53 * tmp53 tmp57 = tmp55 - tmp56 tmp58 = tmp52 * tmp57 tmp59 = tmp1 - tmp58 tmp60 = tmp59 / tmp52 tmp61 = triton_helpers.maximum(tmp60, tmp10) tmp62 = libdevice.sqrt(tmp61) tmp63 = tmp53 - tmp62 tmp65 = tmp63 <= tmp64 tmp66 = tmp65.to(tl.int64) tmp67 = tmp50 + tmp66 tl.store(out_ptr0 + x0, tmp67, xmask) @triton.jit def triton_poi_fused_clamp_div_gather_mul_pow_rsub_sqrt_sub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.full([1], 1, tl.int64) tmp3 = tmp1 - tmp2 tmp4 = tl.full([XBLOCK], 4, tl.int32) tmp5 = tmp3 + tmp4 tmp6 = tmp3 < 0 tmp7 = tl.where(tmp6, tmp5, tmp3) tl.device_assert((0 <= tmp7) & (tmp7 < 4) | ~xmask, 'index out of bounds: 0 <= tmp7 < 4') tmp9 = tl.load(in_ptr2 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp10 = 1 + tmp7 tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tl.load(in_ptr3 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp14 = tmp13 / tmp11 tmp15 = tmp12 * tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp11 * tmp16 tmp18 = 1.0 tmp19 = tmp18 - tmp17 tmp20 = tmp19 / tmp11 tmp21 = 0.0 tmp22 = triton_helpers.maximum(tmp20, tmp21) tmp23 = libdevice.sqrt(tmp22) tmp24 = tmp12 - tmp23 tmp25 = tmp0 - tmp24 tmp26 = triton_helpers.maximum(tmp25, tmp21) tmp27 = tmp26 * tmp26 tl.store(out_ptr0 + x2, tmp27, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) 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.float32) get_raw_stream(0) triton_per_fused_cumsum_div_max_pow_sort_sub_0[grid(64)](arg0_1, buf0, buf1, buf3, buf4, 64, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) triton_poi_fused_clamp_div_le_mul_pow_rsub_sqrt_sub_sum_1[grid(64)]( buf4, buf3, buf1, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = buf1 del buf1 triton_poi_fused_clamp_div_gather_mul_pow_rsub_sqrt_sub_2[grid(256)]( buf0, buf5, buf4, buf3, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf3 del buf4 del buf5 return buf6, def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _entmax_threshold_and_support(X, dim=-1, k=None): """Core computation for 1.5-entmax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: Xsrt, _ = torch.sort(X, dim=dim, descending=True) else: Xsrt, _ = torch.topk(X, k=k, dim=dim) rho = _make_ix_like(Xsrt, dim) mean = Xsrt.cumsum(dim) / rho mean_sq = (Xsrt ** 2).cumsum(dim) / rho ss = rho * (mean_sq - mean ** 2) delta = (1 - ss) / rho delta_nz = torch.clamp(delta, 0) tau = mean - torch.sqrt(delta_nz) support_size = (tau <= Xsrt).sum(dim).unsqueeze(dim) tau_star = tau.gather(dim, support_size - 1) if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): X_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _entmax_threshold_and_support(X_, dim=-1, k=2 * k) _roll_last(tau_star, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau_star, support_size def entmax15(X, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return Entmax15Function.apply(X, dim, k) class Entmax15Function(Function): @classmethod def forward(cls, ctx, X, dim=0, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val X = X / 2 tau_star, _ = _entmax_threshold_and_support(X, dim=dim, k=k) Y = torch.clamp(X - tau_star, min=0) ** 2 ctx.save_for_backward(Y) return Y @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y.sqrt() dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None class Entmax15New(nn.Module): def __init__(self, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Entmax15New, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
roholazandie/entmax
Entmax15
false
7,574
[ "MIT" ]
1
657374e6a792ec6840b6f78bc759cc1f51570aad
https://github.com/roholazandie/entmax/tree/657374e6a792ec6840b6f78bc759cc1f51570aad
TransformerLayer
import torch from torch import nn from typing import Optional class TransformerLayer(nn.Module): """TransformerEncoderLayer is made up of self-attn and feedforward network. This standard encoder layer is based on the paper "Attention Is All You Need". Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application. Args: d_model: the number of expected features in the input (required). nhead: the number of heads in the multiheadattention models (required). dim_feedforward: the dimension of the feedforward network model (default=2048). layer_norm_eps: the eps value in layer normalization components (default=1e-5). Examples:: >>> encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8) >>> src = torch.rand(10, 32, 512) >>> out = encoder_layer(src) """ def __init__(self, d_model, nhead, dim_feedforward_multiplier=4, layer_norm_eps=1e-05, device=None, dtype=None) ->None: super().__init__() self.self_attn = nn.MultiheadAttention(d_model, nhead, dropout=0) dim_feedforward = dim_feedforward_multiplier * d_model self.linear1 = nn.Linear(d_model, dim_feedforward) self.linear2 = nn.Linear(dim_feedforward, d_model) self.norm1 = nn.LayerNorm(d_model, eps=layer_norm_eps) self.norm2 = nn.LayerNorm(d_model, eps=layer_norm_eps) self.activation = nn.CELU() def forward(self, src: 'torch.Tensor', src_mask: 'Optional[torch.Tensor]'=None, src_key_padding_mask: 'Optional[torch.Tensor]'=None) ->torch.Tensor: """Pass the input through the encoder layer. Args: src: the sequence to the encoder layer (required). src_mask: the mask for the src sequence (optional). src_key_padding_mask: the mask for the src keys per batch (optional). Shape: see the docs in Transformer class. """ src2 = self.self_attn(src.swapaxes(0, 1), src.swapaxes(0, 1), src. swapaxes(0, 1), attn_mask=src_mask, key_padding_mask= src_key_padding_mask)[0].swapaxes(0, 1) src = src + src2 src = self.norm1(src) src2 = self.linear2(self.activation(self.linear1(src))) src = src + src2 src = self.norm2(src) return src def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'nhead': 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_add_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 + (8 + 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_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, 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 = 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_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x0, xmask) tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (4 + x0), xmask) tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (8 + x0), xmask) tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (12 + x0), xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tmp27 / tmp15 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (x1 + 4 * y0), xmask & ymask) tmp1 = tl.load(in_ptr1 + (y0 + 4 * x1), xmask & ymask) tmp3 = tl.load(in_ptr2 + y0, ymask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + y0, ymask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + (x1 + 4 * y0), tmp13, xmask & ymask) @triton.jit def triton_poi_fused_celu_8(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = libdevice.expm1(tmp0) tmp4 = tl.where(tmp2, tmp0, tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_add_9(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_out_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_native_layer_norm_10(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-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_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (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,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (16, 4), (4, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (4, 16), (16, 1)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (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), (1, 4), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 16), out=buf1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 32), out=buf2) del primals_2 buf3 = reinterpret_tensor(buf2, (4, 1, 4), (4, 4, 1), 0) del buf2 get_raw_stream(0) triton_poi_fused_add_0[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = reinterpret_tensor(buf0, (4, 4, 1), (1, 4, 16), 0) del buf0 triton_poi_fused_mul_1[grid(16)](buf4, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = reinterpret_tensor(buf1, (4, 1, 4), (4, 4, 1), 0) del buf1 triton_poi_fused_add_2[grid(16)](buf5, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf4, reinterpret_tensor(buf5, (4, 1, 4), (1, 0, 4), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = buf6 del buf6 triton_poi_fused__softmax_4[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf8, reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 0), 0), out=buf9) buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_clone_5[grid(4, 4)](buf9, buf10, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf11 = reinterpret_tensor(buf9, (4, 4), (4, 1), 0) del buf9 extern_kernels.addmm(primals_5, reinterpret_tensor(buf10, (4, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf11) del primals_5 buf12 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf13 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused_add_native_layer_norm_6[grid(4)](primals_1, buf11, buf12, buf13, 4, XBLOCK=4, num_warps=1, num_stages=1) buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_7[grid(4, 4)](primals_1, buf11, buf12, buf13, primals_6, primals_7, buf14, 4, 4, XBLOCK= 4, YBLOCK=4, num_warps=1, num_stages=1) del primals_7 buf15 = reinterpret_tensor(buf7, (4, 16), (16, 1), 0) del buf7 extern_kernels.addmm(primals_9, buf14, reinterpret_tensor(primals_8, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf15) del primals_9 buf16 = empty_strided_cuda((4, 16), (16, 1), torch.float32) triton_poi_fused_celu_8[grid(64)](buf15, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf17 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf16, reinterpret_tensor(primals_10, (16, 4), (1, 16), 0), out=buf17) buf18 = buf17 del buf17 triton_poi_fused_add_9[grid(16)](buf18, buf14, primals_11, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_11 buf19 = buf13 del buf13 buf20 = buf12 del buf12 triton_poi_fused_native_layer_norm_10[grid(4)](buf18, buf19, buf20, 4, XBLOCK=4, num_warps=1, num_stages=1) buf21 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_11[grid(16)](buf18, buf19, buf20, primals_12, primals_13, buf21, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf19 del buf20 del primals_13 return (buf21, primals_1, primals_6, primals_12, buf8, reinterpret_tensor(buf10, (4, 4), (4, 1), 0), buf11, buf14, buf15, buf16, buf18, primals_10, primals_8, primals_4, reinterpret_tensor( buf3, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf4, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf5, (4, 4, 1), (1, 4, 1), 0)) class TransformerLayerNew(nn.Module): """TransformerEncoderLayer is made up of self-attn and feedforward network. This standard encoder layer is based on the paper "Attention Is All You Need". Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in Neural Information Processing Systems, pages 6000-6010. Users may modify or implement in a different way during application. Args: d_model: the number of expected features in the input (required). nhead: the number of heads in the multiheadattention models (required). dim_feedforward: the dimension of the feedforward network model (default=2048). layer_norm_eps: the eps value in layer normalization components (default=1e-5). Examples:: >>> encoder_layer = nn.TransformerEncoderLayer(d_model=512, nhead=8) >>> src = torch.rand(10, 32, 512) >>> out = encoder_layer(src) """ def __init__(self, d_model, nhead, dim_feedforward_multiplier=4, layer_norm_eps=1e-05, device=None, dtype=None) ->None: super().__init__() self.self_attn = nn.MultiheadAttention(d_model, nhead, dropout=0) dim_feedforward = dim_feedforward_multiplier * d_model self.linear1 = nn.Linear(d_model, dim_feedforward) self.linear2 = nn.Linear(dim_feedforward, d_model) self.norm1 = nn.LayerNorm(d_model, eps=layer_norm_eps) self.norm2 = nn.LayerNorm(d_model, eps=layer_norm_eps) self.activation = nn.CELU() def forward(self, input_0): primals_2 = self.self_attn.in_proj_weight primals_3 = self.self_attn.in_proj_bias primals_1 = self.self_attn.out_proj.weight primals_5 = self.self_attn.out_proj.bias primals_8 = self.linear1.weight primals_9 = self.linear1.bias primals_10 = self.linear2.weight primals_6 = self.linear2.bias primals_7 = self.norm1.weight primals_11 = self.norm1.bias primals_12 = self.norm2.weight primals_13 = self.norm2.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, primals_12, primals_13]) return output[0]
rgreenblatt/path
TransformerLayer
false
7,575
[ "MIT" ]
1
2057618ee3a6067c230c1c1c40856d2c9f5006b0
https://github.com/rgreenblatt/path/tree/2057618ee3a6067c230c1c1c40856d2c9f5006b0
AE
import torch import torch.nn as nn class AE(nn.Module): def __init__(self): super(AE, self).__init__() self.leaky_reLU = nn.LeakyReLU(0.2) self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=1, return_indices=True) self.unpool = nn.MaxUnpool2d(kernel_size=2, stride=2, padding=1) self.softmax = nn.Softmax2d() self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size= 3, stride=1, padding=1) self.conv2 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1) self.conv3 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=1, padding=1) self.conv4 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.conv5 = nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=3, stride=1, padding=1) self.conv7 = nn.Conv2d(in_channels=1024, out_channels=256, kernel_size=3, stride=1, padding=1) self.conv8 = nn.Conv2d(in_channels=512, out_channels=128, kernel_size=3, stride=1, padding=1) self.conv9 = nn.Conv2d(in_channels=256, out_channels=64, kernel_size=3, stride=1, padding=1) self.conv10 = nn.Conv2d(in_channels=128, out_channels=1, kernel_size=3, stride=1, padding=1) def forward(self, x): x = self.conv1(x) out1 = self.leaky_reLU(x) x = out1 size1 = x.size() x, indices1 = self.pool(x) x = self.conv2(x) out2 = self.leaky_reLU(x) x = out2 size2 = x.size() x, indices2 = self.pool(x) x = self.conv3(x) out3 = self.leaky_reLU(x) x = out3 size3 = x.size() x, indices3 = self.pool(x) x = self.conv4(x) out4 = self.leaky_reLU(x) x = out4 size4 = x.size() x, indices4 = self.pool(x) x = self.conv5(x) x = self.leaky_reLU(x) x = self.conv6(x) x = self.leaky_reLU(x) x = self.unpool(x, indices4, output_size=size4) x = self.conv7(torch.cat((x, out4), 1)) x = self.leaky_reLU(x) x = self.unpool(x, indices3, output_size=size3) x = self.conv8(torch.cat((x, out3), 1)) x = self.leaky_reLU(x) x = self.unpool(x, indices2, output_size=size2) x = self.conv9(torch.cat((x, out2), 1)) x = self.leaky_reLU(x) x = self.unpool(x, indices1, output_size=size1) x = self.conv10(torch.cat((x, out1), 1)) x = self.softmax(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._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_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.2 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_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 278784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 33 % 33 x0 = xindex % 33 x2 = xindex // 1089 x4 = xindex % 1089 x5 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 64, 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 + (-65 + 2 * x0 + 128 * x1 + 4096 * x2), 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 + (-64 + 2 * x0 + 128 * x1 + 4096 * x2), tmp16 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp22 & tmp9 tmp24 = tl.load(in_ptr0 + (-1 + 2 * x0 + 128 * x1 + 4096 * x2), tmp23 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = tmp22 & tmp15 tmp27 = tl.load(in_ptr0 + (2 * x0 + 128 * x1 + 4096 * x2), tmp26 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp28 = triton_helpers.maximum(tmp27, tmp25) tmp29 = tmp17 > tmp11 tmp30 = tl.full([1], 1, tl.int8) tmp31 = tl.full([1], 0, tl.int8) tmp32 = tl.where(tmp29, tmp30, tmp31) tmp33 = tmp24 > tmp18 tmp34 = tl.full([1], 2, tl.int8) tmp35 = tl.where(tmp33, tmp34, tmp32) tmp36 = tmp27 > tmp25 tmp37 = tl.full([1], 3, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tl.full([1], 2, tl.int32) tmp40 = tl.where((tmp38 < 0) != (tmp39 < 0), tl.where(tmp38 % tmp39 != 0, tmp38 // tmp39 - 1, tmp38 // tmp39), tmp38 // tmp39) tmp41 = tmp40 * tmp39 tmp42 = tmp38 - tmp41 tmp43 = tmp0 + tmp40 tmp44 = tmp6 + tmp42 tmp45 = tmp43 * tmp3 tmp46 = tmp45 + tmp44 tl.store(out_ptr0 + (x4 + 1120 * x2), tmp28, xmask) tl.store(out_ptr2 + x5, tmp46, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 557568 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 1089 % 128 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_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 147968 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 17 % 17 x0 = xindex % 17 x2 = xindex // 289 x4 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 33, 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 + (-34 + 2 * x0 + 66 * x1 + 1089 * x2), 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 + (-33 + 2 * x0 + 66 * x1 + 1089 * x2), tmp16 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp22 & tmp9 tmp24 = tl.load(in_ptr0 + (-1 + 2 * x0 + 66 * x1 + 1089 * x2), tmp23 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = tmp22 & tmp15 tmp27 = tl.load(in_ptr0 + (2 * x0 + 66 * x1 + 1089 * x2), tmp26 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp28 = triton_helpers.maximum(tmp27, tmp25) tmp29 = tmp17 > tmp11 tmp30 = tl.full([1], 1, tl.int8) tmp31 = tl.full([1], 0, tl.int8) tmp32 = tl.where(tmp29, tmp30, tmp31) tmp33 = tmp24 > tmp18 tmp34 = tl.full([1], 2, tl.int8) tmp35 = tl.where(tmp33, tmp34, tmp32) tmp36 = tmp27 > tmp25 tmp37 = tl.full([1], 3, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tl.full([1], 2, tl.int32) tmp40 = tl.where((tmp38 < 0) != (tmp39 < 0), tl.where(tmp38 % tmp39 != 0, tmp38 // tmp39 - 1, tmp38 // tmp39), tmp38 // tmp39) tmp41 = tmp40 * tmp39 tmp42 = tmp38 - tmp41 tmp43 = tmp0 + tmp40 tmp44 = tmp6 + tmp42 tmp45 = tmp43 * tmp3 tmp46 = tmp45 + tmp44 tl.store(out_ptr0 + x4, tmp28, xmask) tl.store(out_ptr2 + x4, tmp46, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 295936 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 289 % 256 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_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 9 % 9 x0 = xindex % 9 x2 = xindex // 81 x4 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 17, 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 + (-18 + 2 * x0 + 34 * x1 + 289 * x2), 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 + (-17 + 2 * x0 + 34 * x1 + 289 * x2), tmp16 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp22 & tmp9 tmp24 = tl.load(in_ptr0 + (-1 + 2 * x0 + 34 * x1 + 289 * x2), tmp23 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = tmp22 & tmp15 tmp27 = tl.load(in_ptr0 + (2 * x0 + 34 * x1 + 289 * x2), tmp26 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp28 = triton_helpers.maximum(tmp27, tmp25) tmp29 = tmp17 > tmp11 tmp30 = tl.full([1], 1, tl.int8) tmp31 = tl.full([1], 0, tl.int8) tmp32 = tl.where(tmp29, tmp30, tmp31) tmp33 = tmp24 > tmp18 tmp34 = tl.full([1], 2, tl.int8) tmp35 = tl.where(tmp33, tmp34, tmp32) tmp36 = tmp27 > tmp25 tmp37 = tl.full([1], 3, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tl.full([1], 2, tl.int32) tmp40 = tl.where((tmp38 < 0) != (tmp39 < 0), tl.where(tmp38 % tmp39 != 0, tmp38 // tmp39 - 1, tmp38 // tmp39), tmp38 // tmp39) tmp41 = tmp40 * tmp39 tmp42 = tmp38 - tmp41 tmp43 = tmp0 + tmp40 tmp44 = tmp6 + tmp42 tmp45 = tmp43 * tmp3 tmp46 = tmp45 + tmp44 tl.store(out_ptr0 + x4, tmp28, xmask) tl.store(out_ptr2 + x4, tmp46, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_6(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 // 81 % 512 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.2 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_max_pool2d_with_indices_7(in_ptr0, out_ptr0, out_ptr2, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 5 % 5 x0 = xindex % 5 x2 = xindex // 25 x4 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 9, 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 + (-10 + 2 * x0 + 18 * x1 + 81 * x2), tmp10, 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 + (-9 + 2 * x0 + 18 * x1 + 81 * x2), tmp16, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp22 & tmp9 tmp24 = tl.load(in_ptr0 + (-1 + 2 * x0 + 18 * x1 + 81 * x2), tmp23, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = tmp22 & tmp15 tmp27 = tl.load(in_ptr0 + (2 * x0 + 18 * x1 + 81 * x2), tmp26, eviction_policy='evict_last', other=float('-inf')) tmp28 = triton_helpers.maximum(tmp27, tmp25) tmp29 = tmp17 > tmp11 tmp30 = tl.full([1], 1, tl.int8) tmp31 = tl.full([1], 0, tl.int8) tmp32 = tl.where(tmp29, tmp30, tmp31) tmp33 = tmp24 > tmp18 tmp34 = tl.full([1], 2, tl.int8) tmp35 = tl.where(tmp33, tmp34, tmp32) tmp36 = tmp27 > tmp25 tmp37 = tl.full([1], 3, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tl.full([1], 2, tl.int32) tmp40 = tl.where((tmp38 < 0) != (tmp39 < 0), tl.where(tmp38 % tmp39 != 0, tmp38 // tmp39 - 1, tmp38 // tmp39), tmp38 // tmp39) tmp41 = tmp40 * tmp39 tmp42 = tmp38 - tmp41 tmp43 = tmp0 + tmp40 tmp44 = tmp6 + tmp42 tmp45 = tmp43 * tmp3 tmp46 = tmp45 + tmp44 tl.store(out_ptr0 + x4, tmp28, None) tl.store(out_ptr2 + x4, tmp46, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_8(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 // 25 % 1024 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.2 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_leaky_relu_9(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 // 25 % 512 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.2 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_cat_10(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) x1 = xindex // 81 % 1024 x0 = xindex % 81 x2 = xindex // 82944 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 512, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 81 * x1 + 41472 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 1024, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 81 * (-512 + x1) + 41472 * x2), tmp6, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_11(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 81 % 256 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_cat_12(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) x1 = xindex // 289 % 512 x0 = xindex % 289 x2 = xindex // 147968 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 289 * x1 + 73984 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 512, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 289 * (-256 + x1) + 73984 * x2), tmp6, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_13(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 147968 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 289 % 128 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_cat_14(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1115136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 1089 % 256 x0 = xindex % 1089 x2 = xindex // 278784 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 1089 * x1 + 139392 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 256, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 1089 * (-128 + x1) + 139392 * x2), tmp6 & xmask, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_15(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 278784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 1089 % 64 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_cat_16(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) x1 = xindex // 4096 % 128 x0 = xindex % 4096 x2 = xindex // 524288 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 262144 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 128, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 4096 * (-64 + x1) + 262144 * x2), tmp6, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, None) @triton.jit def triton_poi_fused__softmax_convolution_17(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 tmp4 = tmp3 - tmp3 tmp5 = tl_math.exp(tmp4) tmp6 = tmp5 / tmp5 tl.store(in_out_ptr0 + x0, tmp6, 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) = 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, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_9, (512,), (1,)) assert_size_stride(primals_10, (1024, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_11, (1024,), (1,)) assert_size_stride(primals_12, (512, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_13, (512,), (1,)) assert_size_stride(primals_14, (256, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_15, (256,), (1,)) assert_size_stride(primals_16, (128, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_17, (128,), (1,)) assert_size_stride(primals_18, (64, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_19, (64,), (1,)) assert_size_stride(primals_20, (1, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_21, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 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 buf0 del primals_2 buf3 = empty_strided_cuda((4, 64, 33, 33), (71680, 1120, 33, 1), torch.float32) buf5 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.int64) triton_poi_fused_max_pool2d_with_indices_1[grid(278784)](buf2, buf3, buf5, 278784, XBLOCK=512, num_warps=8, num_stages=1) buf6 = 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(buf6, (4, 128, 33, 33), (139392, 1089, 33, 1)) buf7 = empty_strided_cuda((4, 128, 33, 33), (139392, 1089, 33, 1), torch.bool) buf8 = empty_strided_cuda((4, 128, 33, 33), (139392, 1089, 33, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_2[grid(557568)](buf6, primals_5, buf7, buf8, 557568, XBLOCK=1024, num_warps=4, num_stages=1) del buf6 del primals_5 buf9 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.int64) triton_poi_fused_max_pool2d_with_indices_3[grid(147968)](buf8, buf9, buf11, 147968, XBLOCK=512, num_warps=8, num_stages=1) buf12 = 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(buf12, (4, 256, 17, 17), (73984, 289, 17, 1)) buf13 = empty_strided_cuda((4, 256, 17, 17), (73984, 289, 17, 1), torch.bool) buf14 = empty_strided_cuda((4, 256, 17, 17), (73984, 289, 17, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_4[grid(295936)](buf12, primals_7, buf13, buf14, 295936, XBLOCK=1024, num_warps=4, num_stages=1) del buf12 del primals_7 buf15 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch .float32) buf17 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch .int64) triton_poi_fused_max_pool2d_with_indices_5[grid(82944)](buf14, buf15, buf17, 82944, XBLOCK=512, num_warps=8, num_stages=1) buf18 = extern_kernels.convolution(buf15, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 512, 9, 9), (41472, 81, 9, 1)) buf19 = empty_strided_cuda((4, 512, 9, 9), (41472, 81, 9, 1), torch .bool) buf20 = empty_strided_cuda((4, 512, 9, 9), (41472, 81, 9, 1), torch .float32) triton_poi_fused_convolution_leaky_relu_6[grid(165888)](buf18, primals_9, buf19, buf20, 165888, XBLOCK=1024, num_warps=4, num_stages=1) del buf18 del primals_9 buf21 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .float32) buf23 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .int64) triton_poi_fused_max_pool2d_with_indices_7[grid(51200)](buf20, buf21, buf23, 51200, XBLOCK=512, num_warps=4, num_stages=1) buf24 = extern_kernels.convolution(buf21, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 1024, 5, 5), (25600, 25, 5, 1)) buf25 = empty_strided_cuda((4, 1024, 5, 5), (25600, 25, 5, 1), torch.bool) buf26 = empty_strided_cuda((4, 1024, 5, 5), (25600, 25, 5, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_8[grid(102400)](buf24, primals_11, buf25, buf26, 102400, XBLOCK=1024, num_warps=4, num_stages=1) del buf24 del primals_11 buf27 = extern_kernels.convolution(buf26, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 512, 5, 5), (12800, 25, 5, 1)) buf28 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .bool) buf29 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .float32) triton_poi_fused_convolution_leaky_relu_9[grid(51200)](buf27, primals_13, buf28, buf29, 51200, XBLOCK=512, num_warps=4, num_stages=1) del buf27 del primals_13 buf30 = torch.ops.aten.max_unpool2d.default(buf29, buf23, [9, 9]) del buf29 buf31 = buf30 del buf30 buf32 = empty_strided_cuda((4, 1024, 9, 9), (82944, 81, 9, 1), torch.float32) triton_poi_fused_cat_10[grid(331776)](buf31, buf20, buf32, 331776, XBLOCK=1024, num_warps=4, num_stages=1) del buf31 buf33 = extern_kernels.convolution(buf32, 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, 256, 9, 9), (20736, 81, 9, 1)) buf34 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch .bool) buf35 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch .float32) triton_poi_fused_convolution_leaky_relu_11[grid(82944)](buf33, primals_15, buf34, buf35, 82944, XBLOCK=1024, num_warps=4, num_stages=1) del buf33 del primals_15 buf36 = torch.ops.aten.max_unpool2d.default(buf35, buf17, [17, 17]) del buf35 buf37 = buf36 del buf36 buf38 = empty_strided_cuda((4, 512, 17, 17), (147968, 289, 17, 1), torch.float32) triton_poi_fused_cat_12[grid(591872)](buf37, buf14, buf38, 591872, XBLOCK=512, num_warps=8, num_stages=1) del buf37 buf39 = extern_kernels.convolution(buf38, primals_16, 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, 17, 17), (36992, 289, 17, 1)) buf40 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.bool) buf41 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_13[grid(147968)](buf39, primals_17, buf40, buf41, 147968, XBLOCK=1024, num_warps=4, num_stages=1) del buf39 del primals_17 buf42 = torch.ops.aten.max_unpool2d.default(buf41, buf11, [33, 33]) del buf41 buf43 = buf42 del buf42 buf44 = empty_strided_cuda((4, 256, 33, 33), (278784, 1089, 33, 1), torch.float32) triton_poi_fused_cat_14[grid(1115136)](buf43, buf8, buf44, 1115136, XBLOCK=1024, num_warps=4, num_stages=1) del buf43 buf45 = extern_kernels.convolution(buf44, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf45, (4, 64, 33, 33), (69696, 1089, 33, 1)) buf46 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.bool) buf47 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_15[grid(278784)](buf45, primals_19, buf46, buf47, 278784, XBLOCK=512, num_warps=8, num_stages=1) del buf45 del primals_19 buf48 = torch.ops.aten.max_unpool2d.default(buf47, buf5, [64, 64]) del buf47 buf49 = buf48 del buf48 buf50 = empty_strided_cuda((4, 128, 64, 64), (524288, 4096, 64, 1), torch.float32) triton_poi_fused_cat_16[grid(2097152)](buf49, buf2, buf50, 2097152, XBLOCK=512, num_warps=8, num_stages=1) del buf49 buf51 = extern_kernels.convolution(buf50, primals_20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf51, (4, 1, 64, 64), (4096, 4096, 64, 1)) buf52 = buf51 del buf51 triton_poi_fused__softmax_convolution_17[grid(16384)](buf52, primals_21, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_21 return (buf52, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, buf1, buf2, buf3, buf5, buf7, buf8, buf9, buf11, buf13, buf14, buf15, buf17, buf19, buf20, buf21, buf23, buf25, buf26, buf28, buf32, buf34, buf38, buf40, buf44, buf46, buf50, buf52) class AENew(nn.Module): def __init__(self): super(AENew, self).__init__() self.leaky_reLU = nn.LeakyReLU(0.2) self.pool = nn.MaxPool2d(kernel_size=2, stride=2, padding=1, return_indices=True) self.unpool = nn.MaxUnpool2d(kernel_size=2, stride=2, padding=1) self.softmax = nn.Softmax2d() self.conv1 = nn.Conv2d(in_channels=3, out_channels=64, kernel_size= 3, stride=1, padding=1) self.conv2 = nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1) self.conv3 = nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=1, padding=1) self.conv4 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.conv5 = nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=3, stride=1, padding=1) self.conv7 = nn.Conv2d(in_channels=1024, out_channels=256, kernel_size=3, stride=1, padding=1) self.conv8 = nn.Conv2d(in_channels=512, out_channels=128, kernel_size=3, stride=1, padding=1) self.conv9 = nn.Conv2d(in_channels=256, out_channels=64, kernel_size=3, stride=1, padding=1) self.conv10 = nn.Conv2d(in_channels=128, out_channels=1, kernel_size=3, stride=1, padding=1) 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_10 = self.conv5.weight primals_11 = self.conv5.bias primals_12 = self.conv6.weight primals_13 = self.conv6.bias primals_14 = self.conv7.weight primals_15 = self.conv7.bias primals_16 = self.conv8.weight primals_17 = self.conv8.bias primals_18 = self.conv9.weight primals_19 = self.conv9.bias primals_20 = self.conv10.weight primals_21 = self.conv10.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]) return output[0]
personwhofloat/Line-Segmentation-Model
AE
false
7,576
[ "MIT" ]
1
f00b65c7914f44fa31e14d41120903d0da2d5496
https://github.com/personwhofloat/Line-Segmentation-Model/tree/f00b65c7914f44fa31e14d41120903d0da2d5496
GeM
import torch import torch.nn.functional as F def gem(x, p=3, eps=1e-06): return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow( 1.0 / p) class GeM(torch.nn.Module): """ Implementation of GeM pooling. https://paperswithcode.com/method/generalized-mean-pooling NOTE: p is learnable, but there is a consensus that it is better to fix the p value at 3. """ def __init__(self, p=3, eps=1e-06): super(GeM, self).__init__() self.p = p self.eps = eps def forward(self, x): return gem(x, p=self.p, eps=self.eps) 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._inductor.runtime.triton_helpers import libdevice 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_avg_pool2d_clamp_pow_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp35 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp40 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp45 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp50 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp55 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp60 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp65 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp70 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp75 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp1 = 1e-06 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = tmp2 * tmp2 tmp4 = tmp3 * tmp2 tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = tmp6 * tmp6 tmp8 = tmp7 * tmp6 tmp9 = tmp8 + tmp4 tmp11 = triton_helpers.maximum(tmp10, tmp1) tmp12 = tmp11 * tmp11 tmp13 = tmp12 * tmp11 tmp14 = tmp13 + tmp9 tmp16 = triton_helpers.maximum(tmp15, tmp1) tmp17 = tmp16 * tmp16 tmp18 = tmp17 * tmp16 tmp19 = tmp18 + tmp14 tmp21 = triton_helpers.maximum(tmp20, tmp1) tmp22 = tmp21 * tmp21 tmp23 = tmp22 * tmp21 tmp24 = tmp23 + tmp19 tmp26 = triton_helpers.maximum(tmp25, tmp1) tmp27 = tmp26 * tmp26 tmp28 = tmp27 * tmp26 tmp29 = tmp28 + tmp24 tmp31 = triton_helpers.maximum(tmp30, tmp1) tmp32 = tmp31 * tmp31 tmp33 = tmp32 * tmp31 tmp34 = tmp33 + tmp29 tmp36 = triton_helpers.maximum(tmp35, tmp1) tmp37 = tmp36 * tmp36 tmp38 = tmp37 * tmp36 tmp39 = tmp38 + tmp34 tmp41 = triton_helpers.maximum(tmp40, tmp1) tmp42 = tmp41 * tmp41 tmp43 = tmp42 * tmp41 tmp44 = tmp43 + tmp39 tmp46 = triton_helpers.maximum(tmp45, tmp1) tmp47 = tmp46 * tmp46 tmp48 = tmp47 * tmp46 tmp49 = tmp48 + tmp44 tmp51 = triton_helpers.maximum(tmp50, tmp1) tmp52 = tmp51 * tmp51 tmp53 = tmp52 * tmp51 tmp54 = tmp53 + tmp49 tmp56 = triton_helpers.maximum(tmp55, tmp1) tmp57 = tmp56 * tmp56 tmp58 = tmp57 * tmp56 tmp59 = tmp58 + tmp54 tmp61 = triton_helpers.maximum(tmp60, tmp1) tmp62 = tmp61 * tmp61 tmp63 = tmp62 * tmp61 tmp64 = tmp63 + tmp59 tmp66 = triton_helpers.maximum(tmp65, tmp1) tmp67 = tmp66 * tmp66 tmp68 = tmp67 * tmp66 tmp69 = tmp68 + tmp64 tmp71 = triton_helpers.maximum(tmp70, tmp1) tmp72 = tmp71 * tmp71 tmp73 = tmp72 * tmp71 tmp74 = tmp73 + tmp69 tmp76 = triton_helpers.maximum(tmp75, tmp1) tmp77 = tmp76 * tmp76 tmp78 = tmp77 * tmp76 tmp79 = tmp78 + tmp74 tmp80 = 0.0625 tmp81 = tmp79 * tmp80 tmp82 = 0.3333333333333333 tmp83 = libdevice.pow(tmp81, tmp82) tl.store(in_out_ptr0 + x0, tmp83, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_avg_pool2d_clamp_pow_0[grid(16)](buf1, arg0_1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf1, def gem(x, p=3, eps=1e-06): return F.avg_pool2d(x.clamp(min=eps).pow(p), (x.size(-2), x.size(-1))).pow( 1.0 / p) class GeMNew(torch.nn.Module): """ Implementation of GeM pooling. https://paperswithcode.com/method/generalized-mean-pooling NOTE: p is learnable, but there is a consensus that it is better to fix the p value at 3. """ def __init__(self, p=3, eps=1e-06): super(GeMNew, self).__init__() self.p = p self.eps = eps def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
rskmoi/landmark-retrieval-2020-with-pytorch
GeM
false
7,577
[ "MIT" ]
1
41917b1f588b5ad396cb1095867a0f042c611675
https://github.com/rskmoi/landmark-retrieval-2020-with-pytorch/tree/41917b1f588b5ad396cb1095867a0f042c611675
L2Norm
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed class L2Norm(nn.Module): """ Scale shall be learnable according to original paper scale: initial scale number chan_num: L2Norm channel number (norm over all channels) """ def __init__(self, scale=20, chan_num=512): super(L2Norm, self).__init__() self.scale = nn.Parameter(torch.Tensor([scale] * chan_num).view(1, chan_num, 1, 1)) def forward(self, data): return self.scale * data * data.pow(2).sum(dim=1, keepdim=True).clamp( min=1e-12).rsqrt() def get_inputs(): return [torch.rand([4, 512, 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 import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_red_fused_pow_sum_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 256 rnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 16 x1 = xindex // 16 _tmp3 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) x3 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 2048 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = _tmp3 + tmp2 _tmp3 = tl.where(rmask & xmask, tmp4, _tmp3) tmp3 = tl.sum(_tmp3, 1)[:, None] tl.store(out_ptr0 + x3, tmp3, xmask) @triton.jit def triton_per_fused_clamp_pow_rsqrt_sum_1(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 4 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 % 16 x1 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 64 * x1), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 1e-12 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = libdevice.rsqrt(tmp6) tl.debug_barrier() tl.store(in_out_ptr0 + x3, tmp7, xmask) @triton.jit def triton_poi_fused_mul_2(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) x1 = xindex // 16 % 512 x3 = xindex x0 = xindex % 16 x2 = xindex // 8192 tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x3, None) tmp3 = tl.load(in_ptr2 + (x0 + 16 * x2), None, eviction_policy='evict_last' ) tmp2 = tmp0 * tmp1 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x3, tmp4, None) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_2, (4, 512, 4, 4), (8192, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 4, 4, 4), (64, 256, 4, 1, 16), torch.float32) get_raw_stream(0) triton_red_fused_pow_sum_0[grid(256)](primals_2, buf0, 256, 128, XBLOCK=64, RBLOCK=8, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32) buf2 = reinterpret_tensor(buf1, (4, 1, 4, 4), (16, 16, 4, 1), 0) del buf1 triton_per_fused_clamp_pow_rsqrt_sum_1[grid(64)](buf2, buf0, 64, 4, XBLOCK=64, num_warps=2, num_stages=1) del buf0 buf3 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch. float32) triton_poi_fused_mul_2[grid(32768)](primals_1, primals_2, buf2, buf3, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 return buf3, primals_2, buf2 class L2NormNew(nn.Module): """ Scale shall be learnable according to original paper scale: initial scale number chan_num: L2Norm channel number (norm over all channels) """ def __init__(self, scale=20, chan_num=512): super(L2NormNew, self).__init__() self.scale = nn.Parameter(torch.Tensor([scale] * chan_num).view(1, chan_num, 1, 1)) def forward(self, input_0): primals_1 = self.scale primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
rotorliu/DALI
L2Norm
false
7,578
[ "ECL-2.0", "Apache-2.0" ]
1
4ea3529fc9b35cbdf09b260ec95197cfd52c0395
https://github.com/rotorliu/DALI/tree/4ea3529fc9b35cbdf09b260ec95197cfd52c0395
SRCNN
import logging import torch import torch.nn as nn def get_root_logger(log_file=None, log_level=logging.INFO): """Get the root logger. The logger will be initialized if it has not been initialized. By default a StreamHandler will be added. If `log_file` is specified, a FileHandler will also be added. The name of the root logger is the top-level package name, e.g., "mmsr". Args: log_file (str | None): The log filename. If specified, a FileHandler will be added to the root logger. log_level (int): The root logger level. Note that only the process of rank 0 is affected, while other processes will set the level to "Error" and be silent most of the time. Returns: logging.Logger: The root logger. """ logger = get_logger(__name__.split('.')[0], log_file, log_level) return logger class SRCNN(nn.Module): """SRCNN network structure for image super resolution. SRCNN has three conv layers. For each layer, we can define the `in_channels`, `out_channels` and `kernel_size`. The input image will first be upsampled with a bicubic upsampler, and then super-resolved in the HR spatial size. Paper: Learning a Deep Convolutional Network for Image Super-Resolution. Args: channels (tuple[int]): A tuple of channel numbers for each layer including channels of input and output . Default: (3, 64, 32, 3). kernel_sizes (tuple[int]): A tuple of kernel sizes for each conv layer. Default: (9, 1, 5). upscale_factor (int): Upsampling factor. Default: 4. """ def __init__(self, channels=(3, 64, 32, 3), kernel_sizes=(9, 1, 5), upscale_factor=4): super(SRCNN, self).__init__() assert len(channels ) == 4, f'The length of channel tuple should be 4, but got {len(channels)}' assert len(kernel_sizes ) == 3, f'The length of kernel tuple should be 3, but got {len(kernel_sizes)}' self.upscale_factor = upscale_factor self.img_upsampler = nn.Upsample(scale_factor=self.upscale_factor, mode='bicubic', align_corners=False) self.conv1 = nn.Conv2d(channels[0], channels[1], kernel_size= kernel_sizes[0], padding=kernel_sizes[0] // 2) self.conv2 = nn.Conv2d(channels[1], channels[2], kernel_size= kernel_sizes[1], padding=kernel_sizes[1] // 2) self.conv3 = nn.Conv2d(channels[2], channels[3], kernel_size= kernel_sizes[2], padding=kernel_sizes[2] // 2) self.relu = nn.ReLU() def forward(self, x): """Forward function. Args: x (Tensor): Input tensor with shape (n, c, h, w). Returns: Tensor: Forward results. """ x = self.img_upsampler(x) out = self.relu(self.conv1(x)) out = self.relu(self.conv2(out)) out = self.conv3(out) return out def init_weights(self, pretrained=None, strict=True): """Init weights for models. Args: pretrained (str, optional): Path for pretrained weights. If given None, pretrained weights will not be loaded. Defaults to None. strict (boo, optional): Whether strictly load the pretrained model. Defaults to True. """ if isinstance(pretrained, str): logger = get_root_logger() load_checkpoint(self, pretrained, strict=strict, logger=logger) elif pretrained is None: pass else: raise TypeError( f'"pretrained" must be a str or None. But received {type(pretrained)}.' ) def get_inputs(): return [torch.rand([4, 3, 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 logging 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__to_copy__unsafe_index_add_arange_clamp_floor_mul_rsub_sub_0( in_out_ptr1, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 16 x0 = xindex % 16 x2 = xindex // 256 x3 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 0.25 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = libdevice.floor(tmp6) tmp8 = tmp7.to(tl.int32) tmp9 = tl.full([1], 1, tl.int64) tmp10 = tmp8 - tmp9 tmp11 = tl.full([1], 0, tl.int64) tmp12 = triton_helpers.maximum(tmp10, tmp11) tmp13 = tl.full([1], 3, tl.int64) tmp14 = triton_helpers.minimum(tmp12, tmp13) tmp15 = x0 tmp16 = tmp15.to(tl.float32) tmp17 = tmp16 + tmp2 tmp18 = tmp17 * tmp4 tmp19 = tmp18 - tmp2 tmp20 = libdevice.floor(tmp19) tmp21 = tmp20.to(tl.int32) tmp22 = tmp21 - tmp9 tmp23 = triton_helpers.maximum(tmp22, tmp11) tmp24 = triton_helpers.minimum(tmp23, tmp13) tmp25 = tl.load(in_ptr0 + (tmp24 + 4 * tmp14 + 16 * x2), xmask, eviction_policy='evict_last') tmp26 = tmp19 - tmp20 tmp27 = 0.0 tmp28 = triton_helpers.maximum(tmp26, tmp27) tmp29 = 1.0 tmp30 = triton_helpers.minimum(tmp28, tmp29) tmp31 = tmp30 + tmp29 tmp32 = -0.75 tmp33 = tmp31 * tmp32 tmp34 = -3.75 tmp35 = tmp33 - tmp34 tmp36 = tmp35 * tmp31 tmp37 = -6.0 tmp38 = tmp36 + tmp37 tmp39 = tmp38 * tmp31 tmp40 = -3.0 tmp41 = tmp39 - tmp40 tmp42 = tmp25 * tmp41 tmp43 = triton_helpers.maximum(tmp21, tmp11) tmp44 = triton_helpers.minimum(tmp43, tmp13) tmp45 = tl.load(in_ptr0 + (tmp44 + 4 * tmp14 + 16 * x2), xmask, eviction_policy='evict_last') tmp46 = 1.25 tmp47 = tmp30 * tmp46 tmp48 = 2.25 tmp49 = tmp47 - tmp48 tmp50 = tmp49 * tmp30 tmp51 = tmp50 * tmp30 tmp52 = tmp51 + tmp29 tmp53 = tmp45 * tmp52 tmp54 = tmp21 + tmp9 tmp55 = triton_helpers.maximum(tmp54, tmp11) tmp56 = triton_helpers.minimum(tmp55, tmp13) tmp57 = tl.load(in_ptr0 + (tmp56 + 4 * tmp14 + 16 * x2), xmask, eviction_policy='evict_last') tmp58 = tmp29 - tmp30 tmp59 = tmp58 * tmp46 tmp60 = tmp59 - tmp48 tmp61 = tmp60 * tmp58 tmp62 = tmp61 * tmp58 tmp63 = tmp62 + tmp29 tmp64 = tmp57 * tmp63 tmp65 = triton_helpers.maximum(tmp8, tmp11) tmp66 = triton_helpers.minimum(tmp65, tmp13) tmp67 = tl.load(in_ptr0 + (tmp24 + 4 * tmp66 + 16 * x2), xmask, eviction_policy='evict_last') tmp68 = tmp67 * tmp41 tmp69 = tl.full([1], 2, tl.int64) tmp70 = tmp21 + tmp69 tmp71 = triton_helpers.maximum(tmp70, tmp11) tmp72 = triton_helpers.minimum(tmp71, tmp13) tmp73 = tl.load(in_ptr0 + (tmp72 + 4 * tmp14 + 16 * x2), xmask, eviction_policy='evict_last') tmp74 = 2.0 tmp75 = tmp74 - tmp30 tmp76 = tmp75 * tmp32 tmp77 = tmp76 - tmp34 tmp78 = tmp77 * tmp75 tmp79 = tmp78 + tmp37 tmp80 = tmp79 * tmp75 tmp81 = tmp80 - tmp40 tmp82 = tmp73 * tmp81 tmp83 = tl.load(in_ptr0 + (tmp44 + 4 * tmp66 + 16 * x2), xmask, eviction_policy='evict_last') tmp84 = tmp83 * tmp52 tmp85 = tl.load(in_ptr0 + (tmp56 + 4 * tmp66 + 16 * x2), xmask, eviction_policy='evict_last') tmp86 = tmp85 * tmp63 tmp87 = tmp8 + tmp9 tmp88 = triton_helpers.maximum(tmp87, tmp11) tmp89 = triton_helpers.minimum(tmp88, tmp13) tmp90 = tl.load(in_ptr0 + (tmp24 + 4 * tmp89 + 16 * x2), xmask, eviction_policy='evict_last') tmp91 = tmp90 * tmp41 tmp92 = tl.load(in_ptr0 + (tmp72 + 4 * tmp66 + 16 * x2), xmask, eviction_policy='evict_last') tmp93 = tmp92 * tmp81 tmp94 = tl.load(in_ptr0 + (tmp44 + 4 * tmp89 + 16 * x2), xmask, eviction_policy='evict_last') tmp95 = tmp94 * tmp52 tmp96 = tl.load(in_ptr0 + (tmp56 + 4 * tmp89 + 16 * x2), xmask, eviction_policy='evict_last') tmp97 = tmp96 * tmp63 tmp98 = tmp8 + tmp69 tmp99 = triton_helpers.maximum(tmp98, tmp11) tmp100 = triton_helpers.minimum(tmp99, tmp13) tmp101 = tl.load(in_ptr0 + (tmp24 + 4 * tmp100 + 16 * x2), xmask, eviction_policy='evict_last') tmp102 = tmp101 * tmp41 tmp103 = tl.load(in_ptr0 + (tmp72 + 4 * tmp89 + 16 * x2), xmask, eviction_policy='evict_last') tmp104 = tmp103 * tmp81 tmp105 = tl.load(in_ptr0 + (tmp44 + 4 * tmp100 + 16 * x2), xmask, eviction_policy='evict_last') tmp106 = tmp105 * tmp52 tmp107 = tl.load(in_ptr0 + (tmp56 + 4 * tmp100 + 16 * x2), xmask, eviction_policy='evict_last') tmp108 = tmp107 * tmp63 tmp109 = tl.load(in_ptr0 + (tmp72 + 4 * tmp100 + 16 * x2), xmask, eviction_policy='evict_last') tmp110 = tmp109 * tmp81 tmp111 = tmp42 + tmp53 tmp112 = tmp111 + tmp64 tmp113 = tmp112 + tmp82 tmp114 = tmp6 - tmp7 tmp115 = triton_helpers.maximum(tmp114, tmp27) tmp116 = triton_helpers.minimum(tmp115, tmp29) tmp117 = tmp116 + tmp29 tmp118 = tmp117 * tmp32 tmp119 = tmp118 - tmp34 tmp120 = tmp119 * tmp117 tmp121 = tmp120 + tmp37 tmp122 = tmp121 * tmp117 tmp123 = tmp122 - tmp40 tmp124 = tmp113 * tmp123 tmp125 = tmp68 + tmp84 tmp126 = tmp125 + tmp86 tmp127 = tmp126 + tmp93 tmp128 = tmp116 * tmp46 tmp129 = tmp128 - tmp48 tmp130 = tmp129 * tmp116 tmp131 = tmp130 * tmp116 tmp132 = tmp131 + tmp29 tmp133 = tmp127 * tmp132 tmp134 = tmp124 + tmp133 tmp135 = tmp91 + tmp95 tmp136 = tmp135 + tmp97 tmp137 = tmp136 + tmp104 tmp138 = tmp29 - tmp116 tmp139 = tmp138 * tmp46 tmp140 = tmp139 - tmp48 tmp141 = tmp140 * tmp138 tmp142 = tmp141 * tmp138 tmp143 = tmp142 + tmp29 tmp144 = tmp137 * tmp143 tmp145 = tmp134 + tmp144 tmp146 = tmp102 + tmp106 tmp147 = tmp146 + tmp108 tmp148 = tmp147 + tmp110 tmp149 = tmp74 - tmp116 tmp150 = tmp149 * tmp32 tmp151 = tmp150 - tmp34 tmp152 = tmp151 * tmp149 tmp153 = tmp152 + tmp37 tmp154 = tmp153 * tmp149 tmp155 = tmp154 - tmp40 tmp156 = tmp148 * tmp155 tmp157 = tmp145 + tmp156 tl.store(in_out_ptr1 + x3, tmp157, xmask) @triton.jit def triton_poi_fused_convolution_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) x3 = xindex x1 = xindex // 256 % 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_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 // 256 % 32 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_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 256 % 3 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 3, 4, 4), (48, 16, 4, 1)) assert_size_stride(primals_2, (64, 3, 9, 9), (243, 81, 9, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (32, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (3, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_7, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf10 = empty_strided_cuda((4, 3, 16, 16), (768, 256, 16, 1), torch .float32) buf18 = buf10 del buf10 buf20 = buf18 del buf18 get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_floor_mul_rsub_sub_0[ grid(3072)](buf20, primals_1, 3072, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf21 = extern_kernels.convolution(buf20, primals_2, stride=(1, 1), padding=(4, 4), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf21, (4, 64, 16, 16), (16384, 256, 16, 1)) buf22 = buf21 del buf21 triton_poi_fused_convolution_relu_1[grid(65536)](buf22, primals_3, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_3 buf23 = extern_kernels.convolution(buf22, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf23, (4, 32, 16, 16), (8192, 256, 16, 1)) buf24 = buf23 del buf23 triton_poi_fused_convolution_relu_2[grid(32768)](buf24, primals_5, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf25 = extern_kernels.convolution(buf24, primals_6, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf25, (4, 3, 16, 16), (768, 256, 16, 1)) buf26 = buf25 del buf25 triton_poi_fused_convolution_3[grid(3072)](buf26, primals_7, 3072, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return buf26, primals_2, primals_4, primals_6, buf20, buf22, buf24 def get_root_logger(log_file=None, log_level=logging.INFO): """Get the root logger. The logger will be initialized if it has not been initialized. By default a StreamHandler will be added. If `log_file` is specified, a FileHandler will also be added. The name of the root logger is the top-level package name, e.g., "mmsr". Args: log_file (str | None): The log filename. If specified, a FileHandler will be added to the root logger. log_level (int): The root logger level. Note that only the process of rank 0 is affected, while other processes will set the level to "Error" and be silent most of the time. Returns: logging.Logger: The root logger. """ logger = get_logger(__name__.split('.')[0], log_file, log_level) return logger class SRCNNNew(nn.Module): """SRCNN network structure for image super resolution. SRCNN has three conv layers. For each layer, we can define the `in_channels`, `out_channels` and `kernel_size`. The input image will first be upsampled with a bicubic upsampler, and then super-resolved in the HR spatial size. Paper: Learning a Deep Convolutional Network for Image Super-Resolution. Args: channels (tuple[int]): A tuple of channel numbers for each layer including channels of input and output . Default: (3, 64, 32, 3). kernel_sizes (tuple[int]): A tuple of kernel sizes for each conv layer. Default: (9, 1, 5). upscale_factor (int): Upsampling factor. Default: 4. """ def __init__(self, channels=(3, 64, 32, 3), kernel_sizes=(9, 1, 5), upscale_factor=4): super(SRCNNNew, self).__init__() assert len(channels ) == 4, f'The length of channel tuple should be 4, but got {len(channels)}' assert len(kernel_sizes ) == 3, f'The length of kernel tuple should be 3, but got {len(kernel_sizes)}' self.upscale_factor = upscale_factor self.img_upsampler = nn.Upsample(scale_factor=self.upscale_factor, mode='bicubic', align_corners=False) self.conv1 = nn.Conv2d(channels[0], channels[1], kernel_size= kernel_sizes[0], padding=kernel_sizes[0] // 2) self.conv2 = nn.Conv2d(channels[1], channels[2], kernel_size= kernel_sizes[1], padding=kernel_sizes[1] // 2) self.conv3 = nn.Conv2d(channels[2], channels[3], kernel_size= kernel_sizes[2], padding=kernel_sizes[2] // 2) self.relu = nn.ReLU() def init_weights(self, pretrained=None, strict=True): """Init weights for models. Args: pretrained (str, optional): Path for pretrained weights. If given None, pretrained weights will not be loaded. Defaults to None. strict (boo, optional): Whether strictly load the pretrained model. Defaults to True. """ if isinstance(pretrained, str): logger = get_root_logger() load_checkpoint(self, pretrained, strict=strict, logger=logger) elif pretrained is None: pass else: raise TypeError( f'"pretrained" must be a str or None. But received {type(pretrained)}.' ) 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_6 = self.conv3.weight primals_7 = self.conv3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
rivergold/mmediting
SRCNN
false
7,579
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
Swish
from torch.autograd import Function import torch from torch import nn def swish(x, beta=1.0): """Swish activation. 'https://arxiv.org/pdf/1710.05941.pdf' Args: x: Input tensor. beta: """ return SwishOP.apply(x, beta) class SwishOP(Function): @staticmethod def forward(ctx, tensor, beta=1.0): ctx.save_for_backward(tensor) ctx.beta = beta swish = tensor / (1 + torch.exp(-beta * tensor)) return swish @staticmethod def backward(ctx, grad_outputs): tensor = ctx.saved_tensors[0] beta = ctx.beta grad_swish = (torch.exp(-beta * tensor) * (1 + beta * tensor) + 1) / ( 1 + torch.exp(-beta * tensor)) ** 2 grad_swish = grad_outputs * grad_swish return grad_swish, None class Swish(nn.Module): """Switch activation from 'SEARCHING FOR ACTIVATION FUNCTIONS' https://arxiv.org/pdf/1710.05941.pdf swish = x / (1 + e^-beta*x) d_swish = (1 + (1+beta*x)) / ((1 + e^-beta*x)^2) """ def __init__(self, beta=1.0): super(Swish, self).__init__() self.beta = beta def forward(self, x): return swish(x, self.beta) 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 math as tl_math from torch.autograd import Function 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_exp_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 = -1.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp4 = 1.0 tmp5 = tmp3 + tmp4 tmp6 = tmp0 / tmp5 tl.store(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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_exp_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, def swish(x, beta=1.0): """Swish activation. 'https://arxiv.org/pdf/1710.05941.pdf' Args: x: Input tensor. beta: """ return SwishOP.apply(x, beta) class SwishOP(Function): @staticmethod def forward(ctx, tensor, beta=1.0): ctx.save_for_backward(tensor) ctx.beta = beta swish = tensor / (1 + torch.exp(-beta * tensor)) return swish @staticmethod def backward(ctx, grad_outputs): tensor = ctx.saved_tensors[0] beta = ctx.beta grad_swish = (torch.exp(-beta * tensor) * (1 + beta * tensor) + 1) / ( 1 + torch.exp(-beta * tensor)) ** 2 grad_swish = grad_outputs * grad_swish return grad_swish, None class SwishNew(nn.Module): """Switch activation from 'SEARCHING FOR ACTIVATION FUNCTIONS' https://arxiv.org/pdf/1710.05941.pdf swish = x / (1 + e^-beta*x) d_swish = (1 + (1+beta*x)) / ((1 + e^-beta*x)^2) """ def __init__(self, beta=1.0): super(SwishNew, self).__init__() self.beta = beta def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
sailfish009/torch-toolbox
Swish
false
7,580
[ "BSD-3-Clause" ]
1
80dfc22c697b9f323e097de72af04f0e5435d7b4
https://github.com/sailfish009/torch-toolbox/tree/80dfc22c697b9f323e097de72af04f0e5435d7b4
Encoder
import torch import torch.nn as nn class Encoder(nn.Module): """ Takes in data, returns mu and sigma for variational approximation of latent variable. """ def __init__(self, alph_size, seq_len, z_dim=30, hidden_architecture=[ 1500, 1500]): super(Encoder, self).__init__() self.hidden1 = nn.Linear(alph_size * seq_len, hidden_architecture[0]) self.hidden2 = nn.Linear(hidden_architecture[0], hidden_architecture[1] ) self.final1 = nn.Linear(hidden_architecture[1], z_dim) self.final2 = nn.Linear(hidden_architecture[1], z_dim) self.relu = nn.ReLU() self.alph_size = alph_size self.seq_len = seq_len def forward(self, x): x = x.reshape(-1, self.seq_len * self.alph_size) hidden1 = self.relu(self.hidden1(x)) hidden2 = self.relu(self.hidden2(hidden1)) z_loc = self.final1(hidden2) z_scale = torch.exp(self.final2(hidden2)) return z_loc, z_scale def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'alph_size': 4, 'seq_len': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 24000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 1500 x1 = xindex // 1500 tmp0 = tl.load(in_out_ptr0 + (x0 + 1504 * x1), 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 + (x0 + 1504 * x1), tmp4, xmask) @triton.jit def triton_poi_fused_exp_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 480 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 30 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl_math.exp(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1500, 16), (16, 1)) assert_size_stride(primals_3, (1500,), (1,)) assert_size_stride(primals_4, (1500, 1500), (1500, 1)) assert_size_stride(primals_5, (1500,), (1,)) assert_size_stride(primals_6, (30, 1500), (1500, 1)) assert_size_stride(primals_7, (30,), (1,)) assert_size_stride(primals_8, (30, 1500), (1500, 1)) assert_size_stride(primals_9, (30,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 1500), (1504, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 16), (16, 1), 0), reinterpret_tensor(primals_2, (16, 1500), (1, 16), 0), out=buf0 ) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(24000)](buf1, primals_3, 24000, XBLOCK =256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((16, 1500), (1504, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (1500, 1500), (1, 1500), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_0[grid(24000)](buf3, primals_5, 24000, XBLOCK =256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((16, 30), (30, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (1500, 30), (1, 1500), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((16, 30), (30, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_8, (1500, 30), ( 1, 1500), 0), out=buf5) buf6 = buf5 del buf5 triton_poi_fused_exp_1[grid(480)](buf6, primals_9, 480, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 return buf4, buf6, reinterpret_tensor(primals_1, (16, 16), (16, 1), 0 ), buf1, buf3, buf6, primals_8, primals_6, primals_4 class EncoderNew(nn.Module): """ Takes in data, returns mu and sigma for variational approximation of latent variable. """ def __init__(self, alph_size, seq_len, z_dim=30, hidden_architecture=[ 1500, 1500]): super(EncoderNew, self).__init__() self.hidden1 = nn.Linear(alph_size * seq_len, hidden_architecture[0]) self.hidden2 = nn.Linear(hidden_architecture[0], hidden_architecture[1] ) self.final1 = nn.Linear(hidden_architecture[1], z_dim) self.final2 = nn.Linear(hidden_architecture[1], z_dim) self.relu = nn.ReLU() self.alph_size = alph_size self.seq_len = seq_len def forward(self, input_0): primals_2 = self.hidden1.weight primals_3 = self.hidden1.bias primals_4 = self.hidden2.weight primals_5 = self.hidden2.bias primals_6 = self.final1.weight primals_7 = self.final1.bias primals_8 = self.final2.weight primals_9 = self.final2.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], output[1]
rorymaizels/AC299r
Encoder
false
7,581
[ "MIT" ]
1
eb4b76ad52a10b9af0579ec3f725ec8fc90b00f1
https://github.com/rorymaizels/AC299r/tree/eb4b76ad52a10b9af0579ec3f725ec8fc90b00f1