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
UpsampleConvLayer
import torch import torch.nn as nn class UpsampleConvLayer(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(UpsampleConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride) def forward(self, x): out = self.reflection_pad(x) out = self.conv2d(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4, 'stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 % 8 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-2 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-2 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1936 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 121 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 11, 11), (484, 121, 11, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(1936)](buf2, primals_3, 1936, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class UpsampleConvLayerNew(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(UpsampleConvLayerNew, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride) def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
joaquingv12/Solving-Image-Processing-Problems-with-Python-Part1
UpsampleConvLayer
false
6,969
[ "MIT" ]
1
42512672d1dc660dabc2d4570e891315f5264b12
https://github.com/joaquingv12/Solving-Image-Processing-Problems-with-Python-Part1/tree/42512672d1dc660dabc2d4570e891315f5264b12
GATModelVAE
import torch import torch.nn as nn from torch.nn.parameter import Parameter import torch.nn.functional as F class GraphConvolution(nn.Module): def __init__(self, input_dim, output_dim, dropout, bias=False): super(GraphConvolution, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = Parameter(torch.FloatTensor(input_dim, output_dim)) self.reset_parameters() if bias: self.bias = Parameter(torch.FloatTensor(output_dim)) nn.init.zeros_(self.bias) else: self.register_parameter('bias', None) self.dropout = nn.Dropout(dropout) def reset_parameters(self): nn.init.xavier_uniform_(self.weight) def forward(self, input, adj): input = self.dropout(input) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) if self.bias is not None: output = output + self.bias return output class InnerProductDecoder(nn.Module): """ 内积用来做decoder,用来生成邻接矩阵 """ def __init__(self, dropout): super(InnerProductDecoder, self).__init__() self.dropout = nn.Dropout(dropout) def forward(self, z): z = self.dropout(z) adj = torch.mm(z, z.t()) return adj class GraphAttentionLayer(nn.Module): def __init__(self, input_dim, output_dim, dropout, alpha): super(GraphAttentionLayer, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = Parameter(torch.FloatTensor(input_dim, output_dim)) self.a = Parameter(torch.FloatTensor(2 * output_dim, 1)) self.reset_parameters() self.dropout = nn.Dropout(dropout) self.leakyrelu = nn.LeakyReLU(alpha) self.elu = nn.ELU() def reset_parameters(self): nn.init.xavier_uniform_(self.weight) nn.init.xavier_normal_(self.a) def forward(self, input, adj): Wh = torch.mm(input, self.weight) Wh1 = torch.matmul(Wh, self.a[:self.output_dim, :]) Wh2 = torch.matmul(Wh, self.a[self.output_dim:, :]) e = Wh1 + Wh2.T e = self.leakyrelu(e) zero_vec = -9000000000000000.0 * torch.ones_like(e) attention = torch.where(adj > 0, e, zero_vec) attention = F.softmax(attention, dim=-1) attention = self.dropout(attention) attention_wh = torch.matmul(attention, Wh) return self.elu(attention_wh) class GATModelVAE(nn.Module): def __init__(self, input_feat_dim, hidden_dim1, hidden_dim2, hidden_dim3, dropout, alpha, vae_bool=True): super(GATModelVAE, self).__init__() self.vae_bool = vae_bool self.gc_att = GraphAttentionLayer(input_feat_dim, hidden_dim1, dropout, alpha) self.gc1 = GraphConvolution(hidden_dim1, hidden_dim2, dropout) self.gc2 = GraphConvolution(hidden_dim2, hidden_dim3, dropout) self.gc3 = GraphConvolution(hidden_dim2, hidden_dim3, dropout) self.ip = InnerProductDecoder(dropout) self.elu = nn.ELU() self.relu = nn.ReLU() def encode(self, input, adj): gc_att = self.elu(self.gc_att(input, adj.to_dense())) hidden1 = self.relu(self.gc1(gc_att, adj)) return self.gc2(hidden1, adj), self.gc3(hidden1, adj) def reparameterize(self, mu, logvar): if self.vae_bool: std = torch.exp(logvar) eps = torch.randn_like(std) return eps.mul(std).add_(mu) else: return mu def forward(self, input, adj): mu, logvar = self.encode(input, adj) z = self.reparameterize(mu, logvar) return self.ip(z), mu, logvar def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_feat_dim': 4, 'hidden_dim1': 4, 'hidden_dim2': 4, 'hidden_dim3': 4, 'dropout': 0.5, 'alpha': 4}]
import torch from torch import device 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 from torch.nn.parameter import Parameter 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_add_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 x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') 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__softmax_add_gt_leaky_relu_mul_where_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last').to(tl .int1) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp5 = tl.load(in_ptr3 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp13 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp16 = tl.load(in_ptr3 + 1) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp23 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp25 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp26 = tl.load(in_ptr3 + 2) tmp27 = tl.broadcast_to(tmp26, [XBLOCK]) tmp33 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp35 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp36 = tl.load(in_ptr3 + 3) tmp37 = tl.broadcast_to(tmp36, [XBLOCK]) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp7 = tmp4 + tmp6 tmp8 = 4.0 tmp9 = tmp7 * tmp8 tmp10 = tl.where(tmp3, tmp7, tmp9) tmp11 = -8999999815811072.0 tmp12 = tl.where(tmp2, tmp10, tmp11) tmp14 = tmp13 > tmp1 tmp18 = tmp4 + tmp17 tmp19 = tmp18 * tmp8 tmp20 = tl.where(tmp15, tmp18, tmp19) tmp21 = tl.where(tmp14, tmp20, tmp11) tmp22 = triton_helpers.maximum(tmp12, tmp21) tmp24 = tmp23 > tmp1 tmp28 = tmp4 + tmp27 tmp29 = tmp28 * tmp8 tmp30 = tl.where(tmp25, tmp28, tmp29) tmp31 = tl.where(tmp24, tmp30, tmp11) tmp32 = triton_helpers.maximum(tmp22, tmp31) tmp34 = tmp33 > tmp1 tmp38 = tmp4 + tmp37 tmp39 = tmp38 * tmp8 tmp40 = tl.where(tmp35, tmp38, tmp39) tmp41 = tl.where(tmp34, tmp40, tmp11) tmp42 = triton_helpers.maximum(tmp32, tmp41) tl.store(out_ptr0 + x0, tmp42, xmask) @triton.jit def triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_2(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) tmp3 = tl.load(in_ptr1 + x2, xmask).to(tl.int1) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 * tmp7 tmp9 = tl.where(tmp3, tmp6, tmp8) tmp10 = -8999999815811072.0 tmp11 = tl.where(tmp2, tmp9, tmp10) tmp13 = tmp11 - tmp12 tmp14 = tl_math.exp(tmp13) tl.store(out_ptr0 + x2, tmp14, xmask) @triton.jit def triton_poi_fused__softmax_3(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_elu_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tmp8 = tmp7 > tmp1 tmp9 = tmp7 * tmp3 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp3 tmp12 = tl.where(tmp8, tmp9, tmp11) tl.store(out_ptr0 + x0, tmp12, xmask) @triton.jit def triton_poi_fused_relu_5(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.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_exp_mul_6(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 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp2 = tl_math.exp(tmp1) tmp3 = tmp0 * 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) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (8, 1), (1, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 1), (1, 1 ), 0), out=buf1) buf2 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 1), (1, 1 ), 4), out=buf2) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_leaky_relu_0[grid(16)](buf1, buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_1[grid(4)]( primals_1, buf3, buf1, buf2, buf4, 4, XBLOCK=4, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_add_gt_leaky_relu_mul_where_2[grid(16)]( primals_1, buf3, buf1, buf2, buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf1 del buf2 del buf4 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_3[grid(16)](buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = buf5 del buf5 extern_kernels.mm(buf6, buf0, out=buf7) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_elu_4[grid(16)](buf7, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf8, primals_5, out=buf9) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, buf9, out=buf10) buf11 = buf10 del buf10 triton_poi_fused_relu_5[grid(16)](buf11, 16, XBLOCK=16, num_warps=1, num_stages=1) buf12 = buf9 del buf9 extern_kernels.mm(buf11, primals_6, out=buf12) buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, buf12, out=buf13) buf14 = buf12 del buf12 extern_kernels.mm(buf11, primals_7, out=buf14) buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, buf14, out=buf15) buf16 = torch.ops.aten.randn.default([4, 4], dtype=torch.float32, device=device(type='cuda', index=0), pin_memory=False) buf17 = buf16 del buf16 buf18 = buf14 del buf14 triton_poi_fused_add_exp_mul_6[grid(16)](buf17, buf15, buf13, buf18, 16, XBLOCK=16, num_warps=1, num_stages=1) buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf18, reinterpret_tensor(buf18, (4, 4), (1, 4), 0), out=buf19) return (buf19, buf13, buf15, primals_1, buf3, buf6, buf7, buf11, buf15, buf17, buf18, reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), reinterpret_tensor(buf8, (4, 4), (1, 4), 0), reinterpret_tensor( primals_5, (4, 4), (1, 4), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), reinterpret_tensor(primals_4, (1, 4), (1, 1), 4), reinterpret_tensor(primals_4, (1, 4), (1, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0)) class GraphConvolution(nn.Module): def __init__(self, input_dim, output_dim, dropout, bias=False): super(GraphConvolution, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = Parameter(torch.FloatTensor(input_dim, output_dim)) self.reset_parameters() if bias: self.bias = Parameter(torch.FloatTensor(output_dim)) nn.init.zeros_(self.bias) else: self.register_parameter('bias', None) self.dropout = nn.Dropout(dropout) def reset_parameters(self): nn.init.xavier_uniform_(self.weight) def forward(self, input, adj): input = self.dropout(input) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) if self.bias is not None: output = output + self.bias return output class InnerProductDecoder(nn.Module): """ 内积用来做decoder,用来生成邻接矩阵 """ def __init__(self, dropout): super(InnerProductDecoder, self).__init__() self.dropout = nn.Dropout(dropout) def forward(self, z): z = self.dropout(z) adj = torch.mm(z, z.t()) return adj class GraphAttentionLayer(nn.Module): def __init__(self, input_dim, output_dim, dropout, alpha): super(GraphAttentionLayer, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = Parameter(torch.FloatTensor(input_dim, output_dim)) self.a = Parameter(torch.FloatTensor(2 * output_dim, 1)) self.reset_parameters() self.dropout = nn.Dropout(dropout) self.leakyrelu = nn.LeakyReLU(alpha) self.elu = nn.ELU() def reset_parameters(self): nn.init.xavier_uniform_(self.weight) nn.init.xavier_normal_(self.a) def forward(self, input, adj): Wh = torch.mm(input, self.weight) Wh1 = torch.matmul(Wh, self.a[:self.output_dim, :]) Wh2 = torch.matmul(Wh, self.a[self.output_dim:, :]) e = Wh1 + Wh2.T e = self.leakyrelu(e) zero_vec = -9000000000000000.0 * torch.ones_like(e) attention = torch.where(adj > 0, e, zero_vec) attention = F.softmax(attention, dim=-1) attention = self.dropout(attention) attention_wh = torch.matmul(attention, Wh) return self.elu(attention_wh) class GATModelVAENew(nn.Module): def __init__(self, input_feat_dim, hidden_dim1, hidden_dim2, hidden_dim3, dropout, alpha, vae_bool=True): super(GATModelVAENew, self).__init__() self.vae_bool = vae_bool self.gc_att = GraphAttentionLayer(input_feat_dim, hidden_dim1, dropout, alpha) self.gc1 = GraphConvolution(hidden_dim1, hidden_dim2, dropout) self.gc2 = GraphConvolution(hidden_dim2, hidden_dim3, dropout) self.gc3 = GraphConvolution(hidden_dim2, hidden_dim3, dropout) self.ip = InnerProductDecoder(dropout) self.elu = nn.ELU() self.relu = nn.ReLU() def encode(self, input, adj): gc_att = self.elu(self.gc_att(input, adj.to_dense())) hidden1 = self.relu(self.gc1(gc_att, adj)) return self.gc2(hidden1, adj), self.gc3(hidden1, adj) def reparameterize(self, mu, logvar): if self.vae_bool: std = torch.exp(logvar) eps = torch.randn_like(std) return eps.mul(std).add_(mu) else: return mu def forward(self, input_0, input_1): primals_1 = self.gc_att.weight primals_4 = self.gc_att.a primals_2 = self.gc1.weight primals_3 = self.gc2.weight primals_5 = self.gc3.weight primals_6 = input_0 primals_7 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0], output[1], output[2]
jiangnanboy/gcn_for_prediction_of_protein_interactions
GATModelVAE
false
6,970
[ "Apache-2.0" ]
1
b2a9eb06cdfe0971d0c352299db1075ec4827dd9
https://github.com/jiangnanboy/gcn_for_prediction_of_protein_interactions/tree/b2a9eb06cdfe0971d0c352299db1075ec4827dd9
ResidualBlock
import torch import torch.nn as nn class ConvLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride) def forward(self, x): out = self.reflection_pad(x) out = self.conv2d(out) return out class ResidualBlock(nn.Module): def __init__(self, channels): super(ResidualBlock, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.relu = nn.PReLU() def forward(self, x): residual = x out = self.relu(self.conv1(x)) out = self.conv2(out) * 0.1 out = torch.add(out, residual) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x2 = xindex // 36 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_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__prelu_kernel_reflection_pad2d_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x2 = xindex // 36 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp5 = tmp4 * tmp0 tmp6 = tl.where(tmp2, tmp0, tmp5) tl.store(out_ptr0 + x3, tmp6, xmask) @triton.jit def triton_poi_fused_add_convolution_mul_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp3 = 0.1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 + tmp5 tl.store(in_out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (1,), (1,)) assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(576)](primals_1, buf0, 576, XBLOCK=128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused__prelu_kernel_reflection_pad2d_2[grid(576)](buf2, primals_4, buf3, 576, XBLOCK=128, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_5, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_add_convolution_mul_3[grid(256)](buf5, primals_6, primals_1, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_6 return buf5, primals_2, primals_4, primals_5, buf0, buf2, buf3 class ConvLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride) def forward(self, x): out = self.reflection_pad(x) out = self.conv2d(out) return out class ResidualBlockNew(nn.Module): def __init__(self, channels): super(ResidualBlockNew, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.relu = nn.PReLU() def forward(self, input_0): primals_2 = self.conv1.conv2d.weight primals_3 = self.conv1.conv2d.bias primals_5 = self.conv2.conv2d.weight primals_6 = self.conv2.conv2d.bias primals_4 = self.relu.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
joaquingv12/Solving-Image-Processing-Problems-with-Python-Part1
ResidualBlock
false
6,971
[ "MIT" ]
1
42512672d1dc660dabc2d4570e891315f5264b12
https://github.com/joaquingv12/Solving-Image-Processing-Problems-with-Python-Part1/tree/42512672d1dc660dabc2d4570e891315f5264b12
Net
import torch import torch.nn.functional as F class Net(torch.nn.Module): def __init__(self): super(Net, self).__init__() self.l1 = torch.nn.Linear(784, 512) self.l2 = torch.nn.Linear(512, 256) self.l3 = torch.nn.Linear(256, 128) self.l4 = torch.nn.Linear(128, 64) self.l5 = torch.nn.Linear(64, 10) def forward(self, x): x = x.view(-1, 784) x = F.relu(self.l1(x)) x = F.relu(self.l2(x)) x = F.relu(self.l3(x)) x = F.relu(self.l4(x)) return self.l5(x) def get_inputs(): return [torch.rand([4, 784])] 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 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 ): 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) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_2(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 % 128 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 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) 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, 784), (784, 1)) assert_size_stride(primals_2, (512, 784), (784, 1)) assert_size_stride(primals_3, (512,), (1,)) assert_size_stride(primals_4, (256, 512), (512, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (128, 256), (256, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (64, 128), (128, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (10, 64), (64, 1)) assert_size_stride(primals_11, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 512), (512, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (784, 512), (1, 784), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(2048)](buf1, primals_3, 2048, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 256), (256, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (512, 256), ( 1, 512), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(1024)](buf3, primals_5, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 128), (128, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_6, (256, 128), ( 1, 256), 0), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_relu_2[grid(512)](buf5, primals_7, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_8, (128, 64), (1, 128), 0), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_relu_3[grid(256)](buf7, primals_9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf8 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_11, buf7, reinterpret_tensor( primals_10, (64, 10), (1, 64), 0), alpha=1, beta=1, out=buf8) del primals_11 return (buf8, primals_1, buf1, buf3, buf5, buf7, primals_10, primals_8, primals_6, primals_4) class NetNew(torch.nn.Module): def __init__(self): super(NetNew, self).__init__() self.l1 = torch.nn.Linear(784, 512) self.l2 = torch.nn.Linear(512, 256) self.l3 = torch.nn.Linear(256, 128) self.l4 = torch.nn.Linear(128, 64) self.l5 = torch.nn.Linear(64, 10) 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_6 = self.l3.weight primals_7 = self.l3.bias primals_8 = self.l4.weight primals_9 = self.l4.bias primals_10 = self.l5.weight primals_11 = self.l5.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]
jobsfan/pytorch
Net
false
6,972
[ "Apache-2.0" ]
1
221ae8e3673f8d2fbf0a58f40a30553c76084831
https://github.com/jobsfan/pytorch/tree/221ae8e3673f8d2fbf0a58f40a30553c76084831
ElectraClassificationHead
from _paritybench_helpers import _mock_config import torch from torch import nn import torch.nn.functional as F class ElectraClassificationHead(nn.Module): """CLS分类""" def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.dropout = nn.Dropout(config.hidden_dropout_prob) self.out_proj = nn.Linear(config.hidden_size, config.num_labels) def forward(self, features, **kwargs): x = features[:, 0, :] x = self.dropout(x) x = self.dense(x) x = F.gelu(x) x = self.dropout(x) x = self.out_proj(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, hidden_dropout_prob= 0.5, num_labels=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._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_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_gelu_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.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865476 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (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.addmm(primals_3, reinterpret_tensor(buf0, (16, 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), (16, 4, 1), torch.float32) triton_poi_fused_gelu_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) 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(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), primals_4 class ElectraClassificationHeadNew(nn.Module): """CLS分类""" def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.dropout = nn.Dropout(config.hidden_dropout_prob) self.out_proj = nn.Linear(config.hidden_size, config.num_labels) def forward(self, input_0): primals_2 = self.dense.weight primals_3 = self.dense.bias primals_4 = self.out_proj.weight primals_5 = self.out_proj.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
johnson7788/TextBrewer
ElectraClassificationHead
false
6,973
[ "Apache-2.0" ]
1
fa7fa4d4a2a8debde5b148d448238f3b4fa1aa9a
https://github.com/johnson7788/TextBrewer/tree/fa7fa4d4a2a8debde5b148d448238f3b4fa1aa9a
ComboLoss
import torch import torch.nn as nn class ComboLoss(nn.Module): def __init__(self, weight=None, size_average=True, alpha=0.5, ce_ratio=0.5 ): super(ComboLoss, self).__init__() self.alpha = alpha self.ce_ratio = ce_ratio def forward(self, inputs, targets, smooth=1): e = 1e-07 inputs = torch.sigmoid(inputs) inputs = inputs.contiguous().view(-1) targets = targets.contiguous().view(-1) intersection = (inputs * targets).sum() dice = (2.0 * intersection + smooth) / (inputs.sum() + targets.sum( ) + smooth) inputs = torch.clamp(inputs, e, 1.0 - e) out = -(self.alpha * (targets * torch.log(inputs)) + (1 - self. alpha) * (1.0 - targets) * torch.log(1.0 - inputs)) weighted_ce = out.mean(-1) combo = self.ce_ratio * weighted_ce - (1 - self.ce_ratio) * dice return combo def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_clamp_div_log_mean_mul_neg_rsub_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tl.sigmoid(tmp1) tmp3 = 1e-07 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 0.9999999 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = tl_math.log(tmp6) tmp8 = tmp0 * tmp7 tmp9 = 0.5 tmp10 = tmp8 * tmp9 tmp11 = 1.0 tmp12 = tmp11 - tmp0 tmp13 = tmp12 * tmp9 tmp14 = tmp11 - tmp6 tmp15 = tl_math.log(tmp14) tmp16 = tmp13 * tmp15 tmp17 = tmp10 + tmp16 tmp18 = -tmp17 tmp19 = tl.broadcast_to(tmp18, [RBLOCK]) tmp21 = triton_helpers.promote_to_tensor(tl.sum(tmp19, 0)) tmp22 = tmp2 * tmp0 tmp23 = tl.broadcast_to(tmp22, [RBLOCK]) tmp25 = triton_helpers.promote_to_tensor(tl.sum(tmp23, 0)) tmp26 = tl.broadcast_to(tmp2, [RBLOCK]) tmp28 = triton_helpers.promote_to_tensor(tl.sum(tmp26, 0)) tmp29 = tl.broadcast_to(tmp0, [RBLOCK]) tmp31 = triton_helpers.promote_to_tensor(tl.sum(tmp29, 0)) tmp32 = 256.0 tmp33 = tmp21 / tmp32 tmp34 = tmp33 * tmp9 tmp35 = 2.0 tmp36 = tmp25 * tmp35 tmp37 = tmp36 + tmp11 tmp38 = tmp28 + tmp31 tmp39 = tmp38 + tmp11 tmp40 = tmp37 / tmp39 tmp41 = tmp40 * tmp9 tmp42 = tmp34 - tmp41 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp42, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf4 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_clamp_div_log_mean_mul_neg_rsub_sub_sum_0[grid(1) ](buf4, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf4, class ComboLossNew(nn.Module): def __init__(self, weight=None, size_average=True, alpha=0.5, ce_ratio=0.5 ): super(ComboLossNew, self).__init__() self.alpha = alpha self.ce_ratio = ce_ratio def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
johnugeorge/medperf
ComboLoss
false
6,974
[ "Apache-2.0" ]
1
5bc3f643064df14e9476bd4d4c1a4c0cce5337d5
https://github.com/johnugeorge/medperf/tree/5bc3f643064df14e9476bd4d4c1a4c0cce5337d5
ImagenetNorm
import torch import torch.nn as nn class ImagenetNorm(nn.Module): def __init__(self, from_raw=True): """ :param from_raw: whether the input image lies in the range of [0, 255] """ super().__init__() self.from_raw = from_raw self.mean = nn.Parameter(torch.tensor([0.485, 0.456, 0.406]), requires_grad=False) self.std = nn.Parameter(torch.tensor([0.229, 0.224, 0.225]), requires_grad=False) def forward(self, x: 'torch.Tensor'): if x.dtype != torch.float: x = x.float() x = x / 255 if self.from_raw else x mean = self.mean.view(1, 3, 1, 1) std = self.std.view(1, 3, 1, 1) return (x - mean) / std def extra_repr(self): return f'from_raw={self.from_raw}' def get_inputs(): return [torch.rand([4, 3, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 3 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.00392156862745098 tmp2 = tmp0 * tmp1 tmp4 = tmp2 - tmp3 tmp6 = tmp4 / tmp5 tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 3, 4, 4), (48, 16, 4, 1)) assert_size_stride(arg1_1, (3,), (1,)) assert_size_stride(arg2_1, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_sub_0[grid(192)](arg0_1, arg1_1, arg2_1, buf0, 192, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf0, class ImagenetNormNew(nn.Module): def __init__(self, from_raw=True): """ :param from_raw: whether the input image lies in the range of [0, 255] """ super().__init__() self.from_raw = from_raw self.mean = nn.Parameter(torch.tensor([0.485, 0.456, 0.406]), requires_grad=False) self.std = nn.Parameter(torch.tensor([0.229, 0.224, 0.225]), requires_grad=False) def extra_repr(self): return f'from_raw={self.from_raw}' def forward(self, input_0): arg1_1 = self.mean arg2_1 = self.std arg0_1 = input_0 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
jokingbear/DM
ImagenetNorm
false
6,975
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
GlobalAverage
import torch import torch.nn as nn class GlobalAverage(nn.Module): def __init__(self, rank=2, keepdims=False): """ :param rank: dimension of image :param keepdims: whether to preserve shape after averaging """ super().__init__() self.axes = list(range(2, 2 + rank)) self.keepdims = keepdims def forward(self, x): return torch.mean(x, dim=self.axes, keepdim=self.keepdims) def extra_repr(self): return f'axes={self.axes}, keepdims={self.keepdims}' def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, arg0_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del arg0_1 return buf1, class GlobalAverageNew(nn.Module): def __init__(self, rank=2, keepdims=False): """ :param rank: dimension of image :param keepdims: whether to preserve shape after averaging """ super().__init__() self.axes = list(range(2, 2 + rank)) self.keepdims = keepdims def extra_repr(self): return f'axes={self.axes}, keepdims={self.keepdims}' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
jokingbear/DM
GlobalAverage
false
6,976
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
FocalLoss
import torch import torch.nn as nn def _assert_inputs(pred, true): assert pred.shape == true.shape, f'predition shape {pred.shape} is not the same as label shape {true.shape}' class FocalLoss(nn.Module): def __init__(self, gamma=2, binary=False): super().__init__() self.gamma = gamma self.binary = binary def forward(self, preds, trues): _assert_inputs(preds, trues) if self.binary: prob = trues * preds + (1 - trues) * (1 - preds) else: prob = (trues * preds).sum(dim=1) ln = (1 - prob).pow(self.gamma) * (prob + 1e-07).log() return -ln.mean() def extra_repr(self): return f'gamma={self.gamma}, binary={self.binary}' def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import 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_log_mean_mul_neg_pow_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp4 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp7 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp8 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp11 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp12 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = 1.0 tmp16 = tmp15 - tmp14 tmp17 = tmp16 * tmp16 tmp18 = 1e-07 tmp19 = tmp14 + tmp18 tmp20 = tl_math.log(tmp19) tmp21 = tmp17 * tmp20 tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp24 = tl.sum(tmp22, 1)[:, None] tmp25 = 64.0 tmp26 = tmp24 / tmp25 tmp27 = -tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp27, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_log_mean_mul_neg_pow_rsub_sum_0[grid(1)](buf2, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, def _assert_inputs(pred, true): assert pred.shape == true.shape, f'predition shape {pred.shape} is not the same as label shape {true.shape}' class FocalLossNew(nn.Module): def __init__(self, gamma=2, binary=False): super().__init__() self.gamma = gamma self.binary = binary def extra_repr(self): return f'gamma={self.gamma}, binary={self.binary}' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
jokingbear/DM
FocalLoss
false
6,977
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
FbetaLoss
import torch import torch.nn as nn def _assert_inputs(pred, true): assert pred.shape == true.shape, f'predition shape {pred.shape} is not the same as label shape {true.shape}' class FbetaLoss(nn.Module): def __init__(self, beta=1, axes=(0,), binary=False, smooth=1e-07): super().__init__() self.beta = beta self.axes = axes self.binary = binary self.smooth = smooth def forward(self, preds, trues): beta2 = self.beta ** 2 if not self.binary: trues = trues[:, 1:, ...] preds = preds[:, 1:, ...] _assert_inputs(preds, trues) p = (beta2 + 1) * (trues * preds).sum(dim=self.axes) s = (beta2 * trues + preds).sum(dim=self.axes) fb = (p + self.smooth) / (s + self.smooth) return (1 - fb).mean() def extra_repr(self): return ( f'beta={self.beta}, axes={self.axes}, binary={self.binary}, smooth={self.smooth}' ) 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_per_fused_add_div_mean_mul_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): rnumel = 48 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, :] rmask = rindex < rnumel r0 = rindex tmp0 = tl.load(in_ptr0 + (16 + r0), rmask, other=0.0) tmp1 = tl.load(in_ptr1 + (16 + r0), rmask, other=0.0) tmp3 = tl.load(in_ptr0 + (80 + r0), rmask, other=0.0) tmp4 = tl.load(in_ptr1 + (80 + r0), rmask, other=0.0) tmp7 = tl.load(in_ptr0 + (144 + r0), rmask, other=0.0) tmp8 = tl.load(in_ptr1 + (144 + r0), rmask, other=0.0) tmp11 = tl.load(in_ptr0 + (208 + r0), rmask, other=0.0) tmp12 = tl.load(in_ptr1 + (208 + r0), rmask, other=0.0) tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = 2.0 tmp16 = tmp14 * tmp15 tmp17 = 1e-07 tmp18 = tmp16 + tmp17 tmp19 = 1.0 tmp20 = tmp0 * tmp19 tmp21 = tmp20 + tmp1 tmp22 = tmp3 * tmp19 tmp23 = tmp22 + tmp4 tmp24 = tmp21 + tmp23 tmp25 = tmp7 * tmp19 tmp26 = tmp25 + tmp8 tmp27 = tmp24 + tmp26 tmp28 = tmp11 * tmp19 tmp29 = tmp28 + tmp12 tmp30 = tmp27 + tmp29 tmp31 = tmp30 + tmp17 tmp32 = tmp18 / tmp31 tmp33 = tmp19 - tmp32 tmp34 = tl.broadcast_to(tmp33, [XBLOCK, RBLOCK]) tmp36 = tl.where(rmask, tmp34, 0) tmp37 = tl.sum(tmp36, 1)[:, None] tmp38 = 48.0 tmp39 = tmp37 / tmp38 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp39, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_div_mean_mul_rsub_sum_0[grid(1)](buf2, arg0_1, arg1_1, 1, 48, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, def _assert_inputs(pred, true): assert pred.shape == true.shape, f'predition shape {pred.shape} is not the same as label shape {true.shape}' class FbetaLossNew(nn.Module): def __init__(self, beta=1, axes=(0,), binary=False, smooth=1e-07): super().__init__() self.beta = beta self.axes = axes self.binary = binary self.smooth = smooth def extra_repr(self): return ( f'beta={self.beta}, axes={self.axes}, binary={self.binary}, smooth={self.smooth}' ) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
jokingbear/DM
FbetaLoss
false
6,978
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
Accuracy
import torch import torch.nn as nn class Accuracy(nn.Module): def __init__(self, binary=False): super().__init__() self.binary = binary def forward(self, preds, trues): if self.binary: preds = preds >= 0.5 else: preds = preds.argmax(dim=1) result = (preds == trues).float().mean() return result def extra_repr(self): return f'binary={self.binary}' def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp17 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp32 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tl.store(out_ptr0 + x2, tmp46, xmask) @triton.jit def triton_per_fused__to_copy_eq_mean_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 % 64 r2 = rindex tmp0 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + r2, None) tmp1 = tmp0.to(tl.float32) tmp3 = tmp1 == tmp2 tmp4 = tmp3.to(tl.float32) tmp5 = tl.broadcast_to(tmp4, [RBLOCK]) tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0)) tmp8 = 256.0 tmp9 = tmp7 / tmp8 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp9, 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.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((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused__to_copy_eq_mean_1[grid(1)](buf2, buf0, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg1_1 del buf0 return buf2, class AccuracyNew(nn.Module): def __init__(self, binary=False): super().__init__() self.binary = binary def extra_repr(self): return f'binary={self.binary}' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
jokingbear/DM
Accuracy
false
6,979
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
GCN_encoder
import torch import torch.nn as nn import torch.nn.init as init class GraphConv(nn.Module): def __init__(self, input_dim, output_dim): super(GraphConv, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = nn.Parameter(torch.FloatTensor(input_dim, output_dim)) def forward(self, x, adj): y = torch.matmul(adj, x) y = torch.matmul(y, self.weight) return y class GCN_encoder(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super(GCN_encoder, self).__init__() self.conv1 = GraphConv(input_dim=input_dim, output_dim=hidden_dim) self.conv2 = GraphConv(input_dim=hidden_dim, output_dim=output_dim) self.relu = nn.ReLU() for m in self.modules(): if isinstance(m, GraphConv): m.weight.data = init.xavier_uniform(m.weight.data, gain=nn. init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, x, adj): x = self.conv1(x, adj) x = self.relu(x) x = self.conv2(x, adj) return x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'hidden_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(in_out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (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((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_2, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(primals_1, (16, 4, 4), (16, 4, 1), 0 ), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), primals_3, out=buf1) del primals_3 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf2, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_2, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf3) buf4 = reinterpret_tensor(buf2, (64, 4), (4, 1), 0) del buf2 extern_kernels.mm(reinterpret_tensor(buf3, (64, 4), (4, 1), 0), primals_4, out=buf4) return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf3, (4, 64), (1, 4), 0), reinterpret_tensor( primals_4, (4, 4), (1, 4), 0), reinterpret_tensor(primals_2, (16, 4, 4), (16, 1, 4), 0), buf5, reinterpret_tensor(buf0, (4, 64), (1, 4), 0) class GraphConv(nn.Module): def __init__(self, input_dim, output_dim): super(GraphConv, self).__init__() self.input_dim = input_dim self.output_dim = output_dim self.weight = nn.Parameter(torch.FloatTensor(input_dim, output_dim)) def forward(self, x, adj): y = torch.matmul(adj, x) y = torch.matmul(y, self.weight) return y class GCN_encoderNew(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim): super(GCN_encoderNew, self).__init__() self.conv1 = GraphConv(input_dim=input_dim, output_dim=hidden_dim) self.conv2 = GraphConv(input_dim=hidden_dim, output_dim=output_dim) self.relu = nn.ReLU() for m in self.modules(): if isinstance(m, GraphConv): m.weight.data = init.xavier_uniform(m.weight.data, gain=nn. init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, input_0, input_1): primals_3 = self.conv1.weight primals_4 = self.conv2.weight primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
jonathangomesselman/graph-generation
GCN_encoder
false
6,980
[ "MIT" ]
1
72a8be30d54a414fcca9ea0fad1a62e38b85ee2f
https://github.com/jonathangomesselman/graph-generation/tree/72a8be30d54a414fcca9ea0fad1a62e38b85ee2f
PolicyNet
import torch import torch.nn as nn import torch.nn.functional as F class PolicyNet(nn.Module): def __init__(self, state_dim, actions_dim, hidden_dim=64): super(PolicyNet, self).__init__() self.input_layer = nn.Linear(state_dim, hidden_dim) self.hidden = nn.Linear(hidden_dim, actions_dim) def forward(self, x): x = F.relu(self.input_layer(x)) return self.hidden(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'actions_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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 % 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) 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, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 64), (64, 1)) assert_size_stride(primals_5, (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_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf1, primals_2, buf3, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), primals_4, buf3 class PolicyNetNew(nn.Module): def __init__(self, state_dim, actions_dim, hidden_dim=64): super(PolicyNetNew, self).__init__() self.input_layer = nn.Linear(state_dim, hidden_dim) self.hidden = nn.Linear(hidden_dim, actions_dim) def forward(self, input_0): primals_1 = self.input_layer.weight primals_2 = self.input_layer.bias primals_4 = self.hidden.weight primals_5 = self.hidden.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
johntiger1/vaal_querying
PolicyNet
false
6,981
[ "BSD-2-Clause" ]
1
c20da3b0b5ca9f25334523f831d0ba8a11f710ca
https://github.com/johntiger1/vaal_querying/tree/c20da3b0b5ca9f25334523f831d0ba8a11f710ca
LabelSmoothingLoss
import torch import torch.nn.functional as F import torch.nn as nn class LabelSmoothingLoss(nn.Module): def __init__(self, smoothing=0.0): super(LabelSmoothingLoss, self).__init__() self.smoothing = smoothing def smooth_one_hot(self, target: 'torch.Tensor', classes: 'int', smoothing: 'float'=0.0): assert 0 <= smoothing < 1 shape = target.size(0), classes with torch.no_grad(): target = torch.empty(size=shape, device=target.device).fill_( smoothing / (classes - 1)).scatter_(1, target.data. unsqueeze(1), 1.0 - smoothing) return target def forward(self, input: 'torch.Tensor', target: 'torch.Tensor'): target = LabelSmoothingLoss.smooth_one_hot(self, target, input.size (-1), self.smoothing) lsm = F.log_softmax(input, -1) loss = -(target * lsm).sum(-1) loss = loss.mean() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.ones([4], dtype=torch.int64)] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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__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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_per_fused__log_softmax_mean_mul_neg_scatter_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 % 4 r2 = rindex tmp0 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + 4 * r2, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (1 + 4 * r2), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (2 + 4 * r2), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + (3 + 4 * r2), None, eviction_policy='evict_last') tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp7 = tl_math.exp(tmp6) tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp12 = tl_math.exp(tmp11) tmp13 = tmp10 + tmp12 tmp15 = tl_math.exp(tmp14) tmp16 = tmp13 + tmp15 tmp17 = tl_math.log(tmp16) tmp18 = tmp6 - tmp17 tmp19 = tmp5 * tmp18 tmp20 = tl.full([1, 1], 1, tl.int64) tmp21 = tmp0 == tmp20 tmp22 = tl.where(tmp21, tmp3, tmp4) tmp23 = tmp8 - tmp17 tmp24 = tmp22 * tmp23 tmp25 = tmp19 + tmp24 tmp26 = tl.full([1, 1], 2, tl.int64) tmp27 = tmp0 == tmp26 tmp28 = tl.where(tmp27, tmp3, tmp4) tmp29 = tmp11 - tmp17 tmp30 = tmp28 * tmp29 tmp31 = tmp25 + tmp30 tmp32 = tl.full([1, 1], 3, tl.int64) tmp33 = tmp0 == tmp32 tmp34 = tl.where(tmp33, tmp3, tmp4) tmp35 = tmp14 - tmp17 tmp36 = tmp34 * tmp35 tmp37 = tmp31 + tmp36 tmp38 = -tmp37 tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = tl.sum(tmp39, 1)[:, None] tmp42 = 64.0 tmp43 = tmp41 / tmp42 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4,), (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)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 triton_per_fused__log_softmax_mean_mul_neg_scatter_sum_1[grid(1)](buf3, arg1_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg1_1 del buf0 return buf3, class LabelSmoothingLossNew(nn.Module): def __init__(self, smoothing=0.0): super(LabelSmoothingLossNew, self).__init__() self.smoothing = smoothing def smooth_one_hot(self, target: 'torch.Tensor', classes: 'int', smoothing: 'float'=0.0): assert 0 <= smoothing < 1 shape = target.size(0), classes with torch.no_grad(): target = torch.empty(size=shape, device=target.device).fill_( smoothing / (classes - 1)).scatter_(1, target.data. unsqueeze(1), 1.0 - smoothing) return target def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
jordiae/DeepLearning-MAI
LabelSmoothingLoss
false
6,982
[ "MIT" ]
1
e12b6975d8de6cbe89f812bf691a7f7e95213552
https://github.com/jordiae/DeepLearning-MAI/tree/e12b6975d8de6cbe89f812bf691a7f7e95213552
BertSelfAttention
from _paritybench_helpers import _mock_config import math import torch from torch import nn class BertSelfAttention(nn.Module): def __init__(self, config): super(BertSelfAttention, self).__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) self.output_score = config.output_score self.output_sum = config.output_sum def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, attention_mask): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(hidden_states) mixed_value_layer = self.value(hidden_states) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_scores = attention_scores + attention_mask attention_probs = nn.Softmax(dim=-1)(attention_scores) if self.output_score is True: attention_probs_sum = attention_scores else: attention_probs_sum = attention_probs if self.output_sum is True: attention_probs_sum = attention_probs_sum.sum(dim=1) attention_probs = self.dropout(attention_probs) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) return context_layer, attention_probs_sum def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, num_attention_heads= 4, attention_probs_dropout_prob=0.5, output_score=4, output_sum=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_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused__softmax_add_div_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 x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp5 * tmp1 tmp8 = tmp6 + tmp7 tmp9 = triton_helpers.maximum(tmp4, tmp8) tmp11 = tmp10 * tmp1 tmp13 = tmp11 + tmp12 tmp14 = triton_helpers.maximum(tmp9, tmp13) tmp16 = tmp15 * tmp1 tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp14, tmp18) tmp20 = tmp4 - tmp19 tmp21 = tl_math.exp(tmp20) tmp22 = tmp8 - tmp19 tmp23 = tl_math.exp(tmp22) tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp19 tmp26 = tl_math.exp(tmp25) tmp27 = tmp24 + tmp26 tmp28 = tmp18 - tmp19 tmp29 = tl_math.exp(tmp28) tmp30 = tmp27 + tmp29 tl.store(out_ptr0 + x2, tmp19, xmask) tl.store(out_ptr1 + x2, tmp30, xmask) @triton.jit def triton_poi_fused__softmax_add_div_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex % 64 x5 = xindex // 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp3 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 - tmp5 tmp7 = tl_math.exp(tmp6) tmp9 = tmp7 / tmp8 tl.store(in_out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = 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), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_2 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf0 triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5) buf6 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf1 buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_add_div_1[grid(64)](buf5, primals_8, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 triton_poi_fused__softmax_add_div_2[grid(256)](buf8, primals_8, buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_8 buf9 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf7 triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_7, buf9, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_7 buf10 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 0), out=buf10) buf11 = reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf6 triton_poi_fused_clone_3[grid(16, 4)](buf10, buf11, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del buf10 return reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0 ), buf8, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0 ), buf8, reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0) class BertSelfAttentionNew(nn.Module): def __init__(self, config): super(BertSelfAttentionNew, self).__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) self.output_score = config.output_score self.output_sum = config.output_sum def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, input_0, input_1): primals_1 = self.query.weight primals_2 = self.query.bias primals_4 = self.key.weight primals_5 = self.key.bias primals_6 = self.value.weight primals_7 = self.value.bias primals_3 = input_0 primals_8 = 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]
johnson7788/TextBrewer
BertSelfAttention
false
6,983
[ "Apache-2.0" ]
1
fa7fa4d4a2a8debde5b148d448238f3b4fa1aa9a
https://github.com/johnson7788/TextBrewer/tree/fa7fa4d4a2a8debde5b148d448238f3b4fa1aa9a
TVLoss
import torch import numpy as np import torch.nn as nn class TVLoss(nn.Module): def __init__(self, norm=2): super().__init__() self.norm = norm def forward(self, x): rank = len(x.shape[2:]) shift_h = torch.cat([x[:, :, 1:], x[:, :, :1]], dim=2) shift_w = torch.cat([x[:, :, :, 1:], x[:, :, :, :1]], dim=3) shifts = [shift_h, shift_w] if rank > 2: shift_z = torch.cat([x[..., 1:], x[..., :1]], dim=-1) shifts.append(shift_z) shifts = torch.stack(shifts, dim=0) x = x[np.newaxis] if self.norm == 1: tv = abs(shifts - x) elif self.norm % 2 == 0: tv = (shifts - x).pow(self.norm) else: tv = abs(shifts - x).pow(self.norm) return tv.sum(dim=0).mean() def extra_repr(self): return f'norm={self.norm}' def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_stack_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 x3 = xindex // 64 x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 % 4 x4 = xindex // 4 % 16 x5 = xindex tmp0 = x3 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = x1 tmp7 = tl.full([1], 3, tl.int64) tmp8 = tmp5 < tmp7 tmp9 = tmp8 & tmp4 tmp10 = tl.load(in_ptr0 + (4 + x0 + 4 * x1 + 16 * x2 + 64 * x3), tmp9 & xmask, other=0.0) tmp11 = tmp5 >= tmp7 tmp13 = tmp11 & tmp4 tmp14 = tl.load(in_ptr0 + (x0 + 16 * x2 + 64 * x3), tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl.where(tmp8, tmp10, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp4, tmp15, tmp16) tmp18 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp21 = x0 tmp23 = tmp21 < tmp7 tmp24 = tmp23 & tmp18 tmp25 = tl.load(in_ptr0 + (1 + 4 * x4 + 64 * (-4 + x3) + x0), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp26 = tmp21 >= tmp7 tmp28 = tmp26 & tmp18 tmp29 = tl.load(in_ptr0 + (4 * x4 + 64 * (-4 + x3)), tmp28 & xmask, eviction_policy='evict_last', other=0.0) tmp30 = tl.where(tmp23, tmp25, tmp29) tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype) tmp32 = tl.where(tmp18, tmp30, tmp31) tmp33 = tl.where(tmp4, tmp17, tmp32) tl.store(out_ptr0 + x5, tmp33, xmask) @triton.jit def triton_per_fused_mean_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp4 = tl.load(in_ptr0 + (256 + r0), None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp5 = tmp4 - tmp1 tmp6 = tmp5 * tmp5 tmp7 = tmp3 + tmp6 tmp8 = tl.broadcast_to(tmp7, [RBLOCK]) tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0)) tmp11 = 256.0 tmp12 = tmp10 / tmp11 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp12, 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((8, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(512)](arg0_1, buf0, 512, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_mean_pow_sub_sum_1[grid(1)](buf2, buf0, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del buf0 return buf2, class TVLossNew(nn.Module): def __init__(self, norm=2): super().__init__() self.norm = norm def extra_repr(self): return f'norm={self.norm}' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
jokingbear/DM
TVLoss
false
6,984
[ "MIT" ]
1
9c4dada1756f3d866455a397511d4f3bacfadc60
https://github.com/jokingbear/DM/tree/9c4dada1756f3d866455a397511d4f3bacfadc60
ActNorm
import torch import torch.nn as nn class ActNorm(nn.Module): """ ActNorm layer. [Kingma and Dhariwal, 2018.] """ def __init__(self, dim): super().__init__() self.dim = dim self.mu = nn.Parameter(torch.zeros(dim, dtype=torch.float)) self.log_sigma = nn.Parameter(torch.zeros(dim, dtype=torch.float)) def forward(self, x): z = x * torch.exp(self.log_sigma) + self.mu log_det = torch.sum(self.log_sigma) return z, log_det def inverse(self, z): x = (z - self.mu) / torch.exp(self.log_sigma) log_det = -torch.sum(self.log_sigma) return x, log_det def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_exp_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 x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp3 = tmp0 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_per_fused_sum_1(in_ptr0, 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.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.sum(tmp1, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp3, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_exp_mul_0[grid(256)](primals_2, primals_1, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf1 = empty_strided_cuda((), (), torch.float32) triton_per_fused_sum_1[grid(1)](primals_1, buf1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) return buf0, buf1, primals_1, primals_2 class ActNormNew(nn.Module): """ ActNorm layer. [Kingma and Dhariwal, 2018.] """ def __init__(self, dim): super().__init__() self.dim = dim self.mu = nn.Parameter(torch.zeros(dim, dtype=torch.float)) self.log_sigma = nn.Parameter(torch.zeros(dim, dtype=torch.float)) def inverse(self, z): x = (z - self.mu) / torch.exp(self.log_sigma) log_det = -torch.sum(self.log_sigma) return x, log_det def forward(self, input_0): primals_1 = self.mu primals_3 = self.log_sigma primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
jsk389/RGB-PowerSpectra-v2
ActNorm
false
6,985
[ "MIT" ]
1
47ca7cae256ad09a7e5a40fe9da82d48c32ff7cc
https://github.com/jsk389/RGB-PowerSpectra-v2/tree/47ca7cae256ad09a7e5a40fe9da82d48c32ff7cc
ConvEncoder
import torch import numpy as np import torch.nn as nn from typing import Tuple def to_sate_tensor(s, device): """ converts a numpy array to a Tensor suitable for passing through DQNs """ return torch.from_numpy(s) class ConvEncoder(nn.Module): def __init__(self, state_shape: 'Tuple', device=None): super(ConvEncoder, self).__init__() in_channels = state_shape[0] nc = 32 self.conv1 = nn.Conv2d(in_channels, nc, (8, 8), stride=(4, 4)) self.conv2 = nn.Conv2d(nc, 2 * nc, (4, 4), stride=(2, 2)) self.conv3 = nn.Conv2d(2 * nc, 2 * nc, (3, 3), stride=(1, 1)) self.relu = nn.ReLU() self.state_shape = state_shape def forward(self, s) ->torch.Tensor: if isinstance(s, np.ndarray): s = to_sate_tensor(s, self.device) a = self.relu(self.conv1(s)) a = self.relu(self.conv2(a)) a = self.relu(self.conv3(a)) return torch.flatten(a, 1) @property def output_shape(self): """ the output shape of this CNN encoder. :return: tuple of output shape """ return 64, 12, 12 def conv_output_shape(h_w, kernel_size=1, stride=1, pad=0, dilation=1): """ Utility function for computing output of convolutions takes a tuple of (h,w) and returns a tuple of (h,w) """ from math import floor if type(kernel_size) is not tuple: kernel_size = kernel_size, kernel_size h = floor((h_w[0] + 2 * pad - dilation * (kernel_size[0] - 1) - 1) / stride + 1) w = floor((h_w[1] + 2 * pad - dilation * (kernel_size[1] - 1) - 1) / stride + 1) return h, w def get_inputs(): return [torch.rand([4, 4, 64, 64])] def get_init_inputs(): return [[], {'state_shape': [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 import torch.nn as nn from typing import Tuple 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 = 28800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 225 % 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_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_2(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, (4, 4, 64, 64), (16384, 4096, 64, 1)) assert_size_stride(primals_2, (32, 4, 8, 8), (256, 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, (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_1, primals_2, 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, 15, 15), (7200, 225, 15, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(28800)](buf1, primals_3, 28800, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 6, 6), (2304, 36, 6, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(9216)](buf3, primals_5, 9216, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 4, 4), (1024, 16, 4, 1)) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_2[grid(4096)](buf5 , primals_7, buf6, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return reinterpret_tensor(buf5, (4, 1024), (1024, 1), 0 ), primals_1, primals_2, primals_4, primals_6, buf1, buf3, buf6 def to_sate_tensor(s, device): """ converts a numpy array to a Tensor suitable for passing through DQNs """ return torch.from_numpy(s) class ConvEncoderNew(nn.Module): def __init__(self, state_shape: 'Tuple', device=None): super(ConvEncoderNew, self).__init__() in_channels = state_shape[0] nc = 32 self.conv1 = nn.Conv2d(in_channels, nc, (8, 8), stride=(4, 4)) self.conv2 = nn.Conv2d(nc, 2 * nc, (4, 4), stride=(2, 2)) self.conv3 = nn.Conv2d(2 * nc, 2 * nc, (3, 3), stride=(1, 1)) self.relu = nn.ReLU() self.state_shape = state_shape @property def output_shape(self): """ the output shape of this CNN encoder. :return: tuple of output shape """ return 64, 12, 12 def conv_output_shape(h_w, kernel_size=1, stride=1, pad=0, dilation=1): """ Utility function for computing output of convolutions takes a tuple of (h,w) and returns a tuple of (h,w) """ from math import floor if type(kernel_size) is not tuple: kernel_size = kernel_size, kernel_size h = floor((h_w[0] + 2 * pad - dilation * (kernel_size[0] - 1) - 1) / stride + 1) w = floor((h_w[1] + 2 * pad - dilation * (kernel_size[1] - 1) - 1) / stride + 1) return h, w 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]
jondeaton/AgarAI
ConvEncoder
false
6,986
[ "MIT" ]
1
0c60896465a969ba6832a4b417cf6199715799a1
https://github.com/jondeaton/AgarAI/tree/0c60896465a969ba6832a4b417cf6199715799a1
UpSample
import torch import torch.nn as nn class UpSample(nn.Module): def __init__(self, feat_in, feat_out, out_shape=None, scale=2): super().__init__() self.conv = nn.Conv2d(feat_in, feat_out, kernel_size=(3, 3), stride =1, padding=1) self.out_shape, self.scale = out_shape, scale def forward(self, x): return self.conv(nn.functional.interpolate(x, size=self.out_shape, scale_factor=self.scale, mode='bilinear', align_corners=True)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'feat_in': 4, 'feat_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.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_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_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 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, primals_1, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 8, 8), (256, 64, 8, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_1[grid(1024)](buf3, primals_3, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf3, primals_2, buf1 class UpSampleNew(nn.Module): def __init__(self, feat_in, feat_out, out_shape=None, scale=2): super().__init__() self.conv = nn.Conv2d(feat_in, feat_out, kernel_size=(3, 3), stride =1, padding=1) self.out_shape, self.scale = out_shape, scale 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]
jpjuvo/deepfake-video-detector
UpSample
false
6,987
[ "MIT" ]
1
7c5ea5f36277ff5405d8466e48e68d00a085fa7e
https://github.com/jpjuvo/deepfake-video-detector/tree/7c5ea5f36277ff5405d8466e48e68d00a085fa7e
TestNet2
import torch import torch.nn as nn import torch.nn.functional as F class TestNet2(nn.Module): def __init__(self): super(TestNet2, self).__init__() self.conv1 = nn.Conv2d(3, 18, 7, padding=3) self.pool = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(18, 36, 5, padding=2) self.conv3 = nn.Conv2d(36, 72, 3, padding=1) self.fc1 = nn.Linear(4 * 4 * 72, 512) self.fc2 = nn.Linear(512, 128) self.fc3 = nn.Linear(128, 10) def forward(self, x): x = self.pool(F.relu(self.conv1(x))) x = self.pool(F.relu(self.conv2(x))) x = self.pool(F.relu(self.conv3(x))) x = x.view(-1, 4 * 4 * 72) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(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 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 = 54 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): ynumel = 648 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 % 18 y1 = yindex // 18 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 18 * x2 + 450 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 2592 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 % 36 y1 = yindex // 36 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 36 * x2 + 324 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 18 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_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 18 x1 = xindex // 18 % 32 x2 = xindex // 576 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 36 * x1 + 2304 * x2), None) tmp1 = tl.load(in_ptr0 + (18 + x0 + 36 * x1 + 2304 * x2), None) tmp3 = tl.load(in_ptr0 + (1152 + x0 + 36 * x1 + 2304 * x2), None) tmp5 = tl.load(in_ptr0 + (1170 + x0 + 36 * x1 + 2304 * x2), None) 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 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 36 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_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 36 x1 = xindex // 36 % 16 x2 = xindex // 576 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 72 * x1 + 2304 * x2), None) tmp1 = tl.load(in_ptr0 + (36 + x0 + 72 * x1 + 2304 * x2), None) tmp3 = tl.load(in_ptr0 + (1152 + x0 + 72 * x1 + 2304 * x2), None) tmp5 = tl.load(in_ptr0 + (1188 + x0 + 72 * x1 + 2304 * x2), None) 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 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 72 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_9(in_ptr0, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 256 xnumel = 72 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 % 8 y1 = yindex // 8 y5 = yindex y4 = yindex // 64 y6 = yindex % 64 tmp0 = tl.load(in_ptr0 + (x2 + 144 * y0 + 2304 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (72 + x2 + 144 * y0 + 2304 * y1), xmask & ymask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (1152 + x2 + 144 * y0 + 2304 * y1), xmask & ymask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (1224 + x2 + 144 * y0 + 2304 * y1), xmask & ymask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1, 1], 1, tl.int8) tmp4 = tl.full([1, 1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1, 1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1, 1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + (x2 + 72 * y5), tmp15, xmask & ymask) tl.store(out_ptr1 + (y6 + 64 * x2 + 4608 * y4), tmp16, xmask & ymask) @triton.jit def triton_poi_fused_relu_10(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) @triton.jit def triton_poi_fused_relu_11(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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) 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, (18, 3, 7, 7), (147, 49, 7, 1)) assert_size_stride(primals_2, (18,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (36, 18, 5, 5), (450, 25, 5, 1)) assert_size_stride(primals_5, (36,), (1,)) assert_size_stride(primals_6, (72, 36, 3, 3), (324, 9, 3, 1)) assert_size_stride(primals_7, (72,), (1,)) assert_size_stride(primals_8, (512, 1152), (1152, 1)) assert_size_stride(primals_9, (512,), (1,)) assert_size_stride(primals_10, (128, 512), (512, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (10, 128), (128, 1)) assert_size_stride(primals_13, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((18, 3, 7, 7), (147, 1, 21, 3), torch.float32 ) get_raw_stream(0) triton_poi_fused_0[grid(54, 49)](primals_1, buf0, 54, 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((36, 18, 5, 5), (450, 1, 90, 18), torch. float32) triton_poi_fused_2[grid(648, 25)](primals_4, buf2, 648, 25, XBLOCK= 32, YBLOCK=32, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((72, 36, 3, 3), (324, 1, 108, 36), torch. float32) triton_poi_fused_3[grid(2592, 9)](primals_6, buf3, 2592, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = extern_kernels.convolution(buf1, buf0, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 18, 64, 64), (73728, 1, 1152, 18)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_4[grid(294912)](buf5, primals_2, 294912, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf6 = empty_strided_cuda((4, 18, 32, 32), (18432, 1, 576, 18), torch.float32) buf7 = empty_strided_cuda((4, 18, 32, 32), (18432, 1, 576, 18), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(73728)](buf5, buf6, buf7, 73728, XBLOCK=512, num_warps=8, num_stages=1) buf8 = extern_kernels.convolution(buf6, buf2, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 36, 32, 32), (36864, 1, 1152, 36)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_6[grid(147456)](buf9, primals_5, 147456, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf10 = empty_strided_cuda((4, 36, 16, 16), (9216, 1, 576, 36), torch.float32) buf11 = empty_strided_cuda((4, 36, 16, 16), (9216, 1, 576, 36), torch.int8) triton_poi_fused_max_pool2d_with_indices_7[grid(36864)](buf9, buf10, buf11, 36864, XBLOCK=512, num_warps=4, num_stages=1) buf12 = extern_kernels.convolution(buf10, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 72, 16, 16), (18432, 1, 1152, 72)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_8[grid(73728)](buf13, primals_7, 73728, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf14 = empty_strided_cuda((4, 72, 8, 8), (4608, 1, 576, 72), torch .int8) buf15 = empty_strided_cuda((4, 72, 8, 8), (4608, 64, 8, 1), torch. float32) triton_poi_fused_max_pool2d_with_indices_9[grid(256, 72)](buf13, buf14, buf15, 256, 72, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf16 = empty_strided_cuda((16, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf15, (16, 1152), (1152, 1), 0), reinterpret_tensor(primals_8, (1152, 512), (1, 1152), 0), out=buf16) buf17 = buf16 del buf16 triton_poi_fused_relu_10[grid(8192)](buf17, primals_9, 8192, XBLOCK =256, num_warps=4, num_stages=1) del primals_9 buf18 = empty_strided_cuda((16, 128), (128, 1), torch.float32) extern_kernels.mm(buf17, reinterpret_tensor(primals_10, (512, 128), (1, 512), 0), out=buf18) buf19 = buf18 del buf18 triton_poi_fused_relu_11[grid(2048)](buf19, primals_11, 2048, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf20 = empty_strided_cuda((16, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_13, buf19, reinterpret_tensor( primals_12, (128, 10), (1, 128), 0), alpha=1, beta=1, out=buf20) del primals_13 return (buf20, buf0, buf1, buf2, buf3, buf5, buf6, buf7, buf9, buf10, buf11, buf13, buf14, reinterpret_tensor(buf15, (16, 1152), (1152, 1 ), 0), buf17, buf19, primals_12, primals_10, primals_8) class TestNet2New(nn.Module): def __init__(self): super(TestNet2New, self).__init__() self.conv1 = nn.Conv2d(3, 18, 7, padding=3) self.pool = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(18, 36, 5, padding=2) self.conv3 = nn.Conv2d(36, 72, 3, padding=1) self.fc1 = nn.Linear(4 * 4 * 72, 512) self.fc2 = nn.Linear(512, 128) self.fc3 = nn.Linear(128, 10) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.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_12 = self.fc3.weight primals_13 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0]
jjmachan/Cifar-pytorch
TestNet2
false
6,988
[ "Apache-2.0" ]
1
11268af2f9f5230b721ac554a2ce83496c41d06c
https://github.com/jjmachan/Cifar-pytorch/tree/11268af2f9f5230b721ac554a2ce83496c41d06c
SReLU
import torch import torch.nn as nn class SReLU(nn.Module): """Shifted ReLU""" def __init__(self, nc): super(SReLU, self).__init__() self.srelu_bias = nn.Parameter(torch.Tensor(1, nc, 1, 1)) self.srelu_relu = nn.ReLU(inplace=True) nn.init.constant_(self.srelu_bias, -1.0) def forward(self, x): return self.srelu_relu(x - self.srelu_bias) + self.srelu_bias def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'nc': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_relu_sub_threshold_backward_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = tmp4 + tmp1 tmp6 = 0.0 tmp7 = tmp4 <= tmp6 tl.store(out_ptr0 + x3, tmp5, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_relu_sub_threshold_backward_0[grid(256)](primals_2 , primals_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_1 del primals_2 return buf0, buf1 class SReLUNew(nn.Module): """Shifted ReLU""" def __init__(self, nc): super(SReLUNew, self).__init__() self.srelu_bias = nn.Parameter(torch.Tensor(1, nc, 1, 1)) self.srelu_relu = nn.ReLU(inplace=True) nn.init.constant_(self.srelu_bias, -1.0) def forward(self, input_0): primals_1 = self.srelu_bias primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
juancprzs/ISONet
SReLU
false
6,989
[ "MIT" ]
1
a0422942b53255d093197aa93c77cc3fa941bcdf
https://github.com/juancprzs/ISONet/tree/a0422942b53255d093197aa93c77cc3fa941bcdf
LOGMSELoss
import torch import torch.nn as nn class LOGMSELoss(nn.Module): def __init__(self): super().__init__() self.mse = nn.MSELoss() def forward(self, input, target): return torch.log(self.mse(input, target)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_log_mse_loss_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tmp9 = tl_math.log(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp9, 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_log_mse_loss_0[grid(1)](buf1, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class LOGMSELossNew(nn.Module): def __init__(self): super().__init__() self.mse = nn.MSELoss() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
julschoen/Latent-Space-Exploration-CT
LOGMSELoss
false
6,990
[ "MIT" ]
1
39440c83362181efc48cad69777e5671a7bf3de9
https://github.com/julschoen/Latent-Space-Exploration-CT/tree/39440c83362181efc48cad69777e5671a7bf3de9
NavigatorUnit
import torch import torch.nn as nn def conv1x1(in_channels, out_channels, stride=1, groups=1, bias=False): """ Convolution 1x1 layer. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int, default 1 Strides of the convolution. groups : int, default 1 Number of groups. bias : bool, default False Whether the layer uses a bias vector. """ return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=stride, groups=groups, bias=bias) def conv3x3(in_channels, out_channels, stride=1, padding=1, dilation=1, groups=1, bias=False): """ Convolution 3x3 layer. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int, default 1 Strides of the convolution. padding : int or tuple/list of 2 int, default 1 Padding value for convolution layer. groups : int, default 1 Number of groups. bias : bool, default False Whether the layer uses a bias vector. """ return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=3, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) class Flatten(nn.Module): """ Simple flatten module. """ def forward(self, x): return x.view(x.size(0), -1) class NavigatorBranch(nn.Module): """ Navigator branch block for Navigator unit. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int Strides of the convolution. """ def __init__(self, in_channels, out_channels, stride): super(NavigatorBranch, self).__init__() mid_channels = 128 self.down_conv = conv3x3(in_channels=in_channels, out_channels= mid_channels, stride=stride, bias=True) self.activ = nn.ReLU(inplace=False) self.tidy_conv = conv1x1(in_channels=mid_channels, out_channels= out_channels, bias=True) self.flatten = Flatten() def forward(self, x): y = self.down_conv(x) y = self.activ(y) z = self.tidy_conv(y) z = self.flatten(z) return z, y class NavigatorUnit(nn.Module): """ Navigator init. """ def __init__(self): super(NavigatorUnit, self).__init__() self.branch1 = NavigatorBranch(in_channels=2048, out_channels=6, stride=1) self.branch2 = NavigatorBranch(in_channels=128, out_channels=6, stride=2) self.branch3 = NavigatorBranch(in_channels=128, out_channels=9, stride=2) def forward(self, x): t1, x = self.branch1(x) t2, x = self.branch2(x) t3, _ = self.branch3(x) return torch.cat((t1, t2, t3), dim=1) def get_inputs(): return [torch.rand([4, 2048, 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 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_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 // 1024 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_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 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 132096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 33024 x1 = xindex // 33024 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 24576, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (24576 * x1 + x0 % 24576), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0 // 4096 % 6, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tmp11 = tl.full([1], 30720, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (6144 * x1 + (-24576 + x0) % 6144), tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl.load(in_ptr3 + (-24576 + x0) // 1024 % 6, tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tl.full([1], 33024, tl.int64) tmp22 = tl.load(in_ptr4 + (2304 * x1 + (-30720 + x0) % 2304), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp23 = tl.load(in_ptr5 + (-30720 + x0) // 256 % 9, tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tmp22 + tmp23 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp19, tmp24, tmp25) tmp27 = tl.where(tmp13, tmp18, tmp26) tmp28 = tl.where(tmp4, tmp9, tmp27) tl.store(out_ptr0 + x2, tmp28, 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, (128, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 2048, 64, 64), (8388608, 4096, 64, 1)) assert_size_stride(primals_4, (6, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_5, (6,), (1,)) assert_size_stride(primals_6, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (6, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_9, (6,), (1,)) assert_size_stride(primals_10, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (9, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_13, (9,), (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, 128, 64, 64), (524288, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(2097152)](buf1, primals_2, 2097152, XBLOCK=512, num_warps=8, 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, 6, 64, 64), (24576, 4096, 64, 1)) buf3 = extern_kernels.convolution(buf1, primals_6, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 128, 32, 32), (131072, 1024, 32, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_relu_1[grid(524288)](buf4, primals_7, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf5 = extern_kernels.convolution(buf4, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 6, 32, 32), (6144, 1024, 32, 1)) buf6 = extern_kernels.convolution(buf4, primals_10, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 16, 16), (32768, 256, 16, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_2[grid(131072)](buf7, primals_11, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_11 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, 9, 16, 16), (2304, 256, 16, 1)) buf9 = empty_strided_cuda((4, 33024), (33024, 1), torch.float32) triton_poi_fused_cat_3[grid(132096)](buf2, primals_5, buf5, primals_9, buf8, primals_13, buf9, 132096, XBLOCK=512, num_warps=8, num_stages=1) del buf2 del buf5 del buf8 del primals_13 del primals_5 del primals_9 return (buf9, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, buf1, buf4, buf7) def conv1x1(in_channels, out_channels, stride=1, groups=1, bias=False): """ Convolution 1x1 layer. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int, default 1 Strides of the convolution. groups : int, default 1 Number of groups. bias : bool, default False Whether the layer uses a bias vector. """ return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=1, stride=stride, groups=groups, bias=bias) def conv3x3(in_channels, out_channels, stride=1, padding=1, dilation=1, groups=1, bias=False): """ Convolution 3x3 layer. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int, default 1 Strides of the convolution. padding : int or tuple/list of 2 int, default 1 Padding value for convolution layer. groups : int, default 1 Number of groups. bias : bool, default False Whether the layer uses a bias vector. """ return nn.Conv2d(in_channels=in_channels, out_channels=out_channels, kernel_size=3, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) class Flatten(nn.Module): """ Simple flatten module. """ def forward(self, x): return x.view(x.size(0), -1) class NavigatorBranch(nn.Module): """ Navigator branch block for Navigator unit. Parameters: ---------- in_channels : int Number of input channels. out_channels : int Number of output channels. stride : int or tuple/list of 2 int Strides of the convolution. """ def __init__(self, in_channels, out_channels, stride): super(NavigatorBranch, self).__init__() mid_channels = 128 self.down_conv = conv3x3(in_channels=in_channels, out_channels= mid_channels, stride=stride, bias=True) self.activ = nn.ReLU(inplace=False) self.tidy_conv = conv1x1(in_channels=mid_channels, out_channels= out_channels, bias=True) self.flatten = Flatten() def forward(self, x): y = self.down_conv(x) y = self.activ(y) z = self.tidy_conv(y) z = self.flatten(z) return z, y class NavigatorUnitNew(nn.Module): """ Navigator init. """ def __init__(self): super(NavigatorUnitNew, self).__init__() self.branch1 = NavigatorBranch(in_channels=2048, out_channels=6, stride=1) self.branch2 = NavigatorBranch(in_channels=128, out_channels=6, stride=2) self.branch3 = NavigatorBranch(in_channels=128, out_channels=9, stride=2) def forward(self, input_0): primals_1 = self.branch1.down_conv.weight primals_2 = self.branch1.down_conv.bias primals_4 = self.branch1.tidy_conv.weight primals_5 = self.branch1.tidy_conv.bias primals_6 = self.branch2.down_conv.weight primals_7 = self.branch2.down_conv.bias primals_8 = self.branch2.tidy_conv.weight primals_9 = self.branch2.tidy_conv.bias primals_10 = self.branch3.down_conv.weight primals_11 = self.branch3.down_conv.bias primals_12 = self.branch3.tidy_conv.weight primals_13 = self.branch3.tidy_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]) return output[0]
iofthetiger/pkuad
NavigatorUnit
false
6,991
[ "Apache-2.0" ]
1
07496d108c614c84be028f344830becc9cac8fe5
https://github.com/iofthetiger/pkuad/tree/07496d108c614c84be028f344830becc9cac8fe5
GAT
import torch import torch.nn as nn import torch.nn.functional as F class GAT(nn.Module): def __init__(self, num_feats): super(GAT, self).__init__() self.num_feats = num_feats self.weight_key = nn.Parameter(torch.zeros(size=(self.num_feats, 1))) self.weight_query = nn.Parameter(torch.zeros(size=(self.num_feats, 1))) nn.init.xavier_uniform_(self.weight_key, gain=1.414) nn.init.xavier_uniform_(self.weight_query, gain=1.414) self.dropout = nn.Dropout(0.5) def forward(self, x): """ :param x: dim: bz x num_node x num_feat :return: dim: bz x num_node x num_node """ batch_size = x.size(0) num_nodes = x.size(1) key = torch.matmul(x, self.weight_key) query = torch.matmul(x, self.weight_query) attn_input = key.repeat(1, 1, num_nodes).view(batch_size, num_nodes * num_nodes, 1) + query.repeat(1, num_nodes, 1) attn_output = attn_input.squeeze(2).view(batch_size, num_nodes, num_nodes) attn_output = F.leaky_relu(attn_output, negative_slope=0.2) attention = F.softmax(attn_output, dim=2) attention = self.dropout(attention) attn_feat = torch.matmul(attention, x).permute(0, 2, 1) return attn_feat def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'num_feats': 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_add_repeat_0(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 x0 = xindex % 16 x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2 // 4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (4 * x1 + x0 % 4), xmask) tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused__softmax_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tmp7 = tmp6 > tmp1 tmp8 = tmp6 * tmp3 tmp9 = tl.where(tmp7, tmp6, tmp8) tmp11 = tmp10 > tmp1 tmp12 = tmp10 * tmp3 tmp13 = tl.where(tmp11, tmp10, tmp12) tmp14 = triton_helpers.maximum(tmp9, tmp13) tmp16 = tmp15 > tmp1 tmp17 = tmp15 * tmp3 tmp18 = tl.where(tmp16, tmp15, tmp17) tmp19 = triton_helpers.maximum(tmp14, tmp18) tmp21 = tmp20 > tmp1 tmp22 = tmp20 * tmp3 tmp23 = tl.where(tmp21, tmp20, tmp22) tmp24 = triton_helpers.maximum(tmp19, tmp23) tmp25 = tmp5 - tmp24 tmp26 = tl_math.exp(tmp25) tl.store(out_ptr0 + x2, tmp26, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 1), (1, 1)) assert_size_stride(primals_3, (4, 1), (1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 1), (1, 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((16, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_3, out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 16, 1), (16, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_repeat_0[grid(64)](buf0, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del buf1 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_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.float32) triton_poi_fused__softmax_2[grid(64)](buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf3 del buf3 extern_kernels.bmm(buf4, primals_1, out=buf5) del buf4 return reinterpret_tensor(buf5, (4, 4, 4), (16, 1, 4), 0 ), primals_1, reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0) class GATNew(nn.Module): def __init__(self, num_feats): super(GATNew, self).__init__() self.num_feats = num_feats self.weight_key = nn.Parameter(torch.zeros(size=(self.num_feats, 1))) self.weight_query = nn.Parameter(torch.zeros(size=(self.num_feats, 1))) nn.init.xavier_uniform_(self.weight_key, gain=1.414) nn.init.xavier_uniform_(self.weight_query, gain=1.414) self.dropout = nn.Dropout(0.5) def forward(self, input_0): primals_2 = self.weight_key primals_3 = self.weight_query primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
juaduan/babybrainguardian
GAT
false
6,992
[ "MIT" ]
1
b871e3a83fef98c2e05dd8857721a3c964a46418
https://github.com/juaduan/babybrainguardian/tree/b871e3a83fef98c2e05dd8857721a3c964a46418
GeneralizedDiceLoss
import torch from torch import nn as nn from torch.autograd import Variable def expand_as_one_hot(input, C, ignore_index=None): """ Converts NxDxHxW label image to NxCxDxHxW, where each label is stored in a separate channel :param input: 4D input image (NxDxHxW) :param C: number of channels/labels :param ignore_index: ignore index to be kept during the expansion :return: 5D output image (NxCxDxHxW) """ assert input.dim() == 4 shape = input.size() shape = list(shape) shape.insert(1, C) shape = tuple(shape) src = input.unsqueeze(0) if ignore_index is not None: expanded_src = src.expand(shape) mask = expanded_src == ignore_index src = src.clone() src[src == ignore_index] = 0 result = torch.zeros(shape).scatter_(1, src, 1) result[mask] = ignore_index return result else: return torch.zeros(shape).scatter_(1, src, 1) def flatten(tensor): """Flattens a given tensor such that the channel axis is first. The shapes are transformed as follows: (N, C, D, H, W) -> (C, N * D * H * W) """ C = tensor.size(1) axis_order = (1, 0) + tuple(range(2, tensor.dim())) transposed = tensor.permute(axis_order) return transposed.view(C, -1) class GeneralizedDiceLoss(nn.Module): """Computes Generalized Dice Loss (GDL) as described in https://arxiv.org/pdf/1707.03237.pdf """ def __init__(self, epsilon=1e-05, weight=None, ignore_index=None, sigmoid_normalization=True): super(GeneralizedDiceLoss, self).__init__() self.epsilon = epsilon self.register_buffer('weight', weight) self.ignore_index = ignore_index if sigmoid_normalization: self.normalization = nn.Sigmoid() else: self.normalization = nn.Softmax(dim=1) def forward(self, input, target): input = self.normalization(input) if target.dim() == 4: target = expand_as_one_hot(target, C=input.size()[1], ignore_index=self.ignore_index) assert input.size() == target.size( ), "'input' and 'target' must have the same shape" if self.ignore_index is not None: mask = target.clone().ne_(self.ignore_index) mask.requires_grad = False input = input * mask target = target * mask input = flatten(input) target = flatten(target) target_sum = target.sum(-1) class_weights = Variable(1.0 / (target_sum * target_sum).clamp(min= self.epsilon), requires_grad=False) intersect = (input * target).sum(-1) * class_weights if self.weight is not None: weight = Variable(self.weight, requires_grad=False) intersect = weight * intersect denominator = (input + target).sum(-1) * class_weights return torch.mean(1.0 - 2.0 * intersect / denominator.clamp(min= self.epsilon)) def get_inputs(): return [torch.ones([4, 4], dtype=torch.int64), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clamp_mul_reciprocal_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + (4 + x0), xmask) tmp3 = tl.load(in_ptr0 + (8 + x0), xmask) tmp5 = tl.load(in_ptr0 + (12 + x0), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tmp6 * tmp6 tmp8 = 1e-05 tmp9 = triton_helpers.maximum(tmp7, tmp8) tmp10 = tl.full([1], 1, tl.int32) tmp11 = tmp10 / tmp9 tmp12 = 1.0 tmp13 = tmp11 * tmp12 tl.store(out_ptr0 + x0, tmp13, xmask) @triton.jit def triton_poi_fused_sigmoid_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tmp2 = tl.sigmoid(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_mul_reciprocal_sum_0[grid(4)](arg1_1, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_sigmoid_1[grid(16)](arg0_1, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf0, reinterpret_tensor(buf1, (4, 4), (1, 4), 0 ), reinterpret_tensor(arg1_1, (4, 4), (1, 4), 0) def expand_as_one_hot(input, C, ignore_index=None): """ Converts NxDxHxW label image to NxCxDxHxW, where each label is stored in a separate channel :param input: 4D input image (NxDxHxW) :param C: number of channels/labels :param ignore_index: ignore index to be kept during the expansion :return: 5D output image (NxCxDxHxW) """ assert input.dim() == 4 shape = input.size() shape = list(shape) shape.insert(1, C) shape = tuple(shape) src = input.unsqueeze(0) if ignore_index is not None: expanded_src = src.expand(shape) mask = expanded_src == ignore_index src = src.clone() src[src == ignore_index] = 0 result = torch.zeros(shape).scatter_(1, src, 1) result[mask] = ignore_index return result else: return torch.zeros(shape).scatter_(1, src, 1) def flatten(tensor): """Flattens a given tensor such that the channel axis is first. The shapes are transformed as follows: (N, C, D, H, W) -> (C, N * D * H * W) """ C = tensor.size(1) axis_order = (1, 0) + tuple(range(2, tensor.dim())) transposed = tensor.permute(axis_order) return transposed.view(C, -1) class GeneralizedDiceLossNew(nn.Module): """Computes Generalized Dice Loss (GDL) as described in https://arxiv.org/pdf/1707.03237.pdf """ def __init__(self, epsilon=1e-05, weight=None, ignore_index=None, sigmoid_normalization=True): super(GeneralizedDiceLossNew, self).__init__() self.epsilon = epsilon self.register_buffer('weight', weight) self.ignore_index = ignore_index if sigmoid_normalization: self.normalization = nn.Sigmoid() else: self.normalization = nn.Softmax(dim=1) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
junweiy/pcs_seg
GeneralizedDiceLoss
false
6,993
[ "MIT" ]
1
38ed98130b34a6d3d0b986cad98b08b791760f0b
https://github.com/junweiy/pcs_seg/tree/38ed98130b34a6d3d0b986cad98b08b791760f0b
LinearScale
import torch import torch.nn as nn class LinearScale(nn.Module): def __init__(self, scale, bias): super(LinearScale, self).__init__() self.scale_v = scale self.bias_v = bias pass def forward(self, x): out = x * self.scale_v + self.bias_v return out def __repr__(self): repr = ( f'{self.__class__.__name__}(scale_v={self.scale_v},bias_v={self.bias_v})' ) return repr def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'scale': 1.0, 'bias': 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_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 = 4.0 tmp4 = tmp2 + tmp3 tl.store(out_ptr0 + x0, tmp4, 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_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class LinearScaleNew(nn.Module): def __init__(self, scale, bias): super(LinearScaleNew, self).__init__() self.scale_v = scale self.bias_v = bias pass def __repr__(self): repr = ( f'{self.__class__.__name__}(scale_v={self.scale_v},bias_v={self.bias_v})' ) return repr def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
justinjohn0306/CIPS-3D
LinearScale
false
6,994
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
EqualLinear
import math import torch import torch.nn as nn import torch.nn.functional as F class EqualLinear(nn.Module): def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1.0, activation=None): """ :param in_dim: :param out_dim: :param bias: :param bias_init: :param lr_mul: 0.01 :param activation: None: Linear; fused_leaky_relu """ super().__init__() self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul)) if bias: self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init)) else: self.bias = None self.activation = activation if self.activation is not None: self.act_layer = nn.LeakyReLU(0.2) self.scale = 1 / math.sqrt(in_dim) * lr_mul self.lr_mul = lr_mul pass def forward(self, input): out = F.linear(input, self.weight * self.scale, bias=self.bias * self.lr_mul) if self.activation: out = self.act_layer(out) return out def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]}), activation={self.activation}' ) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_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 math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_mul_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) 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, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_mul_1[grid(4)](primals_2, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(buf1, reinterpret_tensor(primals_3, (64, 4), ( 4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del buf0 del buf1 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0) class EqualLinearNew(nn.Module): def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1.0, activation=None): """ :param in_dim: :param out_dim: :param bias: :param bias_init: :param lr_mul: 0.01 :param activation: None: Linear; fused_leaky_relu """ super().__init__() self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul)) if bias: self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init)) else: self.bias = None self.activation = activation if self.activation is not None: self.act_layer = nn.LeakyReLU(0.2) self.scale = 1 / math.sqrt(in_dim) * lr_mul self.lr_mul = lr_mul pass def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]}), activation={self.activation}' ) def forward(self, input_0): primals_1 = self.weight primals_2 = self.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
justinjohn0306/CIPS-3D
EqualLinear
false
6,995
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
DiceLoss
import torch from torch import nn as nn from torch.autograd import Variable def expand_as_one_hot(input, C, ignore_index=None): """ Converts NxDxHxW label image to NxCxDxHxW, where each label is stored in a separate channel :param input: 4D input image (NxDxHxW) :param C: number of channels/labels :param ignore_index: ignore index to be kept during the expansion :return: 5D output image (NxCxDxHxW) """ assert input.dim() == 4 shape = input.size() shape = list(shape) shape.insert(1, C) shape = tuple(shape) src = input.unsqueeze(0) if ignore_index is not None: expanded_src = src.expand(shape) mask = expanded_src == ignore_index src = src.clone() src[src == ignore_index] = 0 result = torch.zeros(shape).scatter_(1, src, 1) result[mask] = ignore_index return result else: return torch.zeros(shape).scatter_(1, src, 1) def flatten(tensor): """Flattens a given tensor such that the channel axis is first. The shapes are transformed as follows: (N, C, D, H, W) -> (C, N * D * H * W) """ C = tensor.size(1) axis_order = (1, 0) + tuple(range(2, tensor.dim())) transposed = tensor.permute(axis_order) return transposed.view(C, -1) def compute_per_channel_dice(input, target, epsilon=1e-05, ignore_index= None, weight=None): if target.dim() == 4: target = expand_as_one_hot(target, C=input.size()[1], ignore_index= ignore_index) assert input.size() == target.size( ), "'input' and 'target' must have the same shape" if ignore_index is not None: mask = target.clone().ne_(ignore_index) mask.requires_grad = False input = input * mask target = target * mask input = flatten(input) target = flatten(target) intersect = (input * target).sum(-1) if weight is not None: intersect = weight * intersect denominator = (input + target).sum(-1) return 2.0 * intersect / denominator.clamp(min=epsilon) class DiceLoss(nn.Module): """Computes Dice Loss, which just 1 - DiceCoefficient described above. Additionally allows per-class weights to be provided. """ def __init__(self, epsilon=1e-05, weight=None, ignore_index=None, sigmoid_normalization=True): super(DiceLoss, self).__init__() self.epsilon = epsilon self.register_buffer('weight', weight) self.ignore_index = ignore_index if sigmoid_normalization: self.normalization = nn.Sigmoid() else: self.normalization = nn.Softmax(dim=1) def forward(self, input, target): input = self.normalization(input) if self.weight is not None: weight = Variable(self.weight, requires_grad=False) else: weight = None per_channel_dice = compute_per_channel_dice(input, target, epsilon= self.epsilon, ignore_index=self.ignore_index, weight=weight) return torch.mean(1.0 - per_channel_dice) def get_inputs(): return [torch.ones([4, 4], dtype=torch.int64), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import 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_clamp_div_mean_mul_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp5 = tl.load(in_ptr0 + (4 + r0), None) tmp8 = tl.load(in_ptr1 + (4 + r0), None) tmp11 = tl.load(in_ptr0 + (8 + r0), None) tmp14 = tl.load(in_ptr1 + (8 + r0), None) tmp17 = tl.load(in_ptr0 + (12 + r0), None) tmp20 = tl.load(in_ptr1 + (12 + r0), None) tmp1 = tmp0.to(tl.float32) tmp2 = tl.sigmoid(tmp1) tmp4 = tmp2 * tmp3 tmp6 = tmp5.to(tl.float32) tmp7 = tl.sigmoid(tmp6) tmp9 = tmp7 * tmp8 tmp10 = tmp4 + tmp9 tmp12 = tmp11.to(tl.float32) tmp13 = tl.sigmoid(tmp12) tmp15 = tmp13 * tmp14 tmp16 = tmp10 + tmp15 tmp18 = tmp17.to(tl.float32) tmp19 = tl.sigmoid(tmp18) tmp21 = tmp19 * tmp20 tmp22 = tmp16 + tmp21 tmp23 = 2.0 tmp24 = tmp22 * tmp23 tmp25 = tmp2 + tmp3 tmp26 = tmp7 + tmp8 tmp27 = tmp25 + tmp26 tmp28 = tmp13 + tmp14 tmp29 = tmp27 + tmp28 tmp30 = tmp19 + tmp20 tmp31 = tmp29 + tmp30 tmp32 = 1e-05 tmp33 = triton_helpers.maximum(tmp31, tmp32) tmp34 = tmp24 / tmp33 tmp35 = 1.0 tmp36 = tmp35 - tmp34 tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK]) tmp39 = tl.sum(tmp37, 1)[:, None] tmp40 = 4.0 tmp41 = tmp39 / tmp40 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp41, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_clamp_div_mean_mul_rsub_sum_0[grid(1)](buf2, arg0_1, arg1_1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, def expand_as_one_hot(input, C, ignore_index=None): """ Converts NxDxHxW label image to NxCxDxHxW, where each label is stored in a separate channel :param input: 4D input image (NxDxHxW) :param C: number of channels/labels :param ignore_index: ignore index to be kept during the expansion :return: 5D output image (NxCxDxHxW) """ assert input.dim() == 4 shape = input.size() shape = list(shape) shape.insert(1, C) shape = tuple(shape) src = input.unsqueeze(0) if ignore_index is not None: expanded_src = src.expand(shape) mask = expanded_src == ignore_index src = src.clone() src[src == ignore_index] = 0 result = torch.zeros(shape).scatter_(1, src, 1) result[mask] = ignore_index return result else: return torch.zeros(shape).scatter_(1, src, 1) def flatten(tensor): """Flattens a given tensor such that the channel axis is first. The shapes are transformed as follows: (N, C, D, H, W) -> (C, N * D * H * W) """ C = tensor.size(1) axis_order = (1, 0) + tuple(range(2, tensor.dim())) transposed = tensor.permute(axis_order) return transposed.view(C, -1) def compute_per_channel_dice(input, target, epsilon=1e-05, ignore_index= None, weight=None): if target.dim() == 4: target = expand_as_one_hot(target, C=input.size()[1], ignore_index= ignore_index) assert input.size() == target.size( ), "'input' and 'target' must have the same shape" if ignore_index is not None: mask = target.clone().ne_(ignore_index) mask.requires_grad = False input = input * mask target = target * mask input = flatten(input) target = flatten(target) intersect = (input * target).sum(-1) if weight is not None: intersect = weight * intersect denominator = (input + target).sum(-1) return 2.0 * intersect / denominator.clamp(min=epsilon) class DiceLossNew(nn.Module): """Computes Dice Loss, which just 1 - DiceCoefficient described above. Additionally allows per-class weights to be provided. """ def __init__(self, epsilon=1e-05, weight=None, ignore_index=None, sigmoid_normalization=True): super(DiceLossNew, self).__init__() self.epsilon = epsilon self.register_buffer('weight', weight) self.ignore_index = ignore_index if sigmoid_normalization: self.normalization = nn.Sigmoid() else: self.normalization = nn.Softmax(dim=1) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
junweiy/pcs_seg
DiceLoss
false
6,997
[ "MIT" ]
1
38ed98130b34a6d3d0b986cad98b08b791760f0b
https://github.com/junweiy/pcs_seg/tree/38ed98130b34a6d3d0b986cad98b08b791760f0b
AdvResNet
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F class AdvLinearNet(nn.Module): """ Adversarial linear network. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', epsilon: 'float'= 0.0, q: 'int'=1): """ Initialize a linear network. Inputs: n_inputs: int Dimension of input. n_outputs: int Dimension of output. epsilon: float Adversarial noise magnitude. q: int Adversarial norm. """ super(AdvLinearNet, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.epsilon = torch.tensor(epsilon) self.q = q self.beta = nn.Parameter(torch.rand((n_inputs, n_outputs), requires_grad=True) / np.sqrt(n_outputs)) self.bias = nn.Parameter(torch.zeros(n_outputs, requires_grad=True)) def adv_norm(self) ->torch.Tensor: """ Calculate the adversarial norm, i.e., the perturbation size. Outputs: pert: torch.Tensor Size of adversarial perturbation. """ return torch.norm(self.beta, dim=0, p=self.q) def forward(self, x: 'torch.Tensor', y: 'torch.Tensor', adv: 'bool' ) ->torch.Tensor: """ Apply the linear network. Inputs: x: torch.Tensor Predictor tensor. y: torch.Tensor Target tensor. adv: bool Adversarial perturbation or not. Output: y_hat: torch.Tensor Predicted value of y. """ base_output = torch.matmul(x, self.beta) + self.bias if adv: return base_output - self.epsilon * y * self.adv_norm() return base_output def get_epsilon(self) ->float: """ Get the adversarial perturbation magnitude. Outputs: epsilon: float Magnitude of adversarial perturbation. """ return self.epsilon def extra_repr(self) ->str: """ Extra representation for the adversarial linear predictor. Output: info: str String providing number of inputs and outputs. """ return 'n_inputs={0}, n_outputs={1}'.format(self.n_inputs, self. n_outputs) class AdvOneLayer(nn.Module): """ One hidden layer tree-transformed neural network. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', n_hidden1: 'int', epsilon: 'float'=0.0, q: 'int'=1, gamma: 'float'=1.0): """ Initialize a one hidden layer neural network. Inputs: n_inputs: int Number of inputs. n_outputs: int Number of outputs. n_hidden1: int Number of hidden nodes. epsilon: float Adversarial perturbation size q: int Adversarial perturbation norm. gamma: float Normalizing factor. """ super(AdvOneLayer, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.n_hidden1 = n_hidden1 self.epsilon = torch.tensor(epsilon) self.q = q self.W1 = nn.Parameter(-torch.rand((n_hidden1, n_inputs), requires_grad=True) / (gamma * n_hidden1)) self.W2 = nn.Parameter(torch.rand((n_outputs, n_hidden1), requires_grad=True) / (gamma * n_outputs)) self.bias1 = nn.Parameter(torch.zeros(n_hidden1, requires_grad=True)) self.bias2 = nn.Parameter(torch.zeros(n_outputs, requires_grad=True)) self.pert = None self.output = None def adv_norm_W1(self) ->torch.Tensor: """ Compute the adversarial norm the first layer weights. Outputs: W1_norm: torch.Tensor Norm of first layer of weights. """ return torch.norm(self.W1, p=self.q, dim=1) def forward(self, x: 'torch.Tensor', y: 'torch.Tensor'=None, adv: 'bool'=False) ->torch.Tensor: """ Evaluate the network on data. Inputs: x: torch.Tensor Predictor tensor. y: torch.Tensor Target tensor. Unnecessary if not adversarial. adv: bool Whether or not to use an adversarial perturbation. Outputs: nn_output: torch.Tensor The predicted values of y. """ if adv: batch_size = x.shape[0] W1_norm = self.adv_norm_W1() output = torch.zeros((batch_size, self.n_outputs, self.n_hidden1)) pert_tensor = torch.zeros((batch_size, self.n_outputs, self. n_hidden1)) for i in range(self.n_outputs): for j in range(self.n_hidden1): adv_pert = -self.epsilon * y.float()[:, i] * self.W2[i, j ].sign() * W1_norm[j] hidden1 = F.relu(torch.t(torch.matmul(self.W1[j, :], torch.t(x))) + self.bias1[j] + adv_pert.float()) summand = self.W2[i, j] * self.n_hidden1 output[:, i, j] = summand pert_tensor[:, i, j] = adv_pert self.pert = pert_tensor self.output = output return torch.sum(output, dim=2) + self.bias2 hidden1 = torch.t(F.relu(torch.t(torch.matmul(self.W1, torch.t(x))) + self.bias1)) return torch.t(torch.matmul(self.W2, hidden1)) + self.bias2 def get_epsilon(self) ->float: """ Get adversarial perturbation magnitude. Outputs: epsilon: float Input perturbation magnitude. """ return self.epsilon def extra_repr(self): """ Extra representation for the network. Outputs: output: str String containing number of inputs, number of outputs, number of hidden layers, perturbation size, and perturbation norm. """ output = 'n_inputs={}, n_outputs={}, n_hidden1={}, epsilon={}, p={}' return output.format(self.n_inputs, self.n_outputs, self.n_hidden1, self.epsilon, self.p) class AdvResNet(nn.Module): """ Adversarial resnet, i.e., a one hidden layer neural network and a linear component. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', n_hidden1: 'int', epsilon: 'float'=0.0, p: 'int'=1, gamma: 'float'=1.0): """ Initialize an adversarial resnet. Inputs: n_inputs: int Number of inputs. n_outputs: int Number of outputs. n_hidden1: int Number of hidden nodes. epsilon: float Adversarial perturbation size q: int Adversarial perturbation norm. gamma: float Normalizing factor. """ super(AdvResNet, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.n_hidden1 = n_hidden1 self.epsilon = torch.tensor(epsilon) self.p = p self.one_layer = AdvOneLayer(n_inputs, n_outputs, n_hidden1, epsilon, p, gamma) self.linear = AdvLinearNet(n_inputs, n_outputs, epsilon, p) def forward(self, x: 'torch.Tensor', y: 'torch.Tensor'=None, adv: 'bool'=False) ->torch.Tensor: """ Forward evalution of network. Inputs: x: torch.Tensor Predictor tensor. y: torch.Tensor Target tensor. Unnecessary if not adversarial. adv: bool Whether or not to use an adversarial perturbation. Outputs: nn_output: torch.Tensor The predicted values of y. """ return self.linear(x, y, adv) + self.one_layer(x, y, adv) def get_epsilon(self) ->float: """ Get the adversarial perturbation magnitude. Outputs: epsilon: float Magnitude of adversarial perturbation. """ return self.epsilon def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'n_inputs': 4, 'n_outputs': 4, 'n_hidden1': 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 numpy as np 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_add_relu_threshold_backward_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, 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) tmp1 = tl.load(in_ptr1 + x1, xmask, 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 + (x1 + 4 * y0), tmp4, xmask & ymask) tl.store(out_ptr1 + (y0 + 4 * x1), tmp6, xmask & ymask) @triton.jit def triton_poi_fused_add_relu_t_1(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_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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_out_ptr0 + (x1 + 4 * y0), xmask & ymask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (y0 + 4 * x1), xmask & ymask) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tl.store(in_out_ptr0 + (x1 + 4 * y0), tmp6, 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, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_2, primals_1, out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_4, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf6 = empty_strided_cuda((4, 4), (1, 4), torch.bool) get_raw_stream(0) triton_poi_fused_add_relu_threshold_backward_0[grid(4, 4)](buf1, primals_5, buf2, buf6, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) del primals_5 buf3 = buf1 del buf1 triton_poi_fused_add_relu_t_1[grid(4, 4)](buf2, buf3, 4, 4, XBLOCK= 4, YBLOCK=4, num_warps=1, num_stages=1) buf4 = buf2 del buf2 extern_kernels.mm(primals_6, buf3, out=buf4) buf5 = buf0 del buf0 triton_poi_fused_add_2[grid(4, 4)](buf5, primals_3, buf4, primals_7, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) del buf4 del primals_3 del primals_7 return buf5, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0 ), reinterpret_tensor(buf3, (4, 4), (1, 4), 0), buf6 class AdvLinearNet(nn.Module): """ Adversarial linear network. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', epsilon: 'float'= 0.0, q: 'int'=1): """ Initialize a linear network. Inputs: n_inputs: int Dimension of input. n_outputs: int Dimension of output. epsilon: float Adversarial noise magnitude. q: int Adversarial norm. """ super(AdvLinearNet, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.epsilon = torch.tensor(epsilon) self.q = q self.beta = nn.Parameter(torch.rand((n_inputs, n_outputs), requires_grad=True) / np.sqrt(n_outputs)) self.bias = nn.Parameter(torch.zeros(n_outputs, requires_grad=True)) def adv_norm(self) ->torch.Tensor: """ Calculate the adversarial norm, i.e., the perturbation size. Outputs: pert: torch.Tensor Size of adversarial perturbation. """ return torch.norm(self.beta, dim=0, p=self.q) def forward(self, x: 'torch.Tensor', y: 'torch.Tensor', adv: 'bool' ) ->torch.Tensor: """ Apply the linear network. Inputs: x: torch.Tensor Predictor tensor. y: torch.Tensor Target tensor. adv: bool Adversarial perturbation or not. Output: y_hat: torch.Tensor Predicted value of y. """ base_output = torch.matmul(x, self.beta) + self.bias if adv: return base_output - self.epsilon * y * self.adv_norm() return base_output def get_epsilon(self) ->float: """ Get the adversarial perturbation magnitude. Outputs: epsilon: float Magnitude of adversarial perturbation. """ return self.epsilon def extra_repr(self) ->str: """ Extra representation for the adversarial linear predictor. Output: info: str String providing number of inputs and outputs. """ return 'n_inputs={0}, n_outputs={1}'.format(self.n_inputs, self. n_outputs) class AdvOneLayer(nn.Module): """ One hidden layer tree-transformed neural network. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', n_hidden1: 'int', epsilon: 'float'=0.0, q: 'int'=1, gamma: 'float'=1.0): """ Initialize a one hidden layer neural network. Inputs: n_inputs: int Number of inputs. n_outputs: int Number of outputs. n_hidden1: int Number of hidden nodes. epsilon: float Adversarial perturbation size q: int Adversarial perturbation norm. gamma: float Normalizing factor. """ super(AdvOneLayer, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.n_hidden1 = n_hidden1 self.epsilon = torch.tensor(epsilon) self.q = q self.W1 = nn.Parameter(-torch.rand((n_hidden1, n_inputs), requires_grad=True) / (gamma * n_hidden1)) self.W2 = nn.Parameter(torch.rand((n_outputs, n_hidden1), requires_grad=True) / (gamma * n_outputs)) self.bias1 = nn.Parameter(torch.zeros(n_hidden1, requires_grad=True)) self.bias2 = nn.Parameter(torch.zeros(n_outputs, requires_grad=True)) self.pert = None self.output = None def adv_norm_W1(self) ->torch.Tensor: """ Compute the adversarial norm the first layer weights. Outputs: W1_norm: torch.Tensor Norm of first layer of weights. """ return torch.norm(self.W1, p=self.q, dim=1) def forward(self, x: 'torch.Tensor', y: 'torch.Tensor'=None, adv: 'bool'=False) ->torch.Tensor: """ Evaluate the network on data. Inputs: x: torch.Tensor Predictor tensor. y: torch.Tensor Target tensor. Unnecessary if not adversarial. adv: bool Whether or not to use an adversarial perturbation. Outputs: nn_output: torch.Tensor The predicted values of y. """ if adv: batch_size = x.shape[0] W1_norm = self.adv_norm_W1() output = torch.zeros((batch_size, self.n_outputs, self.n_hidden1)) pert_tensor = torch.zeros((batch_size, self.n_outputs, self. n_hidden1)) for i in range(self.n_outputs): for j in range(self.n_hidden1): adv_pert = -self.epsilon * y.float()[:, i] * self.W2[i, j ].sign() * W1_norm[j] hidden1 = F.relu(torch.t(torch.matmul(self.W1[j, :], torch.t(x))) + self.bias1[j] + adv_pert.float()) summand = self.W2[i, j] * self.n_hidden1 output[:, i, j] = summand pert_tensor[:, i, j] = adv_pert self.pert = pert_tensor self.output = output return torch.sum(output, dim=2) + self.bias2 hidden1 = torch.t(F.relu(torch.t(torch.matmul(self.W1, torch.t(x))) + self.bias1)) return torch.t(torch.matmul(self.W2, hidden1)) + self.bias2 def get_epsilon(self) ->float: """ Get adversarial perturbation magnitude. Outputs: epsilon: float Input perturbation magnitude. """ return self.epsilon def extra_repr(self): """ Extra representation for the network. Outputs: output: str String containing number of inputs, number of outputs, number of hidden layers, perturbation size, and perturbation norm. """ output = 'n_inputs={}, n_outputs={}, n_hidden1={}, epsilon={}, p={}' return output.format(self.n_inputs, self.n_outputs, self.n_hidden1, self.epsilon, self.p) class AdvResNetNew(nn.Module): """ Adversarial resnet, i.e., a one hidden layer neural network and a linear component. """ def __init__(self, n_inputs: 'int', n_outputs: 'int', n_hidden1: 'int', epsilon: 'float'=0.0, p: 'int'=1, gamma: 'float'=1.0): """ Initialize an adversarial resnet. Inputs: n_inputs: int Number of inputs. n_outputs: int Number of outputs. n_hidden1: int Number of hidden nodes. epsilon: float Adversarial perturbation size q: int Adversarial perturbation norm. gamma: float Normalizing factor. """ super(AdvResNetNew, self).__init__() self.n_inputs = n_inputs self.n_outputs = n_outputs self.n_hidden1 = n_hidden1 self.epsilon = torch.tensor(epsilon) self.p = p self.one_layer = AdvOneLayer(n_inputs, n_outputs, n_hidden1, epsilon, p, gamma) self.linear = AdvLinearNet(n_inputs, n_outputs, epsilon, p) def get_epsilon(self) ->float: """ Get the adversarial perturbation magnitude. Outputs: epsilon: float Magnitude of adversarial perturbation. """ return self.epsilon def forward(self, input_0): primals_1 = self.one_layer.W1 primals_2 = self.one_layer.W2 primals_3 = self.one_layer.bias1 primals_5 = self.one_layer.bias2 primals_4 = self.linear.beta primals_7 = self.linear.bias primals_6 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
jtkhim/tree_transform
AdvResNet
false
6,998
[ "MIT" ]
1
f0bf85ede0e28f3d16de5b8b0826be38fe2d89bf
https://github.com/jtkhim/tree_transform/tree/f0bf85ede0e28f3d16de5b8b0826be38fe2d89bf
FiLMLayer_PreSin
import torch import numpy as np import torch.nn as nn class FiLMLayer_PreSin(nn.Module): def __init__(self, in_dim, out_dim, style_dim, use_style_fc=True, which_linear=nn.Linear, **kwargs): super(FiLMLayer_PreSin, self).__init__() self.in_dim = in_dim self.out_dim = out_dim self.style_dim = style_dim self.use_style_fc = use_style_fc self.linear = which_linear(in_dim, out_dim) nn.init.uniform_(self.linear.weight, -np.sqrt(9 / in_dim), np.sqrt( 9 / in_dim)) if use_style_fc: self.gain_fc = which_linear(style_dim, out_dim) self.bias_fc = which_linear(style_dim, out_dim) self.gain_fc.weight.data.mul_(0.25) self.gain_fc.bias.data.fill_(1) self.bias_fc.weight.data.mul_(0.25) else: self.style_dim = out_dim * 2 pass def forward(self, x, style): """ :param x: (b, c) or (b, n, c) :param style: (b, c) :return: """ if self.use_style_fc: gain = self.gain_fc(style) bias = self.bias_fc(style) else: style = rearrange(style, 'b (n c) -> b n c', n=2) gain, bias = style.unbind(dim=1) if x.dim() == 3: gain = rearrange(gain, 'b c -> b 1 c') bias = rearrange(bias, 'b c -> b 1 c') elif x.dim() == 2: pass else: assert 0 x = self.linear(x) x = torch.sin(x) out = gain * x + bias return out def __repr__(self): s = ( f'{self.__class__.__name__}(in_dim={self.in_dim}, out_dim={self.out_dim}, style_dim={self.style_dim}, use_style_fc={self.use_style_fc}, )' ) return s def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_dim': 4, 'out_dim': 4, 'style_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math 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_add_mul_sin_0(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) tmp4 = tl.load(in_out_ptr0 + x2, xmask) tmp5 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tl_math.sin(tmp1) tmp3 = tmp0 * tmp2 tmp6 = tmp4 + tmp5 tmp7 = tmp3 + tmp6 tl.store(in_out_ptr0 + 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,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, primals_3, reinterpret_tensor( primals_1, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_8, primals_6, reinterpret_tensor( primals_7, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_7 del primals_8 buf3 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_add_mul_sin_0[grid(16)](buf3, buf0, buf2, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return buf3, primals_3, primals_6, buf0, buf2 class FiLMLayer_PreSinNew(nn.Module): def __init__(self, in_dim, out_dim, style_dim, use_style_fc=True, which_linear=nn.Linear, **kwargs): super(FiLMLayer_PreSinNew, self).__init__() self.in_dim = in_dim self.out_dim = out_dim self.style_dim = style_dim self.use_style_fc = use_style_fc self.linear = which_linear(in_dim, out_dim) nn.init.uniform_(self.linear.weight, -np.sqrt(9 / in_dim), np.sqrt( 9 / in_dim)) if use_style_fc: self.gain_fc = which_linear(style_dim, out_dim) self.bias_fc = which_linear(style_dim, out_dim) self.gain_fc.weight.data.mul_(0.25) self.gain_fc.bias.data.fill_(1) self.bias_fc.weight.data.mul_(0.25) else: self.style_dim = out_dim * 2 pass def __repr__(self): s = ( f'{self.__class__.__name__}(in_dim={self.in_dim}, out_dim={self.out_dim}, style_dim={self.style_dim}, use_style_fc={self.use_style_fc}, )' ) return s def forward(self, input_0, input_1): primals_1 = self.linear.weight primals_2 = self.linear.bias primals_3 = self.gain_fc.weight primals_5 = self.gain_fc.bias primals_4 = self.bias_fc.weight primals_8 = self.bias_fc.bias primals_6 = input_0 primals_7 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
justinjohn0306/CIPS-3D
FiLMLayer_PreSin
false
6,999
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
ResidualBlock_noBN
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBN(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+- |________________| """ def __init__(self, nc=64): super(ResidualBlock_noBN, self).__init__() self.conv1 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, x): identity = x out = F.relu(self.conv1(x), inplace=True) out = self.conv2(out) return identity + out 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 import torch.nn as nn import torch.nn.init as init 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): 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_1(in_out_ptr0, 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) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_out_ptr0 + x3, None) tmp2 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_2, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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, 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_3, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_1[grid(1048576)](buf3, primals_1, primals_5, 1048576, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1 def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBNNew(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+- |________________| """ def __init__(self, nc=64): super(ResidualBlock_noBNNew, self).__init__() self.conv1 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
jtang98/FFDNet-speckle
ResidualBlock_noBN
false
7,000
[ "MIT" ]
1
084fa2782f0197d0e01ee8c595a16414aaf4ab8d
https://github.com/jtang98/FFDNet-speckle/tree/084fa2782f0197d0e01ee8c595a16414aaf4ab8d
CoordConv
import torch import torch.nn as nn class AddCoords(nn.Module): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ def __init__(self, with_r=False): super().__init__() self.with_r = with_r def forward(self, input_tensor): """ Args: 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): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ 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 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 @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 % 6 x3 = xindex // 96 x4 = xindex % 16 x1 = xindex // 4 % 4 x0 = xindex % 4 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 64 * x3), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 5, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = x1 tmp11 = tmp10.to(tl.float32) tmp12 = 0.3333333333333333 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], 6, 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, tmp31, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 6, 4, 4), (96, 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, 6, 4, 4), (96, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(384)](primals_1, buf0, 384, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 1, 1), (4, 1, 1, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(16)](buf2, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 return buf2, primals_2, buf0 class AddCoords(nn.Module): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ def __init__(self, with_r=False): super().__init__() self.with_r = with_r def forward(self, input_tensor): """ Args: 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 CoordConvNew(nn.Module): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ 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, 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]
justinjohn0306/CIPS-3D
CoordConv
false
7,001
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
EqualConvTranspose2d
import math import torch import torch.nn as nn import torch.nn.functional as F class EqualConvTranspose2d(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, bias=True): super().__init__() self.weight = nn.Parameter(torch.randn(in_channel, out_channel, kernel_size, kernel_size)) self.scale = 1 / math.sqrt(in_channel * kernel_size ** 2) self.stride = stride self.padding = padding if bias: self.bias = nn.Parameter(torch.zeros(out_channel)) else: self.bias = None def forward(self, input): out = F.conv_transpose2d(input, self.weight * self.scale, bias=self .bias, stride=self.stride, padding=self.padding) return out def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[0]}, {self.weight.shape[1]}, {self.weight.shape[2]}, stride={self.stride}, padding={self.padding})' ) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channel': 4, 'out_channel': 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 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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.125 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 49 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (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_mul_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(primals_3, buf0, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 7, 7), (196, 49, 7, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(784)](buf2, primals_2, 784, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf2, primals_3, buf0 class EqualConvTranspose2dNew(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, bias=True): super().__init__() self.weight = nn.Parameter(torch.randn(in_channel, out_channel, kernel_size, kernel_size)) self.scale = 1 / math.sqrt(in_channel * kernel_size ** 2) self.stride = stride self.padding = padding if bias: self.bias = nn.Parameter(torch.zeros(out_channel)) else: self.bias = None def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[0]}, {self.weight.shape[1]}, {self.weight.shape[2]}, stride={self.stride}, padding={self.padding})' ) def forward(self, input_0): primals_1 = self.weight primals_2 = self.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
justinjohn0306/CIPS-3D
EqualConvTranspose2d
false
7,002
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
FiLMLayer
import torch import torch.nn as nn class FiLMLayer(nn.Module): def __init__(self, input_dim, hidden_dim): super().__init__() self.layer = nn.Linear(input_dim, hidden_dim) def forward(self, x, freq, phase_shift): x = self.layer(x) freq = freq.unsqueeze(1).expand_as(x) phase_shift = phase_shift.unsqueeze(1).expand_as(x) return torch.sin(freq * x + phase_shift) def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_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.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_add_mul_sin_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 x0 = xindex % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr1 + x3, xmask) tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl_math.sin(tmp4) tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4, 4), (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((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sin_0[grid(64)](primals_4, buf0, primals_5, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf1, primals_4, primals_5, reinterpret_tensor(primals_3, (16, 4 ), (4, 1), 0), buf0 class FiLMLayerNew(nn.Module): def __init__(self, input_dim, hidden_dim): super().__init__() self.layer = nn.Linear(input_dim, hidden_dim) def forward(self, input_0, input_1, input_2): primals_1 = self.layer.weight primals_2 = self.layer.bias primals_3 = input_0 primals_4 = input_1 primals_5 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
justinjohn0306/CIPS-3D
FiLMLayer
false
7,003
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
CoordConvSinAct
import torch import torch.nn as nn class SinAct(nn.Module): def __init__(self): super(SinAct, self).__init__() def forward(self, x): return torch.sin(x) class CoordConvSinAct(nn.Module): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ def __init__(self, in_channels, out_channels, channels_per_group=16, ** kwargs): super().__init__() self.coord_conv = nn.Conv2d(2, out_channels, **kwargs) self.sin_act = SinAct() self.conv = nn.Conv2d(in_channels, out_channels, **kwargs) pass def forward(self, input): batch, _, H, W = input.shape x, y = torch.meshgrid(torch.linspace(-1, 1, W, device=input.device), torch.linspace(-1, 1, H, device=input.device)) x = x.T y = y.T xy = torch.stack((x, y), dim=0) xy = xy.expand((batch, -1, -1, -1)) xy_fea = self.coord_conv(xy) xy_fea = self.sin_act(xy_fea) out = self.conv(input) out = xy_fea + out return out 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 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_stack_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = 2.0 tmp8 = tmp6 < tmp7 tmp9 = 0.6666666666666666 tmp10 = tmp6 * tmp9 tmp11 = -1.0 tmp12 = tmp10 + tmp11 tmp13 = 3 + -1 * x0 tmp14 = tmp13.to(tl.float32) tmp15 = tmp14 * tmp9 tmp16 = 1.0 tmp17 = tmp16 - tmp15 tmp18 = tl.where(tmp8, tmp12, tmp17) tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp4, tmp18, tmp19) tmp21 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp24 = -4 + x1 tmp25 = tmp24.to(tl.float32) tmp26 = tmp25 < tmp7 tmp27 = tmp25 * tmp9 tmp28 = tmp27 + tmp11 tmp29 = 3 + -1 * (-4 + x1) tmp30 = tmp29.to(tl.float32) tmp31 = tmp30 * tmp9 tmp32 = tmp16 - tmp31 tmp33 = tl.where(tmp26, tmp28, tmp32) tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp21, tmp33, tmp34) tmp36 = tl.where(tmp4, tmp20, tmp35) tl.store(out_ptr0 + x2, tmp36, xmask) @triton.jit def triton_poi_fused_convolution_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 32 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_convolution_sin_2(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_out_ptr1 + x2, xmask) tmp5 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl_math.sin(tmp2) tmp6 = tmp4 + tmp5 tmp7 = tmp3 + tmp6 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(in_out_ptr1 + x2, tmp7, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 2, 4, 4), (32, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(32)](buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32) triton_poi_fused_convolution_1[grid(128)](buf0, buf1, 128, XBLOCK= 128, num_warps=4, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) del buf1 buf4 = 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(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 buf5 = buf4 del buf4 triton_poi_fused_add_convolution_sin_2[grid(16)](buf3, buf5, primals_3, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 del primals_5 return buf5, primals_1, primals_2, primals_4, buf0, buf3 class SinAct(nn.Module): def __init__(self): super(SinAct, self).__init__() def forward(self, x): return torch.sin(x) class CoordConvSinActNew(nn.Module): """ Source: https://github.com/mkocabas/CoordConv-pytorch/blob/master/CoordConv.py """ def __init__(self, in_channels, out_channels, channels_per_group=16, ** kwargs): super().__init__() self.coord_conv = nn.Conv2d(2, out_channels, **kwargs) self.sin_act = SinAct() self.conv = nn.Conv2d(in_channels, out_channels, **kwargs) pass def forward(self, input_0): primals_2 = self.coord_conv.weight primals_3 = self.coord_conv.bias primals_1 = self.conv.weight primals_5 = self.conv.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
justinjohn0306/CIPS-3D
CoordConvSinAct
false
7,004
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
Sine
import torch import torch.nn as nn class Sine(nn.Module): """Sine Activation Function.""" def __init__(self): super().__init__() def forward(self, x): return torch.sin(30.0 * x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_mul_sin_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 = 30.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.sin(tmp2) tl.store(out_ptr0 + x0, tmp3, 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_mul_sin_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SineNew(nn.Module): """Sine Activation Function.""" def __init__(self): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
justinjohn0306/CIPS-3D
Sine
false
7,005
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
FiLMLayerEqualFC
import math import torch import torch.nn as nn import torch.nn.functional as F class EqualLinear(nn.Module): def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1.0, activation=None): """ :param in_dim: :param out_dim: :param bias: :param bias_init: :param lr_mul: 0.01 :param activation: None: Linear; fused_leaky_relu """ super().__init__() self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul)) if bias: self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init)) else: self.bias = None self.activation = activation if self.activation is not None: self.act_layer = nn.LeakyReLU(0.2) self.scale = 1 / math.sqrt(in_dim) * lr_mul self.lr_mul = lr_mul pass def forward(self, input): out = F.linear(input, self.weight * self.scale, bias=self.bias * self.lr_mul) if self.activation: out = self.act_layer(out) return out def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]}), activation={self.activation}' ) class FiLMLayerEqualFC(nn.Module): def __init__(self, input_dim, hidden_dim): super().__init__() self.layer = EqualLinear(input_dim, hidden_dim) pass def forward(self, x, freq, phase_shift): """ :param x: (b, num_points, d) :param freq: (b, d) :param phase_shift: (b, d) :return: """ x = self.layer(x) freq = freq.unsqueeze(1).expand_as(x) phase_shift = phase_shift.unsqueeze(1).expand_as(x) out = torch.sin(freq * x + phase_shift) return out def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_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.triton_helpers import 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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_mul_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_mul_sin_2(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 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr1 + x3, xmask) tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl_math.sin(tmp4) tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (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_mul_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_mul_1[grid(4)](primals_2, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(buf1, reinterpret_tensor(primals_3, (16, 4), ( 4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del buf0 del buf1 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_sin_2[grid(64)](primals_4, buf2, primals_5, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf3, primals_4, primals_5, reinterpret_tensor(primals_3, (16, 4 ), (4, 1), 0), buf2 class EqualLinear(nn.Module): def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1.0, activation=None): """ :param in_dim: :param out_dim: :param bias: :param bias_init: :param lr_mul: 0.01 :param activation: None: Linear; fused_leaky_relu """ super().__init__() self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul)) if bias: self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init)) else: self.bias = None self.activation = activation if self.activation is not None: self.act_layer = nn.LeakyReLU(0.2) self.scale = 1 / math.sqrt(in_dim) * lr_mul self.lr_mul = lr_mul pass def forward(self, input): out = F.linear(input, self.weight * self.scale, bias=self.bias * self.lr_mul) if self.activation: out = self.act_layer(out) return out def __repr__(self): return ( f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]}), activation={self.activation}' ) class FiLMLayerEqualFCNew(nn.Module): def __init__(self, input_dim, hidden_dim): super().__init__() self.layer = EqualLinear(input_dim, hidden_dim) pass def forward(self, input_0, input_1, input_2): primals_1 = self.layer.weight primals_2 = self.layer.bias primals_3 = input_0 primals_4 = input_1 primals_5 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
justinjohn0306/CIPS-3D
FiLMLayerEqualFC
false
7,006
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
CLNLayer
import torch import torch.nn as nn import torch.nn.functional as F class CLN(nn.Module): def __init__(self, in_dim, use_style_fc=False, style_dim=None, which_linear=nn.Linear, spectral_norm=False, eps=1e-05, **kwargs): super(CLN, self).__init__() self.in_dim = in_dim self.use_style_fc = use_style_fc self.style_dim = style_dim self.spectral_norm = spectral_norm if use_style_fc: self.gain = which_linear(style_dim, in_dim) self.bias = which_linear(style_dim, in_dim) if spectral_norm: self.gain = nn.utils.spectral_norm(self.gain) self.bias = nn.utils.spectral_norm(self.bias) else: self.style_dim = in_dim * 2 self.eps = eps pass def forward(self, x, style): """ Calculate class-conditional gains and biases. :param x: (b, c) or (b, n, c) :param style: (b, c) :return: """ if self.use_style_fc: gain = self.gain(style) + 1.0 bias = self.bias(style) else: style = rearrange(style, 'b (n c) -> b n c', n=2) gain, bias = style.unbind(dim=1) gain = gain + 1.0 if x.dim() == 3: gain = rearrange(gain, 'b c -> b 1 c') bias = rearrange(bias, 'b c -> b 1 c') elif x.dim() == 2: pass else: assert 0 out = F.layer_norm(x, normalized_shape=(self.in_dim,), weight=None, bias=None, eps=self.eps) out = out * gain + bias return out def __repr__(self): s = ( f'{self.__class__.__name__}(in_dim={self.in_dim}, style_dim={self.style_dim})' ) return s class CLNLayer(nn.Module): def __repr__(self): return f'{self.__class__.__name__}({self.repr})' def __init__(self, in_dim, out_dim, style_dim): super().__init__() self.in_dim = in_dim self.out_dim = out_dim self.style_dim = style_dim self.repr = ( f'in_dim={in_dim}, out_dim={out_dim}, style_dim={style_dim}') self.linear1 = nn.Linear(in_dim, out_dim) self.cln1 = CLN(in_dim=out_dim, use_style_fc=True, style_dim=style_dim) self.style_dim = self.cln1.style_dim self.act1 = nn.LeakyReLU(0.2, inplace=True) pass def forward(self, x, style): x = self.linear1(x) x = self.cln1(x, style) x = self.act1(x) return x def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_dim': 4, 'out_dim': 4, 'style_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import 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_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_add_leaky_relu_leaky_relu_backward_mul_native_layer_norm_1( in_out_ptr0, 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 + x2, xmask) tmp9 = tl.load(in_out_ptr0 + x2, xmask) tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp4 * tmp7 tmp11 = tmp9 + tmp10 tmp12 = tmp8 + tmp11 tmp13 = 0.0 tmp14 = tmp12 > tmp13 tmp15 = 0.2 tmp16 = tmp12 * tmp15 tmp17 = tl.where(tmp14, tmp12, tmp16) tmp18 = tmp17 > tmp13 tl.store(in_out_ptr0 + x2, tmp17, xmask) tl.store(out_ptr0 + x2, tmp18, 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,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, primals_3, reinterpret_tensor( primals_1, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, primals_6, 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((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_6, reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2) del primals_7 buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf4 = empty_strided_cuda((4, 1), (1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(4)](buf0, buf3, buf4, 4, XBLOCK=4, num_warps=1, num_stages=1) buf5 = buf2 del buf2 buf6 = buf5 del buf5 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_add_leaky_relu_leaky_relu_backward_mul_native_layer_norm_1[ grid(16)](buf6, buf0, buf3, buf4, buf1, primals_8, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf3 del buf4 del primals_8 return buf6, primals_3, primals_6, buf0, buf1, buf7 class CLN(nn.Module): def __init__(self, in_dim, use_style_fc=False, style_dim=None, which_linear=nn.Linear, spectral_norm=False, eps=1e-05, **kwargs): super(CLN, self).__init__() self.in_dim = in_dim self.use_style_fc = use_style_fc self.style_dim = style_dim self.spectral_norm = spectral_norm if use_style_fc: self.gain = which_linear(style_dim, in_dim) self.bias = which_linear(style_dim, in_dim) if spectral_norm: self.gain = nn.utils.spectral_norm(self.gain) self.bias = nn.utils.spectral_norm(self.bias) else: self.style_dim = in_dim * 2 self.eps = eps pass def forward(self, x, style): """ Calculate class-conditional gains and biases. :param x: (b, c) or (b, n, c) :param style: (b, c) :return: """ if self.use_style_fc: gain = self.gain(style) + 1.0 bias = self.bias(style) else: style = rearrange(style, 'b (n c) -> b n c', n=2) gain, bias = style.unbind(dim=1) gain = gain + 1.0 if x.dim() == 3: gain = rearrange(gain, 'b c -> b 1 c') bias = rearrange(bias, 'b c -> b 1 c') elif x.dim() == 2: pass else: assert 0 out = F.layer_norm(x, normalized_shape=(self.in_dim,), weight=None, bias=None, eps=self.eps) out = out * gain + bias return out def __repr__(self): s = ( f'{self.__class__.__name__}(in_dim={self.in_dim}, style_dim={self.style_dim})' ) return s class CLNLayerNew(nn.Module): def __repr__(self): return f'{self.__class__.__name__}({self.repr})' def __init__(self, in_dim, out_dim, style_dim): super().__init__() self.in_dim = in_dim self.out_dim = out_dim self.style_dim = style_dim self.repr = ( f'in_dim={in_dim}, out_dim={out_dim}, style_dim={style_dim}') self.linear1 = nn.Linear(in_dim, out_dim) self.cln1 = CLN(in_dim=out_dim, use_style_fc=True, style_dim=style_dim) self.style_dim = self.cln1.style_dim self.act1 = nn.LeakyReLU(0.2, inplace=True) pass def forward(self, input_0, input_1): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_3 = self.cln1.gain.weight primals_5 = self.cln1.gain.bias primals_4 = self.cln1.bias.weight primals_8 = self.cln1.bias.bias primals_6 = input_0 primals_7 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
justinjohn0306/CIPS-3D
CLNLayer
false
7,007
[ "MIT" ]
1
69a910a7841846419a6b5e03182c8cf061a82584
https://github.com/justinjohn0306/CIPS-3D/tree/69a910a7841846419a6b5e03182c8cf061a82584
TVLoss
import torch import torch.nn as nn class TVLoss(nn.Module): def __init__(self, weight=1.0): super(TVLoss, self).__init__() self.weight = weight self.l1 = nn.L1Loss(reduction='mean') def forward(self, out, gt): grad_out_x = out[:, :, :, 1:] - out[:, :, :, :-1] grad_out_y = out[:, :, 1:, :] - out[:, :, :-1, :] grad_gt_x = gt[:, :, :, 1:] - gt[:, :, :, :-1] grad_gt_y = gt[:, :, 1:, :] - gt[:, :, :-1, :] loss_x = self.l1(grad_out_x, grad_gt_x) loss_y = self.l1(grad_out_y, grad_gt_y) loss = self.weight * (loss_x + loss_y) 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.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_per_fused_abs_add_mean_mul_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): rnumel = 192 RBLOCK: tl.constexpr = 256 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, :] rmask = rindex < rnumel r0 = rindex % 3 r1 = rindex // 3 r2 = rindex % 12 r3 = rindex // 12 tmp0 = tl.load(in_ptr0 + (1 + r0 + 4 * r1), rmask, other=0.0) tmp1 = tl.load(in_ptr0 + (r0 + 4 * r1), rmask, other=0.0) tmp3 = tl.load(in_ptr1 + (1 + r0 + 4 * r1), rmask, other=0.0) tmp4 = tl.load(in_ptr1 + (r0 + 4 * r1), rmask, other=0.0) tmp12 = tl.load(in_ptr0 + (4 + r2 + 16 * r3), rmask, other=0.0) tmp13 = tl.load(in_ptr0 + (r2 + 16 * r3), rmask, other=0.0) tmp15 = tl.load(in_ptr1 + (4 + r2 + 16 * r3), rmask, other=0.0) tmp16 = tl.load(in_ptr1 + (r2 + 16 * r3), rmask, other=0.0) tmp2 = tmp0 - tmp1 tmp5 = tmp3 - tmp4 tmp6 = tmp2 - tmp5 tmp7 = tl_math.abs(tmp6) tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = tl.where(rmask, tmp8, 0) tmp11 = tl.sum(tmp10, 1)[:, None] tmp14 = tmp12 - tmp13 tmp17 = tmp15 - tmp16 tmp18 = tmp14 - tmp17 tmp19 = tl_math.abs(tmp18) tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK]) tmp22 = tl.where(rmask, tmp20, 0) tmp23 = tl.sum(tmp22, 1)[:, None] tmp24 = 192.0 tmp25 = tmp11 / tmp24 tmp26 = tmp23 / tmp24 tmp27 = tmp25 + tmp26 tmp28 = 1.0 tmp29 = tmp27 * tmp28 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp29, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_mean_mul_sub_0[grid(1)](buf2, arg0_1, arg1_1, 1, 192, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class TVLossNew(nn.Module): def __init__(self, weight=1.0): super(TVLossNew, self).__init__() self.weight = weight self.l1 = nn.L1Loss(reduction='mean') def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
juyongjiang/Simple-SR
TVLoss
false
7,008
[ "MIT" ]
1
76820511abc04fbe6e4a79d23c67aee97406d563
https://github.com/juyongjiang/Simple-SR/tree/76820511abc04fbe6e4a79d23c67aee97406d563
ResidualBlock_noBN
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBN(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+-ReLU |________________| """ def __init__(self, nf=64): super(ResidualBlock_noBN, self).__init__() self.conv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, x): identity = x out = F.relu(self.conv1(x), inplace=True) out = self.conv2(out) return F.relu(identity + out) 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 import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @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_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_out_ptr0 + x3, None) tmp2 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = 0.0 tmp8 = tmp6 <= tmp7 tl.store(in_out_ptr0 + x3, tmp6, None) tl.store(out_ptr0 + x3, tmp8, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_2, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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, 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_3, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid( 1048576)](buf3, primals_1, primals_5, buf4, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1, buf4 def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBNNew(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+-ReLU |________________| """ def __init__(self, nf=64): super(ResidualBlock_noBNNew, self).__init__() self.conv1 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
juyongjiang/Simple-SR
ResidualBlock_noBN
false
7,009
[ "MIT" ]
1
76820511abc04fbe6e4a79d23c67aee97406d563
https://github.com/juyongjiang/Simple-SR/tree/76820511abc04fbe6e4a79d23c67aee97406d563
Attention
import torch import torch.nn as nn class Attention(nn.Module): """ Implements Bahdanau Attention. Arguments: encoder_dim (int): Size of the encoder. decoder_dim (int): Size of the decoder. attention_dim (int): Size of the attention layer. """ def __init__(self, encoder_dim, decoder_dim, attention_dim): super().__init__() self.encoder_attn = nn.Linear(encoder_dim, attention_dim, bias=False) self.decoder_attn = nn.Linear(decoder_dim, attention_dim, bias=False) self.value = nn.Linear(attention_dim, 1, bias=False) self.softmax = nn.Softmax(dim=1) def forward(self, encoder_out, decoder_hidden): hidden_ = decoder_hidden.unsqueeze(1) attn_hidden = torch.tanh(self.encoder_attn(encoder_out) + self. decoder_attn(hidden_)) score = self.value(attn_hidden) attn_weights = self.softmax(score) context_vector = attn_weights * encoder_out context_vector = torch.sum(context_vector, 1) return context_vector, attn_weights def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'encoder_dim': 4, 'decoder_dim': 4, 'attention_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.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_tanh_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex % 256 x0 = xindex % 64 x2 = xindex // 256 x4 = xindex tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(out_ptr0 + x4, tmp3, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_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') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 16 x2 = xindex // 64 x3 = xindex % 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (16 + x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr1 + (64 + x3), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (32 + x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr1 + (128 + x3), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (48 + x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr1 + (192 + x3), 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 tl.store(out_ptr0 + x4, tmp14, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (1, 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_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_tanh_0[grid(1024)](buf0, buf1, buf2, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf3 = reinterpret_tensor(buf1, (256, 1), (1, 1), 0) del buf1 extern_kernels.mm(reinterpret_tensor(buf2, (256, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 1), (1, 4), 0), out=buf3) buf4 = reinterpret_tensor(buf0, (4, 4, 4, 4, 1), (64, 16, 4, 1, 256), 0 ) del buf0 triton_poi_fused__softmax_1[grid(256)](buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 4, 4, 4, 1), (64, 16, 4, 1, 1), 0) del buf3 triton_poi_fused__softmax_2[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused_mul_sum_3[grid(256)](buf5, primals_3, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf6, buf5, primals_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), buf2, buf5, primals_5 class AttentionNew(nn.Module): """ Implements Bahdanau Attention. Arguments: encoder_dim (int): Size of the encoder. decoder_dim (int): Size of the decoder. attention_dim (int): Size of the attention layer. """ def __init__(self, encoder_dim, decoder_dim, attention_dim): super().__init__() self.encoder_attn = nn.Linear(encoder_dim, attention_dim, bias=False) self.decoder_attn = nn.Linear(decoder_dim, attention_dim, bias=False) self.value = nn.Linear(attention_dim, 1, bias=False) self.softmax = nn.Softmax(dim=1) def forward(self, input_0, input_1): primals_2 = self.encoder_attn.weight primals_4 = self.decoder_attn.weight primals_5 = self.value.weight primals_1 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0], output[1]
kad99kev/Image-Captioning
Attention
false
7,010
[ "MIT" ]
1
a38d7c6469306d7f226d8003bba92f21b3d9a06c
https://github.com/kad99kev/Image-Captioning/tree/a38d7c6469306d7f226d8003bba92f21b3d9a06c
CNN_decoder_attention
import torch import torch.nn as nn import torch.nn.init as init class CNN_decoder_attention(nn.Module): def __init__(self, input_size, output_size, stride=2): super(CNN_decoder_attention, self).__init__() self.input_size = input_size self.output_size = output_size self.relu = nn.ReLU() self.deconv = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=3, stride=stride) self.bn = nn.BatchNorm1d(int(self.input_size)) self.deconv_out = nn.ConvTranspose1d(in_channels=int(self. input_size), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) self.deconv_attention = nn.ConvTranspose1d(in_channels=int(self. input_size), out_channels=int(self.input_size), kernel_size=1, stride=1, padding=0) self.bn_attention = nn.BatchNorm1d(int(self.input_size)) self.relu_leaky = nn.LeakyReLU(0.2) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): m.weight.data = init.xavier_uniform(m.weight.data, gain=nn. init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, x): """ :param x: batch * channel * length :return: """ x = self.deconv(x) x = self.bn(x) x = self.relu(x) x = self.deconv(x) x = self.bn(x) x = self.relu(x) x_hop1 = self.deconv_out(x) x_hop1_attention = self.deconv_attention(x) x_hop1_attention = self.relu(x_hop1_attention) x_hop1_attention = torch.matmul(x_hop1_attention, x_hop1_attention. view(-1, x_hop1_attention.size(2), x_hop1_attention.size(1))) x = self.deconv(x) x = self.bn(x) x = self.relu(x) x = self.deconv(x) x = self.bn(x) x = self.relu(x) x_hop2 = self.deconv_out(x) x_hop2_attention = self.deconv_attention(x) x_hop2_attention = self.relu(x_hop2_attention) x_hop2_attention = torch.matmul(x_hop2_attention, x_hop2_attention. view(-1, x_hop2_attention.size(2), x_hop2_attention.size(1))) x = self.deconv(x) x = self.bn(x) x = self.relu(x) x = self.deconv(x) x = self.bn(x) x = self.relu(x) x_hop3 = self.deconv_out(x) x_hop3_attention = self.deconv_attention(x) x_hop3_attention = self.relu(x_hop3_attention) x_hop3_attention = torch.matmul(x_hop3_attention, x_hop3_attention. view(-1, x_hop3_attention.size(2), x_hop3_attention.size(1))) return (x_hop1, x_hop2, x_hop3, x_hop1_attention, x_hop2_attention, x_hop3_attention) def get_inputs(): return [torch.rand([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 import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_0( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 144 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 9 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_1( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 304 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 19 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 304 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 19 % 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_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 304 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 19 % 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__native_batch_norm_legit_no_training_convolution_relu_4( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 624 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 39 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_5( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1264 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 79 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused_convolution_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1264 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 79 % 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_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1264 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 79 % 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__native_batch_norm_legit_no_training_convolution_relu_8( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2544 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 159 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_9( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 5104 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 319 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.sqrt(tmp7) tmp9 = tl.full([1], 1, tl.int32) tmp10 = tmp9 / tmp8 tmp11 = 1.0 tmp12 = tmp10 * tmp11 tmp13 = tmp4 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tmp18 = tl.full([1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused_convolution_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 5104 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 319 % 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_bmm_convolution_relu_11(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 5104 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x1 = xindex // 319 % 4 x2 = xindex // 1276 x3 = xindex % 1276 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x3 + 1280 * x2), tmp4, xmask) tl.store(out_ptr1 + (x3 + 1280 * x2), tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4, 3), (12, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 3), (12, 3, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 9), (36, 9, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 9), (36, 9, 1), torch.float32) get_raw_stream(0) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_0[ grid(144)](buf1, primals_2, primals_4, primals_5, primals_6, primals_7, buf2, 144, XBLOCK=128, num_warps=4, num_stages=1) buf3 = extern_kernels.convolution(buf2, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 19), (76, 19, 1)) buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 4, 19), (76, 19, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_1[ grid(304)](buf4, primals_2, primals_4, primals_5, primals_6, primals_7, buf5, 304, XBLOCK=128, num_warps=4, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1,), padding=(1,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 19), (76, 19, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_2[grid(304)](buf7, primals_9, 304, XBLOCK=256, num_warps=4, num_stages=1) buf8 = extern_kernels.convolution(buf5, primals_10, stride=(1,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf8, (4, 4, 19), (76, 19, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_3[grid(304)](buf9, primals_11, 304, XBLOCK=256, num_warps=4, num_stages=1) buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf9, reinterpret_tensor(buf9, (4, 19, 4), (76, 4, 1), 0), out=buf10) buf11 = extern_kernels.convolution(buf5, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf11, (4, 4, 39), (156, 39, 1)) buf12 = buf11 del buf11 buf13 = empty_strided_cuda((4, 4, 39), (156, 39, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_4[ grid(624)](buf12, primals_2, primals_4, primals_5, primals_6, primals_7, buf13, 624, XBLOCK=128, num_warps=4, num_stages=1) buf14 = extern_kernels.convolution(buf13, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf14, (4, 4, 79), (316, 79, 1)) buf15 = buf14 del buf14 buf16 = empty_strided_cuda((4, 4, 79), (316, 79, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_5[ grid(1264)](buf15, primals_2, primals_4, primals_5, primals_6, primals_7, buf16, 1264, XBLOCK=256, num_warps=4, num_stages=1) buf17 = extern_kernels.convolution(buf16, primals_8, stride=(1,), padding=(1,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf17, (4, 4, 79), (316, 79, 1)) buf18 = buf17 del buf17 triton_poi_fused_convolution_6[grid(1264)](buf18, primals_9, 1264, XBLOCK=256, num_warps=4, num_stages=1) buf19 = extern_kernels.convolution(buf16, primals_10, stride=(1,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf19, (4, 4, 79), (316, 79, 1)) buf20 = buf19 del buf19 triton_poi_fused_convolution_relu_7[grid(1264)](buf20, primals_11, 1264, XBLOCK=256, num_warps=4, num_stages=1) buf21 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf20, reinterpret_tensor(buf20, (4, 79, 4), ( 316, 4, 1), 0), out=buf21) buf22 = extern_kernels.convolution(buf16, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf22, (4, 4, 159), (636, 159, 1)) buf23 = buf22 del buf22 buf24 = empty_strided_cuda((4, 4, 159), (636, 159, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_8[ grid(2544)](buf23, primals_2, primals_4, primals_5, primals_6, primals_7, buf24, 2544, XBLOCK=256, num_warps=4, num_stages=1) buf25 = extern_kernels.convolution(buf24, primals_1, stride=(2,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf25, (4, 4, 319), (1276, 319, 1)) buf26 = buf25 del buf25 buf27 = empty_strided_cuda((4, 4, 319), (1276, 319, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_no_training_convolution_relu_9[ grid(5104)](buf26, primals_2, primals_4, primals_5, primals_6, primals_7, buf27, 5104, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 del primals_7 buf28 = extern_kernels.convolution(buf27, primals_8, stride=(1,), padding=(1,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf28, (4, 4, 319), (1276, 319, 1)) buf29 = buf28 del buf28 triton_poi_fused_convolution_10[grid(5104)](buf29, primals_9, 5104, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf30 = extern_kernels.convolution(buf27, primals_10, stride=(1,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf30, (4, 4, 319), (1276, 319, 1)) buf31 = empty_strided_cuda((4, 4, 319), (1280, 319, 1), torch.float32) buf32 = empty_strided_cuda((4, 319, 4), (1280, 4, 1), torch.float32) triton_poi_fused_bmm_convolution_relu_11[grid(5104)](buf30, primals_11, buf31, buf32, 5104, XBLOCK=256, num_warps=4, num_stages=1) del buf30 del primals_11 buf33 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf31, buf32, out=buf33) del buf32 return (buf7, buf18, buf29, buf10, buf21, buf33, primals_1, primals_3, primals_4, primals_5, primals_6, primals_8, primals_10, buf1, buf2, buf4, buf5, buf9, buf12, buf13, buf15, buf16, buf20, buf23, buf24, buf26, buf27, buf31) class CNN_decoder_attentionNew(nn.Module): def __init__(self, input_size, output_size, stride=2): super(CNN_decoder_attentionNew, self).__init__() self.input_size = input_size self.output_size = output_size self.relu = nn.ReLU() self.deconv = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=3, stride=stride) self.bn = nn.BatchNorm1d(int(self.input_size)) self.deconv_out = nn.ConvTranspose1d(in_channels=int(self. input_size), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) self.deconv_attention = nn.ConvTranspose1d(in_channels=int(self. input_size), out_channels=int(self.input_size), kernel_size=1, stride=1, padding=0) self.bn_attention = nn.BatchNorm1d(int(self.input_size)) self.relu_leaky = nn.LeakyReLU(0.2) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): m.weight.data = init.xavier_uniform(m.weight.data, gain=nn. init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, input_0): primals_1 = self.deconv.weight primals_2 = self.deconv.bias primals_4 = self.bn.weight primals_5 = self.bn.bias primals_8 = self.deconv_out.weight primals_6 = self.deconv_out.bias primals_10 = self.deconv_attention.weight primals_7 = self.deconv_attention.bias primals_9 = self.bn_attention.weight primals_11 = self.bn_attention.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0], output[1], output[2], output[3], output[4], output[5]
jonathangomesselman/graph-generation
CNN_decoder_attention
false
7,011
[ "MIT" ]
1
72a8be30d54a414fcca9ea0fad1a62e38b85ee2f
https://github.com/jonathangomesselman/graph-generation/tree/72a8be30d54a414fcca9ea0fad1a62e38b85ee2f
PreNet
import torch import torch.nn as nn class PreNet(nn.Module): def __init__(self): super(PreNet, self).__init__() self.conv1 = nn.Conv2d(4, 8, 3, padding=1) self.act1 = nn.LeakyReLU(0.2, inplace=False) self.conv2 = nn.Conv2d(8, 16, 3, padding=1) self.act2 = nn.LeakyReLU(0.2, inplace=False) def forward(self, labels): conv1 = self.act1(self.conv1(labels)) conv2 = self.act2(self.conv2(conv1)) return conv2 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 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 = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 8 tmp0 = tl.load(in_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_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (8, 4, 3, 3), (36, 9, 3, 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, (16, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_5, (16,), (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, 8, 4, 4), (128, 16, 4, 1)) buf1 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(512)](buf0, primals_2, buf1, buf2, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf0 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, 16, 4, 4), (256, 16, 4, 1)) buf4 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.bool) buf5 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.float32 ) triton_poi_fused_convolution_leaky_relu_1[grid(1024)](buf3, primals_5, buf4, buf5, 1024, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del primals_5 return buf5, primals_1, primals_3, primals_4, buf1, buf2, buf4 class PreNetNew(nn.Module): def __init__(self): super(PreNetNew, self).__init__() self.conv1 = nn.Conv2d(4, 8, 3, padding=1) self.act1 = nn.LeakyReLU(0.2, inplace=False) self.conv2 = nn.Conv2d(8, 16, 3, padding=1) self.act2 = nn.LeakyReLU(0.2, inplace=False) 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]
karavik18/Federated_Learning_for_Missing_MRI_Sequence
PreNet
false
7,012
[ "Apache-2.0" ]
1
42924f8475f354e6b429d05867f99530aa485b96
https://github.com/karavik18/Federated_Learning_for_Missing_MRI_Sequence/tree/42924f8475f354e6b429d05867f99530aa485b96
TransformerFFN
from _paritybench_helpers import _mock_config import torch from torch import nn class BertLayerNorm(nn.Module): def __init__(self, hidden_size, eps=1e-05): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.weight * x + self.bias class TransformerFFN(nn.Module): def __init__(self, config): super(TransformerFFN, self).__init__() self.ffn_type = config.ffn_type assert self.ffn_type in (1, 2) if self.ffn_type in (1, 2): self.wx0 = nn.Linear(config.hidden_size, config.hidden_size) if self.ffn_type in (2,): self.wx1 = nn.Linear(config.hidden_size, config.hidden_size) if self.ffn_type in (1, 2): self.output = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-05) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, x): if self.ffn_type in (1, 2): x0 = self.wx0(x) if self.ffn_type == 1: x1 = x elif self.ffn_type == 2: x1 = self.wx1(x) out = self.output(x0 * x1) out = self.dropout(out) out = self.LayerNorm(out + x) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(ffn_type=1, hidden_size=4, hidden_dropout_prob=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_mean_pow_sub_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') 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_div_mean_mul_sqrt_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 x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x2, xmask) tmp4 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 - tmp4 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tmp10 = tmp5 / tmp9 tmp11 = tmp0 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](buf1, primals_2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(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, 1), (16, 4, 1, 64), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_mean_pow_sub_1[grid(64)](buf2, primals_3, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_sqrt_sub_2[grid(256)](primals_6, buf2, primals_3, buf3, buf4, primals_7, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del buf4 del primals_7 return buf5, primals_3, primals_6, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), buf2, primals_4 class BertLayerNorm(nn.Module): def __init__(self, hidden_size, eps=1e-05): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.weight * x + self.bias class TransformerFFNNew(nn.Module): def __init__(self, config): super(TransformerFFNNew, self).__init__() self.ffn_type = config.ffn_type assert self.ffn_type in (1, 2) if self.ffn_type in (1, 2): self.wx0 = nn.Linear(config.hidden_size, config.hidden_size) if self.ffn_type in (2,): self.wx1 = nn.Linear(config.hidden_size, config.hidden_size) if self.ffn_type in (1, 2): self.output = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=1e-05) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, input_0): primals_1 = self.wx0.weight primals_2 = self.wx0.bias primals_4 = self.output.weight primals_5 = self.output.bias primals_6 = self.LayerNorm.weight primals_7 = self.LayerNorm.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
katsura-jp/generate-syosetu-title
TransformerFFN
false
7,014
[ "MIT" ]
1
f1db8f87d6ebd58117df1e7c0b76a4fe92cae810
https://github.com/katsura-jp/generate-syosetu-title/tree/f1db8f87d6ebd58117df1e7c0b76a4fe92cae810
SurfaceLoss
import torch import torch.nn as nn class SurfaceLoss(nn.Module): def __init__(self, epsilon=1e-05, softmax=True): super(SurfaceLoss, self).__init__() self.weight_map = [] def forward(self, x, distmap): x = torch.softmax(x, dim=1) self.weight_map = distmap score = x.flatten(start_dim=2) * distmap.flatten(start_dim=2) score = torch.mean(score, dim=2) score = torch.mean(score, dim=1) return score def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_per_fused_mean_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + (r2 + 64 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (16 + r2 + 64 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (32 + r2 + 64 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (48 + r2 + 64 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr1 + (r2 + 16 * x3), xmask, other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp10 = tmp8 * tmp9 tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13 = tl.where(xmask, tmp11, 0) tmp14 = tl.sum(tmp13, 1)[:, None] tl.store(out_ptr0 + x3, tmp14, xmask) @triton.jit def triton_poi_fused_mean_mul_2(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') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp1 = 16.0 tmp2 = tmp0 / tmp1 tmp4 = tmp3 / tmp1 tmp5 = tmp2 + tmp4 tmp7 = tmp6 / tmp1 tmp8 = tmp5 + tmp7 tmp10 = tmp9 / tmp1 tmp11 = tmp8 + tmp10 tmp12 = 4.0 tmp13 = tmp11 / tmp12 tl.store(out_ptr0 + x0, tmp13, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_per_fused_mean_mul_1[grid(16)](buf0, arg1_1, buf1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg1_1 del buf0 buf2 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_mean_mul_2[grid(4)](buf1, buf2, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf1 return buf2, class SurfaceLossNew(nn.Module): def __init__(self, epsilon=1e-05, softmax=True): super(SurfaceLossNew, self).__init__() self.weight_map = [] def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kbarkevich/RITnet
SurfaceLoss
false
7,015
[ "MIT" ]
1
5df66c656734aecd2987cf27d9359416b136af2e
https://github.com/kbarkevich/RITnet/tree/5df66c656734aecd2987cf27d9359416b136af2e
GlobalMaxPooling
import torch import torch.nn as nn class GlobalMaxPooling(nn.Module): def __init__(self, dim=0): super(self.__class__, self).__init__() self.dim = dim def forward(self, x): return x.max(dim=self.dim)[0] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + (64 + x0), xmask) tmp3 = tl.load(in_ptr0 + (128 + x0), xmask) tmp5 = tl.load(in_ptr0 + (192 + x0), xmask) tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, 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), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf0, class GlobalMaxPoolingNew(nn.Module): def __init__(self, dim=0): super(self.__class__, self).__init__() self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kbrodt/clog-loss
GlobalMaxPooling
false
7,016
[ "MIT" ]
1
0831b3a01b079609a71490bb921633110927206c
https://github.com/kbrodt/clog-loss/tree/0831b3a01b079609a71490bb921633110927206c
BertAttention
from _paritybench_helpers import _mock_config import math import torch from torch import nn class BertLayerNorm(nn.Module): """ LayerNorm层 """ def __init__(self, hidden_size, eps=1e-12): super(BertLayerNorm, self).__init__() self.gamma = nn.Parameter(torch.ones(hidden_size)) self.beta = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.gamma * x + self.beta class BertSelfAttention(nn.Module): def __init__(self, config: 'BertConfig'): super().__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): """ 拼接multi head的size """ new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, attention_mask, output_attentions=True): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(hidden_states) mixed_value_layer = self.value(hidden_states) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_scores = attention_scores + attention_mask attention_probs = nn.Softmax(dim=-1)(attention_scores) attention_probs = self.dropout(attention_probs) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) if output_attentions: return context_layer, attention_probs return context_layer, None class BertSelfOutput(nn.Module): """ Self Attention的输出 """ def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states class BertAttention(nn.Module): """ Self Attention + Attention Output """ def __init__(self, config): super().__init__() self.self = BertSelfAttention(config) self.output = BertSelfOutput(config) def forward(self, hidden_states, attention_mask, output_attentions=True): self_outputs, attention_metrix = self.self(hidden_states, attention_mask, output_attentions=output_attentions) attention_output = self.output(self_outputs, hidden_states) return attention_output, attention_metrix def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, num_attention_heads= 4, attention_probs_dropout_prob=0.5, layer_norm_eps=1, hidden_dropout_prob=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused__softmax_add_div_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 x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp5 * tmp1 tmp8 = tmp6 + tmp7 tmp9 = triton_helpers.maximum(tmp4, tmp8) tmp11 = tmp10 * tmp1 tmp13 = tmp11 + tmp12 tmp14 = triton_helpers.maximum(tmp9, tmp13) tmp16 = tmp15 * tmp1 tmp18 = tmp16 + tmp17 tmp19 = triton_helpers.maximum(tmp14, tmp18) tmp20 = tmp4 - tmp19 tmp21 = tl_math.exp(tmp20) tmp22 = tmp8 - tmp19 tmp23 = tl_math.exp(tmp22) tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp19 tmp26 = tl_math.exp(tmp25) tmp27 = tmp24 + tmp26 tmp28 = tmp18 - tmp19 tmp29 = tl_math.exp(tmp28) tmp30 = tmp27 + tmp29 tl.store(out_ptr0 + x2, tmp19, xmask) tl.store(out_ptr1 + x2, tmp30, xmask) @triton.jit def triton_poi_fused__softmax_add_div_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex % 64 x5 = xindex // 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp3 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 - tmp5 tmp7 = tl_math.exp(tmp6) tmp9 = tmp7 / tmp8 tl.store(in_out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_mean_pow_sub_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tmp27 / tmp15 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_sqrt_sub_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x2, xmask) tmp4 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 - tmp4 tmp7 = 1.0 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tmp10 = tmp5 / tmp9 tmp11 = tmp0 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12 ) = 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), (16, 4, 1)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_2 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf0 triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5) buf6 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf1 buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_add_div_1[grid(64)](buf5, primals_8, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 triton_poi_fused__softmax_add_div_2[grid(256)](buf8, primals_8, buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_8 buf9 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf7 triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_7, buf9, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_7 buf10 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 0), out=buf10) buf11 = reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf6 triton_poi_fused_clone_3[grid(16, 4)](buf10, buf11, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf12 = reinterpret_tensor(buf10, (16, 4), (4, 1), 0) del buf10 extern_kernels.addmm(primals_10, reinterpret_tensor(buf11, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_10 buf13 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_add_mean_pow_sub_4[grid(16)](buf12, primals_3, buf13, buf14, 16, XBLOCK=16, num_warps=1, num_stages=1) buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_sqrt_sub_5[grid(64)](primals_11, buf12, primals_3, buf13, buf14, primals_12, buf15, 64, XBLOCK= 64, num_warps=1, num_stages=1) del buf13 del buf14 del primals_12 return buf15, buf8, primals_3, primals_11, buf8, reinterpret_tensor(buf11, (16, 4), (4, 1), 0), buf12, primals_9, reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0) class BertLayerNorm(nn.Module): """ LayerNorm层 """ def __init__(self, hidden_size, eps=1e-12): super(BertLayerNorm, self).__init__() self.gamma = nn.Parameter(torch.ones(hidden_size)) self.beta = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.gamma * x + self.beta class BertSelfAttention(nn.Module): def __init__(self, config: 'BertConfig'): super().__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): """ 拼接multi head的size """ new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, attention_mask, output_attentions=True): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(hidden_states) mixed_value_layer = self.value(hidden_states) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_scores = attention_scores + attention_mask attention_probs = nn.Softmax(dim=-1)(attention_scores) attention_probs = self.dropout(attention_probs) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) if output_attentions: return context_layer, attention_probs return context_layer, None class BertSelfOutput(nn.Module): """ Self Attention的输出 """ def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states class BertAttentionNew(nn.Module): """ Self Attention + Attention Output """ def __init__(self, config): super().__init__() self.self = BertSelfAttention(config) self.output = BertSelfOutput(config) def forward(self, input_0, input_1): primals_1 = self.self.query.weight primals_2 = self.self.query.bias primals_4 = self.self.key.weight primals_5 = self.self.key.bias primals_6 = self.self.value.weight primals_7 = self.self.value.bias primals_9 = self.output.dense.weight primals_10 = self.output.dense.bias primals_11 = self.output.LayerNorm.gamma primals_12 = self.output.LayerNorm.beta primals_3 = input_0 primals_8 = 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], output[1]
kalanile/JDQA
BertAttention
false
7,017
[ "MIT" ]
1
68e1d0259d316b3577a1f2fafa773b50f1885762
https://github.com/kalanile/JDQA/tree/68e1d0259d316b3577a1f2fafa773b50f1885762
GlobalSoftMaxPooling
import torch import torch.nn as nn class GlobalSoftMaxPooling(nn.Module): def __init__(self, dim=0): super(self.__class__, self).__init__() self.dim = dim def forward(self, x): return torch.sum(x * torch.softmax(x, dim=self.dim), dim=self.dim) 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 math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (192 + 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_mul_sum_1(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) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tl.load(in_ptr1 + (64 + x0), xmask) tmp4 = tl.load(in_ptr1 + (128 + x0), xmask) tmp6 = tl.load(in_ptr1 + (192 + x0), xmask) tmp10 = tl.load(in_ptr0 + (64 + x0), xmask) tmp14 = tl.load(in_ptr0 + (128 + x0), xmask) tmp18 = tl.load(in_ptr0 + (192 + x0), xmask) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp1 / tmp7 tmp9 = tmp0 * tmp8 tmp11 = tmp2 / tmp7 tmp12 = tmp10 * tmp11 tmp13 = tmp9 + tmp12 tmp15 = tmp4 / tmp7 tmp16 = tmp14 * tmp15 tmp17 = tmp13 + tmp16 tmp19 = tmp6 / tmp7 tmp20 = tmp18 * tmp19 tmp21 = tmp17 + tmp20 tl.store(out_ptr0 + x0, tmp21, 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__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_mul_sum_1[grid(64)](arg0_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del buf0 return buf1, class GlobalSoftMaxPoolingNew(nn.Module): def __init__(self, dim=0): super(self.__class__, self).__init__() self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kbrodt/clog-loss
GlobalSoftMaxPooling
false
7,018
[ "MIT" ]
1
0831b3a01b079609a71490bb921633110927206c
https://github.com/kbrodt/clog-loss/tree/0831b3a01b079609a71490bb921633110927206c
TemporalFusion
import torch import torch.nn as nn class TemporalFusion(nn.Module): def __init__(self, nf, n_frame): super(TemporalFusion, self).__init__() self.n_frame = n_frame self.ref_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.nbr_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.up_conv = nn.Conv2d(nf * n_frame, nf * 4, 1, 1, bias=True) self.ps = nn.PixelShuffle(2) self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True) def forward(self, x): B, N, C, H, W = x.size() emb_ref = self.ref_conv(x[:, N // 2, :, :, :].clone()) emb = self.nbr_conv(x.view(-1, C, H, W)).view(B, N, C, H, W) cor_l = [] for i in range(N): cor = torch.sum(emb[:, i, :, :, :] * emb_ref, dim=1, keepdim=True) cor_l.append(cor) cor_prob = torch.sigmoid(torch.cat(cor_l, dim=1)) cor_prob = cor_prob.unsqueeze(2).repeat(1, 1, C, 1, 1).view(B, -1, H, W ) aggr_fea = x.view(B, -1, H, W) * cor_prob fea = self.lrelu(self.up_conv(aggr_fea)) out = self.ps(fea) return out def get_inputs(): return [torch.rand([4, 4, 4, 4, 4])] def get_init_inputs(): return [[], {'nf': 4, 'n_frame': 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 = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x1 = xindex // 64 x2 = xindex tmp0 = tl.load(in_ptr0 + (128 + x0 + 256 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, 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_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_cat_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 + 256 * x2), tmp4 & xmask, eviction_policy ='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 * tmp6 tmp8 = tl.load(in_ptr0 + (16 + x0 + 256 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tmp8 * tmp9 tmp11 = tmp7 + tmp10 tmp12 = tl.load(in_ptr0 + (32 + x0 + 256 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp13 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp14 = tmp12 * tmp13 tmp15 = tmp11 + tmp14 tmp16 = tl.load(in_ptr0 + (48 + x0 + 256 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tmp16 * tmp17 tmp19 = tmp15 + tmp18 tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp4, tmp19, tmp20) tmp22 = tmp0 >= tmp3 tmp23 = tl.full([1], 2, tl.int64) tmp24 = tmp0 < tmp23 tmp25 = tmp22 & tmp24 tmp26 = tl.load(in_ptr0 + (64 + x0 + 256 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr1 + (x0 + 64 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tmp26 * tmp27 tmp29 = tl.load(in_ptr0 + (80 + x0 + 256 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp30 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp31 = tmp29 * tmp30 tmp32 = tmp28 + tmp31 tmp33 = tl.load(in_ptr0 + (96 + x0 + 256 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp34 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp35 = tmp33 * tmp34 tmp36 = tmp32 + tmp35 tmp37 = tl.load(in_ptr0 + (112 + x0 + 256 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp38 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), tmp25 & xmask, eviction_policy='evict_last', other=0.0) tmp39 = tmp37 * tmp38 tmp40 = tmp36 + tmp39 tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype) tmp42 = tl.where(tmp25, tmp40, tmp41) tmp43 = tmp0 >= tmp23 tmp44 = tl.full([1], 3, tl.int64) tmp45 = tmp0 < tmp44 tmp46 = tmp43 & tmp45 tmp47 = tl.load(in_ptr0 + (128 + x0 + 256 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp48 = tl.load(in_ptr1 + (x0 + 64 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp49 = tmp47 * tmp48 tmp50 = tl.load(in_ptr0 + (144 + x0 + 256 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp51 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp52 = tmp50 * tmp51 tmp53 = tmp49 + tmp52 tmp54 = tl.load(in_ptr0 + (160 + x0 + 256 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp55 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp56 = tmp54 * tmp55 tmp57 = tmp53 + tmp56 tmp58 = tl.load(in_ptr0 + (176 + x0 + 256 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp59 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp60 = tmp58 * tmp59 tmp61 = tmp57 + tmp60 tmp62 = tl.full(tmp61.shape, 0.0, tmp61.dtype) tmp63 = tl.where(tmp46, tmp61, tmp62) tmp64 = tmp0 >= tmp44 tl.full([1], 4, tl.int64) tmp67 = tl.load(in_ptr0 + (192 + x0 + 256 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp68 = tl.load(in_ptr1 + (x0 + 64 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp69 = tmp67 * tmp68 tmp70 = tl.load(in_ptr0 + (208 + x0 + 256 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp71 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp72 = tmp70 * tmp71 tmp73 = tmp69 + tmp72 tmp74 = tl.load(in_ptr0 + (224 + x0 + 256 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp75 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp76 = tmp74 * tmp75 tmp77 = tmp73 + tmp76 tmp78 = tl.load(in_ptr0 + (240 + x0 + 256 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp79 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), tmp64 & xmask, eviction_policy='evict_last', other=0.0) tmp80 = tmp78 * tmp79 tmp81 = tmp77 + tmp80 tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype) tmp83 = tl.where(tmp64, tmp81, tmp82) tmp84 = tl.where(tmp46, tmp63, tmp83) tmp85 = tl.where(tmp25, tmp42, tmp84) tmp86 = tl.where(tmp4, tmp21, tmp85) tl.store(out_ptr0 + x3, tmp86, xmask) @triton.jit def triton_poi_fused_mul_4(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 x0 = xindex % 16 x1 = xindex // 16 % 16 x2 = xindex // 256 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 16 * (x1 // 4) + 64 * x2), xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x3, tmp3, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_pixel_shuffle_5( in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 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 x7 = xindex y8 = yindex y6 = yindex % 16 x4 = xindex % 4 x5 = xindex // 4 y0 = yindex % 2 y1 = yindex // 2 % 2 y9 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x7 + 16 * y8), xmask & ymask, eviction_policy ='evict_last') tmp1 = tl.load(in_ptr1 + y6, ymask, 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) tmp8 = tmp7 > tmp3 tl.store(out_ptr0 + (y0 + 2 * x4 + 8 * y1 + 16 * x5 + 64 * y9), tmp7, xmask & ymask) tl.store(out_ptr1 + (x7 + 16 * y8), tmp8, 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, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (16, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_7, (16,), (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)](primals_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (16, 4, 4, 4), (64, 16, 4, 1), 0), primals_4, stride=(1, 1), padding =(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (16, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_2[grid(1024)](buf4, primals_5, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_cat_3[grid(256)](buf4, buf2, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.float32 ) triton_poi_fused_mul_4[grid(1024)](primals_1, buf5, buf6, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf7 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 16, 4, 4), (256, 16, 4, 1)) buf8 = empty_strided_cuda((4, 4, 4, 2, 4, 2), (256, 64, 16, 8, 2, 1 ), torch.float32) buf9 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_pixel_shuffle_5[ grid(64, 16)](buf7, primals_7, buf8, buf9, 64, 16, XBLOCK=16, YBLOCK=32, num_warps=4, num_stages=1) del buf7 del primals_7 return (reinterpret_tensor(buf8, (4, 4, 8, 8), (256, 64, 8, 1), 0), primals_1, primals_2, primals_4, primals_6, buf0, buf2, buf4, buf5, buf6, buf9) class TemporalFusionNew(nn.Module): def __init__(self, nf, n_frame): super(TemporalFusionNew, self).__init__() self.n_frame = n_frame self.ref_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.nbr_conv = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.up_conv = nn.Conv2d(nf * n_frame, nf * 4, 1, 1, bias=True) self.ps = nn.PixelShuffle(2) self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True) def forward(self, input_0): primals_2 = self.ref_conv.weight primals_3 = self.ref_conv.bias primals_4 = self.nbr_conv.weight primals_5 = self.nbr_conv.bias primals_6 = self.up_conv.weight primals_7 = self.up_conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
juyongjiang/Simple-SR
TemporalFusion
false
7,019
[ "MIT" ]
1
76820511abc04fbe6e4a79d23c67aee97406d563
https://github.com/juyongjiang/Simple-SR/tree/76820511abc04fbe6e4a79d23c67aee97406d563
ConvRelu
import torch from torch import nn import torch.nn.functional as F import torch.cuda import torch.backends.cudnn import torch.backends.mkl import torch.backends.cuda import torch.backends.quantized class ConvRelu(nn.Module): def __init__(self): super(ConvRelu, self).__init__() self.conv = torch.nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding= (4, 2), dilation=(3, 1)) def forward(self, x): return F.relu(self.conv(x), inplace=True) def get_inputs(): return [torch.rand([4, 16, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn import torch.cuda import torch.backends.cudnn import torch.backends.mkl import torch.backends.cuda import torch.backends.quantized 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 = 278784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x1 = xindex // 2112 % 33 x0 = xindex % 2112 x3 = xindex // 2112 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + (x0 + 2176 * x3), tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (33, 16, 3, 5), (240, 15, 5, 1)) assert_size_stride(primals_2, (33,), (1,)) assert_size_stride(primals_3, (4, 16, 64, 64), (65536, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 1), padding=(4, 2), dilation=(3, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 33, 33, 64), (69696, 2112, 64, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 33, 33, 64), (71808, 2176, 64, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(278784)]( buf1, primals_2, buf2, 278784, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 return buf1, primals_1, primals_3, buf2 class ConvReluNew(nn.Module): def __init__(self): super(ConvReluNew, self).__init__() self.conv = torch.nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding= (4, 2), dilation=(3, 1)) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
kevin-14/intel-extension-for-pytorch
ConvRelu
false
7,020
[ "Apache-2.0" ]
1
f0cdcc602658340a957a964447d8e76bf413f66a
https://github.com/kevin-14/intel-extension-for-pytorch/tree/f0cdcc602658340a957a964447d8e76bf413f66a
DenseNet2D_up_block_concat
import torch import torch.nn as nn class DenseNet2D_up_block_concat(nn.Module): def __init__(self, skip_channels, input_channels, output_channels, up_stride, dropout=False, prob=0): super(DenseNet2D_up_block_concat, self).__init__() self.conv11 = nn.Conv2d(skip_channels + input_channels, output_channels, kernel_size=(1, 1), padding=(0, 0)) self.conv12 = nn.Conv2d(output_channels, output_channels, kernel_size=(3, 3), padding=(1, 1)) self.conv21 = nn.Conv2d(skip_channels + input_channels + output_channels, output_channels, kernel_size=(1, 1), padding=( 0, 0)) self.conv22 = nn.Conv2d(output_channels, output_channels, kernel_size=(3, 3), padding=(1, 1)) self.relu = nn.LeakyReLU() self.up_stride = up_stride self.dropout = dropout self.dropout1 = nn.Dropout(p=prob) self.dropout2 = nn.Dropout(p=prob) def forward(self, prev_feature_map, x): x = nn.functional.interpolate(x, scale_factor=self.up_stride, mode= 'bilinear') x = torch.cat((x, prev_feature_map), dim=1) if self.dropout: x1 = self.relu(self.dropout1(self.conv12(self.conv11(x)))) x21 = torch.cat((x, x1), dim=1) out = self.relu(self.dropout2(self.conv22(self.conv21(x21)))) else: x1 = self.relu(self.conv12(self.conv11(x))) x21 = torch.cat((x, x1), dim=1) out = self.relu(self.conv22(self.conv21(x21))) return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'skip_channels': 4, 'input_channels': 4, 'output_channels': 4, 'up_stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_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 x2 = xindex // 16 x4 = xindex // 64 x7 = xindex % 64 tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = tl.full([1], 1, tl.int64) tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 3, tl.int64) tmp13 = triton_helpers.minimum(tmp11, tmp12) tmp14 = x0 tmp15 = tmp14.to(tl.float32) tmp16 = tmp15 + tmp2 tmp17 = tmp16 * tmp4 tmp18 = tmp17 - tmp2 tmp19 = triton_helpers.maximum(tmp18, tmp7) tmp20 = tmp19.to(tl.int32) tmp21 = tmp20 + tmp10 tmp22 = triton_helpers.minimum(tmp21, tmp12) tmp23 = tl.load(in_ptr0 + (tmp22 + 4 * tmp13 + 16 * x2), xmask, eviction_policy='evict_last') tmp24 = tl.load(in_ptr0 + (tmp20 + 4 * tmp13 + 16 * x2), xmask, eviction_policy='evict_last') tmp25 = tmp23 - tmp24 tmp26 = tmp20.to(tl.float32) tmp27 = tmp19 - tmp26 tmp28 = triton_helpers.maximum(tmp27, tmp7) tmp29 = triton_helpers.minimum(tmp28, tmp4) tmp30 = tmp25 * tmp29 tmp31 = tmp24 + tmp30 tmp32 = tl.load(in_ptr0 + (tmp20 + 4 * tmp9 + 16 * x2), xmask, eviction_policy='evict_last') tmp33 = tl.load(in_ptr0 + (tmp22 + 4 * tmp9 + 16 * x2), xmask, eviction_policy='evict_last') tmp34 = tmp33 - tmp32 tmp35 = tmp34 * tmp29 tmp36 = tmp32 + tmp35 tmp37 = tmp31 - tmp36 tmp38 = tmp9.to(tl.float32) tmp39 = tmp8 - tmp38 tmp40 = triton_helpers.maximum(tmp39, tmp7) tmp41 = triton_helpers.minimum(tmp40, tmp4) tmp42 = tmp37 * tmp41 tmp43 = tmp36 + tmp42 tl.store(out_ptr0 + (x7 + 128 * x4), tmp43, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 x1 = xindex // 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 128 * x1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_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 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_cat_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 768 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 12 x0 = xindex % 16 x2 = xindex // 192 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 128 * x2), tmp4 & xmask, other=0.0 ) tmp6 = tmp0 >= tmp3 tl.full([1], 12, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp6 & xmask, other=0.0).to(tl.int1) tmp10 = tl.load(in_ptr2 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp6 & xmask, other=0.0) tmp11 = tl.load(in_ptr3 + (-8 + x1), tmp6 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp10 + tmp11 tmp13 = 0.01 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 + x3, tmp18, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_5(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.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) def call(args): (primals_1, primals_2, primals_3, 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, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 8, 1, 1), (8, 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, 12, 1, 1), (12, 1, 1, 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,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf4 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) buf2 = reinterpret_tensor(buf4, (4, 4, 4, 4), (128, 16, 4, 1), 0) get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid (256)](primals_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf3 = reinterpret_tensor(buf4, (4, 4, 4, 4), (128, 16, 4, 1), 64) triton_poi_fused_cat_1[grid(256)](primals_2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf5 = extern_kernels.convolution(buf4, primals_3, 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 = buf5 del buf5 triton_poi_fused_convolution_2[grid(256)](buf6, primals_4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_4 buf7 = extern_kernels.convolution(buf6, primals_5, 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) triton_poi_fused_convolution_leaky_relu_3[grid(256)](buf7, primals_6, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.float32 ) triton_poi_fused_cat_4[grid(768)](buf4, buf8, buf7, primals_6, buf9, 768, XBLOCK=256, num_warps=4, num_stages=1) del primals_6 buf10 = extern_kernels.convolution(buf9, primals_7, 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 = buf10 del buf10 triton_poi_fused_convolution_2[grid(256)](buf11, primals_8, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_8 buf12 = extern_kernels.convolution(buf11, primals_9, 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_convolution_leaky_relu_5[grid(256)](buf12, primals_10, buf13, buf14, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf12 del primals_10 return (buf14, primals_3, primals_5, primals_7, primals_9, buf4, buf6, buf8, buf9, buf11, buf13) class DenseNet2D_up_block_concatNew(nn.Module): def __init__(self, skip_channels, input_channels, output_channels, up_stride, dropout=False, prob=0): super(DenseNet2D_up_block_concatNew, self).__init__() self.conv11 = nn.Conv2d(skip_channels + input_channels, output_channels, kernel_size=(1, 1), padding=(0, 0)) self.conv12 = nn.Conv2d(output_channels, output_channels, kernel_size=(3, 3), padding=(1, 1)) self.conv21 = nn.Conv2d(skip_channels + input_channels + output_channels, output_channels, kernel_size=(1, 1), padding=( 0, 0)) self.conv22 = nn.Conv2d(output_channels, output_channels, kernel_size=(3, 3), padding=(1, 1)) self.relu = nn.LeakyReLU() self.up_stride = up_stride self.dropout = dropout self.dropout1 = nn.Dropout(p=prob) self.dropout2 = nn.Dropout(p=prob) def forward(self, input_0, input_1): primals_3 = self.conv11.weight primals_4 = self.conv11.bias primals_5 = self.conv12.weight primals_6 = self.conv12.bias primals_7 = self.conv21.weight primals_8 = self.conv21.bias primals_9 = self.conv22.weight primals_10 = self.conv22.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]) return output[0]
kbarkevich/RITnet
DenseNet2D_up_block_concat
false
7,021
[ "MIT" ]
1
5df66c656734aecd2987cf27d9359416b136af2e
https://github.com/kbarkevich/RITnet/tree/5df66c656734aecd2987cf27d9359416b136af2e
BiLinearSim
from _paritybench_helpers import _mock_config import torch from torch.optim.lr_scheduler import * class BiLinearSim(torch.nn.Module): def __init__(self, config): super().__init__() self.linear = torch.nn.Linear(config.hidden_size, config. hidden_size, bias=False) def forward(self, src, tgt): src_ = self.linear(src) output = torch.matmul(src_, tgt.transpose(2, 1)) return output def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 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.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 = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tl.store(out_ptr0 + x4, tmp0, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 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.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(256)](primals_3, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0), out=buf2) del buf0 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (16, 4, 4), (16, 1, 4), 0) class BiLinearSimNew(torch.nn.Module): def __init__(self, config): super().__init__() self.linear = torch.nn.Linear(config.hidden_size, config. hidden_size, bias=False) def forward(self, input_0, input_1): primals_1 = self.linear.weight primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
kiminh/mt-dnn
BiLinearSim
false
7,022
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
FreqEncoder
import torch import torch.nn as nn class FreqEncoder(nn.Module): def __init__(self, input_dim, max_freq_log2, N_freqs, log_sampling=True, include_input=True, periodic_fns=(torch.sin, torch.cos)): super().__init__() self.input_dim = input_dim self.include_input = include_input self.periodic_fns = periodic_fns self.output_dim = 0 if self.include_input: self.output_dim += self.input_dim self.output_dim += self.input_dim * N_freqs * len(self.periodic_fns) if log_sampling: self.freq_bands = 2.0 ** torch.linspace(0.0, max_freq_log2, N_freqs ) else: self.freq_bands = torch.linspace(2.0 ** 0.0, 2.0 ** max_freq_log2, N_freqs) self.freq_bands = self.freq_bands.numpy().tolist() def forward(self, input, **kwargs): out = [] if self.include_input: out.append(input) for i in range(len(self.freq_bands)): freq = self.freq_bands[i] for p_fn in self.periodic_fns: out.append(p_fn(input * freq)) out = torch.cat(out, dim=-1) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'max_freq_log2': 4, 'N_freqs': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_cos_mul_sin_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.sin(tmp2) tmp4 = tl_math.cos(tmp2) tmp5 = 2.5198421478271484 tmp6 = tmp0 * tmp5 tmp7 = tl_math.sin(tmp6) tmp8 = tl_math.cos(tmp6) tmp9 = 6.349603652954102 tmp10 = tmp0 * tmp9 tmp11 = tl_math.sin(tmp10) tmp12 = tl_math.cos(tmp10) tmp13 = 16.0 tmp14 = tmp0 * tmp13 tmp15 = tl_math.sin(tmp14) tmp16 = tl_math.cos(tmp14) tl.store(out_ptr0 + (x0 + 36 * x1), tmp0, xmask) tl.store(out_ptr1 + (x0 + 36 * x1), tmp3, xmask) tl.store(out_ptr2 + (x0 + 36 * x1), tmp4, xmask) tl.store(out_ptr3 + (x0 + 36 * x1), tmp7, xmask) tl.store(out_ptr4 + (x0 + 36 * x1), tmp8, xmask) tl.store(out_ptr5 + (x0 + 36 * x1), tmp11, xmask) tl.store(out_ptr6 + (x0 + 36 * x1), tmp12, xmask) tl.store(out_ptr7 + (x0 + 36 * x1), tmp15, xmask) tl.store(out_ptr8 + (x0 + 36 * x1), tmp16, 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) buf9 = empty_strided_cuda((4, 4, 4, 36), (576, 144, 36, 1), torch. float32) buf0 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 0) buf1 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 4) buf2 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 8) buf3 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 12) buf4 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 16) buf5 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 20) buf6 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 24) buf7 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 28) buf8 = reinterpret_tensor(buf9, (4, 4, 4, 4), (576, 144, 36, 1), 32) get_raw_stream(0) triton_poi_fused_cat_cos_mul_sin_0[grid(256)](arg0_1, buf0, buf1, buf2, buf3, buf4, buf5, buf6, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf9, class FreqEncoderNew(nn.Module): def __init__(self, input_dim, max_freq_log2, N_freqs, log_sampling=True, include_input=True, periodic_fns=(torch.sin, torch.cos)): super().__init__() self.input_dim = input_dim self.include_input = include_input self.periodic_fns = periodic_fns self.output_dim = 0 if self.include_input: self.output_dim += self.input_dim self.output_dim += self.input_dim * N_freqs * len(self.periodic_fns) if log_sampling: self.freq_bands = 2.0 ** torch.linspace(0.0, max_freq_log2, N_freqs ) else: self.freq_bands = torch.linspace(2.0 ** 0.0, 2.0 ** max_freq_log2, N_freqs) self.freq_bands = self.freq_bands.numpy().tolist() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kevin-thankyou-lin/torch-ngp
FreqEncoder
false
7,023
[ "MIT" ]
1
2bb55fb09512e7e8680db434d787c6bea1fa1cda
https://github.com/kevin-thankyou-lin/torch-ngp/tree/2bb55fb09512e7e8680db434d787c6bea1fa1cda
Discriminator
import torch import torch.nn as nn class Discriminator(nn.Module): def __init__(self): super(Discriminator, self).__init__() self.conv1 = nn.Conv2d(2, 16, 4, 2, 1, bias=False) self.act1 = nn.LeakyReLU(0.2, inplace=False) self.conv2 = nn.Conv2d(16, 32, 4, 2, 1, bias=False) self.act2 = nn.LeakyReLU(0.2, inplace=False) self.conv3 = nn.Conv2d(32, 64, 4, 2, 1, bias=False) self.act3 = nn.LeakyReLU(0.2, inplace=False) self.conv4 = nn.Conv2d(64, 128, 4, 2, 1, bias=False) self.act4 = nn.LeakyReLU(0.2, inplace=False) self.conv5 = nn.Conv2d(128, 128, 4, 2, 1, bias=False) self.act5 = nn.LeakyReLU(0.2, inplace=False) self.conv6 = nn.Conv2d(128, 128, 4, 2, 1, bias=False) self.act6 = nn.LeakyReLU(0.2, inplace=False) self.conv7 = nn.Conv2d(128, 2, 3, 1, bias=False) self.pool7 = nn.MaxPool2d(2, stride=2) def forward(self, labels): conv1 = self.act1(self.conv1(labels)) conv2 = self.act2(self.conv2(conv1)) conv3 = self.act3(self.conv3(conv2)) conv4 = self.act4(self.conv4(conv3)) conv5 = self.act5(self.conv5(conv4)) conv6 = self.act6(self.conv6(conv5)) conv7 = self.conv7(conv6) pool7 = self.pool7(conv7) return torch.sigmoid(pool7) def get_inputs(): return [torch.rand([4, 2, 256, 256])] 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_leaky_relu_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_leaky_relu_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_leaky_relu_4(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_leaky_relu_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp5, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_sigmoid_6(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) 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) tmp17 = tl.sigmoid(tmp16) tl.store(out_ptr0 + x0, tmp15, xmask) tl.store(out_ptr1 + x0, tmp17, 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, (16, 2, 4, 4), (32, 16, 4, 1)) assert_size_stride(primals_2, (4, 2, 256, 256), (131072, 65536, 256, 1)) assert_size_stride(primals_3, (32, 16, 4, 4), (256, 16, 4, 1)) assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_5, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_6, (128, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_7, (128, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_8, (2, 128, 3, 3), (1152, 9, 3, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 128, 128), (262144, 16384, 128, 1)) buf1 = empty_strided_cuda((4, 16, 128, 128), (262144, 16384, 128, 1 ), torch.bool) buf2 = empty_strided_cuda((4, 16, 128, 128), (262144, 16384, 128, 1 ), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(1048576)](buf0, buf1, buf2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 buf3 = extern_kernels.convolution(buf2, primals_3, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf4 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.bool) buf5 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(524288)](buf3, buf4, buf5, 524288, XBLOCK=512, num_warps=8, num_stages=1) del buf3 buf6 = extern_kernels.convolution(buf5, primals_4, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf7 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) buf8 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.float32) triton_poi_fused_leaky_relu_2[grid(262144)](buf6, buf7, buf8, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf6 buf9 = extern_kernels.convolution(buf8, primals_5, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 128, 16, 16), (32768, 256, 16, 1)) buf10 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) buf11 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) triton_poi_fused_leaky_relu_3[grid(131072)](buf9, buf10, buf11, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del buf9 buf12 = extern_kernels.convolution(buf11, primals_6, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 128, 8, 8), (8192, 64, 8, 1)) buf13 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch.bool ) buf14 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch. float32) triton_poi_fused_leaky_relu_4[grid(32768)](buf12, buf13, buf14, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf12 buf15 = extern_kernels.convolution(buf14, primals_7, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 128, 4, 4), (2048, 16, 4, 1)) buf16 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.bool ) buf17 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch. float32) triton_poi_fused_leaky_relu_5[grid(8192)](buf15, buf16, buf17, 8192, XBLOCK=256, num_warps=4, num_stages=1) del buf15 buf18 = extern_kernels.convolution(buf17, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 2, 2, 2), (8, 4, 2, 1)) buf19 = empty_strided_cuda((4, 2, 1, 1), (2, 1, 1, 1), torch.int8) buf20 = empty_strided_cuda((4, 2, 1, 1), (2, 1, 1, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_sigmoid_6[grid(8)](buf18, buf19, buf20, 8, XBLOCK=8, num_warps=1, num_stages=1) return (buf20, primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, buf1, buf2, buf4, buf5, buf7, buf8, buf10, buf11, buf13, buf14, buf16, buf17, buf18, buf19, buf20) class DiscriminatorNew(nn.Module): def __init__(self): super(DiscriminatorNew, self).__init__() self.conv1 = nn.Conv2d(2, 16, 4, 2, 1, bias=False) self.act1 = nn.LeakyReLU(0.2, inplace=False) self.conv2 = nn.Conv2d(16, 32, 4, 2, 1, bias=False) self.act2 = nn.LeakyReLU(0.2, inplace=False) self.conv3 = nn.Conv2d(32, 64, 4, 2, 1, bias=False) self.act3 = nn.LeakyReLU(0.2, inplace=False) self.conv4 = nn.Conv2d(64, 128, 4, 2, 1, bias=False) self.act4 = nn.LeakyReLU(0.2, inplace=False) self.conv5 = nn.Conv2d(128, 128, 4, 2, 1, bias=False) self.act5 = nn.LeakyReLU(0.2, inplace=False) self.conv6 = nn.Conv2d(128, 128, 4, 2, 1, bias=False) self.act6 = nn.LeakyReLU(0.2, inplace=False) self.conv7 = nn.Conv2d(128, 2, 3, 1, bias=False) self.pool7 = nn.MaxPool2d(2, stride=2) def forward(self, input_0): primals_1 = self.conv1.weight primals_3 = self.conv2.weight primals_4 = self.conv3.weight primals_5 = self.conv4.weight primals_6 = self.conv5.weight primals_7 = self.conv6.weight primals_8 = self.conv7.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
karavik18/Federated_Learning_for_Missing_MRI_Sequence
Discriminator
false
7,024
[ "Apache-2.0" ]
1
42924f8475f354e6b429d05867f99530aa485b96
https://github.com/karavik18/Federated_Learning_for_Missing_MRI_Sequence/tree/42924f8475f354e6b429d05867f99530aa485b96
CeCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class CeCriterion(Criterion): def __init__(self, alpha=1.0, name='Cross Entropy Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ if weight: loss = torch.mean(F.cross_entropy(input, target, reduce=False, ignore_index=ignore_index) * weight) else: loss = F.cross_entropy(input, target, ignore_index=ignore_index) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch.nn.modules.loss import _Loss 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 @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_div_mul_neg_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r3 = rindex r0 = rindex % 16 r2 = rindex // 64 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr1 + r3, None) tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp15 = tmp13 * tmp14 tmp16 = tl.broadcast_to(tmp15, [RBLOCK]) tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0)) tmp19 = -tmp18 tmp20 = 0.015625 tmp21 = tmp19 * tmp20 tmp22 = 1.0 tmp23 = tmp21 * tmp22 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp23, 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 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused__log_softmax_div_mul_neg_sum_1[grid(1)](buf2, buf0, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del buf0 return buf2, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class CeCriterionNew(Criterion): def __init__(self, alpha=1.0, name='Cross Entropy Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
CeCriterion
false
7,025
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
FC
import torch import torch.nn as nn import torch.nn.functional as F class FC(nn.Module): def __init__(self, cin, cout): super(FC, self).__init__() self.fc1 = nn.Linear(cin, 200) self.fc2 = nn.Linear(200, 100) self.fc3 = nn.Linear(100, 40) self.fc4 = nn.Linear(40, 10) self.fc5 = nn.Linear(10, 1) def forward(self, x): x = x.view(x.size(0), -1) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) x = F.relu(self.fc4(x)) x = self.fc5(x) return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'cin': 4, 'cout': 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_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 200 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 100 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 160 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 40 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 40 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 10 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (200, 4), (4, 1)) assert_size_stride(primals_3, (200,), (1,)) assert_size_stride(primals_4, (100, 200), (200, 1)) assert_size_stride(primals_5, (100,), (1,)) assert_size_stride(primals_6, (40, 100), (100, 1)) assert_size_stride(primals_7, (40,), (1,)) assert_size_stride(primals_8, (10, 40), (40, 1)) assert_size_stride(primals_9, (10,), (1,)) assert_size_stride(primals_10, (1, 10), (10, 1)) assert_size_stride(primals_11, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 200), (200, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 200), (1, 4), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(800)](buf1, primals_3, 800, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 100), (100, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (200, 100), ( 1, 200), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(400)](buf3, primals_5, 400, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 40), (40, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_6, (100, 40), (1, 100), 0), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_relu_2[grid(160)](buf5, primals_7, 160, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_8, (40, 10), (1, 40), 0), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_relu_3[grid(40)](buf7, primals_9, 40, XBLOCK=64, num_warps=1, num_stages=1) del primals_9 buf9 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_11, buf7, reinterpret_tensor( primals_10, (10, 1), (1, 10), 0), alpha=1, beta=1, out=buf9) del primals_11 return (buf9, primals_1, buf1, buf3, buf5, buf7, primals_10, primals_8, primals_6, primals_4) class FCNew(nn.Module): def __init__(self, cin, cout): super(FCNew, self).__init__() self.fc1 = nn.Linear(cin, 200) self.fc2 = nn.Linear(200, 100) self.fc3 = nn.Linear(100, 40) self.fc4 = nn.Linear(40, 10) self.fc5 = nn.Linear(10, 1) 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_8 = self.fc4.weight primals_9 = self.fc4.bias primals_10 = self.fc5.weight primals_11 = self.fc5.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]
kim-younghan/Instance3D
FC
false
7,026
[ "MIT" ]
1
2b7fc3f68594763c47033b55d692ab8ef6d0304a
https://github.com/kim-younghan/Instance3D/tree/2b7fc3f68594763c47033b55d692ab8ef6d0304a
MseCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class MseCriterion(Criterion): def __init__(self, alpha=1.0, name='MSE Regression Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ if weight: loss = torch.mean(F.mse_loss(input.squeeze(), target, reduce= False) * weight.reshape((target.shape[0], 1))) else: loss = F.mse_loss(input.squeeze(), target) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch.nn.modules.loss import _Loss 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 @triton.jit def triton_per_fused_mse_loss_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tmp9 = 1.0 tmp10 = tmp8 * tmp9 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp10, 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_mse_loss_mul_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class MseCriterionNew(Criterion): def __init__(self, alpha=1.0, name='MSE Regression Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
MseCriterion
false
7,027
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
Conv3D
import torch import torch.nn as nn import torch.nn.functional as F class Conv3D(nn.Module): def __init__(self, cin, cout): super(Conv3D, self).__init__() self.conv1 = nn.Conv2d(cin, 8, 3, 1, 1) self.conv2 = nn.Conv2d(8, 16, 3, 1, 1) self.conv3 = nn.Conv2d(16, 32, 3, 1, 1) self.conv4 = nn.Conv2d(32, 16, 3, 1, 1) self.conv5 = nn.Conv2d(16, 8, 4, 2, 1) self.conv6 = nn.Conv2d(8, cout, 4, 3, 1) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = F.relu(self.conv4(x)) x = F.relu(self.conv5(x)) x = F.relu(self.conv6(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'cin': 4, 'cout': 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 = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') 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_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_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 // 16 % 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_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 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_4(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (8, 4, 3, 3), (36, 9, 3, 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, (16, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (32, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (16, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (8, 16, 4, 4), (256, 16, 4, 1)) assert_size_stride(primals_11, (8,), (1,)) assert_size_stride(primals_12, (4, 8, 4, 4), (128, 16, 4, 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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 4, 4), (128, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(512)](buf1, primals_2, 512, 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, 16, 4, 4), (256, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(1024)](buf3, primals_5, 1024, XBLOCK=256, 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, 32, 4, 4), (512, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(2048)](buf5, primals_7, 2048, XBLOCK=128, 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, 16, 4, 4), (256, 16, 4, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_1[grid(1024)](buf7, primals_9, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf8 = extern_kernels.convolution(buf7, primals_10, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 8, 2, 2), (32, 4, 2, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_3[grid(128)](buf9, primals_11, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_11 buf10 = extern_kernels.convolution(buf9, primals_12, stride=(3, 3), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 4, 1, 1), (4, 1, 1, 1)) buf11 = buf10 del buf10 buf12 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_4[grid(16)](buf11, primals_13, buf12, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_13 return (buf11, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, buf1, buf3, buf5, buf7, buf9, buf12) class Conv3DNew(nn.Module): def __init__(self, cin, cout): super(Conv3DNew, self).__init__() self.conv1 = nn.Conv2d(cin, 8, 3, 1, 1) self.conv2 = nn.Conv2d(8, 16, 3, 1, 1) self.conv3 = nn.Conv2d(16, 32, 3, 1, 1) self.conv4 = nn.Conv2d(32, 16, 3, 1, 1) self.conv5 = nn.Conv2d(16, 8, 4, 2, 1) self.conv6 = nn.Conv2d(8, cout, 4, 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_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_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]
kim-younghan/Instance3D
Conv3D
false
7,028
[ "MIT" ]
1
2b7fc3f68594763c47033b55d692ab8ef6d0304a
https://github.com/kim-younghan/Instance3D/tree/2b7fc3f68594763c47033b55d692ab8ef6d0304a
KlCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class KlCriterion(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """input/target: logits """ input = input.float() target = target.float() loss = F.kl_div(F.log_softmax(input, dim=-1, dtype=torch.float32), F.softmax(target, dim=-1, dtype=torch.float32), reduction= 'batchmean') loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch.nn.modules.loss import _Loss 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 @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) 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__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_red_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl. constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp34 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp17 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp18 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp23 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp26 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = libdevice.isnan(tmp8).to(tl.int1) tmp10 = 0.0 tmp11 = tmp8 == tmp10 tmp12 = tl_math.log(tmp8) tmp13 = tmp8 * tmp12 tmp14 = tl.where(tmp11, tmp10, tmp13) tmp15 = float('nan') tmp16 = tl.where(tmp9, tmp15, tmp14) tmp19 = tl_math.exp(tmp18) tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tl_math.log(tmp28) tmp30 = tmp17 - tmp29 tmp31 = tmp8 * tmp30 tmp32 = tmp16 - tmp31 tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK]) tmp35 = _tmp34 + tmp33 _tmp34 = tl.where(rmask, tmp35, _tmp34) tmp34 = tl.sum(_tmp34, 1)[:, None] tmp36 = 0.25 tmp37 = tmp34 * tmp36 tmp38 = 1.0 tmp39 = tmp37 * tmp38 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp39, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](arg0_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_red_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2[grid(1) ](buf4, buf0, buf2, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 return buf4, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class KlCriterionNew(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
KlCriterion
false
7,029
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
HLCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class HLCriterion(Criterion): def __init__(self, alpha=1.0, name='Hellinger Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1, reduction='batchmean'): """input/target: logits """ input = input.float() target = target.float() si = F.softmax(target.detach(), dim=-1, dtype=torch.float32).sqrt_() st = F.softmax(input.detach(), dim=-1, dtype=torch.float32).sqrt_() loss = F.mse_loss(si, st) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch.nn.modules.loss import _Loss 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 @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) 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_red_fused__softmax_mse_loss_mul_sqrt_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp23 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp10 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp11 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp14 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp16 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = libdevice.sqrt(tmp8) tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp17 = tmp15 + tmp16 tmp18 = tmp10 / tmp17 tmp19 = libdevice.sqrt(tmp18) tmp20 = tmp9 - tmp19 tmp21 = tmp20 * tmp20 tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp24 = _tmp23 + tmp22 _tmp23 = tl.where(rmask, tmp24, _tmp23) tmp23 = tl.sum(_tmp23, 1)[:, None] tmp25 = 256.0 tmp26 = tmp23 / tmp25 tmp27 = 1.0 tmp28 = tmp26 * tmp27 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp28, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_0[grid(256)](arg0_1, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_red_fused__softmax_mse_loss_mul_sqrt_1[grid(1)](buf4, buf0, buf1, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf1 return buf4, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class HLCriterionNew(Criterion): def __init__(self, alpha=1.0, name='Hellinger Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
HLCriterion
false
7,030
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
NsKlCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * def stable_kl(logit, target, epsilon=1e-06, reduce=True): logit = logit.view(-1, logit.size(-1)).float() target = target.view(-1, target.size(-1)).float() bs = logit.size(0) p = F.log_softmax(logit, 1).exp() y = F.log_softmax(target, 1).exp() rp = -(1.0 / (p + epsilon) - 1 + epsilon).detach().log() ry = -(1.0 / (y + epsilon) - 1 + epsilon).detach().log() if reduce: return (p * (rp - ry) * 2).sum() / bs else: return (p * (rp - ry) * 2).sum() class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class NsKlCriterion(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """input/target: logits """ input = input.float() target = target.float() loss = stable_kl(input, target.detach()) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn.functional as F from torch.nn.modules.loss import _Loss 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 @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 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_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp52 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp26 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp31 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp34 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) 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 tmp14 = tl_math.exp(tmp13) tmp15 = 1e-06 tmp16 = tmp14 + tmp15 tmp17 = tl.full([1, 1], 1, tl.int32) tmp18 = tmp17 / tmp16 tmp19 = 1.0 tmp20 = tmp18 * tmp19 tmp21 = tmp20 - tmp19 tmp22 = tmp21 + tmp15 tmp23 = tl_math.log(tmp22) tmp24 = -tmp23 tmp27 = tl_math.exp(tmp26) tmp29 = tl_math.exp(tmp28) tmp30 = tmp27 + tmp29 tmp32 = tl_math.exp(tmp31) tmp33 = tmp30 + tmp32 tmp35 = tl_math.exp(tmp34) tmp36 = tmp33 + tmp35 tmp37 = tl_math.log(tmp36) tmp38 = tmp25 - tmp37 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 + tmp15 tmp41 = tmp17 / tmp40 tmp42 = tmp41 * tmp19 tmp43 = tmp42 - tmp19 tmp44 = tmp43 + tmp15 tmp45 = tl_math.log(tmp44) tmp46 = -tmp45 tmp47 = tmp24 - tmp46 tmp48 = tmp14 * tmp47 tmp49 = 2.0 tmp50 = tmp48 * tmp49 tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK]) tmp53 = _tmp52 + tmp51 _tmp52 = tl.where(rmask, tmp53, _tmp52) tmp52 = tl.sum(_tmp52, 1)[:, None] tmp54 = 0.015625 tmp55 = tmp52 * tmp54 tmp56 = 1.0 tmp57 = tmp55 * tmp56 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp57, 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((64, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_0[grid(256)](arg1_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 triton_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1[ grid(1)](buf5, buf0, buf2, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 return buf5, def stable_kl(logit, target, epsilon=1e-06, reduce=True): logit = logit.view(-1, logit.size(-1)).float() target = target.view(-1, target.size(-1)).float() bs = logit.size(0) p = F.log_softmax(logit, 1).exp() y = F.log_softmax(target, 1).exp() rp = -(1.0 / (p + epsilon) - 1 + epsilon).detach().log() ry = -(1.0 / (y + epsilon) - 1 + epsilon).detach().log() if reduce: return (p * (rp - ry) * 2).sum() / bs else: return (p * (rp - ry) * 2).sum() class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class NsKlCriterionNew(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
NsKlCriterion
false
7,031
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
SelfAttentionWide
import torch from torch import nn import torch.nn.functional as F def mask_(matrices, maskval=0.0, mask_diagonal=True): """ Masks out all values in the given batch of matrices where i <= j holds, i < j if mask_diagonal is false In place operation :param tns: :return: """ _b, h, w = matrices.size() indices = torch.triu_indices(h, w, offset=0 if mask_diagonal else 1) matrices[:, indices[0], indices[1]] = maskval class SelfAttentionWide(nn.Module): def __init__(self, emb, heads=8, mask=False): """ :param emb: :param heads: :param mask: """ super().__init__() self.emb = emb self.heads = heads self.mask = mask self.tokeys = nn.Linear(emb, emb * heads, bias=False) self.toqueries = nn.Linear(emb, emb * heads, bias=False) self.tovalues = nn.Linear(emb, emb * heads, bias=False) self.unifyheads = nn.Linear(heads * emb, emb) def forward(self, x): """ @kewlcoder - Here, b: denotes the batch size t: denotes the max sequence length(max number of words/tokens in the sentence/input) e: the embedding dimensionality """ b, t, e = x.size() h = self.heads assert e == self.emb, f'Input embedding dim ({e}) should match layer embedding dim ({self.emb})' """ @kewlcoder - x(input) when fed to a linear layer (b,t,e) * (e, e*h) => (b,t,e*h) """ keys = self.tokeys(x).view(b, t, h, e) queries = self.toqueries(x).view(b, t, h, e) values = self.tovalues(x).view(b, t, h, e) """ Since the head and batch dimension are not next to each other, we need to transpose before we reshape. (This is costly, but it seems to be unavoidable.) """ keys = keys.transpose(1, 2).contiguous().view(b * h, t, e) queries = queries.transpose(1, 2).contiguous().view(b * h, t, e) values = values.transpose(1, 2).contiguous().view(b * h, t, e) queries = queries / e ** (1 / 4) keys = keys / e ** (1 / 4) """ @kewlcoder - we divide by sqrt(e) because in a 2D vector space if a vector has c value in each dimension, the aggregate vector becomes sqrt(2) * c. Thus, for n-dim vector space it would have an impact of sqrt(n). Thus, as dim(e) increases, the product would become bigger and bigger and to supress that, we divide by sqrt(e). For every item in the batch and for every head individually, compute dot = (Q*K/sqrt(emb)) """ dot = torch.bmm(queries, keys.transpose(1, 2)) """ @kewlcoder - Here, each element (i,j) of the sub-matrix (t,t) represents the attention weight to be given to word j for calculating the weighted attention generated vector for word i in the sequence(or vice-versa). """ assert dot.size() == (b * h, t, t) if self.mask: mask_(dot, maskval=float('-inf'), mask_diagonal=False) dot = F.softmax(dot, dim=2) out = torch.bmm(dot, values).view(b, h, t, e) """ can also use - https://pytorch.org/docs/stable/generated/torch.einsum.html https://github.com/pbloem/former/issues/4 """ out = out.transpose(1, 2).contiguous().view(b, t, h * e) """ @kewlcoder - (b,t,h*e)(h*e, e) => (b,t,e) -> We finally get attention weighted embedding/hidden layer that can be used for various downstream tasks. """ return self.unifyheads(out) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'emb': 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_div_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 % 4 x1 = xindex // 4 % 32 x2 = xindex // 128 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x1 % 8) + 32 * x2 + 128 * (x1 // 8) ), xmask) tmp1 = 0.7071067811865475 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_div_1(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 % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x2 % 8) + 32 * x1 + 128 * (x2 // 8) ), xmask) tmp1 = 0.7071067811865475 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused__softmax_2(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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_clone_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 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 % 8 x3 = xindex // 128 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 32 * x1 + 128 * x3), xmask) tl.store(out_ptr0 + x4, tmp0, xmask) @triton.jit def triton_poi_fused_clone_5(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 % 4 x1 = xindex // 4 % 8 x2 = xindex // 32 % 4 x3 = xindex // 128 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 128 * x3), xmask) tl.store(out_ptr0 + x4, tmp0, xmask) @triton.jit def triton_poi_fused_transpose_6(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 % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 128 * x1), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (32, 4), (4, 1)) assert_size_stride(primals_3, (32, 4), (4, 1)) assert_size_stride(primals_4, (32, 4), (4, 1)) assert_size_stride(primals_5, (4, 32), (32, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 32), (1, 4), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 32), (1, 4), 0), out=buf2) del primals_4 buf3 = empty_strided_cuda((32, 4, 4), (4, 128, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(512)](buf1, buf3, 512, XBLOCK=128, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf1, (32, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_div_1[grid(512)](buf0, buf4, 512, XBLOCK=256, num_warps=4, num_stages=1) buf5 = reinterpret_tensor(buf0, (32, 4, 4), (16, 4, 1), 0) del buf0 extern_kernels.bmm(buf3, reinterpret_tensor(buf4, (32, 4, 4), (16, 1, 4), 0), out=buf5) buf6 = empty_strided_cuda((32, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_2[grid(512)](buf5, buf6, 512, XBLOCK=256, num_warps=4, num_stages=1) buf7 = buf5 del buf5 triton_poi_fused__softmax_3[grid(512)](buf6, buf7, 512, XBLOCK=128, num_warps=4, num_stages=1) buf8 = reinterpret_tensor(buf6, (4, 8, 4, 4), (128, 16, 4, 1), 0) del buf6 triton_poi_fused_clone_4[grid(512)](buf2, buf8, 512, XBLOCK=128, num_warps=4, num_stages=1) buf9 = reinterpret_tensor(buf2, (32, 4, 4), (16, 4, 1), 0) del buf2 extern_kernels.bmm(buf7, reinterpret_tensor(buf8, (32, 4, 4), (16, 4, 1), 0), out=buf9) buf10 = empty_strided_cuda((4, 4, 8, 4), (128, 32, 4, 1), torch.float32 ) triton_poi_fused_clone_5[grid(512)](buf9, buf10, 512, XBLOCK=128, num_warps=4, num_stages=1) buf11 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(buf10, (16, 32), (32, 1), 0), reinterpret_tensor(primals_5, (32, 4), (1, 32), 0), alpha=1, beta=1, out=buf11) del primals_6 buf12 = reinterpret_tensor(buf9, (32, 4, 4), (16, 1, 4), 0) del buf9 triton_poi_fused_transpose_6[grid(512)](buf3, buf12, 512, XBLOCK= 128, num_warps=4, num_stages=1) del buf3 return reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0 ), buf7, reinterpret_tensor(buf10, (16, 32), (32, 1), 0 ), primals_5, reinterpret_tensor(buf8, (32, 4, 4), (16, 1, 4), 0 ), buf12, buf4 def mask_(matrices, maskval=0.0, mask_diagonal=True): """ Masks out all values in the given batch of matrices where i <= j holds, i < j if mask_diagonal is false In place operation :param tns: :return: """ _b, h, w = matrices.size() indices = torch.triu_indices(h, w, offset=0 if mask_diagonal else 1) matrices[:, indices[0], indices[1]] = maskval class SelfAttentionWideNew(nn.Module): def __init__(self, emb, heads=8, mask=False): """ :param emb: :param heads: :param mask: """ super().__init__() self.emb = emb self.heads = heads self.mask = mask self.tokeys = nn.Linear(emb, emb * heads, bias=False) self.toqueries = nn.Linear(emb, emb * heads, bias=False) self.tovalues = nn.Linear(emb, emb * heads, bias=False) self.unifyheads = nn.Linear(heads * emb, emb) def forward(self, input_0): primals_2 = self.tokeys.weight primals_3 = self.toqueries.weight primals_4 = self.tovalues.weight primals_5 = self.unifyheads.weight primals_6 = self.unifyheads.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
kewlcoder/former
SelfAttentionWide
false
7,032
[ "MIT" ]
1
975cbdeedc69dd4fc3df6732fffbeb1c020b6982
https://github.com/kewlcoder/former/tree/975cbdeedc69dd4fc3df6732fffbeb1c020b6982
JSCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class JSCriterion(Criterion): def __init__(self, alpha=1.0, name='JS Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1, reduction='batchmean'): """input/target: logits """ input = input.float() target = target.float() m = F.softmax(target.detach(), dim=-1, dtype=torch.float32 ) + F.softmax(input.detach(), dim=-1, dtype=torch.float32) m = 0.5 * m loss = F.kl_div(F.log_softmax(input, dim=-1, dtype=torch.float32), m, reduction=reduction) + F.kl_div(F.log_softmax(target, dim=-1, dtype=torch.float32), m, reduction=reduction) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch.nn.modules.loss import _Loss 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 @triton.jit def triton_poi_fused__log_softmax__softmax_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 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) tl.store(out_ptr1 + x2, tmp8, xmask) @triton.jit def triton_red_fused__log_softmax__softmax_add_div_mul_sub_sum_xlogy_1( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp46 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp65 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp10 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp13 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp29 = tl.load(in_ptr2 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp30 = tl.load(in_ptr2 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp32 = tl.load(in_ptr2 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp35 = tl.load(in_ptr2 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp38 = tl.load(in_ptr2 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp48 = tl.load(in_ptr3 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp49 = tl.load(in_ptr3 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp51 = tl.load(in_ptr3 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp54 = tl.load(in_ptr3 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp57 = tl.load(in_ptr3 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp12 = tmp10 + tmp11 tmp14 = tmp12 + tmp13 tmp16 = tmp14 + tmp15 tmp17 = tmp9 / tmp16 tmp18 = tmp8 + tmp17 tmp19 = 0.5 tmp20 = tmp18 * tmp19 tmp21 = libdevice.isnan(tmp20).to(tl.int1) tmp22 = 0.0 tmp23 = tmp20 == tmp22 tmp24 = tl_math.log(tmp20) tmp25 = tmp20 * tmp24 tmp26 = tl.where(tmp23, tmp22, tmp25) tmp27 = float('nan') tmp28 = tl.where(tmp21, tmp27, tmp26) tmp31 = tl_math.exp(tmp30) tmp33 = tl_math.exp(tmp32) tmp34 = tmp31 + tmp33 tmp36 = tl_math.exp(tmp35) tmp37 = tmp34 + tmp36 tmp39 = tl_math.exp(tmp38) tmp40 = tmp37 + tmp39 tmp41 = tl_math.log(tmp40) tmp42 = tmp29 - tmp41 tmp43 = tmp20 * tmp42 tmp44 = tmp28 - tmp43 tmp45 = tl.broadcast_to(tmp44, [XBLOCK, RBLOCK]) tmp47 = _tmp46 + tmp45 _tmp46 = tl.where(rmask, tmp47, _tmp46) tmp50 = tl_math.exp(tmp49) tmp52 = tl_math.exp(tmp51) tmp53 = tmp50 + tmp52 tmp55 = tl_math.exp(tmp54) tmp56 = tmp53 + tmp55 tmp58 = tl_math.exp(tmp57) tmp59 = tmp56 + tmp58 tmp60 = tl_math.log(tmp59) tmp61 = tmp48 - tmp60 tmp62 = tmp20 * tmp61 tmp63 = tmp28 - tmp62 tmp64 = tl.broadcast_to(tmp63, [XBLOCK, RBLOCK]) tmp66 = _tmp65 + tmp64 _tmp65 = tl.where(rmask, tmp66, _tmp65) tmp46 = tl.sum(_tmp46, 1)[:, None] tmp65 = tl.sum(_tmp65, 1)[:, None] tmp67 = 0.25 tmp68 = tmp46 * tmp67 tmp69 = tmp65 * tmp67 tmp70 = tmp68 + tmp69 tmp71 = 1.0 tmp72 = tmp70 * tmp71 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp72, 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) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax__softmax_0[grid(256)](arg1_1, buf0, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 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) triton_poi_fused__log_softmax__softmax_0[grid(256)](arg0_1, buf1, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf4 = empty_strided_cuda((), (), torch.float32) buf7 = buf4 del buf4 triton_red_fused__log_softmax__softmax_add_div_mul_sub_sum_xlogy_1[grid (1)](buf7, buf0, buf1, buf3, buf5, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf1 del buf3 del buf5 return buf7, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class JSCriterionNew(Criterion): def __init__(self, alpha=1.0, name='JS Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
JSCriterion
false
7,033
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
NsSymKlCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * def stable_kl(logit, target, epsilon=1e-06, reduce=True): logit = logit.view(-1, logit.size(-1)).float() target = target.view(-1, target.size(-1)).float() bs = logit.size(0) p = F.log_softmax(logit, 1).exp() y = F.log_softmax(target, 1).exp() rp = -(1.0 / (p + epsilon) - 1 + epsilon).detach().log() ry = -(1.0 / (y + epsilon) - 1 + epsilon).detach().log() if reduce: return (p * (rp - ry) * 2).sum() / bs else: return (p * (rp - ry) * 2).sum() class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class NsSymKlCriterion(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """input/target: logits """ input = input.float() target = target.float() loss = stable_kl(input, target.detach()) + stable_kl(target, input. detach()) loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn.functional as F from torch.nn.modules.loss import _Loss 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 @triton.jit def triton_poi_fused__log_softmax_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 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) tl.store(out_ptr1 + x2, tmp8, xmask) @triton.jit def triton_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp52 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp102 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp26 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp31 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp34 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp54 = tl.load(in_ptr2 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp55 = tl.load(in_ptr2 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp57 = tl.load(in_ptr2 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp60 = tl.load(in_ptr2 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp63 = tl.load(in_ptr2 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp76 = tl.load(in_ptr3 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp77 = tl.load(in_ptr3 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp79 = tl.load(in_ptr3 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp82 = tl.load(in_ptr3 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp85 = tl.load(in_ptr3 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) 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 tmp14 = tl_math.exp(tmp13) tmp15 = 1e-06 tmp16 = tmp14 + tmp15 tmp17 = tl.full([1, 1], 1, tl.int32) tmp18 = tmp17 / tmp16 tmp19 = 1.0 tmp20 = tmp18 * tmp19 tmp21 = tmp20 - tmp19 tmp22 = tmp21 + tmp15 tmp23 = tl_math.log(tmp22) tmp24 = -tmp23 tmp27 = tl_math.exp(tmp26) tmp29 = tl_math.exp(tmp28) tmp30 = tmp27 + tmp29 tmp32 = tl_math.exp(tmp31) tmp33 = tmp30 + tmp32 tmp35 = tl_math.exp(tmp34) tmp36 = tmp33 + tmp35 tmp37 = tl_math.log(tmp36) tmp38 = tmp25 - tmp37 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 + tmp15 tmp41 = tmp17 / tmp40 tmp42 = tmp41 * tmp19 tmp43 = tmp42 - tmp19 tmp44 = tmp43 + tmp15 tmp45 = tl_math.log(tmp44) tmp46 = -tmp45 tmp47 = tmp24 - tmp46 tmp48 = tmp14 * tmp47 tmp49 = 2.0 tmp50 = tmp48 * tmp49 tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK]) tmp53 = _tmp52 + tmp51 _tmp52 = tl.where(rmask, tmp53, _tmp52) tmp56 = tl_math.exp(tmp55) tmp58 = tl_math.exp(tmp57) tmp59 = tmp56 + tmp58 tmp61 = tl_math.exp(tmp60) tmp62 = tmp59 + tmp61 tmp64 = tl_math.exp(tmp63) tmp65 = tmp62 + tmp64 tmp66 = tl_math.log(tmp65) tmp67 = tmp54 - tmp66 tmp68 = tl_math.exp(tmp67) tmp69 = tmp68 + tmp15 tmp70 = tmp17 / tmp69 tmp71 = tmp70 * tmp19 tmp72 = tmp71 - tmp19 tmp73 = tmp72 + tmp15 tmp74 = tl_math.log(tmp73) tmp75 = -tmp74 tmp78 = tl_math.exp(tmp77) tmp80 = tl_math.exp(tmp79) tmp81 = tmp78 + tmp80 tmp83 = tl_math.exp(tmp82) tmp84 = tmp81 + tmp83 tmp86 = tl_math.exp(tmp85) tmp87 = tmp84 + tmp86 tmp88 = tl_math.log(tmp87) tmp89 = tmp76 - tmp88 tmp90 = tl_math.exp(tmp89) tmp91 = tmp90 + tmp15 tmp92 = tmp17 / tmp91 tmp93 = tmp92 * tmp19 tmp94 = tmp93 - tmp19 tmp95 = tmp94 + tmp15 tmp96 = tl_math.log(tmp95) tmp97 = -tmp96 tmp98 = tmp75 - tmp97 tmp99 = tmp68 * tmp98 tmp100 = tmp99 * tmp49 tmp101 = tl.broadcast_to(tmp100, [XBLOCK, RBLOCK]) tmp103 = _tmp102 + tmp101 _tmp102 = tl.where(rmask, tmp103, _tmp102) tmp52 = tl.sum(_tmp52, 1)[:, None] tmp102 = tl.sum(_tmp102, 1)[:, None] tmp104 = 0.015625 tmp105 = tmp52 * tmp104 tmp106 = tmp102 * tmp104 tmp107 = tmp105 + tmp106 tmp108 = 1.0 tmp109 = tmp107 * tmp108 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp109, 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((64, 4), (4, 1), torch.float32) buf7 = empty_strided_cuda((64, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_0[grid(256)](arg1_1, buf2, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 buf4 = empty_strided_cuda((), (), torch.float32) buf10 = buf4 del buf4 triton_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1[ grid(1)](buf10, buf0, buf2, buf5, buf7, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 del buf5 del buf7 return buf10, def stable_kl(logit, target, epsilon=1e-06, reduce=True): logit = logit.view(-1, logit.size(-1)).float() target = target.view(-1, target.size(-1)).float() bs = logit.size(0) p = F.log_softmax(logit, 1).exp() y = F.log_softmax(target, 1).exp() rp = -(1.0 / (p + epsilon) - 1 + epsilon).detach().log() ry = -(1.0 / (y + epsilon) - 1 + epsilon).detach().log() if reduce: return (p * (rp - ry) * 2).sum() / bs else: return (p * (rp - ry) * 2).sum() class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class NsSymKlCriterionNew(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
NsSymKlCriterion
false
7,034
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
BERTLhuc
from _paritybench_helpers import _mock_config import torch import torch.nn as nn from torch.nn.parameter import Parameter class BERTLhuc(nn.Module): def __init__(self, config): super(BERTLhuc, self).__init__() self.lhuc = Parameter(torch.zeros(config.hidden_size)) def forward(self, hidden_states): hidden_states = hidden_states * 2.0 * nn.functional.sigmoid(self.lhuc) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4)}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn from torch.nn.parameter 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_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) tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp1 = 2.0 tmp2 = tmp0 * tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tl.store(out_ptr0 + x2, 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, (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_1, primals_2, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf0, primals_1, primals_2 class BERTLhucNew(nn.Module): def __init__(self, config): super(BERTLhucNew, self).__init__() self.lhuc = Parameter(torch.zeros(config.hidden_size)) def forward(self, input_0): primals_2 = self.lhuc primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
DAQuestionAnswering/Bert-n-Pals
BERTLhuc
false
7,035
[ "MIT" ]
1
d5a288b9ac62259e70c249635108ba3906e19f00
https://github.com/DAQuestionAnswering/Bert-n-Pals/tree/d5a288b9ac62259e70c249635108ba3906e19f00
Cosine
from _paritybench_helpers import _mock_config import torch from torch.optim.lr_scheduler import * class Cosine(torch.nn.Module): def __init__(self, config): super().__init__() def forward(self, src, tgt): src = src.float() tgt = tgt.float() return (torch.matmul(src, tgt.transpose(2, 1)) / (src.norm(p=2, dim =-1, keepdim=True) * tgt.norm(p=2, dim=-1, keepdim=True) + 1e-09) ).squeeze() def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config()}]
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.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 = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tl.store(out_ptr0 + x4, tmp0, xmask) @triton.jit def triton_poi_fused_add_linalg_vector_norm_mul_1(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 + 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') tmp12 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr1 + (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) tmp13 = tmp12 * tmp12 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp23 = libdevice.sqrt(tmp22) tmp24 = tmp11 * tmp23 tmp25 = 1e-09 tmp26 = tmp24 + tmp25 tl.store(out_ptr0 + x0, tmp26, xmask) @triton.jit def triton_poi_fused_add_div_linalg_vector_norm_mul_squeeze_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 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): 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_clone_0[grid(256)](arg1_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (16, 4, 4), (16, 4, 1 ), 0), reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0), out =buf1) del buf0 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_linalg_vector_norm_mul_1[grid(64)](arg0_1, arg1_1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf3 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_add_div_linalg_vector_norm_mul_squeeze_2[grid(256)]( buf3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf2 return buf3, class CosineNew(torch.nn.Module): def __init__(self, config): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
Cosine
false
7,036
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
ConvLayer
import torch from torch import nn class ConvLayer(nn.Module): """1-D Convolution layer to extract high-level features of each time-series input :param n_features: Number of input features/nodes :param window_size: length of the input sequence :param kernel_size: size of kernel to use in the convolution operation """ def __init__(self, n_features, kernel_size=7): super(ConvLayer, self).__init__() self.padding = nn.ConstantPad1d((kernel_size - 1) // 2, 0.0) self.conv = nn.Conv1d(in_channels=n_features, out_channels= n_features, kernel_size=kernel_size) self.relu = nn.ReLU() def forward(self, x): x = x.permute(0, 2, 1) x = self.padding(x) x = self.relu(self.conv(x)) return x.permute(0, 2, 1) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'n_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 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_constant_pad_nd_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 10 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 = -3 + x2 tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1, 1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-12 + y0 + 4 * x2 + 16 * y1), tmp5 & xmask & ymask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + (x2 + 10 * y3), tmp6, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) 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), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 7), (28, 7, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 10), (40, 10, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(16, 10)](primals_1, buf0, 16, 10, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4), (16, 4, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_1[grid(64)](buf2, primals_3, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0 ), primals_2, buf0, buf3 class ConvLayerNew(nn.Module): """1-D Convolution layer to extract high-level features of each time-series input :param n_features: Number of input features/nodes :param window_size: length of the input sequence :param kernel_size: size of kernel to use in the convolution operation """ def __init__(self, n_features, kernel_size=7): super(ConvLayerNew, self).__init__() self.padding = nn.ConstantPad1d((kernel_size - 1) // 2, 0.0) self.conv = nn.Conv1d(in_channels=n_features, out_channels= n_features, kernel_size=kernel_size) self.relu = nn.ReLU() 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]
kj21choi/LATAD
ConvLayer
false
7,037
[ "MIT" ]
1
80d91e0f251ad0225342ee30e2461a39fa9cca97
https://github.com/kj21choi/LATAD/tree/80d91e0f251ad0225342ee30e2461a39fa9cca97
SymKlCriterion
import torch import torch.nn.functional as F from torch.nn.modules.loss import _Loss from torch.optim.lr_scheduler import * class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class SymKlCriterion(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """input/target: logits """ input = input.float() target = target.float() loss = F.kl_div(F.log_softmax(input, dim=-1, dtype=torch.float32), F.softmax(target.detach(), dim=-1, dtype=torch.float32), reduction='batchmean') + F.kl_div(F.log_softmax(target, dim=-1, dtype=torch.float32), F.softmax(input.detach(), dim=-1, dtype= torch.float32), reduction='batchmean') loss = loss * self.alpha return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch.nn.modules.loss import _Loss 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 @triton.jit def triton_poi_fused__log_softmax__softmax_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 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) tl.store(out_ptr1 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax__softmax_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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, tmp8, xmask) tl.store(out_ptr1 + x2, tmp9, xmask) @triton.jit def triton_red_fused__log_softmax__softmax_add_div_mul_sub_sum_xlogy_2( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp34 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp68 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp17 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp18 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp23 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp26 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp36 = tl.load(in_ptr2 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp37 = tl.load(in_ptr2 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp38 = tl.load(in_ptr2 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp40 = tl.load(in_ptr2 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp42 = tl.load(in_ptr2 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp51 = tl.load(in_ptr3 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp52 = tl.load(in_ptr3 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp54 = tl.load(in_ptr3 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp57 = tl.load(in_ptr3 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp60 = tl.load(in_ptr3 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = libdevice.isnan(tmp8).to(tl.int1) tmp10 = 0.0 tmp11 = tmp8 == tmp10 tmp12 = tl_math.log(tmp8) tmp13 = tmp8 * tmp12 tmp14 = tl.where(tmp11, tmp10, tmp13) tmp15 = float('nan') tmp16 = tl.where(tmp9, tmp15, tmp14) tmp19 = tl_math.exp(tmp18) tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tl_math.log(tmp28) tmp30 = tmp17 - tmp29 tmp31 = tmp8 * tmp30 tmp32 = tmp16 - tmp31 tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK]) tmp35 = _tmp34 + tmp33 _tmp34 = tl.where(rmask, tmp35, _tmp34) tmp39 = tmp37 + tmp38 tmp41 = tmp39 + tmp40 tmp43 = tmp41 + tmp42 tmp44 = tmp36 / tmp43 tmp45 = libdevice.isnan(tmp44).to(tl.int1) tmp46 = tmp44 == tmp10 tmp47 = tl_math.log(tmp44) tmp48 = tmp44 * tmp47 tmp49 = tl.where(tmp46, tmp10, tmp48) tmp50 = tl.where(tmp45, tmp15, tmp49) tmp53 = tl_math.exp(tmp52) tmp55 = tl_math.exp(tmp54) tmp56 = tmp53 + tmp55 tmp58 = tl_math.exp(tmp57) tmp59 = tmp56 + tmp58 tmp61 = tl_math.exp(tmp60) tmp62 = tmp59 + tmp61 tmp63 = tl_math.log(tmp62) tmp64 = tmp51 - tmp63 tmp65 = tmp44 * tmp64 tmp66 = tmp50 - tmp65 tmp67 = tl.broadcast_to(tmp66, [XBLOCK, RBLOCK]) tmp69 = _tmp68 + tmp67 _tmp68 = tl.where(rmask, tmp69, _tmp68) tmp34 = tl.sum(_tmp34, 1)[:, None] tmp68 = tl.sum(_tmp68, 1)[:, None] tmp70 = 0.25 tmp71 = tmp34 * tmp70 tmp72 = tmp68 * tmp70 tmp73 = tmp71 + tmp72 tmp74 = 1.0 tmp75 = tmp73 * tmp74 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp75, 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) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax__softmax_0[grid(256)](arg1_1, buf0, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__softmax_1[grid(256)](arg0_1, buf2, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf3 = empty_strided_cuda((), (), torch.float32) buf8 = buf3 del buf3 triton_red_fused__log_softmax__softmax_add_div_mul_sub_sum_xlogy_2[grid (1)](buf8, buf0, buf2, buf4, buf6, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 del buf4 del buf6 return buf8, class Criterion(_Loss): def __init__(self, alpha=1.0, name='criterion'): super().__init__() """Alpha is used to weight each loss term """ self.alpha = alpha self.name = name def forward(self, input, target, weight=None, ignore_index=-1): """weight: sample weight """ return class SymKlCriterionNew(Criterion): def __init__(self, alpha=1.0, name='KL Div Criterion'): super().__init__() self.alpha = alpha self.name = name def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kiminh/mt-dnn
SymKlCriterion
false
7,038
[ "MIT" ]
1
133884b380244dbe74acc4d7507e551b2c5035b3
https://github.com/kiminh/mt-dnn/tree/133884b380244dbe74acc4d7507e551b2c5035b3
NN1
import torch import torch.nn as nn class NN1(nn.Module): def __init__(self, input_dimension): super(NN1, self).__init__() self.linear1 = nn.Linear(input_dimension, 60) self.linear2 = nn.Linear(60, 25) self.linear3 = nn.Linear(25, 1) self.sig = nn.Sigmoid() self.relu = nn.ReLU() self.dropout = nn.Dropout(p=0.2) def forward(self, x): x = self.relu(self.linear1(x)) x = self.dropout(x) x = self.relu(self.linear2(x)) x = self.dropout(x) x = self.linear3(x) return self.sig(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dimension': 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_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3840 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 60 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 25 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (60, 4), (4, 1)) assert_size_stride(primals_2, (60,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (25, 60), (60, 1)) assert_size_stride(primals_5, (25,), (1,)) assert_size_stride(primals_6, (1, 25), (25, 1)) assert_size_stride(primals_7, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 60), (60, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 60), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 60), (960, 240, 60, 1), 0) del buf0 buf7 = empty_strided_cuda((4, 4, 4, 60), (960, 240, 60, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(3840)](buf1, primals_2, buf7, 3840, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 25), (25, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 60), (60, 1), 0), reinterpret_tensor(primals_4, (60, 25), (1, 60), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 25), (400, 100, 25, 1), 0) del buf2 buf6 = empty_strided_cuda((4, 4, 4, 25), (400, 100, 25, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(1600)](buf3, primals_5, buf6, 1600, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 25), (25, 1), 0), reinterpret_tensor(primals_6, (25, 1), (1, 25), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf4 triton_poi_fused_sigmoid_2[grid(64)](buf5, primals_7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_7 return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 60), (60, 1), 0), reinterpret_tensor( buf3, (64, 25), (25, 1), 0), buf5, primals_6, buf6, primals_4, buf7 class NN1New(nn.Module): def __init__(self, input_dimension): super(NN1New, self).__init__() self.linear1 = nn.Linear(input_dimension, 60) self.linear2 = nn.Linear(60, 25) self.linear3 = nn.Linear(25, 1) self.sig = nn.Sigmoid() self.relu = nn.ReLU() self.dropout = nn.Dropout(p=0.2) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
kirtanp/MAMO-fair
NN1
false
7,039
[ "Apache-2.0" ]
1
fd0fc39383f11a9e1ec401233b89c2399860fb94
https://github.com/kirtanp/MAMO-fair/tree/fd0fc39383f11a9e1ec401233b89c2399860fb94
Transformation
import torch from torch import nn class Transformation(torch.nn.Module): def __init__(self, input_size): super(Transformation, self).__init__() self.input_size = input_size self.linear1 = torch.nn.Linear(self.input_size, self.input_size) self.linear2 = torch.nn.Linear(self.input_size, self.input_size) self.linear3 = torch.nn.Linear(self.input_size, self.input_size) self.linear4 = torch.nn.Linear(self.input_size, self.input_size) self.leaky_relu = nn.LeakyReLU(0.3) def forward(self, x): """ Transforms input x with a mask M(x) followed by multiplication with x. """ h = self.linear1(x.float()) h = self.leaky_relu(h) h = self.linear2(h) h = self.leaky_relu(h) h = self.linear3(h) h = self.leaky_relu(h) h = self.linear4(h) m = torch.sigmoid(h) t_x = m * x.float() return t_x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch 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 = 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.3 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_mul_sigmoid_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, 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, 4), (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.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((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_3, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 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) 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_0[grid(256)](buf3, primals_5, buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf6 = buf3 del buf3 extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_leaky_relu_0[grid(256)](buf6, primals_7, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf9 = buf6 del buf6 extern_kernels.addmm(primals_9, reinterpret_tensor(buf8, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf9) del primals_9 buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_1[grid(256)](buf9, primals_1, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf10, primals_1, buf1, reinterpret_tensor(buf2, (64, 4), (4, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 4), (4, 1), 0 ), buf7, reinterpret_tensor(buf8, (64, 4), (4, 1), 0 ), buf9, primals_8, primals_6, primals_4 class TransformationNew(torch.nn.Module): def __init__(self, input_size): super(TransformationNew, self).__init__() self.input_size = input_size self.linear1 = torch.nn.Linear(self.input_size, self.input_size) self.linear2 = torch.nn.Linear(self.input_size, self.input_size) self.linear3 = torch.nn.Linear(self.input_size, self.input_size) self.linear4 = torch.nn.Linear(self.input_size, self.input_size) self.leaky_relu = nn.LeakyReLU(0.3) def forward(self, input_0): primals_2 = self.linear1.weight primals_3 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_8 = self.linear4.weight primals_9 = self.linear4.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]
kj21choi/LATAD
Transformation
false
7,040
[ "MIT" ]
1
80d91e0f251ad0225342ee30e2461a39fa9cca97
https://github.com/kj21choi/LATAD/tree/80d91e0f251ad0225342ee30e2461a39fa9cca97
TemporalAttentionLayer
import torch from torch import nn class TemporalAttentionLayer(nn.Module): """Single Graph Temporal Attention Layer :param n_features: number of input features/nodes :param window_size: length of the input sequence :param dropout: percentage of nodes to dropout :param alpha: negative slope used in the leaky rely activation function :param embed_dim: embedding dimension (output dimension of linear transformation) :param use_gatv2: whether to use the modified attention mechanism of GATv2 instead of standard GAT :param use_bias: whether to include a bias term in the attention layer """ def __init__(self, n_features, window_size, dropout, alpha, embed_dim= None, use_gatv2=True, use_bias=True): super(TemporalAttentionLayer, self).__init__() self.n_features = n_features self.window_size = window_size self.dropout = dropout self.use_gatv2 = use_gatv2 self.embed_dim = embed_dim if embed_dim is not None else n_features self.num_nodes = window_size self.use_bias = use_bias if self.use_gatv2: self.embed_dim *= 2 lin_input_dim = 2 * n_features a_input_dim = self.embed_dim else: lin_input_dim = n_features a_input_dim = 2 * self.embed_dim self.lin = nn.Linear(lin_input_dim, self.embed_dim) self.a = nn.Parameter(torch.empty((a_input_dim, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) if self.use_bias: self.bias = nn.Parameter(torch.empty(window_size, window_size)) self.leakyrelu = nn.LeakyReLU(alpha) self.sigmoid = nn.Sigmoid() def forward(self, x): if self.use_gatv2: a_input = self._make_attention_input(x) a_input = self.leakyrelu(self.lin(a_input)) e = torch.matmul(a_input, self.a).squeeze(3) else: Wx = self.lin(x) a_input = self._make_attention_input(Wx) e = self.leakyrelu(torch.matmul(a_input, self.a)).squeeze(3) if self.use_bias: e += self.bias attention = torch.softmax(e, dim=2) attention = torch.dropout(attention, self.dropout, train=self.training) h = self.sigmoid(torch.matmul(attention, x)) return h def _make_attention_input(self, v): """Preparing the temporal attention mechanism. Creating matrix with all possible combinations of concatenations of node values: (v1, v2..)_t1 || (v1, v2..)_t1 (v1, v2..)_t1 || (v1, v2..)_t2 ... ... (v1, v2..)_tn || (v1, v2..)_t1 (v1, v2..)_tn || (v1, v2..)_t2 """ K = self.num_nodes blocks_repeating = v.repeat_interleave(K, dim=1) blocks_alternating = v.repeat(1, K, 1) combined = torch.cat((blocks_repeating, blocks_alternating), dim=2) if self.use_gatv2: return combined.view(v.size(0), K, K, 2 * self.n_features) else: return combined.view(v.size(0), K, K, 2 * self.embed_dim) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'n_features': 4, 'window_size': 4, 'dropout': 0.5, 'alpha': 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_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 * (x1 // 4) + 16 * x2 + x0), 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, 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 = 4.0 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__softmax_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 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + 4 * x2, 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 + 16 * x1 + 16 * ((1 + 4 * x0) // 16)), 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 + 16 * x1 + 16 * ((1 + 2 * x0) // 8)), 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 + 16 * x1 + 16 * ((3 + 4 * x0) // 16)), 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 = triton_helpers.maximum(tmp2, tmp5) tmp9 = tmp7 + tmp8 tmp10 = triton_helpers.maximum(tmp6, tmp9) tmp13 = tmp11 + tmp12 tmp14 = triton_helpers.maximum(tmp10, tmp13) tmp15 = tmp2 - tmp14 tmp16 = tl_math.exp(tmp15) tmp17 = tmp5 - tmp14 tmp18 = tl_math.exp(tmp17) tmp19 = tmp16 + tmp18 tmp20 = tmp9 - tmp14 tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp23 = tmp13 - tmp14 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tl.store(out_ptr0 + x2, tmp14, xmask) tl.store(out_ptr1 + x2, tmp25, xmask) @triton.jit def triton_poi_fused__softmax_3(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 x4 = xindex x3 = xindex % 16 x5 = xindex // 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(out_ptr0 + x4, tmp7, xmask) @triton.jit def triton_poi_fused_sigmoid_4(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) def call(args): primals_1, primals_2, 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, (8, 8), (8, 1)) assert_size_stride(primals_3, (8,), (1,)) assert_size_stride(primals_4, (8, 1), (1, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](primals_1, buf0, 512, XBLOCK=256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 8), (8, 1), 0), reinterpret_tensor(primals_2, (8, 8), (1, 8), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(512)](buf1, primals_3, buf2, buf3, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del primals_3 buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 8), (8, 1), 0), primals_4, out=buf4) buf5 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf6 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_2[grid(16)](buf4, primals_5, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf4, primals_5, buf5, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf5 del buf6 del primals_5 buf8 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(buf7, primals_1, out=buf8) buf9 = buf8 del buf8 triton_poi_fused_sigmoid_4[grid(64)](buf9, 64, XBLOCK=64, num_warps =1, num_stages=1) return buf9, reinterpret_tensor(buf0, (64, 8), (8, 1), 0 ), buf2, buf7, buf9, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf3, (8, 64), (1, 8), 0 ), reinterpret_tensor(primals_4, (1, 8), (1, 1), 0) class TemporalAttentionLayerNew(nn.Module): """Single Graph Temporal Attention Layer :param n_features: number of input features/nodes :param window_size: length of the input sequence :param dropout: percentage of nodes to dropout :param alpha: negative slope used in the leaky rely activation function :param embed_dim: embedding dimension (output dimension of linear transformation) :param use_gatv2: whether to use the modified attention mechanism of GATv2 instead of standard GAT :param use_bias: whether to include a bias term in the attention layer """ def __init__(self, n_features, window_size, dropout, alpha, embed_dim= None, use_gatv2=True, use_bias=True): super(TemporalAttentionLayerNew, self).__init__() self.n_features = n_features self.window_size = window_size self.dropout = dropout self.use_gatv2 = use_gatv2 self.embed_dim = embed_dim if embed_dim is not None else n_features self.num_nodes = window_size self.use_bias = use_bias if self.use_gatv2: self.embed_dim *= 2 lin_input_dim = 2 * n_features a_input_dim = self.embed_dim else: lin_input_dim = n_features a_input_dim = 2 * self.embed_dim self.lin = nn.Linear(lin_input_dim, self.embed_dim) self.a = nn.Parameter(torch.empty((a_input_dim, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) if self.use_bias: self.bias = nn.Parameter(torch.empty(window_size, window_size)) self.leakyrelu = nn.LeakyReLU(alpha) self.sigmoid = nn.Sigmoid() def _make_attention_input(self, v): """Preparing the temporal attention mechanism. Creating matrix with all possible combinations of concatenations of node values: (v1, v2..)_t1 || (v1, v2..)_t1 (v1, v2..)_t1 || (v1, v2..)_t2 ... ... (v1, v2..)_tn || (v1, v2..)_t1 (v1, v2..)_tn || (v1, v2..)_t2 """ K = self.num_nodes blocks_repeating = v.repeat_interleave(K, dim=1) blocks_alternating = v.repeat(1, K, 1) combined = torch.cat((blocks_repeating, blocks_alternating), dim=2) if self.use_gatv2: return combined.view(v.size(0), K, K, 2 * self.n_features) else: return combined.view(v.size(0), K, K, 2 * self.embed_dim) def forward(self, input_0): primals_4 = self.a primals_5 = self.bias primals_2 = self.lin.weight primals_3 = self.lin.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
kj21choi/LATAD
TemporalAttentionLayer
false
7,041
[ "MIT" ]
1
80d91e0f251ad0225342ee30e2461a39fa9cca97
https://github.com/kj21choi/LATAD/tree/80d91e0f251ad0225342ee30e2461a39fa9cca97
UpConv
import torch import torch.nn as nn class UpConv(nn.Module): def __init__(self, input_nc, output_nc, kernel_size): super(UpConv, self).__init__() self.deconv = nn.ConvTranspose2d(in_channels=input_nc, out_channels =output_nc, kernel_size=2, bias=True, stride=2, padding=0) self.activation_fn = nn.ELU() def forward(self, input): return self.activation_fn(self.deconv(input)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_nc': 4, 'output_nc': 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 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_elu_0(in_out_ptr0, 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 x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp9, xmask) def call(args): primals_1, primals_2, primals_3 = 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 8, 8), (256, 64, 8, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_elu_0[grid(1024)](buf1, primals_2, buf2, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf2, primals_1, primals_3, buf1 class UpConvNew(nn.Module): def __init__(self, input_nc, output_nc, kernel_size): super(UpConvNew, self).__init__() self.deconv = nn.ConvTranspose2d(in_channels=input_nc, out_channels =output_nc, kernel_size=2, bias=True, stride=2, padding=0) self.activation_fn = nn.ELU() def forward(self, input_0): primals_1 = self.deconv.weight primals_2 = self.deconv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
kkrish39/realtime-depth-prediction-from-monocular-videos
UpConv
false
7,042
[ "BSD-3-Clause" ]
1
9cde9c1a6df6c91af1ada80b3aaeebae03fc59dc
https://github.com/kkrish39/realtime-depth-prediction-from-monocular-videos/tree/9cde9c1a6df6c91af1ada80b3aaeebae03fc59dc
FeatureAttentionLayer
import torch from torch import nn class FeatureAttentionLayer(nn.Module): """Single Graph Feature/Spatial Attention Layer :param n_features: Number of input features/nodes :param window_size: length of the input sequence :param dropout: percentage of nodes to dropout :param alpha: negative slope used in the leaky rely activation function :param embed_dim: embedding dimension (output dimension of linear transformation) :param use_gatv2: whether to use the modified attention mechanism of GATv2 instead of standard GAT :param use_bias: whether to include a bias term in the attention layer """ def __init__(self, n_features, window_size, dropout, alpha, embed_dim= None, use_gatv2=True, use_bias=True): super(FeatureAttentionLayer, self).__init__() self.n_features = n_features self.window_size = window_size self.dropout = dropout self.embed_dim = embed_dim if embed_dim is not None else window_size self.use_gatv2 = use_gatv2 self.num_nodes = n_features self.use_bias = use_bias if self.use_gatv2: self.embed_dim *= 2 lin_input_dim = 2 * window_size a_input_dim = self.embed_dim else: lin_input_dim = window_size a_input_dim = 2 * self.embed_dim self.lin = nn.Linear(lin_input_dim, self.embed_dim) self.a = nn.Parameter(torch.empty((a_input_dim, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) if self.use_bias: self.bias = nn.Parameter(torch.empty(n_features, n_features)) self.leakyrelu = nn.LeakyReLU(alpha) self.sigmoid = nn.Sigmoid() def forward(self, x): x = x.permute(0, 2, 1) if self.use_gatv2: a_input = self._make_attention_input(x) a_input = self.leakyrelu(self.lin(a_input)) e = torch.matmul(a_input, self.a).squeeze(3) else: Wx = self.lin(x) a_input = self._make_attention_input(Wx) e = self.leakyrelu(torch.matmul(a_input, self.a)).squeeze(3) if self.use_bias: e += self.bias attention = torch.softmax(e, dim=2) attention = torch.dropout(attention, self.dropout, train=self.training) h = self.sigmoid(torch.matmul(attention, x)) return h.permute(0, 2, 1) def _make_attention_input(self, v): """Preparing the feature attention mechanism. Creating matrix with all possible combinations of concatenations of node. Each node consists of all values of that node within the window v1 || v1, ... v1 || vK, v2 || v1, ... v2 || vK, ... ... vK || v1, ... vK || vK, """ K = self.num_nodes blocks_repeating = v.repeat_interleave(K, dim=1) blocks_alternating = v.repeat(1, K, 1) combined = torch.cat((blocks_repeating, blocks_alternating), dim=2) if self.use_gatv2: return combined.view(v.size(0), K, K, 2 * self.window_size) else: return combined.view(v.size(0), K, K, 2 * self.embed_dim) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'n_features': 4, 'window_size': 4, 'dropout': 0.5, 'alpha': 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_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 * x0 + 16 * x2 + x1 // 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 * (-4 + x0) + 16 * x2 + x1 % 4), 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, 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 = 4.0 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__softmax_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 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + 4 * x2, 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 + 16 * x1 + 16 * ((1 + 4 * x0) // 16)), 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 + 16 * x1 + 16 * ((1 + 2 * x0) // 8)), 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 + 16 * x1 + 16 * ((3 + 4 * x0) // 16)), 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 = triton_helpers.maximum(tmp2, tmp5) tmp9 = tmp7 + tmp8 tmp10 = triton_helpers.maximum(tmp6, tmp9) tmp13 = tmp11 + tmp12 tmp14 = triton_helpers.maximum(tmp10, tmp13) tmp15 = tmp2 - tmp14 tmp16 = tl_math.exp(tmp15) tmp17 = tmp5 - tmp14 tmp18 = tl_math.exp(tmp17) tmp19 = tmp16 + tmp18 tmp20 = tmp9 - tmp14 tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp23 = tmp13 - tmp14 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tl.store(out_ptr0 + x2, tmp14, xmask) tl.store(out_ptr1 + x2, tmp25, xmask) @triton.jit def triton_poi_fused__softmax_3(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 x4 = xindex x3 = xindex % 16 x5 = xindex // 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x5, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(out_ptr0 + x4, tmp7, xmask) @triton.jit def triton_poi_fused_sigmoid_sigmoid_backward_4(in_out_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.sigmoid(tmp0) tmp2 = 1.0 tmp3 = tmp2 - tmp1 tmp4 = tmp1 * tmp3 tl.store(in_out_ptr0 + x0, tmp1, xmask) tl.store(out_ptr0 + x0, tmp4, 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, (8, 8), (8, 1)) assert_size_stride(primals_3, (8,), (1,)) assert_size_stride(primals_4, (8, 1), (1, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 16, 8), (128, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](primals_1, buf0, 512, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 8), (8, 1), 0), reinterpret_tensor(primals_2, (8, 8), (1, 8), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(512)](buf1, primals_3, buf2, buf3, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del primals_3 buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 8), (8, 1), 0), primals_4, out=buf4) buf5 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf6 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_2[grid(16)](buf4, primals_5, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf4, primals_5, buf5, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf5 del buf6 del primals_5 buf8 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(buf7, reinterpret_tensor(primals_1, (4, 4, 4), ( 16, 1, 4), 0), out=buf8) buf9 = buf8 del buf8 buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_sigmoid_sigmoid_backward_4[grid(64)](buf9, buf10, 64, XBLOCK=64, num_warps=1, num_stages=1) return reinterpret_tensor(buf9, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf0, (64, 8), (8, 1), 0 ), buf2, buf7, buf10, primals_1, reinterpret_tensor(buf3, (8, 64), (1, 8), 0), reinterpret_tensor(primals_4, (1, 8), (1, 1), 0) class FeatureAttentionLayerNew(nn.Module): """Single Graph Feature/Spatial Attention Layer :param n_features: Number of input features/nodes :param window_size: length of the input sequence :param dropout: percentage of nodes to dropout :param alpha: negative slope used in the leaky rely activation function :param embed_dim: embedding dimension (output dimension of linear transformation) :param use_gatv2: whether to use the modified attention mechanism of GATv2 instead of standard GAT :param use_bias: whether to include a bias term in the attention layer """ def __init__(self, n_features, window_size, dropout, alpha, embed_dim= None, use_gatv2=True, use_bias=True): super(FeatureAttentionLayerNew, self).__init__() self.n_features = n_features self.window_size = window_size self.dropout = dropout self.embed_dim = embed_dim if embed_dim is not None else window_size self.use_gatv2 = use_gatv2 self.num_nodes = n_features self.use_bias = use_bias if self.use_gatv2: self.embed_dim *= 2 lin_input_dim = 2 * window_size a_input_dim = self.embed_dim else: lin_input_dim = window_size a_input_dim = 2 * self.embed_dim self.lin = nn.Linear(lin_input_dim, self.embed_dim) self.a = nn.Parameter(torch.empty((a_input_dim, 1))) nn.init.xavier_uniform_(self.a.data, gain=1.414) if self.use_bias: self.bias = nn.Parameter(torch.empty(n_features, n_features)) self.leakyrelu = nn.LeakyReLU(alpha) self.sigmoid = nn.Sigmoid() def _make_attention_input(self, v): """Preparing the feature attention mechanism. Creating matrix with all possible combinations of concatenations of node. Each node consists of all values of that node within the window v1 || v1, ... v1 || vK, v2 || v1, ... v2 || vK, ... ... vK || v1, ... vK || vK, """ K = self.num_nodes blocks_repeating = v.repeat_interleave(K, dim=1) blocks_alternating = v.repeat(1, K, 1) combined = torch.cat((blocks_repeating, blocks_alternating), dim=2) if self.use_gatv2: return combined.view(v.size(0), K, K, 2 * self.window_size) else: return combined.view(v.size(0), K, K, 2 * self.embed_dim) def forward(self, input_0): primals_4 = self.a primals_5 = self.bias primals_2 = self.lin.weight primals_3 = self.lin.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
kj21choi/LATAD
FeatureAttentionLayer
false
7,043
[ "MIT" ]
1
80d91e0f251ad0225342ee30e2461a39fa9cca97
https://github.com/kj21choi/LATAD/tree/80d91e0f251ad0225342ee30e2461a39fa9cca97
Attention
import torch import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): def __init__(self, nf=64): super(Attention, self).__init__() self.sAtt_1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.max_pool = nn.MaxPool2d(3, stride=2, padding=1) self.avg_pool = nn.AvgPool2d(3, stride=2, padding=1) self.sAtt_2 = nn.Conv2d(nf * 2, nf, 1, 1, bias=True) self.sAtt_3 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_4 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_5 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_L1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_L2 = nn.Conv2d(nf * 2, nf, 3, 1, 1, bias=True) self.sAtt_L3 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_add_1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_add_2 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True) def forward(self, x): att = self.lrelu(self.sAtt_1(x)) att_max = self.max_pool(att) att_avg = self.avg_pool(att) att = self.lrelu(self.sAtt_2(torch.cat([att_max, att_avg], dim=1))) att_L = self.lrelu(self.sAtt_L1(att)) att_max = self.max_pool(att_L) att_avg = self.avg_pool(att_L) att_L = self.lrelu(self.sAtt_L2(torch.cat([att_max, att_avg], dim=1))) att_L = self.lrelu(self.sAtt_L3(att_L)) att_L = F.interpolate(att_L, scale_factor=2, mode='bilinear', align_corners=False) att = self.lrelu(self.sAtt_3(att)) att = att + att_L att = self.lrelu(self.sAtt_4(att)) att = F.interpolate(att, scale_factor=2, mode='bilinear', align_corners=False) att = self.sAtt_5(att) att_add = self.sAtt_add_2(self.lrelu(self.sAtt_add_1(att))) att = torch.sigmoid(att) out = x * att * 2 + att_add return out 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 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_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 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(in_out_ptr0 + x3, tmp7, None) @triton.jit def triton_poi_fused_avg_pool2d_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, 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 // 32 % 32 x0 = xindex % 32 x5 = xindex // 32 x3 = xindex // 65536 x6 = xindex % 65536 x7 = 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 * x5), 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 + (-64 + 2 * x0 + 128 * x5), tmp16, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-63 + 2 * x0 + 128 * x5), tmp23, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x1 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-1 + 2 * x0 + 128 * x5), tmp30, eviction_policy='evict_last', other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (2 * x0 + 128 * x5), tmp33, eviction_policy= 'evict_last', other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x5), tmp36, eviction_policy='evict_last', other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x1 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (63 + 2 * x0 + 128 * x5), tmp43, eviction_policy='evict_last', other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x5), tmp46, eviction_policy='evict_last', other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x5), tmp49, eviction_policy='evict_last', 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) tmp77 = tl.load(in_ptr0 + (-65 + 2 * x0 + 128 * x5), tmp10, eviction_policy='evict_last', other=0.0) tmp78 = tl.load(in_ptr0 + (-64 + 2 * x0 + 128 * x5), tmp16, eviction_policy='evict_last', other=0.0) tmp79 = tmp78 + tmp77 tmp80 = tl.load(in_ptr0 + (-63 + 2 * x0 + 128 * x5), tmp23, eviction_policy='evict_last', other=0.0) tmp81 = tmp80 + tmp79 tmp82 = tl.load(in_ptr0 + (-1 + 2 * x0 + 128 * x5), tmp30, eviction_policy='evict_last', other=0.0) tmp83 = tmp82 + tmp81 tmp84 = tl.load(in_ptr0 + (2 * x0 + 128 * x5), tmp33, eviction_policy= 'evict_last', other=0.0) tmp85 = tmp84 + tmp83 tmp86 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x5), tmp36, eviction_policy='evict_last', other=0.0) tmp87 = tmp86 + tmp85 tmp88 = tl.load(in_ptr0 + (63 + 2 * x0 + 128 * x5), tmp43, eviction_policy='evict_last', other=0.0) tmp89 = tmp88 + tmp87 tmp90 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x5), tmp46, eviction_policy='evict_last', other=0.0) tmp91 = tmp90 + tmp89 tmp92 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x5), tmp49, eviction_policy='evict_last', other=0.0) tmp93 = tmp92 + tmp91 tmp94 = 1 + -2 * x0 + -2 * x1 + (65 * (65 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 65)) * (65 * (65 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 65)) + -2 * x0 * (65 * (65 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 65)) + -2 * x1 * (65 * (65 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 65)) + 4 * x0 * x1 + (65 * (65 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 65)) + (65 * (65 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 65)) tmp95 = tmp93 / tmp94 tl.store(out_ptr0 + (x6 + 131072 * x3), tmp51, None) tl.store(out_ptr1 + x7, tmp76, None) tl.store(out_ptr2 + (x6 + 131072 * x3), tmp95, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, 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(in_out_ptr0 + x3, tmp7, None) @triton.jit def triton_poi_fused_avg_pool2d_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, 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 // 16 % 16 x0 = xindex % 16 x5 = xindex // 16 x3 = xindex // 16384 x6 = xindex % 16384 x7 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, 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 + (-33 + 2 * x0 + 64 * x5), 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 + (-32 + 2 * x0 + 64 * x5), tmp16, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-31 + 2 * x0 + 64 * x5), tmp23, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x1 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-1 + 2 * x0 + 64 * x5), tmp30, eviction_policy='evict_last', other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (2 * x0 + 64 * x5), tmp33, eviction_policy= 'evict_last', other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x5), tmp36, eviction_policy='evict_last', other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x1 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (31 + 2 * x0 + 64 * x5), tmp43, eviction_policy='evict_last', other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x5), tmp46, eviction_policy='evict_last', other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x5), tmp49, eviction_policy='evict_last', 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) tmp77 = tl.load(in_ptr0 + (-33 + 2 * x0 + 64 * x5), tmp10, eviction_policy='evict_last', other=0.0) tmp78 = tl.load(in_ptr0 + (-32 + 2 * x0 + 64 * x5), tmp16, eviction_policy='evict_last', other=0.0) tmp79 = tmp78 + tmp77 tmp80 = tl.load(in_ptr0 + (-31 + 2 * x0 + 64 * x5), tmp23, eviction_policy='evict_last', other=0.0) tmp81 = tmp80 + tmp79 tmp82 = tl.load(in_ptr0 + (-1 + 2 * x0 + 64 * x5), tmp30, eviction_policy='evict_last', other=0.0) tmp83 = tmp82 + tmp81 tmp84 = tl.load(in_ptr0 + (2 * x0 + 64 * x5), tmp33, eviction_policy= 'evict_last', other=0.0) tmp85 = tmp84 + tmp83 tmp86 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x5), tmp36, eviction_policy='evict_last', other=0.0) tmp87 = tmp86 + tmp85 tmp88 = tl.load(in_ptr0 + (31 + 2 * x0 + 64 * x5), tmp43, eviction_policy='evict_last', other=0.0) tmp89 = tmp88 + tmp87 tmp90 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x5), tmp46, eviction_policy='evict_last', other=0.0) tmp91 = tmp90 + tmp89 tmp92 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x5), tmp49, eviction_policy='evict_last', other=0.0) tmp93 = tmp92 + tmp91 tmp94 = 1 + -2 * x0 + -2 * x1 + (33 * (33 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 33)) * (33 * (33 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 33)) + -2 * x0 * (33 * (33 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 33)) + -2 * x1 * (33 * (33 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 33)) + 4 * x0 * x1 + (33 * (33 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 33)) + (33 * (33 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 33)) tmp95 = tmp93 / tmp94 tl.store(out_ptr0 + (x6 + 32768 * x3), tmp51, None) tl.store(out_ptr1 + x7, tmp76, None) tl.store(out_ptr2 + (x6 + 32768 * x3), tmp95, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, 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(in_out_ptr0 + x3, tmp7, None) @triton.jit def triton_poi_fused__to_copy_5(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_clamp_6(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tmp9 = tl.full([1], 1, tl.int64) tmp10 = tmp8 + tmp9 tmp11 = tl.full([1], 15, tl.int64) tmp12 = triton_helpers.minimum(tmp10, tmp11) tl.store(out_ptr0 + x0, tmp12, xmask) @triton.jit def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_7(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 - tmp9 tmp11 = triton_helpers.maximum(tmp10, tmp6) tmp12 = 1.0 tmp13 = triton_helpers.minimum(tmp11, tmp12) tl.store(out_ptr0 + x0, tmp13, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_leaky_relu_leaky_relu_backward_mul_sub_8( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, out_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 // 32 % 32 x0 = xindex % 32 x5 = xindex // 1024 x2 = xindex // 1024 % 64 x6 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp17 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp27 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp48 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp50 = tl.load(in_ptr8 + x6, None) tmp51 = tl.load(in_ptr9 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 16, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 16 * tmp4 + 256 * x5), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = 0.0 tmp13 = tmp11 > tmp12 tmp14 = 0.1 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 + 16 * tmp4 + 256 * x5), None, 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 + 16 * tmp33 + 256 * x5), None, 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 + 16 * tmp33 + 256 * x5), None, 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 tmp52 = tmp50 + tmp51 tmp53 = tmp52 > tmp12 tmp54 = tmp52 * tmp14 tmp55 = tl.where(tmp53, tmp52, tmp54) tmp56 = tmp29 + tmp49 tmp57 = tmp55 + tmp56 tmp58 = tmp55 > tmp12 tl.store(in_out_ptr0 + x6, tmp57, None) tl.store(out_ptr1 + x6, tmp58, None) @triton.jit def triton_poi_fused__to_copy_9(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_clamp_10(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tmp9 = tl.full([1], 1, tl.int64) tmp10 = tmp8 + tmp9 tmp11 = tl.full([1], 31, tl.int64) tmp12 = triton_helpers.minimum(tmp10, tmp11) tl.store(out_ptr0 + x0, tmp12, xmask) @triton.jit def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_11(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 - tmp2 tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp7.to(tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 - tmp9 tmp11 = triton_helpers.maximum(tmp10, tmp6) tmp12 = 1.0 tmp13 = triton_helpers.minimum(tmp11, tmp12) tl.store(out_ptr0 + x0, tmp13, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_leaky_relu_mul_sub_12( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 x6 = xindex // 4096 x2 = xindex // 4096 % 64 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp17 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp27 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp48 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 32, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 32 * tmp4 + 1024 * x6), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = 0.0 tmp13 = tmp11 > tmp12 tmp14 = 0.1 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 + 32 * tmp4 + 1024 * x6), None, 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 + 32 * tmp33 + 1024 * x6), None, 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 + 32 * tmp33 + 1024 * x6), None, 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 tl.store(in_out_ptr0 + x4, tmp50, None) @triton.jit def triton_poi_fused_convolution_13(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_poi_fused_add_convolution_mul_sigmoid_14(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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) tmp6 = tl.load(in_out_ptr0 + x3, None) tmp7 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = 2.0 tmp5 = tmp3 * tmp4 tmp8 = tmp6 + tmp7 tmp9 = tmp5 + tmp8 tl.store(in_out_ptr0 + x3, tmp9, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_15(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 // 1024 % 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.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(out_ptr0 + x3, tmp8, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_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) x3 = xindex x1 = xindex // 256 % 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.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(out_ptr0 + 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, 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, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_4, (64, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (64, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (64, 128, 3, 3), (1152, 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,)) assert_size_stride(primals_12, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (64, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_15, (64,), (1,)) assert_size_stride(primals_16, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_17, (64,), (1,)) assert_size_stride(primals_18, (64, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_19, (64,), (1,)) assert_size_stride(primals_20, (64, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_21, (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, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf1, primals_2, 1048576, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf5 = empty_strided_cuda((4, 128, 32, 32), (131072, 1024, 32, 1), torch.float32) buf2 = reinterpret_tensor(buf5, (4, 64, 32, 32), (131072, 1024, 32, 1), 0) buf3 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.int8) buf4 = reinterpret_tensor(buf5, (4, 64, 32, 32), (131072, 1024, 32, 1), 65536) triton_poi_fused_avg_pool2d_max_pool2d_with_indices_1[grid(262144)]( buf1, buf2, buf3, buf4, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_4, 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, 32, 32), (65536, 1024, 32, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf7, primals_5, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf8 = extern_kernels.convolution(buf7, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf9, primals_7, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf13 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) buf10 = reinterpret_tensor(buf13, (4, 64, 16, 16), (32768, 256, 16, 1), 0) buf11 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.int8) buf12 = reinterpret_tensor(buf13, (4, 64, 16, 16), (32768, 256, 16, 1), 16384) triton_poi_fused_avg_pool2d_max_pool2d_with_indices_3[grid(65536)](buf9 , buf10, buf11, buf12, 65536, XBLOCK=256, num_warps=4, num_stages=1 ) buf14 = extern_kernels.convolution(buf13, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 64, 16, 16), (16384, 256, 16, 1)) buf15 = buf14 del buf14 triton_poi_fused_convolution_leaky_relu_4[grid(65536)](buf15, primals_9, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_9 buf16 = extern_kernels.convolution(buf15, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 64, 16, 16), (16384, 256, 16, 1)) buf17 = empty_strided_cuda((32, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_5[grid(32)](buf17, 32, XBLOCK=32, num_warps=1, num_stages=1) buf18 = empty_strided_cuda((32, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_6[grid(32)](buf18, 32, XBLOCK=32, num_warps=1, num_stages=1) buf19 = empty_strided_cuda((32,), (1,), torch.int64) triton_poi_fused__to_copy_5[grid(32)](buf19, 32, XBLOCK=32, num_warps=1, num_stages=1) buf20 = empty_strided_cuda((32,), (1,), torch.int64) triton_poi_fused_add_clamp_6[grid(32)](buf20, 32, XBLOCK=32, num_warps=1, num_stages=1) buf21 = empty_strided_cuda((32,), (1,), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_7[grid(32)](buf21, 32, XBLOCK=32, num_warps=1, num_stages=1) buf23 = empty_strided_cuda((32, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_7[grid(32)](buf23, 32, XBLOCK=32, num_warps=1, num_stages=1) buf25 = extern_kernels.convolution(buf7, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf25, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf24 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.float32) buf26 = buf24 del buf24 buf44 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) triton_poi_fused__unsafe_index_add_convolution_leaky_relu_leaky_relu_backward_mul_sub_8[ grid(262144)](buf26, buf17, buf19, buf16, primals_11, buf20, buf21, buf18, buf23, buf25, primals_13, buf44, 262144, XBLOCK= 512, num_warps=8, num_stages=1) del buf25 del primals_13 buf27 = extern_kernels.convolution(buf26, primals_14, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf28 = empty_strided_cuda((64, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_9[grid(64)](buf28, 64, XBLOCK=64, num_warps=1, num_stages=1) buf29 = empty_strided_cuda((64, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_10[grid(64)](buf29, 64, XBLOCK=64, num_warps=1, num_stages=1) buf30 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused__to_copy_9[grid(64)](buf30, 64, XBLOCK=64, num_warps=1, num_stages=1) buf31 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused_add_clamp_10[grid(64)](buf31, 64, XBLOCK=64, num_warps=1, num_stages=1) buf32 = empty_strided_cuda((64,), (1,), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_11[grid(64)](buf32, 64, XBLOCK=64, num_warps=1, num_stages=1) buf34 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_11[grid(64)](buf34, 64, XBLOCK=64, num_warps=1, num_stages=1) buf35 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) buf36 = buf35 del buf35 triton_poi_fused__unsafe_index_add_convolution_leaky_relu_mul_sub_12[ grid(1048576)](buf36, buf28, buf30, buf27, primals_15, buf31, buf32, buf29, buf34, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) buf37 = extern_kernels.convolution(buf36, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf37, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf38 = buf37 del buf37 triton_poi_fused_convolution_13[grid(1048576)](buf38, primals_17, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf39 = extern_kernels.convolution(buf38, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf39, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf40 = buf39 del buf39 triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf40, primals_19, 1048576, XBLOCK=512, num_warps=8, num_stages=1) del primals_19 buf41 = extern_kernels.convolution(buf40, primals_20, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf41, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf42 = buf41 del buf41 triton_poi_fused_add_convolution_mul_sigmoid_14[grid(1048576)](buf42, primals_3, buf38, primals_21, 1048576, XBLOCK=512, num_warps=8, num_stages=1) del primals_21 buf43 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_15[grid (262144)](buf27, primals_15, buf43, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf27 del primals_15 buf45 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_16[grid (65536)](buf16, primals_11, buf45, 65536, XBLOCK=512, num_warps =4, num_stages=1) del buf16 del primals_11 return (buf42, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, buf1, buf3, buf5, buf7, buf9, buf11, buf13, buf15, buf17, buf18, buf19, buf20, buf21, buf23, buf26, buf28, buf29, buf30, buf31, buf32, buf34, buf36, buf38, buf40, buf43, buf44, buf45) class AttentionNew(nn.Module): def __init__(self, nf=64): super(AttentionNew, self).__init__() self.sAtt_1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.max_pool = nn.MaxPool2d(3, stride=2, padding=1) self.avg_pool = nn.AvgPool2d(3, stride=2, padding=1) self.sAtt_2 = nn.Conv2d(nf * 2, nf, 1, 1, bias=True) self.sAtt_3 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_4 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_5 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_L1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_L2 = nn.Conv2d(nf * 2, nf, 3, 1, 1, bias=True) self.sAtt_L3 = nn.Conv2d(nf, nf, 3, 1, 1, bias=True) self.sAtt_add_1 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.sAtt_add_2 = nn.Conv2d(nf, nf, 1, 1, bias=True) self.lrelu = nn.LeakyReLU(negative_slope=0.1, inplace=True) def forward(self, input_0): primals_1 = self.sAtt_1.weight primals_2 = self.sAtt_1.bias primals_4 = self.sAtt_2.weight primals_5 = self.sAtt_2.bias primals_10 = self.sAtt_3.weight primals_7 = self.sAtt_3.bias primals_6 = self.sAtt_4.weight primals_9 = self.sAtt_4.bias primals_12 = self.sAtt_5.weight primals_11 = self.sAtt_5.bias primals_14 = self.sAtt_L1.weight primals_13 = self.sAtt_L1.bias primals_8 = self.sAtt_L2.weight primals_15 = self.sAtt_L2.bias primals_16 = self.sAtt_L3.weight primals_17 = self.sAtt_L3.bias primals_18 = self.sAtt_add_1.weight primals_19 = self.sAtt_add_1.bias primals_20 = self.sAtt_add_2.weight primals_21 = self.sAtt_add_2.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]
juyongjiang/Simple-SR
Attention
false
7,044
[ "MIT" ]
1
76820511abc04fbe6e4a79d23c67aee97406d563
https://github.com/juyongjiang/Simple-SR/tree/76820511abc04fbe6e4a79d23c67aee97406d563
MSELoss
import torch import torch.nn as nn import torch.utils.data class MSELoss(nn.Module): def __init__(self): super(self.__class__, self).__init__() def forward(self, input, target): return torch.mean(torch.sum((input - target) ** 2, 1)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_mean_pow_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp4 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp5 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp9 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp10 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp14 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp15 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) 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 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK]) tmp21 = tl.sum(tmp19, 1)[:, None] tmp22 = 64.0 tmp23 = tmp21 / tmp22 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp23, 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_mean_pow_sub_sum_0[grid(1)](buf1, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class MSELossNew(nn.Module): def __init__(self): super(self.__class__, 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]
klovbe/UnsupervisedDeepLearning-Pytorch
MSELoss
false
7,045
[ "MIT" ]
1
35e8e49cd4024179db173f3dab2e6d1a5d037d35
https://github.com/klovbe/UnsupervisedDeepLearning-Pytorch/tree/35e8e49cd4024179db173f3dab2e6d1a5d037d35
BCELoss
import torch import torch.nn as nn import torch.utils.data class BCELoss(nn.Module): def __init__(self): super(self.__class__, self).__init__() def forward(self, input, target): return -torch.mean(torch.sum(target * torch.log(torch.clamp(input, min=1e-10)) + (1 - target) * torch.log(torch.clamp(1 - input, min=1e-10)), 1)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_clamp_log_mean_mul_neg_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp13 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp14 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp25 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp26 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp37 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp38 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp2 = 1e-10 tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp4 = tl_math.log(tmp3) tmp5 = tmp0 * tmp4 tmp6 = 1.0 tmp7 = tmp6 - tmp0 tmp8 = tmp6 - tmp1 tmp9 = triton_helpers.maximum(tmp8, tmp2) tmp10 = tl_math.log(tmp9) tmp11 = tmp7 * tmp10 tmp12 = tmp5 + tmp11 tmp15 = triton_helpers.maximum(tmp14, tmp2) tmp16 = tl_math.log(tmp15) tmp17 = tmp13 * tmp16 tmp18 = tmp6 - tmp13 tmp19 = tmp6 - tmp14 tmp20 = triton_helpers.maximum(tmp19, tmp2) tmp21 = tl_math.log(tmp20) tmp22 = tmp18 * tmp21 tmp23 = tmp17 + tmp22 tmp24 = tmp12 + tmp23 tmp27 = triton_helpers.maximum(tmp26, tmp2) tmp28 = tl_math.log(tmp27) tmp29 = tmp25 * tmp28 tmp30 = tmp6 - tmp25 tmp31 = tmp6 - tmp26 tmp32 = triton_helpers.maximum(tmp31, tmp2) tmp33 = tl_math.log(tmp32) tmp34 = tmp30 * tmp33 tmp35 = tmp29 + tmp34 tmp36 = tmp24 + tmp35 tmp39 = triton_helpers.maximum(tmp38, tmp2) tmp40 = tl_math.log(tmp39) tmp41 = tmp37 * tmp40 tmp42 = tmp6 - tmp37 tmp43 = tmp6 - tmp38 tmp44 = triton_helpers.maximum(tmp43, tmp2) tmp45 = tl_math.log(tmp44) tmp46 = tmp42 * tmp45 tmp47 = tmp41 + tmp46 tmp48 = tmp36 + tmp47 tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK]) tmp51 = tl.sum(tmp49, 1)[:, None] tmp52 = 64.0 tmp53 = tmp51 / tmp52 tmp54 = -tmp53 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp54, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_clamp_log_mean_mul_neg_rsub_sum_0[grid(1)](buf2, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class BCELossNew(nn.Module): def __init__(self): super(self.__class__, 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]
klovbe/UnsupervisedDeepLearning-Pytorch
BCELoss
false
7,046
[ "MIT" ]
1
35e8e49cd4024179db173f3dab2e6d1a5d037d35
https://github.com/klovbe/UnsupervisedDeepLearning-Pytorch/tree/35e8e49cd4024179db173f3dab2e6d1a5d037d35
MaxMarginCriterion
import torch import torch.nn as nn class MaxMarginCriterion(nn.Module): def __init__(self, visual_rank_weight, lang_rank_weight, margin): super(MaxMarginCriterion, self).__init__() self.visual_rank = visual_rank_weight > 0 self.lang_rank = lang_rank_weight > 0 self.visual_rank_weight = visual_rank_weight self.lang_rank_weight = lang_rank_weight self.margin = margin def forward(self, cossim): N = cossim.size(0) batch_size = 0 if self.visual_rank and not self.lang_rank: batch_size = N // 2 assert isinstance(batch_size, int) paired = cossim[:batch_size] unpaired = cossim[batch_size:] visual_rank_loss = self.visual_rank_weight * torch.clamp(self. margin + unpaired - paired, min=0) lang_rank_loss = 0.0 elif not self.visual_rank and self.lang_rank: batch_size = N // 2 assert isinstance(batch_size, int) cossim[:batch_size] unpaired = cossim[batch_size:] lang_rank_loss = self.lang_rank_weight * torch.clamp(self. margin + unpaired - paired, min=0) visual_rank_loss = 0.0 elif self.visual_rank and self.lang_rank: batch_size = N // 3 assert isinstance(batch_size, int) paired = cossim[:batch_size] visual_unpaired = cossim[batch_size:batch_size * 2] lang_unpaired = cossim[batch_size * 2:] visual_rank_loss = self.visual_rank_weight * torch.clamp(self. margin + visual_unpaired - paired, 0) lang_rank_loss = self.lang_rank_weight * torch.clamp(self. margin + lang_unpaired - paired, 0) else: raise NotImplementedError loss = (visual_rank_loss + lang_rank_loss).sum() / batch_size return loss def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'visual_rank_weight': 4, 'lang_rank_weight': 4, 'margin': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_mul_sub_sum_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 128 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 64 r2 = rindex tmp0 = tl.load(in_ptr0 + (64 + r0), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (128 + r2), None) tmp1 = 4.0 tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp5 = 0.0 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = tmp6 * tmp1 tmp9 = tmp8 + tmp1 tmp10 = tmp9 - tmp3 tmp11 = triton_helpers.maximum(tmp10, tmp5) tmp12 = tmp11 * tmp1 tmp13 = tmp7 + tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.sum(tmp14, 1)[:, None] tmp17 = 1.0 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp18, 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_add_clamp_div_mul_sub_sum_0[grid(1)](buf1, arg0_1, 1, 128, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf1, class MaxMarginCriterionNew(nn.Module): def __init__(self, visual_rank_weight, lang_rank_weight, margin): super(MaxMarginCriterionNew, self).__init__() self.visual_rank = visual_rank_weight > 0 self.lang_rank = lang_rank_weight > 0 self.visual_rank_weight = visual_rank_weight self.lang_rank_weight = lang_rank_weight self.margin = margin def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kmario23/MAttNet
MaxMarginCriterion
false
7,047
[ "MIT" ]
1
0d66321eb5dc9c8523a5ebf45f608b0672b051ab
https://github.com/kmario23/MAttNet/tree/0d66321eb5dc9c8523a5ebf45f608b0672b051ab
TanhTransform
import torch import torch.nn as nn def arctanh(x, eps=1e-06): """ Calculates the inverse hyperbolic tangent. """ x *= 1.0 - eps return torch.log((1 + x) / (1 - x)) * 0.5 class TanhTransform(nn.Module): """ Computes the tanh transform used to remove box constraints from C&W paper NOTE: This reparamterization trick is highly numerically unstable even for small-ish values so should really only be used for inputs that are bounded above or below by relatively small values Args: xmin (float or torch.Tensor): the lower bound for input values should either be a float or broadcastable with the input tensor where each element in the tensor corresponds to the lower bound of an input feature xmax (float or torch.Tensor): the lower bound for input values should either be a float or broadcastable with the input tensor where each element in the tensor corresponds to the upper bound of an input feature """ def __init__(self, xmin=0, xmax=1): super(TanhTransform, self).__init__() delta = xmax - xmin self.delta_2 = delta / 2 self.xmax = xmax self.xmin = xmin def forward(self, x): out = (x.tanh() + 1) * self.delta_2 + self.xmin return out def invert_forward(self, x): z = (x - self.xmin) / self.delta_2 - 1 return arctanh(z) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_tanh_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 = libdevice.tanh(tmp0) tmp2 = 1.0 tmp3 = tmp1 + tmp2 tmp4 = 0.5 tmp5 = tmp3 * tmp4 tmp6 = 0.0 tmp7 = tmp5 + tmp6 tl.store(out_ptr0 + x0, tmp7, 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_mul_tanh_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, def arctanh(x, eps=1e-06): """ Calculates the inverse hyperbolic tangent. """ x *= 1.0 - eps return torch.log((1 + x) / (1 - x)) * 0.5 class TanhTransformNew(nn.Module): """ Computes the tanh transform used to remove box constraints from C&W paper NOTE: This reparamterization trick is highly numerically unstable even for small-ish values so should really only be used for inputs that are bounded above or below by relatively small values Args: xmin (float or torch.Tensor): the lower bound for input values should either be a float or broadcastable with the input tensor where each element in the tensor corresponds to the lower bound of an input feature xmax (float or torch.Tensor): the lower bound for input values should either be a float or broadcastable with the input tensor where each element in the tensor corresponds to the upper bound of an input feature """ def __init__(self, xmin=0, xmax=1): super(TanhTransformNew, self).__init__() delta = xmax - xmin self.delta_2 = delta / 2 self.xmax = xmax self.xmin = xmin def invert_forward(self, x): z = (x - self.xmin) / self.delta_2 - 1 return arctanh(z) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
knalbant/oppel
TanhTransform
false
7,048
[ "MIT" ]
1
03f840565ef64587ddb7a8b4145d8df7fb0279a3
https://github.com/knalbant/oppel/tree/03f840565ef64587ddb7a8b4145d8df7fb0279a3
BCEFocalLoss
import torch import torch.nn as nn class BCEFocalLoss(nn.Module): def __init__(self, alpha=0.25, gamma=2.0): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, preds, targets): bce_loss = nn.BCEWithLogitsLoss(reduction='none')(preds, targets) probas = torch.sigmoid(preds) loss = targets * self.alpha * (1.0 - probas ) ** self.gamma * bce_loss + (1.0 - targets ) * probas ** self.gamma * bce_loss loss = loss.mean() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math 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_binary_cross_entropy_with_logits_mean_mul_pow_rsub_sigmoid_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = 1.0 tmp6 = tmp5 - tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp2 * tmp7 tmp9 = tmp5 - tmp0 tmp10 = tmp9 * tmp3 tmp11 = 0.0 tmp12 = triton_helpers.minimum(tmp11, tmp3) tmp13 = tl_math.abs(tmp3) tmp14 = -tmp13 tmp15 = tl_math.exp(tmp14) tmp16 = libdevice.log1p(tmp15) tmp17 = tmp12 - tmp16 tmp18 = tmp10 - tmp17 tmp19 = tmp8 * tmp18 tmp20 = tmp4 * tmp4 tmp21 = tmp9 * tmp20 tmp22 = tmp21 * tmp18 tmp23 = tmp19 + tmp22 tmp24 = tl.broadcast_to(tmp23, [RBLOCK]) tmp26 = triton_helpers.promote_to_tensor(tl.sum(tmp24, 0)) tmp27 = 256.0 tmp28 = tmp26 / tmp27 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp28, 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_binary_cross_entropy_with_logits_mean_mul_pow_rsub_sigmoid_0[ grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class BCEFocalLossNew(nn.Module): def __init__(self, alpha=0.25, gamma=2.0): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
koukyo1994/riadd-competition
BCEFocalLoss
false
7,049
[ "MIT" ]
1
0e399305aef21d40125cadccee55be1f0b310216
https://github.com/koukyo1994/riadd-competition/tree/0e399305aef21d40125cadccee55be1f0b310216
LSEPLoss
import torch import torch.nn as nn def lsep_loss_stable(input, target, average=True): n = input.size(0) differences = input.unsqueeze(1) - input.unsqueeze(2) where_lower = (target.unsqueeze(1) < target.unsqueeze(2)).float() differences = differences.view(n, -1) where_lower = where_lower.view(n, -1) max_difference, _index = torch.max(differences, dim=1, keepdim=True) differences = differences - max_difference exps = differences.exp() * where_lower lsep = max_difference + torch.log(torch.exp(-max_difference) + exps.sum(-1) ) if average: return lsep.mean() else: return lsep class LSEPLoss(nn.Module): def __init__(self): super().__init__() def forward(self, preds, targets): return lsep_loss_stable(preds, targets) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_exp_max_mul_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (64 * x0 + r1 % 64), None) tmp1 = tl.load(in_ptr0 + (16 * (r1 // 64) + 64 * x0 + r1 % 16), None) tmp8 = tl.load(in_ptr1 + (64 * x0 + r1 % 64), None) tmp9 = tl.load(in_ptr1 + (16 * (r1 // 64) + 64 * x0 + r1 % 16), None) tmp2 = tmp0 - tmp1 tmp3 = tl.broadcast_to(tmp2, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp3, 0)) tmp6 = tmp2 - tmp5 tmp7 = tl_math.exp(tmp6) tmp10 = tmp8 < tmp9 tmp11 = tmp10.to(tl.float32) tmp12 = tmp7 * tmp11 tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tl.store(out_ptr0 + x0, tmp5, None) tl.store(out_ptr1 + x0, tmp15, None) @triton.jit def triton_per_fused_add_exp_log_mean_neg_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex // 4 r0 = rindex % 4 tmp0 = tl.load(in_ptr0 + r1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last') tmp1 = -tmp0 tmp2 = tl_math.exp(tmp1) tmp4 = tmp2 + tmp3 tmp5 = tl_math.log(tmp4) tmp6 = tmp0 + tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 16.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 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), (1, 4), torch.float32) buf2 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_exp_max_mul_sub_sum_0[grid(4)](arg0_1, arg1_1, buf0, buf2, 4, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused_add_exp_log_mean_neg_1[grid(1)](buf4, buf0, buf2, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf2 return buf4, def lsep_loss_stable(input, target, average=True): n = input.size(0) differences = input.unsqueeze(1) - input.unsqueeze(2) where_lower = (target.unsqueeze(1) < target.unsqueeze(2)).float() differences = differences.view(n, -1) where_lower = where_lower.view(n, -1) max_difference, _index = torch.max(differences, dim=1, keepdim=True) differences = differences - max_difference exps = differences.exp() * where_lower lsep = max_difference + torch.log(torch.exp(-max_difference) + exps.sum(-1) ) if average: return lsep.mean() else: return lsep class LSEPLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
koukyo1994/riadd-competition
LSEPLoss
false
7,050
[ "MIT" ]
1
0e399305aef21d40125cadccee55be1f0b310216
https://github.com/koukyo1994/riadd-competition/tree/0e399305aef21d40125cadccee55be1f0b310216
SwaVLoss
import torch import torch.nn.functional as F from typing import List import torch.nn as nn @torch.no_grad() def sinkhorn(out: 'torch.Tensor', iterations: 'int'=3, epsilon: 'float'=0.05): """Distributed sinkhorn algorithm. As outlined in [0] and implemented in [1]. [0]: SwaV, 2020, https://arxiv.org/abs/2006.09882 [1]: https://github.com/facebookresearch/swav/ Args: out: Similarity of the features and the SwaV prototypes. iterations: Number of sinkhorn iterations. epsilon: Temperature parameter. Returns: Soft codes Q assigning each feature to a prototype. """ Q = torch.exp(out / epsilon).t() sum_Q = torch.sum(Q) Q /= sum_Q B = Q.shape[1] K = Q.shape[0] for i in range(iterations): sum_of_rows = torch.sum(Q, dim=1, keepdim=True) Q /= sum_of_rows Q /= K Q /= torch.sum(Q, dim=0, keepdim=True) Q /= B Q *= B return Q.t() class SwaVLoss(nn.Module): """Implementation of the SwaV loss. Attributes: temperature: Temperature parameter used for cross entropy calculations. sinkhorn_iterations: Number of iterations of the sinkhorn algorithm. sinkhorn_epsilon: Temperature parameter used in the sinkhorn algorithm. """ def __init__(self, temperature: 'float'=0.1, sinkhorn_iterations: 'int' =3, sinkhorn_epsilon: 'float'=0.05): super(SwaVLoss, self).__init__() self.temperature = temperature self.sinkhorn_iterations = sinkhorn_iterations self.sinkhorn_epsilon = sinkhorn_epsilon def subloss(self, z: 'torch.Tensor', q: 'torch.Tensor'): """Calculates the cross entropy for the SwaV prediction problem. Args: z: Similarity of the features and the SwaV prototypes. q: Codes obtained from Sinkhorn iterations. Returns: Cross entropy between predictions z and codes q. """ return -torch.mean(torch.sum(q * F.log_softmax(z / self.temperature, dim=1), dim=1)) def forward(self, high_resolution_outputs: 'List[torch.Tensor]', low_resolution_outputs: 'List[torch.Tensor]'): """Computes the SwaV loss for a set of high and low resolution outputs. Args: high_resolution_outputs: List of similarities of features and SwaV prototypes for the high resolution crops. low_resolution_outputs: List of similarities of features and SwaV prototypes for the low resolution crops. Returns: Swapping assignments between views loss (SwaV) as described in [0]. [0]: SwaV, 2020, https://arxiv.org/abs/2006.09882 """ n_crops = len(high_resolution_outputs) + len(low_resolution_outputs) loss = 0.0 for i in range(len(high_resolution_outputs)): with torch.no_grad(): q = sinkhorn(high_resolution_outputs[i].detach(), iterations=self.sinkhorn_iterations, epsilon=self. sinkhorn_epsilon) subloss = 0.0 for v in range(len(high_resolution_outputs)): if v != i: subloss += self.subloss(high_resolution_outputs[v], q) for v in range(len(low_resolution_outputs)): subloss += self.subloss(low_resolution_outputs[v], q) loss += subloss / (n_crops - 1) return loss / len(high_resolution_outputs) def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn.functional as F import torch.nn as nn 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_sum_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.sum(tmp4, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) @triton.jit def triton_poi_fused_sum_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) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (4 + x0), xmask) tmp12 = tl.load(in_ptr0 + (8 + x0), xmask) tmp17 = tl.load(in_ptr0 + (12 + x0), xmask) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp7 * tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tmp9 / tmp5 tmp11 = tmp6 + tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 + tmp15 tmp18 = tmp17 * tmp1 tmp19 = tl_math.exp(tmp18) tmp20 = tmp19 / tmp5 tmp21 = tmp16 + tmp20 tl.store(out_ptr0 + x0, tmp21, xmask) @triton.jit def triton_poi_fused_sum_2(in_ptr0, in_ptr1, in_ptr2, 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') tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp12 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr2 + 1) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp25 = tl.load(in_ptr2 + 2) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp30 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp34 = tl.load(in_ptr2 + 3) tmp35 = tl.broadcast_to(tmp34, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp9 = tmp6 / tmp8 tmp10 = 0.25 tmp11 = tmp9 * tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp18 = tmp15 / tmp17 tmp19 = tmp18 * tmp10 tmp20 = tmp11 + tmp19 tmp22 = tmp21 * tmp1 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp27 = tmp24 / tmp26 tmp28 = tmp27 * tmp10 tmp29 = tmp20 + tmp28 tmp31 = tmp30 * tmp1 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp36 = tmp33 / tmp35 tmp37 = tmp36 * tmp10 tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_sum_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x0, xmask) tmp11 = tl.load(in_ptr3 + 0) tmp12 = tl.broadcast_to(tmp11, [XBLOCK]) tmp15 = tl.load(in_ptr0 + (4 + x0), xmask) tmp21 = tl.load(in_ptr3 + 1) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp26 = tl.load(in_ptr0 + (8 + x0), xmask) tmp32 = tl.load(in_ptr3 + 2) tmp33 = tl.broadcast_to(tmp32, [XBLOCK]) tmp37 = tl.load(in_ptr0 + (12 + x0), xmask) tmp43 = tl.load(in_ptr3 + 3) tmp44 = tl.broadcast_to(tmp43, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp6 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp13 = tmp10 / tmp12 tmp14 = tmp13 * tmp9 tmp16 = tmp15 * tmp1 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 / tmp5 tmp19 = tmp18 / tmp7 tmp20 = tmp19 * tmp9 tmp23 = tmp20 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = tmp14 + tmp24 tmp27 = tmp26 * tmp1 tmp28 = tl_math.exp(tmp27) tmp29 = tmp28 / tmp5 tmp30 = tmp29 / tmp7 tmp31 = tmp30 * tmp9 tmp34 = tmp31 / tmp33 tmp35 = tmp34 * tmp9 tmp36 = tmp25 + tmp35 tmp38 = tmp37 * tmp1 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 / tmp5 tmp41 = tmp40 / tmp7 tmp42 = tmp41 * tmp9 tmp45 = tmp42 / tmp44 tmp46 = tmp45 * tmp9 tmp47 = tmp36 + tmp46 tl.store(out_ptr0 + x0, tmp47, xmask) @triton.jit def triton_poi_fused_div_4(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 x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp6 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp12 = tmp10 / tmp11 tmp13 = tmp12 * tmp9 tmp15 = tmp13 / tmp14 tmp16 = tmp15 * tmp9 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_div_5(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 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_div_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_mul_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp11 = 4.0 tmp12 = tmp10 * tmp11 tl.store(out_ptr0 + x2, tmp12, xmask) @triton.jit def triton_per_fused_sum_8(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex r2 = rindex // 4 tmp0 = tl.load(in_ptr0 + (16 + r0), None) tmp9 = tl.load(in_ptr0 + (16 + 4 * r2), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (17 + 4 * r2), None, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (18 + 4 * r2), None, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr0 + (19 + 4 * r2), None, eviction_policy='evict_last' ) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.sum(tmp4, 1)[:, None] tmp7 = 1.0 tmp8 = tmp0 * tmp7 tmp10 = tmp9 * tmp7 tmp12 = tmp11 * tmp7 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp15 = tmp14 * tmp7 tmp16 = triton_helpers.maximum(tmp13, tmp15) tmp18 = tmp17 * tmp7 tmp19 = triton_helpers.maximum(tmp16, tmp18) tmp20 = tmp8 - tmp19 tmp21 = 10.0 tmp22 = tmp20 * tmp21 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp22, None) tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp22, None) tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) @triton.jit def triton_poi_fused_sum_9(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 + (16 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (20 + x0), xmask) tmp12 = tl.load(in_ptr0 + (24 + x0), xmask) tmp17 = tl.load(in_ptr0 + (28 + x0), xmask) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp7 * tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tmp9 / tmp5 tmp11 = tmp6 + tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 + tmp15 tmp18 = tmp17 * tmp1 tmp19 = tl_math.exp(tmp18) tmp20 = tmp19 / tmp5 tmp21 = tmp16 + tmp20 tl.store(out_ptr0 + x0, tmp21, xmask) @triton.jit def triton_poi_fused_sum_10(in_ptr0, in_ptr1, in_ptr2, 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 + (16 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp12 = tl.load(in_ptr0 + (17 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr2 + 1) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (18 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr2 + 2) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp30 = tl.load(in_ptr0 + (19 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp34 = tl.load(in_ptr2 + 3) tmp35 = tl.broadcast_to(tmp34, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp9 = tmp6 / tmp8 tmp10 = 0.25 tmp11 = tmp9 * tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp18 = tmp15 / tmp17 tmp19 = tmp18 * tmp10 tmp20 = tmp11 + tmp19 tmp22 = tmp21 * tmp1 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp27 = tmp24 / tmp26 tmp28 = tmp27 * tmp10 tmp29 = tmp20 + tmp28 tmp31 = tmp30 * tmp1 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp36 = tmp33 / tmp35 tmp37 = tmp36 * tmp10 tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_sum_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 + (16 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x0, xmask) tmp11 = tl.load(in_ptr3 + 0) tmp12 = tl.broadcast_to(tmp11, [XBLOCK]) tmp15 = tl.load(in_ptr0 + (20 + x0), xmask) tmp21 = tl.load(in_ptr3 + 1) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp26 = tl.load(in_ptr0 + (24 + x0), xmask) tmp32 = tl.load(in_ptr3 + 2) tmp33 = tl.broadcast_to(tmp32, [XBLOCK]) tmp37 = tl.load(in_ptr0 + (28 + x0), xmask) tmp43 = tl.load(in_ptr3 + 3) tmp44 = tl.broadcast_to(tmp43, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp6 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp13 = tmp10 / tmp12 tmp14 = tmp13 * tmp9 tmp16 = tmp15 * tmp1 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 / tmp5 tmp19 = tmp18 / tmp7 tmp20 = tmp19 * tmp9 tmp23 = tmp20 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = tmp14 + tmp24 tmp27 = tmp26 * tmp1 tmp28 = tl_math.exp(tmp27) tmp29 = tmp28 / tmp5 tmp30 = tmp29 / tmp7 tmp31 = tmp30 * tmp9 tmp34 = tmp31 / tmp33 tmp35 = tmp34 * tmp9 tmp36 = tmp25 + tmp35 tmp38 = tmp37 * tmp1 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 / tmp5 tmp41 = tmp40 / tmp7 tmp42 = tmp41 * tmp9 tmp45 = tmp42 / tmp44 tmp46 = tmp45 * tmp9 tmp47 = tmp36 + tmp46 tl.store(out_ptr0 + x0, tmp47, xmask) @triton.jit def triton_poi_fused_div_12(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + (16 + x2), xmask) tmp3 = tl.load(in_ptr0 + (16 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (17 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (18 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (19 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + 0) tmp21 = tl.broadcast_to(tmp20, [XBLOCK]) tmp23 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr4 + x0, 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 = 10.0 tmp16 = tmp14 * tmp15 tmp17 = 20.0 tmp18 = tmp0 * tmp17 tmp19 = tl_math.exp(tmp18) tmp22 = tmp19 / tmp21 tmp24 = tmp22 / tmp23 tmp25 = 0.25 tmp26 = tmp24 * tmp25 tmp28 = tmp26 / tmp27 tmp29 = tmp28 * tmp25 tmp31 = tmp29 / tmp30 tmp32 = tmp31 * tmp25 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp32, xmask) @triton.jit def triton_per_fused_sum_13(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex r2 = rindex // 4 tmp0 = tl.load(in_ptr0 + (32 + r0), None) tmp9 = tl.load(in_ptr0 + (32 + 4 * r2), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (33 + 4 * r2), None, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (34 + 4 * r2), None, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr0 + (35 + 4 * r2), None, eviction_policy='evict_last' ) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.sum(tmp4, 1)[:, None] tmp7 = 1.0 tmp8 = tmp0 * tmp7 tmp10 = tmp9 * tmp7 tmp12 = tmp11 * tmp7 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp15 = tmp14 * tmp7 tmp16 = triton_helpers.maximum(tmp13, tmp15) tmp18 = tmp17 * tmp7 tmp19 = triton_helpers.maximum(tmp16, tmp18) tmp20 = tmp8 - tmp19 tmp21 = 10.0 tmp22 = tmp20 * tmp21 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp22, None) tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) @triton.jit def triton_poi_fused_sum_14(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 + (32 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (36 + x0), xmask) tmp12 = tl.load(in_ptr0 + (40 + x0), xmask) tmp17 = tl.load(in_ptr0 + (44 + x0), xmask) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp7 * tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tmp9 / tmp5 tmp11 = tmp6 + tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 + tmp15 tmp18 = tmp17 * tmp1 tmp19 = tl_math.exp(tmp18) tmp20 = tmp19 / tmp5 tmp21 = tmp16 + tmp20 tl.store(out_ptr0 + x0, tmp21, xmask) @triton.jit def triton_poi_fused_sum_15(in_ptr0, in_ptr1, in_ptr2, 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 + (32 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp12 = tl.load(in_ptr0 + (33 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr2 + 1) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (34 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr2 + 2) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp30 = tl.load(in_ptr0 + (35 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp34 = tl.load(in_ptr2 + 3) tmp35 = tl.broadcast_to(tmp34, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp9 = tmp6 / tmp8 tmp10 = 0.25 tmp11 = tmp9 * tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp18 = tmp15 / tmp17 tmp19 = tmp18 * tmp10 tmp20 = tmp11 + tmp19 tmp22 = tmp21 * tmp1 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp27 = tmp24 / tmp26 tmp28 = tmp27 * tmp10 tmp29 = tmp20 + tmp28 tmp31 = tmp30 * tmp1 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp36 = tmp33 / tmp35 tmp37 = tmp36 * tmp10 tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_sum_16(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 + (32 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x0, xmask) tmp11 = tl.load(in_ptr3 + 0) tmp12 = tl.broadcast_to(tmp11, [XBLOCK]) tmp15 = tl.load(in_ptr0 + (36 + x0), xmask) tmp21 = tl.load(in_ptr3 + 1) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp26 = tl.load(in_ptr0 + (40 + x0), xmask) tmp32 = tl.load(in_ptr3 + 2) tmp33 = tl.broadcast_to(tmp32, [XBLOCK]) tmp37 = tl.load(in_ptr0 + (44 + x0), xmask) tmp43 = tl.load(in_ptr3 + 3) tmp44 = tl.broadcast_to(tmp43, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp6 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp13 = tmp10 / tmp12 tmp14 = tmp13 * tmp9 tmp16 = tmp15 * tmp1 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 / tmp5 tmp19 = tmp18 / tmp7 tmp20 = tmp19 * tmp9 tmp23 = tmp20 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = tmp14 + tmp24 tmp27 = tmp26 * tmp1 tmp28 = tl_math.exp(tmp27) tmp29 = tmp28 / tmp5 tmp30 = tmp29 / tmp7 tmp31 = tmp30 * tmp9 tmp34 = tmp31 / tmp33 tmp35 = tmp34 * tmp9 tmp36 = tmp25 + tmp35 tmp38 = tmp37 * tmp1 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 / tmp5 tmp41 = tmp40 / tmp7 tmp42 = tmp41 * tmp9 tmp45 = tmp42 / tmp44 tmp46 = tmp45 * tmp9 tmp47 = tmp36 + tmp46 tl.store(out_ptr0 + x0, tmp47, xmask) @triton.jit def triton_poi_fused_div_17(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, 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 + (32 + x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (33 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (34 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (35 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + 0) tmp21 = tl.broadcast_to(tmp20, [XBLOCK]) tmp23 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr4 + x0, 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 = 10.0 tmp16 = tmp14 * tmp15 tmp17 = 20.0 tmp18 = tmp0 * tmp17 tmp19 = tl_math.exp(tmp18) tmp22 = tmp19 / tmp21 tmp24 = tmp22 / tmp23 tmp25 = 0.25 tmp26 = tmp24 * tmp25 tmp28 = tmp26 / tmp27 tmp29 = tmp28 * tmp25 tmp31 = tmp29 / tmp30 tmp32 = tmp31 * tmp25 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp32, xmask) @triton.jit def triton_per_fused_sum_18(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + (48 + r0), None) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.sum(tmp4, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) @triton.jit def triton_poi_fused_sum_19(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 + (48 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (52 + x0), xmask) tmp12 = tl.load(in_ptr0 + (56 + x0), xmask) tmp17 = tl.load(in_ptr0 + (60 + x0), xmask) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp7 * tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tmp9 / tmp5 tmp11 = tmp6 + tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 + tmp15 tmp18 = tmp17 * tmp1 tmp19 = tl_math.exp(tmp18) tmp20 = tmp19 / tmp5 tmp21 = tmp16 + tmp20 tl.store(out_ptr0 + x0, tmp21, xmask) @triton.jit def triton_poi_fused_sum_20(in_ptr0, in_ptr1, in_ptr2, 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 + (48 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp12 = tl.load(in_ptr0 + (49 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr2 + 1) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (50 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr2 + 2) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp30 = tl.load(in_ptr0 + (51 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp34 = tl.load(in_ptr2 + 3) tmp35 = tl.broadcast_to(tmp34, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp9 = tmp6 / tmp8 tmp10 = 0.25 tmp11 = tmp9 * tmp10 tmp13 = tmp12 * tmp1 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp18 = tmp15 / tmp17 tmp19 = tmp18 * tmp10 tmp20 = tmp11 + tmp19 tmp22 = tmp21 * tmp1 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp27 = tmp24 / tmp26 tmp28 = tmp27 * tmp10 tmp29 = tmp20 + tmp28 tmp31 = tmp30 * tmp1 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp36 = tmp33 / tmp35 tmp37 = tmp36 * tmp10 tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_sum_21(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 + (48 + x0), xmask) tmp4 = tl.load(in_ptr1 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp7 = tl.load(in_ptr2 + x0, xmask) tmp11 = tl.load(in_ptr3 + 0) tmp12 = tl.broadcast_to(tmp11, [XBLOCK]) tmp15 = tl.load(in_ptr0 + (52 + x0), xmask) tmp21 = tl.load(in_ptr3 + 1) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp26 = tl.load(in_ptr0 + (56 + x0), xmask) tmp32 = tl.load(in_ptr3 + 2) tmp33 = tl.broadcast_to(tmp32, [XBLOCK]) tmp37 = tl.load(in_ptr0 + (60 + x0), xmask) tmp43 = tl.load(in_ptr3 + 3) tmp44 = tl.broadcast_to(tmp43, [XBLOCK]) tmp1 = 20.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.exp(tmp2) tmp6 = tmp3 / tmp5 tmp8 = tmp6 / tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tmp13 = tmp10 / tmp12 tmp14 = tmp13 * tmp9 tmp16 = tmp15 * tmp1 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 / tmp5 tmp19 = tmp18 / tmp7 tmp20 = tmp19 * tmp9 tmp23 = tmp20 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = tmp14 + tmp24 tmp27 = tmp26 * tmp1 tmp28 = tl_math.exp(tmp27) tmp29 = tmp28 / tmp5 tmp30 = tmp29 / tmp7 tmp31 = tmp30 * tmp9 tmp34 = tmp31 / tmp33 tmp35 = tmp34 * tmp9 tmp36 = tmp25 + tmp35 tmp38 = tmp37 * tmp1 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 / tmp5 tmp41 = tmp40 / tmp7 tmp42 = tmp41 * tmp9 tmp45 = tmp42 / tmp44 tmp46 = tmp45 * tmp9 tmp47 = tmp36 + tmp46 tl.store(out_ptr0 + x0, tmp47, xmask) @triton.jit def triton_poi_fused_div_22(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 + (48 + x2), xmask) tmp3 = tl.load(in_ptr0 + (48 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (49 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (50 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (51 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + 0) tmp21 = tl.broadcast_to(tmp20, [XBLOCK]) tmp23 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr4 + x0, 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 = 10.0 tmp16 = tmp14 * tmp15 tmp17 = 20.0 tmp18 = tmp0 * tmp17 tmp19 = tl_math.exp(tmp18) tmp22 = tmp19 / tmp21 tmp24 = tmp22 / tmp23 tmp25 = 0.25 tmp26 = tmp24 * tmp25 tmp28 = tmp26 / tmp27 tmp29 = tmp28 * tmp25 tmp31 = tmp29 / tmp30 tmp32 = tmp31 * tmp25 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp16, xmask) tl.store(out_ptr3 + x2, tmp32, xmask) @triton.jit def triton_poi_fused_23(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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) 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_24(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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 + (16 + x2), xmask) tmp3 = tl.load(in_ptr0 + (16 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (17 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (18 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (19 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_25(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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 + (32 + x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (33 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (34 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (35 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_26(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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 + (48 + x2), xmask) tmp3 = tl.load(in_ptr0 + (48 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (49 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (50 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (51 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) tl.store(out_ptr2 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_27(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) 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_28(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 + (16 + x2), xmask) tmp3 = tl.load(in_ptr0 + (16 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (17 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (18 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (19 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_29(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 + (32 + x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (33 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (34 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (35 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_30(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 + (48 + x2), xmask) tmp3 = tl.load(in_ptr0 + (48 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (49 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp8 = tl.load(in_ptr0 + (50 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (51 + 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 = 10.0 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_per_fused__log_softmax_add_div_mean_mul_neg_sum_31(in_out_ptr0, 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, in_ptr13, in_ptr14, in_ptr15, in_ptr16, in_ptr17, in_ptr18, in_ptr19, in_ptr20, in_ptr21, in_ptr22, in_ptr23, in_ptr24, in_ptr25, in_ptr26, in_ptr27, in_ptr28, in_ptr29, in_ptr30, in_ptr31, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp9 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp15 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp23 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last') tmp32 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp35 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp38 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp56 = tl.load(in_ptr3 + 4 * r0, None, eviction_policy='evict_last') tmp58 = tl.load(in_ptr3 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp61 = tl.load(in_ptr3 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp64 = tl.load(in_ptr3 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp82 = tl.load(in_ptr4 + 4 * r0, None, eviction_policy='evict_last') tmp84 = tl.load(in_ptr4 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp87 = tl.load(in_ptr4 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp90 = tl.load(in_ptr4 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp108 = tl.load(in_ptr5 + 4 * r0, None, eviction_policy='evict_last') tmp110 = tl.load(in_ptr5 + (1 + 4 * r0), None, eviction_policy='evict_last' ) tmp113 = tl.load(in_ptr5 + (2 + 4 * r0), None, eviction_policy='evict_last' ) tmp116 = tl.load(in_ptr5 + (3 + 4 * r0), None, eviction_policy='evict_last' ) tmp134 = tl.load(in_ptr6 + 4 * r0, None, eviction_policy='evict_last') tmp136 = tl.load(in_ptr6 + (1 + 4 * r0), None, eviction_policy='evict_last' ) tmp139 = tl.load(in_ptr6 + (2 + 4 * r0), None, eviction_policy='evict_last' ) tmp142 = tl.load(in_ptr6 + (3 + 4 * r0), None, eviction_policy='evict_last' ) tmp160 = tl.load(in_ptr7 + 4 * r0, None, eviction_policy='evict_last') tmp162 = tl.load(in_ptr7 + (1 + 4 * r0), None, eviction_policy='evict_last' ) tmp165 = tl.load(in_ptr7 + (2 + 4 * r0), None, eviction_policy='evict_last' ) tmp168 = tl.load(in_ptr7 + (3 + 4 * r0), None, eviction_policy='evict_last' ) tmp186 = tl.load(in_ptr8 + 4 * r0, None, eviction_policy='evict_last') tmp187 = tl.load(in_ptr9 + 4 * r0, None, eviction_policy='evict_last') tmp189 = tl.load(in_ptr9 + (1 + 4 * r0), None, eviction_policy='evict_last' ) tmp192 = tl.load(in_ptr9 + (2 + 4 * r0), None, eviction_policy='evict_last' ) tmp195 = tl.load(in_ptr9 + (3 + 4 * r0), None, eviction_policy='evict_last' ) tmp201 = tl.load(in_ptr8 + (1 + 4 * r0), None, eviction_policy='evict_last' ) tmp205 = tl.load(in_ptr8 + (2 + 4 * r0), None, eviction_policy='evict_last' ) tmp209 = tl.load(in_ptr8 + (3 + 4 * r0), None, eviction_policy='evict_last' ) tmp216 = tl.load(in_ptr10 + 4 * r0, None, eviction_policy='evict_last') tmp218 = tl.load(in_ptr10 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp221 = tl.load(in_ptr10 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp224 = tl.load(in_ptr10 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp242 = tl.load(in_ptr11 + 4 * r0, None, eviction_policy='evict_last') tmp244 = tl.load(in_ptr11 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp247 = tl.load(in_ptr11 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp250 = tl.load(in_ptr11 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp268 = tl.load(in_ptr12 + 4 * r0, None, eviction_policy='evict_last') tmp270 = tl.load(in_ptr12 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp273 = tl.load(in_ptr12 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp276 = tl.load(in_ptr12 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp294 = tl.load(in_ptr13 + 4 * r0, None, eviction_policy='evict_last') tmp296 = tl.load(in_ptr13 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp299 = tl.load(in_ptr13 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp302 = tl.load(in_ptr13 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp320 = tl.load(in_ptr14 + 4 * r0, None, eviction_policy='evict_last') tmp322 = tl.load(in_ptr14 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp325 = tl.load(in_ptr14 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp328 = tl.load(in_ptr14 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp346 = tl.load(in_ptr15 + 4 * r0, None, eviction_policy='evict_last') tmp348 = tl.load(in_ptr15 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp351 = tl.load(in_ptr15 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp354 = tl.load(in_ptr15 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp372 = tl.load(in_ptr16 + 4 * r0, None, eviction_policy='evict_last') tmp373 = tl.load(in_ptr17 + 4 * r0, None, eviction_policy='evict_last') tmp375 = tl.load(in_ptr17 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp378 = tl.load(in_ptr17 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp381 = tl.load(in_ptr17 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp387 = tl.load(in_ptr16 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp391 = tl.load(in_ptr16 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp395 = tl.load(in_ptr16 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp402 = tl.load(in_ptr18 + 4 * r0, None, eviction_policy='evict_last') tmp404 = tl.load(in_ptr18 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp407 = tl.load(in_ptr18 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp410 = tl.load(in_ptr18 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp428 = tl.load(in_ptr19 + 4 * r0, None, eviction_policy='evict_last') tmp430 = tl.load(in_ptr19 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp433 = tl.load(in_ptr19 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp436 = tl.load(in_ptr19 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp454 = tl.load(in_ptr20 + 4 * r0, None, eviction_policy='evict_last') tmp456 = tl.load(in_ptr20 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp459 = tl.load(in_ptr20 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp462 = tl.load(in_ptr20 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp480 = tl.load(in_ptr21 + 4 * r0, None, eviction_policy='evict_last') tmp482 = tl.load(in_ptr21 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp485 = tl.load(in_ptr21 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp488 = tl.load(in_ptr21 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp506 = tl.load(in_ptr22 + 4 * r0, None, eviction_policy='evict_last') tmp508 = tl.load(in_ptr22 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp511 = tl.load(in_ptr22 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp514 = tl.load(in_ptr22 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp532 = tl.load(in_ptr23 + 4 * r0, None, eviction_policy='evict_last') tmp534 = tl.load(in_ptr23 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp537 = tl.load(in_ptr23 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp540 = tl.load(in_ptr23 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp558 = tl.load(in_ptr24 + 4 * r0, None, eviction_policy='evict_last') tmp559 = tl.load(in_ptr25 + 4 * r0, None, eviction_policy='evict_last') tmp561 = tl.load(in_ptr25 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp564 = tl.load(in_ptr25 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp567 = tl.load(in_ptr25 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp573 = tl.load(in_ptr24 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp577 = tl.load(in_ptr24 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp581 = tl.load(in_ptr24 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp588 = tl.load(in_ptr26 + 4 * r0, None, eviction_policy='evict_last') tmp590 = tl.load(in_ptr26 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp593 = tl.load(in_ptr26 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp596 = tl.load(in_ptr26 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp614 = tl.load(in_ptr27 + 4 * r0, None, eviction_policy='evict_last') tmp616 = tl.load(in_ptr27 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp619 = tl.load(in_ptr27 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp622 = tl.load(in_ptr27 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp640 = tl.load(in_ptr28 + 4 * r0, None, eviction_policy='evict_last') tmp642 = tl.load(in_ptr28 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp645 = tl.load(in_ptr28 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp648 = tl.load(in_ptr28 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp666 = tl.load(in_ptr29 + 4 * r0, None, eviction_policy='evict_last') tmp668 = tl.load(in_ptr29 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp671 = tl.load(in_ptr29 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp674 = tl.load(in_ptr29 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp692 = tl.load(in_ptr30 + 4 * r0, None, eviction_policy='evict_last') tmp694 = tl.load(in_ptr30 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp697 = tl.load(in_ptr30 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp700 = tl.load(in_ptr30 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp718 = tl.load(in_ptr31 + 4 * r0, None, eviction_policy='evict_last') tmp720 = tl.load(in_ptr31 + (1 + 4 * r0), None, eviction_policy= 'evict_last') tmp723 = tl.load(in_ptr31 + (2 + 4 * r0), None, eviction_policy= 'evict_last') tmp726 = tl.load(in_ptr31 + (3 + 4 * r0), None, eviction_policy= 'evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp1 - tmp12 tmp14 = tmp0 * tmp13 tmp16 = tmp3 - tmp12 tmp17 = tmp15 * tmp16 tmp18 = tmp14 + tmp17 tmp20 = tmp6 - tmp12 tmp21 = tmp19 * tmp20 tmp22 = tmp18 + tmp21 tmp24 = tmp9 - tmp12 tmp25 = tmp23 * tmp24 tmp26 = tmp22 + tmp25 tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK]) tmp29 = tl.sum(tmp27, 1)[:, None] tmp31 = tl_math.exp(tmp30) tmp33 = tl_math.exp(tmp32) tmp34 = tmp31 + tmp33 tmp36 = tl_math.exp(tmp35) tmp37 = tmp34 + tmp36 tmp39 = tl_math.exp(tmp38) tmp40 = tmp37 + tmp39 tmp41 = tl_math.log(tmp40) tmp42 = tmp30 - tmp41 tmp43 = tmp0 * tmp42 tmp44 = tmp32 - tmp41 tmp45 = tmp15 * tmp44 tmp46 = tmp43 + tmp45 tmp47 = tmp35 - tmp41 tmp48 = tmp19 * tmp47 tmp49 = tmp46 + tmp48 tmp50 = tmp38 - tmp41 tmp51 = tmp23 * tmp50 tmp52 = tmp49 + tmp51 tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK]) tmp55 = tl.sum(tmp53, 1)[:, None] tmp57 = tl_math.exp(tmp56) tmp59 = tl_math.exp(tmp58) tmp60 = tmp57 + tmp59 tmp62 = tl_math.exp(tmp61) tmp63 = tmp60 + tmp62 tmp65 = tl_math.exp(tmp64) tmp66 = tmp63 + tmp65 tmp67 = tl_math.log(tmp66) tmp68 = tmp56 - tmp67 tmp69 = tmp0 * tmp68 tmp70 = tmp58 - tmp67 tmp71 = tmp15 * tmp70 tmp72 = tmp69 + tmp71 tmp73 = tmp61 - tmp67 tmp74 = tmp19 * tmp73 tmp75 = tmp72 + tmp74 tmp76 = tmp64 - tmp67 tmp77 = tmp23 * tmp76 tmp78 = tmp75 + tmp77 tmp79 = tl.broadcast_to(tmp78, [XBLOCK, RBLOCK]) tmp81 = tl.sum(tmp79, 1)[:, None] tmp83 = tl_math.exp(tmp82) tmp85 = tl_math.exp(tmp84) tmp86 = tmp83 + tmp85 tmp88 = tl_math.exp(tmp87) tmp89 = tmp86 + tmp88 tmp91 = tl_math.exp(tmp90) tmp92 = tmp89 + tmp91 tmp93 = tl_math.log(tmp92) tmp94 = tmp82 - tmp93 tmp95 = tmp0 * tmp94 tmp96 = tmp84 - tmp93 tmp97 = tmp15 * tmp96 tmp98 = tmp95 + tmp97 tmp99 = tmp87 - tmp93 tmp100 = tmp19 * tmp99 tmp101 = tmp98 + tmp100 tmp102 = tmp90 - tmp93 tmp103 = tmp23 * tmp102 tmp104 = tmp101 + tmp103 tmp105 = tl.broadcast_to(tmp104, [XBLOCK, RBLOCK]) tmp107 = tl.sum(tmp105, 1)[:, None] tmp109 = tl_math.exp(tmp108) tmp111 = tl_math.exp(tmp110) tmp112 = tmp109 + tmp111 tmp114 = tl_math.exp(tmp113) tmp115 = tmp112 + tmp114 tmp117 = tl_math.exp(tmp116) tmp118 = tmp115 + tmp117 tmp119 = tl_math.log(tmp118) tmp120 = tmp108 - tmp119 tmp121 = tmp0 * tmp120 tmp122 = tmp110 - tmp119 tmp123 = tmp15 * tmp122 tmp124 = tmp121 + tmp123 tmp125 = tmp113 - tmp119 tmp126 = tmp19 * tmp125 tmp127 = tmp124 + tmp126 tmp128 = tmp116 - tmp119 tmp129 = tmp23 * tmp128 tmp130 = tmp127 + tmp129 tmp131 = tl.broadcast_to(tmp130, [XBLOCK, RBLOCK]) tmp133 = tl.sum(tmp131, 1)[:, None] tmp135 = tl_math.exp(tmp134) tmp137 = tl_math.exp(tmp136) tmp138 = tmp135 + tmp137 tmp140 = tl_math.exp(tmp139) tmp141 = tmp138 + tmp140 tmp143 = tl_math.exp(tmp142) tmp144 = tmp141 + tmp143 tmp145 = tl_math.log(tmp144) tmp146 = tmp134 - tmp145 tmp147 = tmp0 * tmp146 tmp148 = tmp136 - tmp145 tmp149 = tmp15 * tmp148 tmp150 = tmp147 + tmp149 tmp151 = tmp139 - tmp145 tmp152 = tmp19 * tmp151 tmp153 = tmp150 + tmp152 tmp154 = tmp142 - tmp145 tmp155 = tmp23 * tmp154 tmp156 = tmp153 + tmp155 tmp157 = tl.broadcast_to(tmp156, [XBLOCK, RBLOCK]) tmp159 = tl.sum(tmp157, 1)[:, None] tmp161 = tl_math.exp(tmp160) tmp163 = tl_math.exp(tmp162) tmp164 = tmp161 + tmp163 tmp166 = tl_math.exp(tmp165) tmp167 = tmp164 + tmp166 tmp169 = tl_math.exp(tmp168) tmp170 = tmp167 + tmp169 tmp171 = tl_math.log(tmp170) tmp172 = tmp160 - tmp171 tmp173 = tmp0 * tmp172 tmp174 = tmp162 - tmp171 tmp175 = tmp15 * tmp174 tmp176 = tmp173 + tmp175 tmp177 = tmp165 - tmp171 tmp178 = tmp19 * tmp177 tmp179 = tmp176 + tmp178 tmp180 = tmp168 - tmp171 tmp181 = tmp23 * tmp180 tmp182 = tmp179 + tmp181 tmp183 = tl.broadcast_to(tmp182, [XBLOCK, RBLOCK]) tmp185 = tl.sum(tmp183, 1)[:, None] tmp188 = tl_math.exp(tmp187) tmp190 = tl_math.exp(tmp189) tmp191 = tmp188 + tmp190 tmp193 = tl_math.exp(tmp192) tmp194 = tmp191 + tmp193 tmp196 = tl_math.exp(tmp195) tmp197 = tmp194 + tmp196 tmp198 = tl_math.log(tmp197) tmp199 = tmp187 - tmp198 tmp200 = tmp186 * tmp199 tmp202 = tmp189 - tmp198 tmp203 = tmp201 * tmp202 tmp204 = tmp200 + tmp203 tmp206 = tmp192 - tmp198 tmp207 = tmp205 * tmp206 tmp208 = tmp204 + tmp207 tmp210 = tmp195 - tmp198 tmp211 = tmp209 * tmp210 tmp212 = tmp208 + tmp211 tmp213 = tl.broadcast_to(tmp212, [XBLOCK, RBLOCK]) tmp215 = tl.sum(tmp213, 1)[:, None] tmp217 = tl_math.exp(tmp216) tmp219 = tl_math.exp(tmp218) tmp220 = tmp217 + tmp219 tmp222 = tl_math.exp(tmp221) tmp223 = tmp220 + tmp222 tmp225 = tl_math.exp(tmp224) tmp226 = tmp223 + tmp225 tmp227 = tl_math.log(tmp226) tmp228 = tmp216 - tmp227 tmp229 = tmp186 * tmp228 tmp230 = tmp218 - tmp227 tmp231 = tmp201 * tmp230 tmp232 = tmp229 + tmp231 tmp233 = tmp221 - tmp227 tmp234 = tmp205 * tmp233 tmp235 = tmp232 + tmp234 tmp236 = tmp224 - tmp227 tmp237 = tmp209 * tmp236 tmp238 = tmp235 + tmp237 tmp239 = tl.broadcast_to(tmp238, [XBLOCK, RBLOCK]) tmp241 = tl.sum(tmp239, 1)[:, None] tmp243 = tl_math.exp(tmp242) tmp245 = tl_math.exp(tmp244) tmp246 = tmp243 + tmp245 tmp248 = tl_math.exp(tmp247) tmp249 = tmp246 + tmp248 tmp251 = tl_math.exp(tmp250) tmp252 = tmp249 + tmp251 tmp253 = tl_math.log(tmp252) tmp254 = tmp242 - tmp253 tmp255 = tmp186 * tmp254 tmp256 = tmp244 - tmp253 tmp257 = tmp201 * tmp256 tmp258 = tmp255 + tmp257 tmp259 = tmp247 - tmp253 tmp260 = tmp205 * tmp259 tmp261 = tmp258 + tmp260 tmp262 = tmp250 - tmp253 tmp263 = tmp209 * tmp262 tmp264 = tmp261 + tmp263 tmp265 = tl.broadcast_to(tmp264, [XBLOCK, RBLOCK]) tmp267 = tl.sum(tmp265, 1)[:, None] tmp269 = tl_math.exp(tmp268) tmp271 = tl_math.exp(tmp270) tmp272 = tmp269 + tmp271 tmp274 = tl_math.exp(tmp273) tmp275 = tmp272 + tmp274 tmp277 = tl_math.exp(tmp276) tmp278 = tmp275 + tmp277 tmp279 = tl_math.log(tmp278) tmp280 = tmp268 - tmp279 tmp281 = tmp186 * tmp280 tmp282 = tmp270 - tmp279 tmp283 = tmp201 * tmp282 tmp284 = tmp281 + tmp283 tmp285 = tmp273 - tmp279 tmp286 = tmp205 * tmp285 tmp287 = tmp284 + tmp286 tmp288 = tmp276 - tmp279 tmp289 = tmp209 * tmp288 tmp290 = tmp287 + tmp289 tmp291 = tl.broadcast_to(tmp290, [XBLOCK, RBLOCK]) tmp293 = tl.sum(tmp291, 1)[:, None] tmp295 = tl_math.exp(tmp294) tmp297 = tl_math.exp(tmp296) tmp298 = tmp295 + tmp297 tmp300 = tl_math.exp(tmp299) tmp301 = tmp298 + tmp300 tmp303 = tl_math.exp(tmp302) tmp304 = tmp301 + tmp303 tmp305 = tl_math.log(tmp304) tmp306 = tmp294 - tmp305 tmp307 = tmp186 * tmp306 tmp308 = tmp296 - tmp305 tmp309 = tmp201 * tmp308 tmp310 = tmp307 + tmp309 tmp311 = tmp299 - tmp305 tmp312 = tmp205 * tmp311 tmp313 = tmp310 + tmp312 tmp314 = tmp302 - tmp305 tmp315 = tmp209 * tmp314 tmp316 = tmp313 + tmp315 tmp317 = tl.broadcast_to(tmp316, [XBLOCK, RBLOCK]) tmp319 = tl.sum(tmp317, 1)[:, None] tmp321 = tl_math.exp(tmp320) tmp323 = tl_math.exp(tmp322) tmp324 = tmp321 + tmp323 tmp326 = tl_math.exp(tmp325) tmp327 = tmp324 + tmp326 tmp329 = tl_math.exp(tmp328) tmp330 = tmp327 + tmp329 tmp331 = tl_math.log(tmp330) tmp332 = tmp320 - tmp331 tmp333 = tmp186 * tmp332 tmp334 = tmp322 - tmp331 tmp335 = tmp201 * tmp334 tmp336 = tmp333 + tmp335 tmp337 = tmp325 - tmp331 tmp338 = tmp205 * tmp337 tmp339 = tmp336 + tmp338 tmp340 = tmp328 - tmp331 tmp341 = tmp209 * tmp340 tmp342 = tmp339 + tmp341 tmp343 = tl.broadcast_to(tmp342, [XBLOCK, RBLOCK]) tmp345 = tl.sum(tmp343, 1)[:, None] tmp347 = tl_math.exp(tmp346) tmp349 = tl_math.exp(tmp348) tmp350 = tmp347 + tmp349 tmp352 = tl_math.exp(tmp351) tmp353 = tmp350 + tmp352 tmp355 = tl_math.exp(tmp354) tmp356 = tmp353 + tmp355 tmp357 = tl_math.log(tmp356) tmp358 = tmp346 - tmp357 tmp359 = tmp186 * tmp358 tmp360 = tmp348 - tmp357 tmp361 = tmp201 * tmp360 tmp362 = tmp359 + tmp361 tmp363 = tmp351 - tmp357 tmp364 = tmp205 * tmp363 tmp365 = tmp362 + tmp364 tmp366 = tmp354 - tmp357 tmp367 = tmp209 * tmp366 tmp368 = tmp365 + tmp367 tmp369 = tl.broadcast_to(tmp368, [XBLOCK, RBLOCK]) tmp371 = tl.sum(tmp369, 1)[:, None] tmp374 = tl_math.exp(tmp373) tmp376 = tl_math.exp(tmp375) tmp377 = tmp374 + tmp376 tmp379 = tl_math.exp(tmp378) tmp380 = tmp377 + tmp379 tmp382 = tl_math.exp(tmp381) tmp383 = tmp380 + tmp382 tmp384 = tl_math.log(tmp383) tmp385 = tmp373 - tmp384 tmp386 = tmp372 * tmp385 tmp388 = tmp375 - tmp384 tmp389 = tmp387 * tmp388 tmp390 = tmp386 + tmp389 tmp392 = tmp378 - tmp384 tmp393 = tmp391 * tmp392 tmp394 = tmp390 + tmp393 tmp396 = tmp381 - tmp384 tmp397 = tmp395 * tmp396 tmp398 = tmp394 + tmp397 tmp399 = tl.broadcast_to(tmp398, [XBLOCK, RBLOCK]) tmp401 = tl.sum(tmp399, 1)[:, None] tmp403 = tl_math.exp(tmp402) tmp405 = tl_math.exp(tmp404) tmp406 = tmp403 + tmp405 tmp408 = tl_math.exp(tmp407) tmp409 = tmp406 + tmp408 tmp411 = tl_math.exp(tmp410) tmp412 = tmp409 + tmp411 tmp413 = tl_math.log(tmp412) tmp414 = tmp402 - tmp413 tmp415 = tmp372 * tmp414 tmp416 = tmp404 - tmp413 tmp417 = tmp387 * tmp416 tmp418 = tmp415 + tmp417 tmp419 = tmp407 - tmp413 tmp420 = tmp391 * tmp419 tmp421 = tmp418 + tmp420 tmp422 = tmp410 - tmp413 tmp423 = tmp395 * tmp422 tmp424 = tmp421 + tmp423 tmp425 = tl.broadcast_to(tmp424, [XBLOCK, RBLOCK]) tmp427 = tl.sum(tmp425, 1)[:, None] tmp429 = tl_math.exp(tmp428) tmp431 = tl_math.exp(tmp430) tmp432 = tmp429 + tmp431 tmp434 = tl_math.exp(tmp433) tmp435 = tmp432 + tmp434 tmp437 = tl_math.exp(tmp436) tmp438 = tmp435 + tmp437 tmp439 = tl_math.log(tmp438) tmp440 = tmp428 - tmp439 tmp441 = tmp372 * tmp440 tmp442 = tmp430 - tmp439 tmp443 = tmp387 * tmp442 tmp444 = tmp441 + tmp443 tmp445 = tmp433 - tmp439 tmp446 = tmp391 * tmp445 tmp447 = tmp444 + tmp446 tmp448 = tmp436 - tmp439 tmp449 = tmp395 * tmp448 tmp450 = tmp447 + tmp449 tmp451 = tl.broadcast_to(tmp450, [XBLOCK, RBLOCK]) tmp453 = tl.sum(tmp451, 1)[:, None] tmp455 = tl_math.exp(tmp454) tmp457 = tl_math.exp(tmp456) tmp458 = tmp455 + tmp457 tmp460 = tl_math.exp(tmp459) tmp461 = tmp458 + tmp460 tmp463 = tl_math.exp(tmp462) tmp464 = tmp461 + tmp463 tmp465 = tl_math.log(tmp464) tmp466 = tmp454 - tmp465 tmp467 = tmp372 * tmp466 tmp468 = tmp456 - tmp465 tmp469 = tmp387 * tmp468 tmp470 = tmp467 + tmp469 tmp471 = tmp459 - tmp465 tmp472 = tmp391 * tmp471 tmp473 = tmp470 + tmp472 tmp474 = tmp462 - tmp465 tmp475 = tmp395 * tmp474 tmp476 = tmp473 + tmp475 tmp477 = tl.broadcast_to(tmp476, [XBLOCK, RBLOCK]) tmp479 = tl.sum(tmp477, 1)[:, None] tmp481 = tl_math.exp(tmp480) tmp483 = tl_math.exp(tmp482) tmp484 = tmp481 + tmp483 tmp486 = tl_math.exp(tmp485) tmp487 = tmp484 + tmp486 tmp489 = tl_math.exp(tmp488) tmp490 = tmp487 + tmp489 tmp491 = tl_math.log(tmp490) tmp492 = tmp480 - tmp491 tmp493 = tmp372 * tmp492 tmp494 = tmp482 - tmp491 tmp495 = tmp387 * tmp494 tmp496 = tmp493 + tmp495 tmp497 = tmp485 - tmp491 tmp498 = tmp391 * tmp497 tmp499 = tmp496 + tmp498 tmp500 = tmp488 - tmp491 tmp501 = tmp395 * tmp500 tmp502 = tmp499 + tmp501 tmp503 = tl.broadcast_to(tmp502, [XBLOCK, RBLOCK]) tmp505 = tl.sum(tmp503, 1)[:, None] tmp507 = tl_math.exp(tmp506) tmp509 = tl_math.exp(tmp508) tmp510 = tmp507 + tmp509 tmp512 = tl_math.exp(tmp511) tmp513 = tmp510 + tmp512 tmp515 = tl_math.exp(tmp514) tmp516 = tmp513 + tmp515 tmp517 = tl_math.log(tmp516) tmp518 = tmp506 - tmp517 tmp519 = tmp372 * tmp518 tmp520 = tmp508 - tmp517 tmp521 = tmp387 * tmp520 tmp522 = tmp519 + tmp521 tmp523 = tmp511 - tmp517 tmp524 = tmp391 * tmp523 tmp525 = tmp522 + tmp524 tmp526 = tmp514 - tmp517 tmp527 = tmp395 * tmp526 tmp528 = tmp525 + tmp527 tmp529 = tl.broadcast_to(tmp528, [XBLOCK, RBLOCK]) tmp531 = tl.sum(tmp529, 1)[:, None] tmp533 = tl_math.exp(tmp532) tmp535 = tl_math.exp(tmp534) tmp536 = tmp533 + tmp535 tmp538 = tl_math.exp(tmp537) tmp539 = tmp536 + tmp538 tmp541 = tl_math.exp(tmp540) tmp542 = tmp539 + tmp541 tmp543 = tl_math.log(tmp542) tmp544 = tmp532 - tmp543 tmp545 = tmp372 * tmp544 tmp546 = tmp534 - tmp543 tmp547 = tmp387 * tmp546 tmp548 = tmp545 + tmp547 tmp549 = tmp537 - tmp543 tmp550 = tmp391 * tmp549 tmp551 = tmp548 + tmp550 tmp552 = tmp540 - tmp543 tmp553 = tmp395 * tmp552 tmp554 = tmp551 + tmp553 tmp555 = tl.broadcast_to(tmp554, [XBLOCK, RBLOCK]) tmp557 = tl.sum(tmp555, 1)[:, None] tmp560 = tl_math.exp(tmp559) tmp562 = tl_math.exp(tmp561) tmp563 = tmp560 + tmp562 tmp565 = tl_math.exp(tmp564) tmp566 = tmp563 + tmp565 tmp568 = tl_math.exp(tmp567) tmp569 = tmp566 + tmp568 tmp570 = tl_math.log(tmp569) tmp571 = tmp559 - tmp570 tmp572 = tmp558 * tmp571 tmp574 = tmp561 - tmp570 tmp575 = tmp573 * tmp574 tmp576 = tmp572 + tmp575 tmp578 = tmp564 - tmp570 tmp579 = tmp577 * tmp578 tmp580 = tmp576 + tmp579 tmp582 = tmp567 - tmp570 tmp583 = tmp581 * tmp582 tmp584 = tmp580 + tmp583 tmp585 = tl.broadcast_to(tmp584, [XBLOCK, RBLOCK]) tmp587 = tl.sum(tmp585, 1)[:, None] tmp589 = tl_math.exp(tmp588) tmp591 = tl_math.exp(tmp590) tmp592 = tmp589 + tmp591 tmp594 = tl_math.exp(tmp593) tmp595 = tmp592 + tmp594 tmp597 = tl_math.exp(tmp596) tmp598 = tmp595 + tmp597 tmp599 = tl_math.log(tmp598) tmp600 = tmp588 - tmp599 tmp601 = tmp558 * tmp600 tmp602 = tmp590 - tmp599 tmp603 = tmp573 * tmp602 tmp604 = tmp601 + tmp603 tmp605 = tmp593 - tmp599 tmp606 = tmp577 * tmp605 tmp607 = tmp604 + tmp606 tmp608 = tmp596 - tmp599 tmp609 = tmp581 * tmp608 tmp610 = tmp607 + tmp609 tmp611 = tl.broadcast_to(tmp610, [XBLOCK, RBLOCK]) tmp613 = tl.sum(tmp611, 1)[:, None] tmp615 = tl_math.exp(tmp614) tmp617 = tl_math.exp(tmp616) tmp618 = tmp615 + tmp617 tmp620 = tl_math.exp(tmp619) tmp621 = tmp618 + tmp620 tmp623 = tl_math.exp(tmp622) tmp624 = tmp621 + tmp623 tmp625 = tl_math.log(tmp624) tmp626 = tmp614 - tmp625 tmp627 = tmp558 * tmp626 tmp628 = tmp616 - tmp625 tmp629 = tmp573 * tmp628 tmp630 = tmp627 + tmp629 tmp631 = tmp619 - tmp625 tmp632 = tmp577 * tmp631 tmp633 = tmp630 + tmp632 tmp634 = tmp622 - tmp625 tmp635 = tmp581 * tmp634 tmp636 = tmp633 + tmp635 tmp637 = tl.broadcast_to(tmp636, [XBLOCK, RBLOCK]) tmp639 = tl.sum(tmp637, 1)[:, None] tmp641 = tl_math.exp(tmp640) tmp643 = tl_math.exp(tmp642) tmp644 = tmp641 + tmp643 tmp646 = tl_math.exp(tmp645) tmp647 = tmp644 + tmp646 tmp649 = tl_math.exp(tmp648) tmp650 = tmp647 + tmp649 tmp651 = tl_math.log(tmp650) tmp652 = tmp640 - tmp651 tmp653 = tmp558 * tmp652 tmp654 = tmp642 - tmp651 tmp655 = tmp573 * tmp654 tmp656 = tmp653 + tmp655 tmp657 = tmp645 - tmp651 tmp658 = tmp577 * tmp657 tmp659 = tmp656 + tmp658 tmp660 = tmp648 - tmp651 tmp661 = tmp581 * tmp660 tmp662 = tmp659 + tmp661 tmp663 = tl.broadcast_to(tmp662, [XBLOCK, RBLOCK]) tmp665 = tl.sum(tmp663, 1)[:, None] tmp667 = tl_math.exp(tmp666) tmp669 = tl_math.exp(tmp668) tmp670 = tmp667 + tmp669 tmp672 = tl_math.exp(tmp671) tmp673 = tmp670 + tmp672 tmp675 = tl_math.exp(tmp674) tmp676 = tmp673 + tmp675 tmp677 = tl_math.log(tmp676) tmp678 = tmp666 - tmp677 tmp679 = tmp558 * tmp678 tmp680 = tmp668 - tmp677 tmp681 = tmp573 * tmp680 tmp682 = tmp679 + tmp681 tmp683 = tmp671 - tmp677 tmp684 = tmp577 * tmp683 tmp685 = tmp682 + tmp684 tmp686 = tmp674 - tmp677 tmp687 = tmp581 * tmp686 tmp688 = tmp685 + tmp687 tmp689 = tl.broadcast_to(tmp688, [XBLOCK, RBLOCK]) tmp691 = tl.sum(tmp689, 1)[:, None] tmp693 = tl_math.exp(tmp692) tmp695 = tl_math.exp(tmp694) tmp696 = tmp693 + tmp695 tmp698 = tl_math.exp(tmp697) tmp699 = tmp696 + tmp698 tmp701 = tl_math.exp(tmp700) tmp702 = tmp699 + tmp701 tmp703 = tl_math.log(tmp702) tmp704 = tmp692 - tmp703 tmp705 = tmp558 * tmp704 tmp706 = tmp694 - tmp703 tmp707 = tmp573 * tmp706 tmp708 = tmp705 + tmp707 tmp709 = tmp697 - tmp703 tmp710 = tmp577 * tmp709 tmp711 = tmp708 + tmp710 tmp712 = tmp700 - tmp703 tmp713 = tmp581 * tmp712 tmp714 = tmp711 + tmp713 tmp715 = tl.broadcast_to(tmp714, [XBLOCK, RBLOCK]) tmp717 = tl.sum(tmp715, 1)[:, None] tmp719 = tl_math.exp(tmp718) tmp721 = tl_math.exp(tmp720) tmp722 = tmp719 + tmp721 tmp724 = tl_math.exp(tmp723) tmp725 = tmp722 + tmp724 tmp727 = tl_math.exp(tmp726) tmp728 = tmp725 + tmp727 tmp729 = tl_math.log(tmp728) tmp730 = tmp718 - tmp729 tmp731 = tmp558 * tmp730 tmp732 = tmp720 - tmp729 tmp733 = tmp573 * tmp732 tmp734 = tmp731 + tmp733 tmp735 = tmp723 - tmp729 tmp736 = tmp577 * tmp735 tmp737 = tmp734 + tmp736 tmp738 = tmp726 - tmp729 tmp739 = tmp581 * tmp738 tmp740 = tmp737 + tmp739 tmp741 = tl.broadcast_to(tmp740, [XBLOCK, RBLOCK]) tmp743 = tl.sum(tmp741, 1)[:, None] tmp744 = 4.0 tmp745 = tmp587 / tmp744 tmp746 = -tmp745 tmp747 = 0.0 tmp748 = tmp746 + tmp747 tmp749 = tmp613 / tmp744 tmp750 = -tmp749 tmp751 = tmp748 + tmp750 tmp752 = tmp639 / tmp744 tmp753 = -tmp752 tmp754 = tmp751 + tmp753 tmp755 = tmp665 / tmp744 tmp756 = -tmp755 tmp757 = tmp754 + tmp756 tmp758 = tmp691 / tmp744 tmp759 = -tmp758 tmp760 = tmp757 + tmp759 tmp761 = tmp717 / tmp744 tmp762 = -tmp761 tmp763 = tmp760 + tmp762 tmp764 = tmp743 / tmp744 tmp765 = -tmp764 tmp766 = tmp763 + tmp765 tmp767 = 0.14285714285714285 tmp768 = tmp766 * tmp767 tmp769 = tmp401 / tmp744 tmp770 = -tmp769 tmp771 = tmp770 + tmp747 tmp772 = tmp427 / tmp744 tmp773 = -tmp772 tmp774 = tmp771 + tmp773 tmp775 = tmp453 / tmp744 tmp776 = -tmp775 tmp777 = tmp774 + tmp776 tmp778 = tmp479 / tmp744 tmp779 = -tmp778 tmp780 = tmp777 + tmp779 tmp781 = tmp505 / tmp744 tmp782 = -tmp781 tmp783 = tmp780 + tmp782 tmp784 = tmp531 / tmp744 tmp785 = -tmp784 tmp786 = tmp783 + tmp785 tmp787 = tmp557 / tmp744 tmp788 = -tmp787 tmp789 = tmp786 + tmp788 tmp790 = tmp789 * tmp767 tmp791 = tmp215 / tmp744 tmp792 = -tmp791 tmp793 = tmp792 + tmp747 tmp794 = tmp241 / tmp744 tmp795 = -tmp794 tmp796 = tmp793 + tmp795 tmp797 = tmp267 / tmp744 tmp798 = -tmp797 tmp799 = tmp796 + tmp798 tmp800 = tmp293 / tmp744 tmp801 = -tmp800 tmp802 = tmp799 + tmp801 tmp803 = tmp319 / tmp744 tmp804 = -tmp803 tmp805 = tmp802 + tmp804 tmp806 = tmp345 / tmp744 tmp807 = -tmp806 tmp808 = tmp805 + tmp807 tmp809 = tmp371 / tmp744 tmp810 = -tmp809 tmp811 = tmp808 + tmp810 tmp812 = tmp811 * tmp767 tmp813 = tmp29 / tmp744 tmp814 = -tmp813 tmp815 = tmp814 + tmp747 tmp816 = tmp55 / tmp744 tmp817 = -tmp816 tmp818 = tmp815 + tmp817 tmp819 = tmp81 / tmp744 tmp820 = -tmp819 tmp821 = tmp818 + tmp820 tmp822 = tmp107 / tmp744 tmp823 = -tmp822 tmp824 = tmp821 + tmp823 tmp825 = tmp133 / tmp744 tmp826 = -tmp825 tmp827 = tmp824 + tmp826 tmp828 = tmp159 / tmp744 tmp829 = -tmp828 tmp830 = tmp827 + tmp829 tmp831 = tmp185 / tmp744 tmp832 = -tmp831 tmp833 = tmp830 + tmp832 tmp834 = tmp833 * tmp767 tmp835 = tmp768 + tmp747 tmp836 = tmp835 + tmp790 tmp837 = tmp836 + tmp812 tmp838 = tmp837 + tmp834 tmp839 = 0.25 tmp840 = tmp838 * tmp839 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp840, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_sum_0[grid(1)](arg0_1, buf0, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused_sum_1[grid(4)](arg0_1, buf0, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((1, 4), (4, 1), torch.float32) triton_poi_fused_sum_2[grid(4)](arg0_1, buf0, buf1, buf2, 4, XBLOCK =4, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused_sum_3[grid(4)](arg0_1, buf0, buf1, buf2, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_4[grid(16)](arg0_1, buf0, buf1, buf2, buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_5[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = buf4 del buf4 triton_poi_fused_div_6[grid(16)](buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = buf5 del buf5 triton_poi_fused_mul_7[grid(16)](buf6, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) buf23 = buf0 del buf0 buf56 = reinterpret_tensor(buf6, (4, 4), (4, 1), 0) del buf6 buf79 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_per_fused_sum_8[grid(1)](arg0_1, buf23, buf56, buf79, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf24 = buf3 del buf3 triton_poi_fused_sum_9[grid(4)](arg0_1, buf23, buf24, 4, XBLOCK=4, num_warps=1, num_stages=1) buf25 = buf2 del buf2 triton_poi_fused_sum_10[grid(4)](arg0_1, buf23, buf24, buf25, 4, XBLOCK=4, num_warps=1, num_stages=1) buf26 = buf1 del buf1 triton_poi_fused_sum_11[grid(4)](arg0_1, buf23, buf24, buf25, buf26, 4, XBLOCK=4, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf27 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_12[grid(16)](arg0_1, buf23, buf24, buf25, buf26, buf8, buf27, 16, XBLOCK=16, num_warps=1, num_stages=1) buf46 = buf23 del buf23 buf81 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_per_fused_sum_13[grid(1)](arg0_1, buf46, buf81, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf47 = buf26 del buf26 triton_poi_fused_sum_14[grid(4)](arg0_1, buf46, buf47, 4, XBLOCK=4, num_warps=1, num_stages=1) buf48 = buf25 del buf25 triton_poi_fused_sum_15[grid(4)](arg0_1, buf46, buf47, buf48, 4, XBLOCK=4, num_warps=1, num_stages=1) buf49 = buf24 del buf24 triton_poi_fused_sum_16[grid(4)](arg0_1, buf46, buf47, buf48, buf49, 4, XBLOCK=4, num_warps=1, num_stages=1) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf33 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf50 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_17[grid(16)](arg0_1, buf46, buf47, buf48, buf49, buf10, buf33, buf50, 16, XBLOCK=16, num_warps=1, num_stages=1) buf69 = buf46 del buf46 triton_per_fused_sum_18[grid(1)](arg0_1, buf69, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf70 = buf49 del buf49 triton_poi_fused_sum_19[grid(4)](arg0_1, buf69, buf70, 4, XBLOCK=4, num_warps=1, num_stages=1) buf71 = buf48 del buf48 triton_poi_fused_sum_20[grid(4)](arg0_1, buf69, buf70, buf71, 4, XBLOCK=4, num_warps=1, num_stages=1) buf72 = buf47 del buf47 triton_poi_fused_sum_21[grid(4)](arg0_1, buf69, buf70, buf71, buf72, 4, XBLOCK=4, num_warps=1, num_stages=1) buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf35 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf58 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf73 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_22[grid(16)](arg0_1, buf69, buf70, buf71, buf72, buf12, buf35, buf58, buf73, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf70 del buf71 del buf72 buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf37 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf60 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_23[grid(16)](arg1_1, buf14, buf37, buf60, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf39 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf62 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_24[grid(16)](arg1_1, buf16, buf39, buf62, 16, XBLOCK=16, num_warps=1, num_stages=1) buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf41 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf64 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_25[grid(16)](arg1_1, buf18, buf41, buf64, 16, XBLOCK=16, num_warps=1, num_stages=1) buf20 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf43 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf66 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_26[grid(16)](arg1_1, buf20, buf43, buf66, 16, XBLOCK=16, num_warps=1, num_stages=1) buf28 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_5[grid(16)](buf27, buf28, 16, XBLOCK=16, num_warps=1, num_stages=1) buf29 = buf27 del buf27 triton_poi_fused_div_6[grid(16)](buf28, buf29, 16, XBLOCK=16, num_warps=1, num_stages=1) buf30 = buf28 del buf28 triton_poi_fused_mul_7[grid(16)](buf29, buf30, 16, XBLOCK=16, num_warps=1, num_stages=1) buf31 = reinterpret_tensor(buf29, (4, 4), (4, 1), 0) del buf29 buf54 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf77 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_23[grid(16)](arg0_1, buf31, buf54, buf77, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 buf51 = empty_strided_cuda((4, 4), (1, 4), torch.float32) triton_poi_fused_div_5[grid(16)](buf50, buf51, 16, XBLOCK=16, num_warps=1, num_stages=1) buf52 = buf50 del buf50 triton_poi_fused_div_6[grid(16)](buf51, buf52, 16, XBLOCK=16, num_warps=1, num_stages=1) buf53 = buf51 del buf51 triton_poi_fused_mul_7[grid(16)](buf52, buf53, 16, XBLOCK=16, num_warps=1, num_stages=1) buf74 = buf52 del buf52 triton_poi_fused_div_5[grid(16)](buf73, buf74, 16, XBLOCK=16, num_warps=1, num_stages=1) buf75 = buf73 del buf73 triton_poi_fused_div_6[grid(16)](buf74, buf75, 16, XBLOCK=16, num_warps=1, num_stages=1) buf76 = buf74 del buf74 triton_poi_fused_mul_7[grid(16)](buf75, buf76, 16, XBLOCK=16, num_warps=1, num_stages=1) buf83 = reinterpret_tensor(buf75, (4, 4), (4, 1), 0) del buf75 triton_poi_fused_27[grid(16)](arg1_1, buf83, 16, XBLOCK=16, num_warps=1, num_stages=1) buf85 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_28[grid(16)](arg1_1, buf85, 16, XBLOCK=16, num_warps=1, num_stages=1) buf87 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_29[grid(16)](arg1_1, buf87, 16, XBLOCK=16, num_warps=1, num_stages=1) buf89 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_30[grid(16)](arg1_1, buf89, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg1_1 buf11 = buf69 del buf69 buf22 = buf11 del buf11 buf92 = buf22 del buf22 triton_per_fused__log_softmax_add_div_mean_mul_neg_sum_31[grid(1)]( buf92, buf76, buf77, buf79, buf81, buf83, buf85, buf87, buf89, buf53, buf54, buf56, buf58, buf60, buf62, buf64, buf66, buf30, buf31, buf33, buf35, buf37, buf39, buf41, buf43, buf7, buf8, buf10, buf12, buf14, buf16, buf18, buf20, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf10 del buf12 del buf14 del buf16 del buf18 del buf20 del buf30 del buf31 del buf33 del buf35 del buf37 del buf39 del buf41 del buf43 del buf53 del buf54 del buf56 del buf58 del buf60 del buf62 del buf64 del buf66 del buf7 del buf76 del buf77 del buf79 del buf8 del buf81 del buf83 del buf85 del buf87 del buf89 return buf92, @torch.no_grad() def sinkhorn(out: 'torch.Tensor', iterations: 'int'=3, epsilon: 'float'=0.05): """Distributed sinkhorn algorithm. As outlined in [0] and implemented in [1]. [0]: SwaV, 2020, https://arxiv.org/abs/2006.09882 [1]: https://github.com/facebookresearch/swav/ Args: out: Similarity of the features and the SwaV prototypes. iterations: Number of sinkhorn iterations. epsilon: Temperature parameter. Returns: Soft codes Q assigning each feature to a prototype. """ Q = torch.exp(out / epsilon).t() sum_Q = torch.sum(Q) Q /= sum_Q B = Q.shape[1] K = Q.shape[0] for i in range(iterations): sum_of_rows = torch.sum(Q, dim=1, keepdim=True) Q /= sum_of_rows Q /= K Q /= torch.sum(Q, dim=0, keepdim=True) Q /= B Q *= B return Q.t() class SwaVLossNew(nn.Module): """Implementation of the SwaV loss. Attributes: temperature: Temperature parameter used for cross entropy calculations. sinkhorn_iterations: Number of iterations of the sinkhorn algorithm. sinkhorn_epsilon: Temperature parameter used in the sinkhorn algorithm. """ def __init__(self, temperature: 'float'=0.1, sinkhorn_iterations: 'int' =3, sinkhorn_epsilon: 'float'=0.05): super(SwaVLossNew, self).__init__() self.temperature = temperature self.sinkhorn_iterations = sinkhorn_iterations self.sinkhorn_epsilon = sinkhorn_epsilon def subloss(self, z: 'torch.Tensor', q: 'torch.Tensor'): """Calculates the cross entropy for the SwaV prediction problem. Args: z: Similarity of the features and the SwaV prototypes. q: Codes obtained from Sinkhorn iterations. Returns: Cross entropy between predictions z and codes q. """ return -torch.mean(torch.sum(q * F.log_softmax(z / self.temperature, dim=1), dim=1)) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
jianzhnie/self_supervised
SwaVLoss
false
7,051
[ "Apache-2.0" ]
1
d1e0f31ab032150ab0ad007c1e19773135a5fb79
https://github.com/jianzhnie/self_supervised/tree/d1e0f31ab032150ab0ad007c1e19773135a5fb79
UNet
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.utils.data from torch.cuda import * def conv3x3(in_channels, out_channels): return nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True) def maxpool2x2(): return nn.MaxPool2d(kernel_size=2, stride=2, padding=0) def concat(xh, xv): return torch.cat([xh, xv], dim=1) class UpConv2x2(nn.Module): def __init__(self, channels): super(UpConv2x2, self).__init__() self.conv = nn.Conv2d(channels, channels // 2, kernel_size=2, stride=1, padding=0, bias=True) def forward(self, x): x = F.interpolate(x, scale_factor=2, mode='nearest') x = F.pad(x, (0, 1, 0, 1)) x = self.conv(x) return x class ConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(ConvBlock, self).__init__() self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, x): x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class DownConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(DownConvBlock, self).__init__() self.maxpool = maxpool2x2() self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, x): x = self.maxpool(x) x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class UpConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(UpConvBlock, self).__init__() self.upconv = UpConv2x2(in_channels) self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, xh, xv): """ Args: xh: torch Variable, activations from same resolution feature maps (gray arrow in diagram) xv: torch Variable, activations from lower resolution feature maps (green arrow in diagram) """ xv = self.upconv(xv) x = concat(xh, xv) x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class UNet(nn.Module): def __init__(self): super(UNet, self).__init__() fs = [16, 32, 64, 128, 256] self.conv_in = ConvBlock(1, fs[0]) self.dconv1 = DownConvBlock(fs[0], fs[1]) self.dconv2 = DownConvBlock(fs[1], fs[2]) self.dconv3 = DownConvBlock(fs[2], fs[3]) self.dconv4 = DownConvBlock(fs[3], fs[4]) self.uconv1 = UpConvBlock(fs[4], fs[3]) self.uconv2 = UpConvBlock(fs[3], fs[2]) self.uconv3 = UpConvBlock(fs[2], fs[1]) self.uconv4 = UpConvBlock(fs[1], fs[0]) self.conv_out = conv3x3(fs[0], 1) self._initialize_weights() def forward(self, x): x1 = self.conv_in(x) x2 = self.dconv1(x1) x3 = self.dconv2(x2) x4 = self.dconv3(x3) x5 = self.dconv4(x4) x6 = self.uconv1(x4, x5) x7 = self.uconv2(x3, x6) x8 = self.uconv3(x2, x7) x9 = self.uconv4(x1, x8) x10 = self.conv_out(x9) return x10 def _initialize_weights(self): conv_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] for m in conv_modules: n = m.weight.shape[1] * m.weight.shape[2] * m.weight.shape[3] m.weight.data.normal_(0, np.sqrt(2.0 / n)) m.bias.data.zero_() def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.utils.data from torch.cuda 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_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 16 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_red_fused__native_batch_norm_legit_1(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 32 rnumel = 8192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 16 x1 = xindex // 16 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x3 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (4096 * x0 + 65536 * (r2 // 4096) + 131072 * x1 + r2 % 4096), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4 = tmp4_tmp[:, None] tl.store(out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr1 + x3, tmp3, xmask) tl.store(out_ptr2 + x3, tmp4, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 2 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 + (x0 + 16 * r1), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (x0 + 16 * r1), xmask, other=0.0) tmp2 = tl.load(in_ptr2 + (x0 + 16 * r1), xmask, other=0.0) tmp3 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(xmask, tmp3, 0) tmp8 = tl.where(xmask, tmp4, 0) tmp9 = tl.where(xmask, tmp5, 0) tmp10, tmp11, tmp12 = triton_helpers.welford(tmp7, tmp8, tmp9, 1) tmp13 = tmp10[:, None] tmp14 = tmp11[:, None] tmp12[:, None] tmp16 = 16384.0 tmp17 = tmp14 / tmp16 tmp18 = 1e-05 tmp19 = tmp17 + tmp18 tmp20 = libdevice.rsqrt(tmp19) tl.store(out_ptr2 + x0, tmp20, xmask) tl.store(out_ptr0 + x0, tmp13, xmask) tl.store(out_ptr1 + x0, tmp14, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 16 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 16384.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_4(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_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) x3 = xindex x1 = xindex // 1024 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_red_fused__native_batch_norm_legit_6(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 32 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] 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 % 1024 r2 = rindex // 1024 tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0 + 32768 * r2), 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) tl.store(out_ptr1 + x0, tmp3, xmask) tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x0, tmp9, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_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) x3 = xindex x1 = xindex // 1024 % 32 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 4096.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 64 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x1), None, eviction_policy ='evict_last') tmp5 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x1), None, eviction_policy ='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_per_fused__native_batch_norm_legit_10(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex % 256 r2 = rindex // 256 x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0 + 16384 * r2), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x0, tmp18, None) tl.store(out_ptr0 + x0, tmp8, None) tl.store(out_ptr1 + x0, tmp13, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_11(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1024.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_12(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 32 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 32 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + 2 * x0 + 32 * x1), None, eviction_policy ='evict_last') tmp5 = tl.load(in_ptr0 + (17 + 2 * x0 + 32 * x1), None, eviction_policy ='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_13(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_per_fused__native_batch_norm_legit_14(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex % 64 r2 = rindex // 64 x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0 + 8192 * r2), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 256, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x0, tmp18, None) tl.store(out_ptr0 + x0, tmp8, None) tl.store(out_ptr1 + x0, tmp13, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_15(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 256.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_16(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (8 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (9 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_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) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_per_fused__native_batch_norm_legit_18(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex % 16 r2 = rindex // 16 x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0 + 4096 * r2), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 64, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 64.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.rsqrt(tmp20) tl.store(out_ptr2 + x0, tmp21, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) tl.store(out_ptr1 + x0, tmp16, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_19(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 64.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_20( in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 64.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tmp16 = 0.0 tmp17 = tmp15 <= tmp16 tl.store(out_ptr0 + x3, tmp15, None) tl.store(out_ptr1 + x3, tmp17, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_21(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_constant_pad_nd_22(in_ptr0, in_ptr1, out_ptr0, 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 = x1 tmp1 = tl.full([1], 8, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + x1, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.full([XBLOCK], 4, tl.int32) tmp8 = tmp6 + tmp7 tmp9 = tmp6 < 0 tmp10 = tl.where(tmp9, tmp8, tmp6) tmp11 = tl.load(in_ptr0 + x0, tmp5 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp11 + tmp7 tmp13 = tmp11 < 0 tmp14 = tl.where(tmp13, tmp12, tmp11) tmp15 = tl.load(in_ptr1 + (tmp14 + 4 * tmp10 + 16 * x2), tmp5 & xmask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + x4, tmp15, xmask) @triton.jit def triton_poi_fused_cat_23(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 // 64 % 256 x0 = xindex % 64 x2 = xindex // 16384 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 + 64 * x1 + 8192 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 256, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 64 * (-128 + x1) + 8192 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-128 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_24( in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 // 64 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 256.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tmp16 = 0.0 tmp17 = tmp15 <= tmp16 tl.store(out_ptr0 + x3, tmp15, None) tl.store(out_ptr1 + x3, tmp17, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_25(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_constant_pad_nd_26(in_ptr0, in_ptr1, out_ptr0, 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 = x1 tmp1 = tl.full([1], 16, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + x1, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.full([XBLOCK], 8, tl.int32) tmp8 = tmp6 + tmp7 tmp9 = tmp6 < 0 tmp10 = tl.where(tmp9, tmp8, tmp6) tmp11 = tl.load(in_ptr0 + x0, tmp5 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp11 + tmp7 tmp13 = tmp11 < 0 tmp14 = tl.where(tmp13, tmp12, tmp11) tmp15 = tl.load(in_ptr1 + (tmp14 + 8 * tmp10 + 64 * x2), tmp5 & xmask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + x4, tmp15, xmask) @triton.jit def triton_poi_fused_cat_27(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 // 256 % 128 x0 = xindex % 256 x2 = xindex // 32768 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 + 256 * x1 + 16384 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 128, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 256 * (-64 + x1) + 16384 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-64 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_28( in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 // 256 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1024.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tmp16 = 0.0 tmp17 = tmp15 <= tmp16 tl.store(out_ptr0 + x3, tmp15, None) tl.store(out_ptr1 + x3, tmp17, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_29(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_constant_pad_nd_30(in_ptr0, in_ptr1, out_ptr0, 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 tmp0 = x1 tmp1 = tl.full([1], 32, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + x1, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.full([XBLOCK], 16, tl.int32) tmp8 = tmp6 + tmp7 tmp9 = tmp6 < 0 tmp10 = tl.where(tmp9, tmp8, tmp6) tmp11 = tl.load(in_ptr0 + x0, tmp5 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp11 + tmp7 tmp13 = tmp11 < 0 tmp14 = tl.where(tmp13, tmp12, tmp11) tmp15 = tl.load(in_ptr1 + (tmp14 + 16 * tmp10 + 256 * x2), tmp5 & xmask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + x4, tmp15, xmask) @triton.jit def triton_poi_fused_cat_31(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 // 1024 % 64 x0 = xindex % 1024 x2 = xindex // 65536 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 1024 * x1 + 32768 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 64, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 1024 * (-32 + x1) + 32768 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-32 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_32( in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 // 1024 % 32 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 4096.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tmp16 = 0.0 tmp17 = tmp15 <= tmp16 tl.store(out_ptr0 + x3, tmp15, None) tl.store(out_ptr1 + x3, tmp17, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_33(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_constant_pad_nd_34(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 540800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 65 % 65 x0 = xindex % 65 x2 = xindex // 4225 x4 = xindex tmp0 = x1 tmp1 = tl.full([1], 64, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + x1, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.full([XBLOCK], 32, tl.int32) tmp8 = tmp6 + tmp7 tmp9 = tmp6 < 0 tmp10 = tl.where(tmp9, tmp8, tmp6) tmp11 = tl.load(in_ptr0 + x0, tmp5 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp11 + tmp7 tmp13 = tmp11 < 0 tmp14 = tl.where(tmp13, tmp12, tmp11) tmp15 = tl.load(in_ptr1 + (tmp14 + 32 * tmp10 + 1024 * x2), tmp5 & xmask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + x4, tmp15, xmask) @triton.jit def triton_poi_fused_cat_35(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 // 4096 % 32 x0 = xindex % 4096 x2 = xindex // 131072 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 16, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 65536 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 32, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 4096 * (-16 + x1) + 65536 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-16 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused_convolution_36(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, None) def call(args): (primals_1, primals_2, primals_3, 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 ) = args args.clear() assert_size_stride(primals_1, (16, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (16,), (1,)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (32, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_11, (32,), (1,)) assert_size_stride(primals_12, (32,), (1,)) assert_size_stride(primals_13, (32,), (1,)) assert_size_stride(primals_14, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_15, (32,), (1,)) assert_size_stride(primals_16, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_17, (32,), (1,)) assert_size_stride(primals_18, (64, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_19, (64,), (1,)) assert_size_stride(primals_20, (64,), (1,)) assert_size_stride(primals_21, (64,), (1,)) assert_size_stride(primals_22, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_23, (64,), (1,)) assert_size_stride(primals_24, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_25, (64,), (1,)) assert_size_stride(primals_26, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_27, (128,), (1,)) assert_size_stride(primals_28, (128,), (1,)) assert_size_stride(primals_29, (128,), (1,)) assert_size_stride(primals_30, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_31, (128,), (1,)) assert_size_stride(primals_32, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_33, (128,), (1,)) assert_size_stride(primals_34, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_35, (256,), (1,)) assert_size_stride(primals_36, (256,), (1,)) assert_size_stride(primals_37, (256,), (1,)) assert_size_stride(primals_38, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_39, (256,), (1,)) assert_size_stride(primals_40, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_41, (256,), (1,)) assert_size_stride(primals_42, (128, 256, 2, 2), (1024, 4, 2, 1)) assert_size_stride(primals_43, (128,), (1,)) assert_size_stride(primals_44, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_45, (128,), (1,)) assert_size_stride(primals_46, (128,), (1,)) assert_size_stride(primals_47, (128,), (1,)) assert_size_stride(primals_48, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_49, (128,), (1,)) assert_size_stride(primals_50, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_51, (128,), (1,)) assert_size_stride(primals_52, (64, 128, 2, 2), (512, 4, 2, 1)) assert_size_stride(primals_53, (64,), (1,)) assert_size_stride(primals_54, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_55, (64,), (1,)) assert_size_stride(primals_56, (64,), (1,)) assert_size_stride(primals_57, (64,), (1,)) assert_size_stride(primals_58, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_59, (64,), (1,)) assert_size_stride(primals_60, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_61, (64,), (1,)) assert_size_stride(primals_62, (32, 64, 2, 2), (256, 4, 2, 1)) assert_size_stride(primals_63, (32,), (1,)) assert_size_stride(primals_64, (32, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_65, (32,), (1,)) assert_size_stride(primals_66, (32,), (1,)) assert_size_stride(primals_67, (32,), (1,)) assert_size_stride(primals_68, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_69, (32,), (1,)) assert_size_stride(primals_70, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_71, (32,), (1,)) assert_size_stride(primals_72, (16, 32, 2, 2), (128, 4, 2, 1)) assert_size_stride(primals_73, (16,), (1,)) assert_size_stride(primals_74, (16, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_75, (16,), (1,)) assert_size_stride(primals_76, (16,), (1,)) assert_size_stride(primals_77, (16,), (1,)) assert_size_stride(primals_78, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_79, (16,), (1,)) assert_size_stride(primals_80, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_81, (16,), (1,)) assert_size_stride(primals_82, (1, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_83, (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, 16, 64, 64), (65536, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(262144)](buf1, primals_2, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((1, 16, 1, 1, 2), (32, 1, 32, 32, 16), torch.float32) buf3 = empty_strided_cuda((1, 16, 1, 1, 2), (32, 1, 32, 32, 16), torch.float32) buf4 = empty_strided_cuda((1, 16, 1, 1, 2), (32, 1, 32, 32, 16), torch.float32) triton_red_fused__native_batch_norm_legit_1[grid(32)](buf1, buf2, buf3, buf4, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf6 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf8 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf2, buf3, buf4, buf5, buf6, buf8, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) buf9 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf1, buf5, buf6, primals_4, primals_5, buf9, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf10 = 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(buf10, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf11 = buf10 del buf10 triton_poi_fused_convolution_0[grid(262144)](buf11, primals_7, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf12 = buf4 del buf4 buf13 = buf3 del buf3 buf14 = buf2 del buf2 triton_red_fused__native_batch_norm_legit_1[grid(32)](buf11, buf12, buf13, buf14, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf15 = buf6 del buf6 buf16 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf18 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf12, buf13, buf14, buf15, buf16, buf18, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) buf19 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf11, buf15, buf16, primals_4, primals_5, buf19, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf20 = extern_kernels.convolution(buf19, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf21 = buf20 del buf20 triton_poi_fused_convolution_0[grid(262144)](buf21, primals_9, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf22 = buf14 del buf14 buf23 = buf13 del buf13 buf24 = buf12 del buf12 triton_red_fused__native_batch_norm_legit_1[grid(32)](buf21, buf22, buf23, buf24, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf25 = buf16 del buf16 buf26 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf28 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf22, buf23, buf24, buf25, buf26, buf28, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) buf29 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf21, buf25, buf26, primals_4, primals_5, buf29, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf30 = empty_strided_cuda((4, 16, 32, 32), (16384, 1024, 32, 1), torch.float32) buf31 = empty_strided_cuda((4, 16, 32, 32), (16384, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_4[grid(65536)](buf29, buf30, buf31, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf32 = extern_kernels.convolution(buf30, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf33 = buf32 del buf32 triton_poi_fused_convolution_5[grid(131072)](buf33, primals_11, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf34 = reinterpret_tensor(buf24, (1, 32, 1, 1), (32, 1, 32, 32), 0) del buf24 buf35 = reinterpret_tensor(buf23, (1, 32, 1, 1), (32, 1, 32, 32), 0) del buf23 buf37 = reinterpret_tensor(buf22, (1, 32, 1, 1), (32, 1, 32, 32), 0) del buf22 triton_red_fused__native_batch_norm_legit_6[grid(32)](buf33, buf34, buf35, buf37, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf38 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_7[grid(131072)](buf33, buf34, buf35, primals_12, primals_13, buf38, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf39 = extern_kernels.convolution(buf38, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf39, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf40 = buf39 del buf39 triton_poi_fused_convolution_5[grid(131072)](buf40, primals_15, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf41 = buf35 del buf35 buf42 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) buf44 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) triton_red_fused__native_batch_norm_legit_6[grid(32)](buf40, buf41, buf42, buf44, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf45 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_7[grid(131072)](buf40, buf41, buf42, primals_12, primals_13, buf45, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf46 = extern_kernels.convolution(buf45, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf47 = buf46 del buf46 triton_poi_fused_convolution_5[grid(131072)](buf47, primals_17, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf48 = buf42 del buf42 buf49 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) buf51 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) triton_red_fused__native_batch_norm_legit_6[grid(32)](buf47, buf48, buf49, buf51, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf52 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_7[grid(131072)](buf47, buf48, buf49, primals_12, primals_13, buf52, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_13 buf53 = empty_strided_cuda((4, 32, 16, 16), (8192, 256, 16, 1), torch.float32) buf54 = empty_strided_cuda((4, 32, 16, 16), (8192, 256, 16, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_8[grid(32768)](buf52, buf53, buf54, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf55 = extern_kernels.convolution(buf53, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf55, (4, 64, 16, 16), (16384, 256, 16, 1)) buf56 = buf55 del buf55 triton_poi_fused_convolution_9[grid(65536)](buf56, primals_19, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_19 buf57 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf58 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf60 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf56, buf57, buf58, buf60, 64, 1024, num_warps=8, num_stages=1) buf61 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_11[grid(65536)](buf56, buf57, buf58, primals_20, primals_21, buf61, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf62 = extern_kernels.convolution(buf61, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 64, 16, 16), (16384, 256, 16, 1)) buf63 = buf62 del buf62 triton_poi_fused_convolution_9[grid(65536)](buf63, primals_23, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_23 buf64 = buf58 del buf58 buf65 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf67 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf63, buf64, buf65, buf67, 64, 1024, num_warps=8, num_stages=1) buf68 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_11[grid(65536)](buf63, buf64, buf65, primals_20, primals_21, buf68, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf69 = extern_kernels.convolution(buf68, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf69, (4, 64, 16, 16), (16384, 256, 16, 1)) buf70 = buf69 del buf69 triton_poi_fused_convolution_9[grid(65536)](buf70, primals_25, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_25 buf71 = buf65 del buf65 buf72 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf74 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf70, buf71, buf72, buf74, 64, 1024, num_warps=8, num_stages=1) buf75 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_11[grid(65536)](buf70, buf71, buf72, primals_20, primals_21, buf75, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_21 buf76 = empty_strided_cuda((4, 64, 8, 8), (4096, 64, 8, 1), torch. float32) buf77 = empty_strided_cuda((4, 64, 8, 8), (4096, 64, 8, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_12[grid(16384)](buf75, buf76, buf77, 16384, XBLOCK=256, num_warps=4, num_stages=1) buf78 = extern_kernels.convolution(buf76, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf78, (4, 128, 8, 8), (8192, 64, 8, 1)) buf79 = buf78 del buf78 triton_poi_fused_convolution_13[grid(32768)](buf79, primals_27, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_27 buf80 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf81 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf83 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf79, buf80, buf81, buf83, 128, 256, num_warps=2, num_stages=1) buf84 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch. float32) triton_poi_fused__native_batch_norm_legit_relu_15[grid(32768)](buf79, buf80, buf81, primals_28, primals_29, buf84, 32768, XBLOCK=256, num_warps=4, num_stages=1) buf85 = extern_kernels.convolution(buf84, primals_30, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf85, (4, 128, 8, 8), (8192, 64, 8, 1)) buf86 = buf85 del buf85 triton_poi_fused_convolution_13[grid(32768)](buf86, primals_31, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_31 buf87 = buf81 del buf81 buf88 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf90 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf86, buf87, buf88, buf90, 128, 256, num_warps=2, num_stages=1) buf91 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch. float32) triton_poi_fused__native_batch_norm_legit_relu_15[grid(32768)](buf86, buf87, buf88, primals_28, primals_29, buf91, 32768, XBLOCK=256, num_warps=4, num_stages=1) buf92 = extern_kernels.convolution(buf91, primals_32, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf92, (4, 128, 8, 8), (8192, 64, 8, 1)) buf93 = buf92 del buf92 triton_poi_fused_convolution_13[grid(32768)](buf93, primals_33, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_33 buf94 = buf88 del buf88 buf95 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf97 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf93, buf94, buf95, buf97, 128, 256, num_warps=2, num_stages=1) buf98 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch. float32) triton_poi_fused__native_batch_norm_legit_relu_15[grid(32768)](buf93, buf94, buf95, primals_28, primals_29, buf98, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_29 buf99 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch. float32) buf100 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_16[grid(8192)](buf98, buf99, buf100, 8192, XBLOCK=128, num_warps=4, num_stages=1) buf101 = extern_kernels.convolution(buf99, primals_34, stride=(1, 1 ), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf101, (4, 256, 4, 4), (4096, 16, 4, 1)) buf102 = buf101 del buf101 triton_poi_fused_convolution_17[grid(16384)](buf102, primals_35, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_35 buf103 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf104 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf106 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused__native_batch_norm_legit_18[grid(256)](buf102, buf103, buf104, buf106, 256, 64, XBLOCK=8, num_warps=4, num_stages=1) buf107 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch .float32) triton_poi_fused__native_batch_norm_legit_relu_19[grid(16384)](buf102, buf103, buf104, primals_36, primals_37, buf107, 16384, XBLOCK= 128, num_warps=4, num_stages=1) buf108 = extern_kernels.convolution(buf107, primals_38, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf108, (4, 256, 4, 4), (4096, 16, 4, 1)) buf109 = buf108 del buf108 triton_poi_fused_convolution_17[grid(16384)](buf109, primals_39, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_39 buf110 = buf104 del buf104 buf111 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf113 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused__native_batch_norm_legit_18[grid(256)](buf109, buf110, buf111, buf113, 256, 64, XBLOCK=8, num_warps=4, num_stages=1) buf114 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch .float32) triton_poi_fused__native_batch_norm_legit_relu_19[grid(16384)](buf109, buf110, buf111, primals_36, primals_37, buf114, 16384, XBLOCK= 128, num_warps=4, num_stages=1) buf115 = extern_kernels.convolution(buf114, primals_40, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf115, (4, 256, 4, 4), (4096, 16, 4, 1)) buf116 = buf115 del buf115 triton_poi_fused_convolution_17[grid(16384)](buf116, primals_41, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_41 buf117 = buf111 del buf111 buf118 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf120 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused__native_batch_norm_legit_18[grid(256)](buf116, buf117, buf118, buf120, 256, 64, XBLOCK=8, num_warps=4, num_stages=1) buf121 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch .float32) buf236 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch .bool) triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_20[ grid(16384)](buf116, buf117, buf118, primals_36, primals_37, buf121, buf236, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf118 del primals_37 buf122 = empty_strided_cuda((8,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_21[grid(8)](buf122, 8, XBLOCK=8, num_warps=1, num_stages=1) buf123 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch.float32) triton_poi_fused__unsafe_index_constant_pad_nd_22[grid(82944)](buf122, buf121, buf123, 82944, XBLOCK=512, num_warps=8, num_stages=1) del buf121 buf124 = extern_kernels.convolution(buf123, primals_42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf124, (4, 128, 8, 8), (8192, 64, 8, 1)) buf125 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch.float32) triton_poi_fused_cat_23[grid(65536)](buf98, buf124, primals_43, buf125, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_43 buf126 = extern_kernels.convolution(buf125, primals_44, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf126, (4, 128, 8, 8), (8192, 64, 8, 1)) buf127 = buf126 del buf126 triton_poi_fused_convolution_13[grid(32768)](buf127, primals_45, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_45 buf128 = buf95 del buf95 buf129 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf131 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf127, buf128, buf129, buf131, 128, 256, num_warps=2, num_stages=1) buf132 = buf124 del buf124 triton_poi_fused__native_batch_norm_legit_relu_15[grid(32768)](buf127, buf128, buf129, primals_46, primals_47, buf132, 32768, XBLOCK= 256, num_warps=4, num_stages=1) buf133 = extern_kernels.convolution(buf132, primals_48, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf133, (4, 128, 8, 8), (8192, 64, 8, 1)) buf134 = buf133 del buf133 triton_poi_fused_convolution_13[grid(32768)](buf134, primals_49, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_49 buf135 = buf129 del buf129 buf136 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf138 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf134, buf135, buf136, buf138, 128, 256, num_warps=2, num_stages=1) buf139 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch .float32) triton_poi_fused__native_batch_norm_legit_relu_15[grid(32768)](buf134, buf135, buf136, primals_46, primals_47, buf139, 32768, XBLOCK= 256, num_warps=4, num_stages=1) buf140 = extern_kernels.convolution(buf139, primals_50, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf140, (4, 128, 8, 8), (8192, 64, 8, 1)) buf141 = buf140 del buf140 triton_poi_fused_convolution_13[grid(32768)](buf141, primals_51, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_51 buf142 = buf136 del buf136 buf143 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf145 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_14[grid(128)](buf141, buf142, buf143, buf145, 128, 256, num_warps=2, num_stages=1) buf146 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch .float32) buf235 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch .bool) triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_24[ grid(32768)](buf141, buf142, buf143, primals_46, primals_47, buf146, buf235, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf143 del primals_47 buf147 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_25[grid(16)](buf147, 16, XBLOCK=16, num_warps=1, num_stages=1) buf148 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.float32) triton_poi_fused__unsafe_index_constant_pad_nd_26[grid(147968)](buf147, buf146, buf148, 147968, XBLOCK=512, num_warps=8, num_stages=1) del buf146 buf149 = extern_kernels.convolution(buf148, primals_52, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf149, (4, 64, 16, 16), (16384, 256, 16, 1)) buf150 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) triton_poi_fused_cat_27[grid(131072)](buf75, buf149, primals_53, buf150, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_53 buf151 = extern_kernels.convolution(buf150, primals_54, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf151, (4, 64, 16, 16), (16384, 256, 16, 1)) buf152 = buf151 del buf151 triton_poi_fused_convolution_9[grid(65536)](buf152, primals_55, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_55 buf153 = buf72 del buf72 buf154 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf156 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf152, buf153, buf154, buf156, 64, 1024, num_warps=8, num_stages=1) buf157 = buf149 del buf149 triton_poi_fused__native_batch_norm_legit_relu_11[grid(65536)](buf152, buf153, buf154, primals_56, primals_57, buf157, 65536, XBLOCK= 512, num_warps=4, num_stages=1) buf158 = extern_kernels.convolution(buf157, primals_58, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf158, (4, 64, 16, 16), (16384, 256, 16, 1)) buf159 = buf158 del buf158 triton_poi_fused_convolution_9[grid(65536)](buf159, primals_59, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_59 buf160 = buf154 del buf154 buf161 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf163 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf159, buf160, buf161, buf163, 64, 1024, num_warps=8, num_stages=1) buf164 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_11[grid(65536)](buf159, buf160, buf161, primals_56, primals_57, buf164, 65536, XBLOCK= 512, num_warps=4, num_stages=1) buf165 = extern_kernels.convolution(buf164, primals_60, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf165, (4, 64, 16, 16), (16384, 256, 16, 1)) buf166 = buf165 del buf165 triton_poi_fused_convolution_9[grid(65536)](buf166, primals_61, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_61 buf167 = buf161 del buf161 buf168 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf170 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_per_fused__native_batch_norm_legit_10[grid(64)](buf166, buf167, buf168, buf170, 64, 1024, num_warps=8, num_stages=1) buf171 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) buf234 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.bool) triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_28[ grid(65536)](buf166, buf167, buf168, primals_56, primals_57, buf171, buf234, 65536, XBLOCK=512, num_warps=4, num_stages=1) del buf168 del primals_57 buf172 = empty_strided_cuda((32,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_29[grid(32)](buf172, 32, XBLOCK=32, num_warps=1, num_stages=1) buf173 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.float32) triton_poi_fused__unsafe_index_constant_pad_nd_30[grid(278784)](buf172, buf171, buf173, 278784, XBLOCK=512, num_warps=8, num_stages=1) del buf171 buf174 = extern_kernels.convolution(buf173, primals_62, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf174, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf175 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.float32) triton_poi_fused_cat_31[grid(262144)](buf52, buf174, primals_63, buf175, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_63 buf176 = extern_kernels.convolution(buf175, primals_64, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf176, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf177 = buf176 del buf176 triton_poi_fused_convolution_5[grid(131072)](buf177, primals_65, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_65 buf178 = buf49 del buf49 buf179 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) buf181 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) triton_red_fused__native_batch_norm_legit_6[grid(32)](buf177, buf178, buf179, buf181, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf182 = buf174 del buf174 triton_poi_fused__native_batch_norm_legit_relu_7[grid(131072)](buf177, buf178, buf179, primals_66, primals_67, buf182, 131072, XBLOCK= 512, num_warps=8, num_stages=1) buf183 = extern_kernels.convolution(buf182, primals_68, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf183, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf184 = buf183 del buf183 triton_poi_fused_convolution_5[grid(131072)](buf184, primals_69, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_69 buf185 = buf179 del buf179 buf186 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) buf188 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) triton_red_fused__native_batch_norm_legit_6[grid(32)](buf184, buf185, buf186, buf188, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf189 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_7[grid(131072)](buf184, buf185, buf186, primals_66, primals_67, buf189, 131072, XBLOCK= 512, num_warps=8, num_stages=1) buf190 = extern_kernels.convolution(buf189, primals_70, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf190, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf191 = buf190 del buf190 triton_poi_fused_convolution_5[grid(131072)](buf191, primals_71, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_71 buf192 = buf186 del buf186 buf193 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) buf195 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch. float32) triton_red_fused__native_batch_norm_legit_6[grid(32)](buf191, buf192, buf193, buf195, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf196 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) buf233 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.bool) triton_poi_fused__native_batch_norm_legit_relu_threshold_backward_32[ grid(131072)](buf191, buf192, buf193, primals_66, primals_67, buf196, buf233, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_67 buf197 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_33[grid(64)](buf197, 64, XBLOCK=64, num_warps=1, num_stages=1) buf198 = empty_strided_cuda((4, 32, 65, 65), (135200, 4225, 65, 1), torch.float32) triton_poi_fused__unsafe_index_constant_pad_nd_34[grid(540800)](buf197, buf196, buf198, 540800, XBLOCK=512, num_warps=8, num_stages=1) del buf196 buf199 = extern_kernels.convolution(buf198, primals_72, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf199, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf200 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.float32) triton_poi_fused_cat_35[grid(524288)](buf29, buf199, primals_73, buf200, 524288, XBLOCK=512, num_warps=8, num_stages=1) del primals_73 buf201 = extern_kernels.convolution(buf200, primals_74, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf201, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf202 = buf201 del buf201 triton_poi_fused_convolution_0[grid(262144)](buf202, primals_75, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_75 buf203 = reinterpret_tensor(buf193, (1, 16, 1, 1, 2), (32, 1, 32, 32, 16), 0) del buf193 buf204 = empty_strided_cuda((1, 16, 1, 1, 2), (32, 1, 32, 32, 16), torch.float32) buf205 = empty_strided_cuda((1, 16, 1, 1, 2), (32, 1, 32, 32, 16), torch.float32) triton_red_fused__native_batch_norm_legit_1[grid(32)](buf202, buf203, buf204, buf205, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf206 = buf26 del buf26 buf207 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf209 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf203, buf204, buf205, buf206, buf207, buf209, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) buf210 = buf199 del buf199 triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf202, buf206, buf207, primals_76, primals_77, buf210, 262144, XBLOCK= 512, num_warps=8, num_stages=1) buf211 = extern_kernels.convolution(buf210, primals_78, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf211, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf212 = buf211 del buf211 triton_poi_fused_convolution_0[grid(262144)](buf212, primals_79, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_79 buf213 = buf205 del buf205 buf214 = buf204 del buf204 buf215 = buf203 del buf203 triton_red_fused__native_batch_norm_legit_1[grid(32)](buf212, buf213, buf214, buf215, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf216 = buf207 del buf207 buf217 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf219 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf213, buf214, buf215, buf216, buf217, buf219, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) buf220 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf212, buf216, buf217, primals_76, primals_77, buf220, 262144, XBLOCK= 512, num_warps=8, num_stages=1) buf221 = extern_kernels.convolution(buf220, primals_80, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf221, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf222 = buf221 del buf221 triton_poi_fused_convolution_0[grid(262144)](buf222, primals_81, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_81 buf223 = buf215 del buf215 buf224 = buf214 del buf214 buf225 = buf213 del buf213 triton_red_fused__native_batch_norm_legit_1[grid(32)](buf222, buf223, buf224, buf225, 32, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf226 = buf217 del buf217 buf227 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf229 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_2[grid(16)](buf223, buf224, buf225, buf226, buf227, buf229, 16, 2, XBLOCK=8, num_warps=2, num_stages=1) del buf223 del buf224 del buf225 buf230 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) triton_poi_fused__native_batch_norm_legit_relu_3[grid(262144)](buf222, buf226, buf227, primals_76, primals_77, buf230, 262144, XBLOCK= 512, num_warps=8, num_stages=1) del buf227 del primals_77 buf231 = extern_kernels.convolution(buf230, primals_82, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf231, (4, 1, 64, 64), (4096, 4096, 64, 1)) buf232 = buf231 del buf231 triton_poi_fused_convolution_36[grid(16384)](buf232, primals_83, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_83 return (buf232, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, primals_28, primals_30, primals_32, primals_34, primals_36, primals_38, primals_40, primals_42, primals_44, primals_46, primals_48, primals_50, primals_52, primals_54, primals_56, primals_58, primals_60, primals_62, primals_64, primals_66, primals_68, primals_70, primals_72, primals_74, primals_76, primals_78, primals_80, primals_82, buf1, reinterpret_tensor(buf8, (16,), (1,), 0), buf9, buf11, reinterpret_tensor(buf18, (16,), (1,), 0), buf19, buf21, reinterpret_tensor(buf28, (16,), (1,), 0), buf29, buf30, buf31, buf33, reinterpret_tensor(buf37, (32,), (1,), 0), buf38, buf40, reinterpret_tensor(buf44, (32,), (1,), 0), buf45, buf47, reinterpret_tensor(buf51, (32,), (1,), 0), buf52, buf53, buf54, buf56, reinterpret_tensor(buf60, (64,), (1,), 0), buf61, buf63, reinterpret_tensor(buf67, (64,), (1,), 0), buf68, buf70, reinterpret_tensor(buf74, (64,), (1,), 0), buf75, buf76, buf77, buf79, reinterpret_tensor(buf83, (128,), (1,), 0), buf84, buf86, reinterpret_tensor(buf90, (128,), (1,), 0), buf91, buf93, reinterpret_tensor(buf97, (128,), (1,), 0), buf98, buf99, buf100, buf102, reinterpret_tensor(buf106, (256,), (1,), 0), buf107, buf109, reinterpret_tensor(buf113, (256,), (1,), 0), buf114, buf116, reinterpret_tensor(buf120, (256,), (1,), 0), buf122, buf123, buf125, buf127, reinterpret_tensor(buf131, (128,), (1,), 0), buf132, buf134, reinterpret_tensor(buf138, (128,), (1,), 0), buf139, buf141, reinterpret_tensor(buf145, (128,), (1,), 0), buf147, buf148, buf150, buf152, reinterpret_tensor(buf156, (64,), (1,), 0), buf157, buf159, reinterpret_tensor(buf163, (64,), (1,), 0), buf164, buf166, reinterpret_tensor(buf170, (64,), (1,), 0), buf172, buf173, buf175, buf177, reinterpret_tensor(buf181, (32,), (1,), 0), buf182, buf184, reinterpret_tensor(buf188, (32,), (1,), 0), buf189, buf191, reinterpret_tensor(buf195, (32,), (1,), 0), buf197, buf198, buf200, buf202, reinterpret_tensor(buf209, (16,), (1,), 0), buf210, buf212, reinterpret_tensor(buf219, (16,), (1,), 0), buf220, buf222, reinterpret_tensor(buf229, (16,), (1,), 0), buf230, reinterpret_tensor(buf226, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf216, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf206, (1, 16, 1, 1), (16, 1, 1, 1), 0), buf233, reinterpret_tensor(buf192, (1, 32, 1, 1), (32, 1, 1, 1), 0), reinterpret_tensor(buf185, (1, 32, 1, 1), (32, 1, 1, 1), 0), reinterpret_tensor(buf178, (1, 32, 1, 1), (32, 1, 1, 1), 0), buf234, reinterpret_tensor(buf167, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf160, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf153, (1, 64, 1, 1), (64, 1, 1, 1), 0), buf235, reinterpret_tensor(buf142, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf135, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf128, (1, 128, 1, 1), (128, 1, 1, 1), 0), buf236, reinterpret_tensor(buf117, (1, 256, 1, 1), (256, 1, 1, 1), 0), reinterpret_tensor(buf110, (1, 256, 1, 1), (256, 1, 1, 1), 0), reinterpret_tensor(buf103, (1, 256, 1, 1), (256, 1, 1, 1), 0), reinterpret_tensor(buf94, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf87, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf80, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf71, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf64, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf57, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf48, (1, 32, 1, 1), (32, 1, 1, 1), 0), reinterpret_tensor(buf41, (1, 32, 1, 1), (32, 1, 1, 1), 0), reinterpret_tensor(buf34, (1, 32, 1, 1), (32, 1, 1, 1), 0), reinterpret_tensor(buf25, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf15, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf5, (1, 16, 1, 1), (16, 1, 1, 1), 0)) def conv3x3(in_channels, out_channels): return nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1, bias=True) def maxpool2x2(): return nn.MaxPool2d(kernel_size=2, stride=2, padding=0) def concat(xh, xv): return torch.cat([xh, xv], dim=1) class UpConv2x2(nn.Module): def __init__(self, channels): super(UpConv2x2, self).__init__() self.conv = nn.Conv2d(channels, channels // 2, kernel_size=2, stride=1, padding=0, bias=True) def forward(self, x): x = F.interpolate(x, scale_factor=2, mode='nearest') x = F.pad(x, (0, 1, 0, 1)) x = self.conv(x) return x class ConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(ConvBlock, self).__init__() self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, x): x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class DownConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(DownConvBlock, self).__init__() self.maxpool = maxpool2x2() self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, x): x = self.maxpool(x) x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class UpConvBlock(nn.Module): def __init__(self, in_channels, out_channels): """ Args: in_channels: number of channels in input (1st) feature map out_channels: number of channels in output feature maps """ super(UpConvBlock, self).__init__() self.upconv = UpConv2x2(in_channels) self.conv1 = conv3x3(in_channels, out_channels) self.conv2 = conv3x3(out_channels, out_channels) self.conv3 = conv3x3(out_channels, out_channels) self.norm = nn.BatchNorm2d(out_channels, track_running_stats=False) def forward(self, xh, xv): """ Args: xh: torch Variable, activations from same resolution feature maps (gray arrow in diagram) xv: torch Variable, activations from lower resolution feature maps (green arrow in diagram) """ xv = self.upconv(xv) x = concat(xh, xv) x = F.relu(self.norm(self.conv1(x))) x = F.relu(self.norm(self.conv2(x))) x = F.relu(self.norm(self.conv3(x))) return x class UNetNew(nn.Module): def __init__(self): super(UNetNew, self).__init__() fs = [16, 32, 64, 128, 256] self.conv_in = ConvBlock(1, fs[0]) self.dconv1 = DownConvBlock(fs[0], fs[1]) self.dconv2 = DownConvBlock(fs[1], fs[2]) self.dconv3 = DownConvBlock(fs[2], fs[3]) self.dconv4 = DownConvBlock(fs[3], fs[4]) self.uconv1 = UpConvBlock(fs[4], fs[3]) self.uconv2 = UpConvBlock(fs[3], fs[2]) self.uconv3 = UpConvBlock(fs[2], fs[1]) self.uconv4 = UpConvBlock(fs[1], fs[0]) self.conv_out = conv3x3(fs[0], 1) self._initialize_weights() def _initialize_weights(self): conv_modules = [m for m in self.modules() if isinstance(m, nn.Conv2d)] for m in conv_modules: n = m.weight.shape[1] * m.weight.shape[2] * m.weight.shape[3] m.weight.data.normal_(0, np.sqrt(2.0 / n)) m.bias.data.zero_() def forward(self, input_0): primals_1 = self.conv_in.conv1.weight primals_2 = self.conv_in.conv1.bias primals_6 = self.conv_in.conv2.weight primals_4 = self.conv_in.conv2.bias primals_8 = self.conv_in.conv3.weight primals_5 = self.conv_in.conv3.bias primals_7 = self.conv_in.norm.weight primals_9 = self.conv_in.norm.bias primals_10 = self.dconv1.conv1.weight primals_11 = self.dconv1.conv1.bias primals_14 = self.dconv1.conv2.weight primals_12 = self.dconv1.conv2.bias primals_16 = self.dconv1.conv3.weight primals_13 = self.dconv1.conv3.bias primals_15 = self.dconv1.norm.weight primals_17 = self.dconv1.norm.bias primals_18 = self.dconv2.conv1.weight primals_19 = self.dconv2.conv1.bias primals_22 = self.dconv2.conv2.weight primals_20 = self.dconv2.conv2.bias primals_24 = self.dconv2.conv3.weight primals_21 = self.dconv2.conv3.bias primals_23 = self.dconv2.norm.weight primals_25 = self.dconv2.norm.bias primals_26 = self.dconv3.conv1.weight primals_27 = self.dconv3.conv1.bias primals_30 = self.dconv3.conv2.weight primals_28 = self.dconv3.conv2.bias primals_32 = self.dconv3.conv3.weight primals_29 = self.dconv3.conv3.bias primals_31 = self.dconv3.norm.weight primals_33 = self.dconv3.norm.bias primals_34 = self.dconv4.conv1.weight primals_35 = self.dconv4.conv1.bias primals_38 = self.dconv4.conv2.weight primals_36 = self.dconv4.conv2.bias primals_40 = self.dconv4.conv3.weight primals_37 = self.dconv4.conv3.bias primals_39 = self.dconv4.norm.weight primals_41 = self.dconv4.norm.bias primals_42 = self.uconv1.upconv.conv.weight primals_43 = self.uconv1.upconv.conv.bias primals_44 = self.uconv1.conv1.weight primals_45 = self.uconv1.conv1.bias primals_48 = self.uconv1.conv2.weight primals_46 = self.uconv1.conv2.bias primals_50 = self.uconv1.conv3.weight primals_47 = self.uconv1.conv3.bias primals_49 = self.uconv1.norm.weight primals_51 = self.uconv1.norm.bias primals_52 = self.uconv2.upconv.conv.weight primals_53 = self.uconv2.upconv.conv.bias primals_54 = self.uconv2.conv1.weight primals_55 = self.uconv2.conv1.bias primals_58 = self.uconv2.conv2.weight primals_56 = self.uconv2.conv2.bias primals_60 = self.uconv2.conv3.weight primals_57 = self.uconv2.conv3.bias primals_59 = self.uconv2.norm.weight primals_61 = self.uconv2.norm.bias primals_62 = self.uconv3.upconv.conv.weight primals_63 = self.uconv3.upconv.conv.bias primals_64 = self.uconv3.conv1.weight primals_65 = self.uconv3.conv1.bias primals_68 = self.uconv3.conv2.weight primals_66 = self.uconv3.conv2.bias primals_70 = self.uconv3.conv3.weight primals_67 = self.uconv3.conv3.bias primals_69 = self.uconv3.norm.weight primals_71 = self.uconv3.norm.bias primals_72 = self.uconv4.upconv.conv.weight primals_73 = self.uconv4.upconv.conv.bias primals_74 = self.uconv4.conv1.weight primals_75 = self.uconv4.conv1.bias primals_78 = self.uconv4.conv2.weight primals_76 = self.uconv4.conv2.bias primals_80 = self.uconv4.conv3.weight primals_77 = self.uconv4.conv3.bias primals_79 = self.uconv4.norm.weight primals_81 = self.uconv4.norm.bias primals_82 = self.conv_out.weight primals_83 = self.conv_out.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, 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]) return output[0]
jabae/detectEM
UNet
false
7,052
[ "MIT" ]
1
2d1a5116164d0bed0a8ea767a227d05a8970a448
https://github.com/jabae/detectEM/tree/2d1a5116164d0bed0a8ea767a227d05a8970a448
SoftEntropy
import torch from torch import nn import torch.nn.functional as F from torch.nn import * from torch.optim.lr_scheduler import * class SoftEntropy(nn.Module): def __init__(self): super(SoftEntropy, self).__init__() self.logsoftmax = nn.LogSoftmax(dim=1) def forward(self, inputs, targets): log_probs = self.logsoftmax(inputs) loss = (-F.softmax(targets, dim=1).detach() * log_probs).mean(0).sum() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn from torch.nn import * 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 @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax__softmax_mul_neg_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 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') tmp10 = tl.load(in_ptr1 + x3, xmask) tmp11 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = -tmp8 tmp12 = tl_math.exp(tmp11) tmp14 = tl_math.exp(tmp13) tmp15 = tmp12 + tmp14 tmp17 = tl_math.exp(tmp16) tmp18 = tmp15 + tmp17 tmp20 = tl_math.exp(tmp19) tmp21 = tmp18 + tmp20 tmp22 = tl_math.log(tmp21) tmp23 = tmp10 - tmp22 tmp24 = tmp9 * tmp23 tl.store(out_ptr0 + x3, tmp24, xmask) @triton.jit def triton_per_fused_mean_sum_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr0 + (64 + r0), None) tmp3 = tl.load(in_ptr0 + (128 + r0), None) tmp5 = tl.load(in_ptr0 + (192 + r0), None) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.sum(tmp9, 1)[:, None] tl.store(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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](arg0_1, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__softmax_mul_neg_2[grid(256)](buf0, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf1 buf3 = empty_strided_cuda((), (), torch.float32) triton_per_fused_mean_sum_3[grid(1)](buf2, buf3, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf2 return buf3, class SoftEntropyNew(nn.Module): def __init__(self): super(SoftEntropyNew, self).__init__() self.logsoftmax = nn.LogSoftmax(dim=1) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
knifefield/uda-reid-contest
SoftEntropy
false
7,053
[ "MIT" ]
1
8b642cb4c5e63bb1dbfb07d0ac6dacdc26729e91
https://github.com/knifefield/uda-reid-contest/tree/8b642cb4c5e63bb1dbfb07d0ac6dacdc26729e91
AugCNN
import torch import torch.nn as nn from torch.nn import functional as F def apply_init_(modules): """ Initialize NN modules """ for m in modules: if isinstance(m, nn.Conv2d): nn.init.xavier_uniform_(m.weight) if m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): nn.init.constant_(m.weight, 1) if m.bias is not None: nn.init.constant_(m.bias, 0) class Conv2d_tf(nn.Conv2d): """ Conv2d with the padding behavior from TF """ def __init__(self, *args, **kwargs): super(Conv2d_tf, self).__init__(*args, **kwargs) self.padding = kwargs.get('padding', 'SAME') def _compute_padding(self, input, dim): input_size = input.size(dim + 2) filter_size = self.weight.size(dim + 2) effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1 out_size = (input_size + self.stride[dim] - 1) // self.stride[dim] total_padding = max(0, (out_size - 1) * self.stride[dim] + effective_filter_size - input_size) additional_padding = int(total_padding % 2 != 0) return additional_padding, total_padding def forward(self, input): if self.padding == 'VALID': return F.conv2d(input, self.weight, self.bias, self.stride, padding=0, dilation=self.dilation, groups=self.groups) rows_odd, padding_rows = self._compute_padding(input, dim=0) cols_odd, padding_cols = self._compute_padding(input, dim=1) if rows_odd or cols_odd: input = F.pad(input, [0, cols_odd, 0, rows_odd]) return F.conv2d(input, self.weight, self.bias, self.stride, padding =(padding_rows // 2, padding_cols // 2), dilation=self.dilation, groups=self.groups) class AugCNN(nn.Module): """ Convolutional Neural Network used as Augmentation """ def __init__(self): super(AugCNN, self).__init__() self.aug = Conv2d_tf(3, 3, kernel_size=3) apply_init_(self.modules()) self.train() def forward(self, obs): return self.aug(obs) 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 torch.nn as nn from torch.nn import functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 3 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_2, (3, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_3, (3,), (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, 3, 64, 64), (12288, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(49152)](buf1, primals_3, 49152, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf1, primals_1, primals_2 def apply_init_(modules): """ Initialize NN modules """ for m in modules: if isinstance(m, nn.Conv2d): nn.init.xavier_uniform_(m.weight) if m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): nn.init.constant_(m.weight, 1) if m.bias is not None: nn.init.constant_(m.bias, 0) class Conv2d_tf(nn.Conv2d): """ Conv2d with the padding behavior from TF """ def __init__(self, *args, **kwargs): super(Conv2d_tf, self).__init__(*args, **kwargs) self.padding = kwargs.get('padding', 'SAME') def _compute_padding(self, input, dim): input_size = input.size(dim + 2) filter_size = self.weight.size(dim + 2) effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1 out_size = (input_size + self.stride[dim] - 1) // self.stride[dim] total_padding = max(0, (out_size - 1) * self.stride[dim] + effective_filter_size - input_size) additional_padding = int(total_padding % 2 != 0) return additional_padding, total_padding def forward(self, input): if self.padding == 'VALID': return F.conv2d(input, self.weight, self.bias, self.stride, padding=0, dilation=self.dilation, groups=self.groups) rows_odd, padding_rows = self._compute_padding(input, dim=0) cols_odd, padding_cols = self._compute_padding(input, dim=1) if rows_odd or cols_odd: input = F.pad(input, [0, cols_odd, 0, rows_odd]) return F.conv2d(input, self.weight, self.bias, self.stride, padding =(padding_rows // 2, padding_cols // 2), dilation=self.dilation, groups=self.groups) class AugCNNNew(nn.Module): """ Convolutional Neural Network used as Augmentation """ def __init__(self): super(AugCNNNew, self).__init__() self.aug = Conv2d_tf(3, 3, kernel_size=3) apply_init_(self.modules()) self.train() def forward(self, input_0): primals_2 = self.aug.weight primals_3 = self.aug.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
krg-nandu/prj-taxRL
AugCNN
false
7,054
[ "MIT" ]
1
be65d004c196aff73714dcb346c814ae97db30e2
https://github.com/krg-nandu/prj-taxRL/tree/be65d004c196aff73714dcb346c814ae97db30e2
PSNRLoss
import torch import torch.nn as nn from torch.nn.functional import mse_loss def psnr_loss(input: 'torch.Tensor', target: 'torch.Tensor', max_val: 'float' ) ->torch.Tensor: """Function that computes PSNR See :class:`~kornia.losses.PSNR` for details. """ if not torch.is_tensor(input) or not torch.is_tensor(target): raise TypeError( f'Expected 2 torch tensors but got {type(input)} and {type(target)}' ) if input.shape != target.shape: raise TypeError( f'Expected tensors of equal shapes, but got {input.shape} and {target.shape}' ) mse_val = mse_loss(input, target, reduction='mean') max_val_tensor: 'torch.Tensor' = torch.tensor(max_val) return 10 * torch.log10(max_val_tensor * max_val_tensor / mse_val) class PSNRLoss(nn.Module): """Creates a criterion that calculates the PSNR between 2 images. Given an m x n image, .. math:: \\text{MSE}(I,T) = \\frac{1}{m\\,n}\\sum_{i=0}^{m-1}\\sum_{j=0}^{n-1} [I(i,j) - T(i,j)]^2 Arguments: max_val (float): Maximum value of input Shape: - input: :math:`(*)` - approximation: :math:`(*)` same shape as input - output: :math:`()` a scalar Examples: >>> kornia.losses.psnr(torch.ones(1), 1.2*torch.ones(1), 2) tensor(20.0000) # 10 * log(4/((1.2-1)**2)) / log(10) reference: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Definition """ def __init__(self, max_val: 'float') ->None: super(PSNRLoss, self).__init__() self.max_val = max_val def forward(self, input: 'torch.Tensor', target: 'torch.Tensor' ) ->torch.Tensor: return psnr_loss(input, target, self.max_val) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'max_val': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn.functional import mse_loss 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_div_log10_mse_loss_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tmp9 = 16.0 tmp10 = tmp9 / tmp8 tmp11 = libdevice.log10(tmp10) tmp12 = 10.0 tmp13 = tmp11 * tmp12 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp13, 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_div_log10_mse_loss_mul_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 psnr_loss(input: 'torch.Tensor', target: 'torch.Tensor', max_val: 'float' ) ->torch.Tensor: """Function that computes PSNR See :class:`~kornia.losses.PSNR` for details. """ if not torch.is_tensor(input) or not torch.is_tensor(target): raise TypeError( f'Expected 2 torch tensors but got {type(input)} and {type(target)}' ) if input.shape != target.shape: raise TypeError( f'Expected tensors of equal shapes, but got {input.shape} and {target.shape}' ) mse_val = mse_loss(input, target, reduction='mean') max_val_tensor: 'torch.Tensor' = torch.tensor(max_val) return 10 * torch.log10(max_val_tensor * max_val_tensor / mse_val) class PSNRLossNew(nn.Module): """Creates a criterion that calculates the PSNR between 2 images. Given an m x n image, .. math:: \\text{MSE}(I,T) = \\frac{1}{m\\,n}\\sum_{i=0}^{m-1}\\sum_{j=0}^{n-1} [I(i,j) - T(i,j)]^2 Arguments: max_val (float): Maximum value of input Shape: - input: :math:`(*)` - approximation: :math:`(*)` same shape as input - output: :math:`()` a scalar Examples: >>> kornia.losses.psnr(torch.ones(1), 1.2*torch.ones(1), 2) tensor(20.0000) # 10 * log(4/((1.2-1)**2)) / log(10) reference: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio#Definition """ def __init__(self, max_val: 'float') ->None: super(PSNRLossNew, self).__init__() self.max_val = max_val def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
kshitij12345/kornia
PSNRLoss
false
7,055
[ "Apache-2.0" ]
1
4fcc9a570dfa38f67ec812c8fdfabe434b3e466e
https://github.com/kshitij12345/kornia/tree/4fcc9a570dfa38f67ec812c8fdfabe434b3e466e
SeparatedLoss
import torch import torch.nn as nn class BCEFocalLoss(nn.Module): def __init__(self, alpha=0.25, gamma=2.0): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, preds, targets): bce_loss = nn.BCEWithLogitsLoss(reduction='none')(preds, targets) probas = torch.sigmoid(preds) loss = targets * self.alpha * (1.0 - probas ) ** self.gamma * bce_loss + (1.0 - targets ) * probas ** self.gamma * bce_loss loss = loss.mean() return loss class SeparatedLoss(nn.Module): def __init__(self, loss_disease_risk='BCEWithLogitsLoss', loss_disease= 'BCEFocalLoss', weights=[1.0, 1.0]): super().__init__() if loss_disease_risk == 'BCEWithLogitsLoss': self.loss_disease_risk = nn.BCEWithLogitsLoss() elif loss_disease_risk == 'BCEFocalLoss': self.loss_disease_risk = BCEFocalLoss() else: raise NotImplementedError if loss_disease == 'BCEWithLogitsLoss': self.loss_disease = nn.BCEWithLogitsLoss() elif loss_disease == 'BCEFocalLoss': self.loss_disease = BCEFocalLoss() self.weights = weights def forward(self, preds, targets): risk_pred = preds[:, 0] risk_targ = targets[:, 0] disease_pred = preds[:, 1:] disease_targ = targets[:, 1:] loss_disease_risk = self.loss_disease_risk(risk_pred, risk_targ) loss_disease = self.loss_disease(disease_pred, disease_targ) return self.weights[0] * loss_disease_risk + self.weights[1 ] * loss_disease def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_binary_cross_entropy_with_logits_0(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp3 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp2 * tmp3 tmp5 = 0.0 tmp6 = triton_helpers.minimum(tmp5, tmp3) tmp7 = tl_math.abs(tmp3) tmp8 = -tmp7 tmp9 = tl_math.exp(tmp8) tmp10 = libdevice.log1p(tmp9) tmp11 = tmp6 - tmp10 tmp12 = tmp4 - tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.sum(tmp13, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp15, None) @triton.jit def triton_per_fused_add_binary_cross_entropy_with_logits_mean_mul_pow_rsub_sigmoid_1( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): rnumel = 192 RBLOCK: tl.constexpr = 256 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, :] rmask = rindex < rnumel r0 = rindex % 48 r1 = rindex // 48 tmp0 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), rmask, other=0.0) tmp3 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), rmask, other=0.0) tmp28 = tl.load(in_out_ptr0 + 0) tmp29 = tl.broadcast_to(tmp28, [XBLOCK, 1]) tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = 1.0 tmp6 = tmp5 - tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp2 * tmp7 tmp9 = tmp5 - tmp0 tmp10 = tmp9 * tmp3 tmp11 = 0.0 tmp12 = triton_helpers.minimum(tmp11, tmp3) tmp13 = tl_math.abs(tmp3) tmp14 = -tmp13 tmp15 = tl_math.exp(tmp14) tmp16 = libdevice.log1p(tmp15) tmp17 = tmp12 - tmp16 tmp18 = tmp10 - tmp17 tmp19 = tmp8 * tmp18 tmp20 = tmp4 * tmp4 tmp21 = tmp9 * tmp20 tmp22 = tmp21 * tmp18 tmp23 = tmp19 + tmp22 tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK]) tmp26 = tl.where(rmask, tmp24, 0) tmp27 = tl.sum(tmp26, 1)[:, None] tmp30 = 64.0 tmp31 = tmp29 / tmp30 tmp32 = tmp31 * tmp5 tmp33 = 192.0 tmp34 = tmp27 / tmp33 tmp35 = tmp34 * tmp5 tmp36 = tmp32 + tmp35 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp36, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 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) get_raw_stream(0) triton_per_fused_binary_cross_entropy_with_logits_0[grid(1)](arg1_1, arg0_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) buf2 = buf0 del buf0 triton_per_fused_add_binary_cross_entropy_with_logits_mean_mul_pow_rsub_sigmoid_1[ grid(1)](buf2, arg1_1, arg0_1, 1, 192, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class BCEFocalLoss(nn.Module): def __init__(self, alpha=0.25, gamma=2.0): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, preds, targets): bce_loss = nn.BCEWithLogitsLoss(reduction='none')(preds, targets) probas = torch.sigmoid(preds) loss = targets * self.alpha * (1.0 - probas ) ** self.gamma * bce_loss + (1.0 - targets ) * probas ** self.gamma * bce_loss loss = loss.mean() return loss class SeparatedLossNew(nn.Module): def __init__(self, loss_disease_risk='BCEWithLogitsLoss', loss_disease= 'BCEFocalLoss', weights=[1.0, 1.0]): super().__init__() if loss_disease_risk == 'BCEWithLogitsLoss': self.loss_disease_risk = nn.BCEWithLogitsLoss() elif loss_disease_risk == 'BCEFocalLoss': self.loss_disease_risk = BCEFocalLoss() else: raise NotImplementedError if loss_disease == 'BCEWithLogitsLoss': self.loss_disease = nn.BCEWithLogitsLoss() elif loss_disease == 'BCEFocalLoss': self.loss_disease = BCEFocalLoss() self.weights = weights def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
koukyo1994/riadd-competition
SeparatedLoss
false
7,056
[ "MIT" ]
1
0e399305aef21d40125cadccee55be1f0b310216
https://github.com/koukyo1994/riadd-competition/tree/0e399305aef21d40125cadccee55be1f0b310216
MyNet
import torch import torch.nn as nn from torch.testing._internal.common_utils import * class MyNet(nn.Module): def __init__(self): super().__init__() self.elu = nn.ELU() def forward(self, x): return self.elu(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.testing._internal.common_utils import * 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_elu_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 = 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) 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_elu_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class MyNetNew(nn.Module): def __init__(self): super().__init__() self.elu = nn.ELU() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
LexcaliburR/notebook
MyNet
false
7,057
[ "MIT" ]
1
84a8f3801dff20d07caa0ed2584e722656fb5726
https://github.com/LexcaliburR/notebook/tree/84a8f3801dff20d07caa0ed2584e722656fb5726
TripletLoss
import torch from torch import nn import torch.nn.functional as F from torch.nn import * from torch.optim.lr_scheduler import * def _batch_hard(mat_distance, mat_similarity, indice=False): sorted_mat_distance, positive_indices = torch.sort(mat_distance + - 9999999.0 * (1 - mat_similarity), dim=1, descending=True) hard_p = sorted_mat_distance[:, 0] hard_p_indice = positive_indices[:, 0] sorted_mat_distance, negative_indices = torch.sort(mat_distance + 9999999.0 * mat_similarity, dim=1, descending=False) hard_n = sorted_mat_distance[:, 0] hard_n_indice = negative_indices[:, 0] if indice: return hard_p, hard_n, hard_p_indice, hard_n_indice return hard_p, hard_n def euclidean_dist(x, y): m, n = x.size(0), y.size(0) xx = torch.pow(x, 2).sum(1, keepdim=True).expand(m, n) yy = torch.pow(y, 2).sum(1, keepdim=True).expand(n, m).t() dist = xx + yy dist.addmm_(1, -2, x, y.t()) dist = dist.clamp(min=1e-12).sqrt() return dist class TripletLoss(nn.Module): """ Compute Triplet loss augmented with Batch Hard Details can be seen in 'In defense of the Triplet Loss for Person Re-Identification' """ def __init__(self, margin, normalize_feature=False): super(TripletLoss, self).__init__() self.margin = margin self.normalize_feature = normalize_feature self.margin_loss = nn.MarginRankingLoss(margin=margin) def forward(self, emb, label): if self.normalize_feature: emb = F.normalize(emb) mat_dist = euclidean_dist(emb, emb) assert mat_dist.size(0) == mat_dist.size(1) N = mat_dist.size(0) mat_sim = label.expand(N, N).eq(label.expand(N, N).t()).float() dist_ap, dist_an = _batch_hard(mat_dist, mat_sim) assert dist_an.size(0) == dist_ap.size(0) y = torch.ones_like(dist_ap) loss = self.margin_loss(dist_an, dist_ap, y) prec = (dist_an.data > dist_ap.data).sum() * 1.0 / y.size(0) return loss, prec def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'margin': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch import nn from torch.nn import * 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_per_fused__to_copy_add_clamp_eq_mul_rsub_sort_sqrt_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr ): xnumel = 4 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_out_ptr0 + (r1 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + 4 * r1, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (1 + 4 * r1), None, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * r1), None, eviction_policy='evict_last') tmp20 = tl.load(in_ptr0 + (3 + 4 * r1), None, eviction_policy='evict_last') tmp28 = tl.load(in_ptr1 + (r1 + 4 * x0), xmask, other=0.0) tmp29 = tl.load(in_ptr1 + (x0 + 4 * r1), xmask, other=0.0) tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp13 = tmp12 * tmp12 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp23 = tmp11 + tmp22 tmp24 = tmp0 + tmp23 tmp25 = 1e-12 tmp26 = triton_helpers.maximum(tmp24, tmp25) tmp27 = libdevice.sqrt(tmp26) tmp30 = tmp28 == tmp29 tmp31 = tmp30.to(tl.float32) tmp32 = 1.0 tmp33 = tmp32 - tmp31 tmp34 = -9999999.0 tmp35 = tmp33 * tmp34 tmp36 = tmp27 + tmp35 tmp37 = r1 tmp38 = tmp37.to(tl.int16) tmp39 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK]) tmp40 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41, _tmp42 = triton_helpers.sort_with_index(tmp39, tmp40, None, 1, stable=False, descending=True) tmp43 = 9999999.0 tmp44 = tmp31 * tmp43 tmp45 = tmp27 + tmp44 tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK]) tmp47, _tmp48 = triton_helpers.sort_with_index(tmp46, tmp40, None, 1, stable=False, descending=False) tl.store(in_out_ptr0 + (r1 + 4 * x0), tmp24, xmask) tl.store(out_ptr0 + (r1 + 4 * x0), tmp41, xmask) tl.store(out_ptr1 + (r1 + 4 * x0), tmp47, xmask) @triton.jit def triton_per_fused_add_clamp_min_div_gt_mean_mul_neg_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, 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 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = -1.0 tmp4 = tmp3 * tmp2 tmp5 = 4.0 tmp6 = tmp4 + tmp5 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.sum(tmp9, 1)[:, None] tmp12 = tmp0 > tmp1 tmp13 = tmp12.to(tl.int64) tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.sum(tmp14, 1)[:, None] tmp17 = tmp16.to(tl.float32) tmp18 = 1.0 tmp19 = tmp17 * tmp18 tmp20 = 0.25 tmp21 = tmp19 * tmp20 tmp22 = tmp11 / tmp5 tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp21, None) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp22, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(arg0_1, reinterpret_tensor(arg0_1, (4, 4), (1, 4), 0), out=buf0) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused__to_copy_add_clamp_eq_mul_rsub_sort_sqrt_0[grid(4)]( buf1, arg0_1, arg1_1, buf2, buf4, 4, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del buf1 buf6 = empty_strided_cuda((), (), torch.float32) buf9 = empty_strided_cuda((), (), torch.float32) buf8 = buf6 del buf6 triton_per_fused_add_clamp_min_div_gt_mean_mul_neg_sub_sum_1[grid(1)]( buf8, buf4, buf2, buf9, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf2 del buf4 return buf8, buf9 def _batch_hard(mat_distance, mat_similarity, indice=False): sorted_mat_distance, positive_indices = torch.sort(mat_distance + - 9999999.0 * (1 - mat_similarity), dim=1, descending=True) hard_p = sorted_mat_distance[:, 0] hard_p_indice = positive_indices[:, 0] sorted_mat_distance, negative_indices = torch.sort(mat_distance + 9999999.0 * mat_similarity, dim=1, descending=False) hard_n = sorted_mat_distance[:, 0] hard_n_indice = negative_indices[:, 0] if indice: return hard_p, hard_n, hard_p_indice, hard_n_indice return hard_p, hard_n def euclidean_dist(x, y): m, n = x.size(0), y.size(0) xx = torch.pow(x, 2).sum(1, keepdim=True).expand(m, n) yy = torch.pow(y, 2).sum(1, keepdim=True).expand(n, m).t() dist = xx + yy dist.addmm_(1, -2, x, y.t()) dist = dist.clamp(min=1e-12).sqrt() return dist class TripletLossNew(nn.Module): """ Compute Triplet loss augmented with Batch Hard Details can be seen in 'In defense of the Triplet Loss for Person Re-Identification' """ def __init__(self, margin, normalize_feature=False): super(TripletLossNew, self).__init__() self.margin = margin self.normalize_feature = normalize_feature self.margin_loss = nn.MarginRankingLoss(margin=margin) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0], output[1]
knifefield/uda-reid-contest
TripletLoss
false
7,058
[ "MIT" ]
1
8b642cb4c5e63bb1dbfb07d0ac6dacdc26729e91
https://github.com/knifefield/uda-reid-contest/tree/8b642cb4c5e63bb1dbfb07d0ac6dacdc26729e91
BinaryFocalLoss
import torch class BinaryFocalLoss(torch.nn.Module): """ from https://github.com/qubvel/segmentation_models""" def __init__(self, gamma=2.0, alpha=0.25, eps=1e-07): super().__init__() self.gamma = gamma self.alpha = alpha self.eps = eps def forward(self, pr, gt): pr = torch.clamp(pr, self.eps, 1 - self.eps) loss_1 = -gt * (self.alpha * torch.pow(1 - pr, self.gamma) ) * torch.log(pr) loss_0 = -(1 - gt) * ((1 - self.alpha) * torch.pow(pr, self.gamma) ) * torch.log(1 - pr) loss = loss_0 + loss_1 return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_clamp_log_mul_neg_pow_rsub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp4 = tl.load(in_ptr1 + x0, xmask) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp3 = -tmp2 tmp5 = 1e-07 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = 0.9999999 tmp8 = triton_helpers.minimum(tmp6, tmp7) tmp9 = tmp8 * tmp8 tmp10 = 0.75 tmp11 = tmp9 * tmp10 tmp12 = tmp3 * tmp11 tmp13 = tmp1 - tmp8 tmp14 = tl_math.log(tmp13) tmp15 = tmp12 * tmp14 tmp16 = -tmp0 tmp17 = tmp13 * tmp13 tmp18 = 0.25 tmp19 = tmp17 * tmp18 tmp20 = tmp16 * tmp19 tmp21 = tl_math.log(tmp8) tmp22 = tmp20 * tmp21 tmp23 = tmp15 + tmp22 tl.store(out_ptr0 + x0, tmp23, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_clamp_log_mul_neg_pow_rsub_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class BinaryFocalLossNew(torch.nn.Module): """ from https://github.com/qubvel/segmentation_models""" def __init__(self, gamma=2.0, alpha=0.25, eps=1e-07): super().__init__() self.gamma = gamma self.alpha = alpha 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]
kungfuai/d3m-segmentation-research
BinaryFocalLoss
false
7,059
[ "MIT" ]
1
5bc44ddd0e8522fb2b369866ad47aa62a24a8f63
https://github.com/kungfuai/d3m-segmentation-research/tree/5bc44ddd0e8522fb2b369866ad47aa62a24a8f63
PredictiveEntropy
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class PredictiveEntropy(nn.Module): def __init__(self): super(PredictiveEntropy, self).__init__() def forward(self, x): b = F.softmax(x, dim=1) * F.log_softmax(x, dim=1) b = -1.0 * b.sum(dim=1) return b 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 math as tl_math import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax__softmax_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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) tl.store(out_ptr1 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax__softmax_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 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') tmp9 = tl.load(in_ptr1 + x3, xmask) tmp10 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp11 = tl_math.exp(tmp10) tmp13 = tl_math.exp(tmp12) tmp14 = tmp11 + tmp13 tmp16 = tl_math.exp(tmp15) tmp17 = tmp14 + tmp16 tmp19 = tl_math.exp(tmp18) tmp20 = tmp17 + tmp19 tmp21 = tl_math.log(tmp20) tmp22 = tmp9 - tmp21 tmp23 = tmp8 * tmp22 tl.store(out_ptr0 + x3, tmp23, xmask) @triton.jit def triton_poi_fused_mul_sum_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = -1.0 tmp8 = tmp6 * tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax__softmax_0[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__softmax_mul_1[grid(256)](buf0, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf1 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_mul_sum_2[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf2 return buf3, class PredictiveEntropyNew(nn.Module): def __init__(self): super(PredictiveEntropyNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kowshikthopalli/MULDENS
PredictiveEntropy
false
7,060
[ "MIT" ]
1
e2d5f8ec51024c5bdda6d1fcde4a96a3f31e6930
https://github.com/kowshikthopalli/MULDENS/tree/e2d5f8ec51024c5bdda6d1fcde4a96a3f31e6930
CalibrationModel
import torch class CalibrationModel(torch.nn.Module): """ Adds temperature scaling parameters to trained model""" def __init__(self): super().__init__() self.temperature = torch.nn.Parameter(torch.ones(1) * 1.5) def forward(self, logits, device=torch.device('cpu')): return logits / self.temperature 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 / tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf0, primals_1, primals_2 class CalibrationModelNew(torch.nn.Module): """ Adds temperature scaling parameters to trained model""" def __init__(self): super().__init__() self.temperature = torch.nn.Parameter(torch.ones(1) * 1.5) def forward(self, input_0): primals_1 = self.temperature primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
kungfuai/d3m-segmentation-research
CalibrationModel
false
7,061
[ "MIT" ]
1
5bc44ddd0e8522fb2b369866ad47aa62a24a8f63
https://github.com/kungfuai/d3m-segmentation-research/tree/5bc44ddd0e8522fb2b369866ad47aa62a24a8f63
BasicBlock
import torch import torch.nn as nn from torch.nn import functional as F def apply_init_(modules): """ Initialize NN modules """ for m in modules: if isinstance(m, nn.Conv2d): nn.init.xavier_uniform_(m.weight) if m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): nn.init.constant_(m.weight, 1) if m.bias is not None: nn.init.constant_(m.bias, 0) class Conv2d_tf(nn.Conv2d): """ Conv2d with the padding behavior from TF """ def __init__(self, *args, **kwargs): super(Conv2d_tf, self).__init__(*args, **kwargs) self.padding = kwargs.get('padding', 'SAME') def _compute_padding(self, input, dim): input_size = input.size(dim + 2) filter_size = self.weight.size(dim + 2) effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1 out_size = (input_size + self.stride[dim] - 1) // self.stride[dim] total_padding = max(0, (out_size - 1) * self.stride[dim] + effective_filter_size - input_size) additional_padding = int(total_padding % 2 != 0) return additional_padding, total_padding def forward(self, input): if self.padding == 'VALID': return F.conv2d(input, self.weight, self.bias, self.stride, padding=0, dilation=self.dilation, groups=self.groups) rows_odd, padding_rows = self._compute_padding(input, dim=0) cols_odd, padding_cols = self._compute_padding(input, dim=1) if rows_odd or cols_odd: input = F.pad(input, [0, cols_odd, 0, rows_odd]) return F.conv2d(input, self.weight, self.bias, self.stride, padding =(padding_rows // 2, padding_cols // 2), dilation=self.dilation, groups=self.groups) class BasicBlock(nn.Module): """ Residual Network Block """ def __init__(self, n_channels, stride=1): super(BasicBlock, self).__init__() self.conv1 = Conv2d_tf(n_channels, n_channels, kernel_size=3, stride=1, padding=(1, 1)) self.relu = nn.ReLU(inplace=True) self.conv2 = Conv2d_tf(n_channels, n_channels, kernel_size=3, stride=1, padding=(1, 1)) self.stride = stride apply_init_(self.modules()) self.train() def forward(self, x): identity = x out = self.relu(x) out = self.conv1(out) out = self.relu(out) out = self.conv2(out) out += identity return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_poi_fused_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_add_convolution_2[grid(256)](buf4, primals_5, buf0, primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf4, primals_2, primals_4, buf0, buf2 def apply_init_(modules): """ Initialize NN modules """ for m in modules: if isinstance(m, nn.Conv2d): nn.init.xavier_uniform_(m.weight) if m.bias is not None: nn.init.constant_(m.bias, 0) elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)): nn.init.constant_(m.weight, 1) if m.bias is not None: nn.init.constant_(m.bias, 0) class Conv2d_tf(nn.Conv2d): """ Conv2d with the padding behavior from TF """ def __init__(self, *args, **kwargs): super(Conv2d_tf, self).__init__(*args, **kwargs) self.padding = kwargs.get('padding', 'SAME') def _compute_padding(self, input, dim): input_size = input.size(dim + 2) filter_size = self.weight.size(dim + 2) effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1 out_size = (input_size + self.stride[dim] - 1) // self.stride[dim] total_padding = max(0, (out_size - 1) * self.stride[dim] + effective_filter_size - input_size) additional_padding = int(total_padding % 2 != 0) return additional_padding, total_padding def forward(self, input): if self.padding == 'VALID': return F.conv2d(input, self.weight, self.bias, self.stride, padding=0, dilation=self.dilation, groups=self.groups) rows_odd, padding_rows = self._compute_padding(input, dim=0) cols_odd, padding_cols = self._compute_padding(input, dim=1) if rows_odd or cols_odd: input = F.pad(input, [0, cols_odd, 0, rows_odd]) return F.conv2d(input, self.weight, self.bias, self.stride, padding =(padding_rows // 2, padding_cols // 2), dilation=self.dilation, groups=self.groups) class BasicBlockNew(nn.Module): """ Residual Network Block """ def __init__(self, n_channels, stride=1): super(BasicBlockNew, self).__init__() self.conv1 = Conv2d_tf(n_channels, n_channels, kernel_size=3, stride=1, padding=(1, 1)) self.relu = nn.ReLU(inplace=True) self.conv2 = Conv2d_tf(n_channels, n_channels, kernel_size=3, stride=1, padding=(1, 1)) self.stride = stride apply_init_(self.modules()) self.train() def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
krg-nandu/prj-taxRL
BasicBlock
false
7,062
[ "MIT" ]
1
be65d004c196aff73714dcb346c814ae97db30e2
https://github.com/krg-nandu/prj-taxRL/tree/be65d004c196aff73714dcb346c814ae97db30e2
Linear_2L_KFRA
import torch import torch.nn as nn import torch.utils.data def sample_K_laplace_MN(MAP, upper_Qinv, lower_HHinv): Z = MAP.data.new(MAP.size()).normal_(mean=0, std=1) all_mtx_sample = MAP + torch.matmul(torch.matmul(lower_HHinv, Z), upper_Qinv) weight_mtx_sample = all_mtx_sample[:, :-1] bias_mtx_sample = all_mtx_sample[:, -1] return weight_mtx_sample, bias_mtx_sample class Linear_2L_KFRA(nn.Module): def __init__(self, input_dim, output_dim, n_hid): super(Linear_2L_KFRA, self).__init__() self.n_hid = n_hid self.input_dim = input_dim self.output_dim = output_dim self.fc1 = nn.Linear(input_dim, self.n_hid) self.fc2 = nn.Linear(self.n_hid, self.n_hid) self.fc3 = nn.Linear(self.n_hid, output_dim) self.act = nn.ReLU(inplace=True) self.one = None self.a2 = None self.h2 = None self.a1 = None self.h1 = None self.a0 = None def forward(self, x): self.one = x.new(x.shape[0], 1).fill_(1) a0 = x.view(-1, self.input_dim) self.a0 = torch.cat((a0.data, self.one), dim=1) h1 = self.fc1(a0) self.h1 = h1.data a1 = self.act(h1) self.a1 = torch.cat((a1.data, self.one), dim=1) h2 = self.fc2(a1) self.h2 = h2.data a2 = self.act(h2) self.a2 = torch.cat((a2.data, self.one), dim=1) h3 = self.fc3(a2) return h3 def sample_predict(self, x, Nsamples, Qinv1, HHinv1, MAP1, Qinv2, HHinv2, MAP2, Qinv3, HHinv3, MAP3): predictions = x.data.new(Nsamples, x.shape[0], self.output_dim) x = x.view(-1, self.input_dim) for i in range(Nsamples): w1, b1 = sample_K_laplace_MN(MAP1, Qinv1, HHinv1) a = torch.matmul(x, torch.t(w1)) + b1.unsqueeze(0) a = self.act(a) w2, b2 = sample_K_laplace_MN(MAP2, Qinv2, HHinv2) a = torch.matmul(a, torch.t(w2)) + b2.unsqueeze(0) a = self.act(a) w3, b3 = sample_K_laplace_MN(MAP3, Qinv3, HHinv3) y = torch.matmul(a, torch.t(w3)) + b3.unsqueeze(0) predictions[i] = y return predictions def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4, 'n_hid': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_fill_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = 1.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 20 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 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], 5, tl.int64) tmp9 = 1.0 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp6, tmp9, tmp10) tmp12 = tl.where(tmp4, tmp5, tmp11) tl.store(out_ptr0 + x2, tmp12, xmask) @triton.jit def triton_poi_fused_relu_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.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_fill_0[grid(4)](buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 5), (5, 1), torch.float32) triton_poi_fused_cat_1[grid(20)](primals_1, buf1, 20, XBLOCK=32, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf2) del primals_2 buf3 = buf2 del buf2 triton_poi_fused_relu_2[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((4, 5), (5, 1), torch.float32) triton_poi_fused_cat_1[grid(20)](buf3, buf4, 20, XBLOCK=32, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf5) buf6 = buf5 del buf5 triton_poi_fused_relu_2[grid(16)](buf6, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf7 = empty_strided_cuda((4, 5), (5, 1), torch.float32) triton_poi_fused_cat_1[grid(20)](buf6, buf7, 20, XBLOCK=32, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf6, reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf8) del primals_7 return (buf8, buf7, buf6, buf4, buf3, buf1, buf0, primals_1, buf3, buf6, primals_6, primals_4) def sample_K_laplace_MN(MAP, upper_Qinv, lower_HHinv): Z = MAP.data.new(MAP.size()).normal_(mean=0, std=1) all_mtx_sample = MAP + torch.matmul(torch.matmul(lower_HHinv, Z), upper_Qinv) weight_mtx_sample = all_mtx_sample[:, :-1] bias_mtx_sample = all_mtx_sample[:, -1] return weight_mtx_sample, bias_mtx_sample class Linear_2L_KFRANew(nn.Module): def __init__(self, input_dim, output_dim, n_hid): super(Linear_2L_KFRANew, self).__init__() self.n_hid = n_hid self.input_dim = input_dim self.output_dim = output_dim self.fc1 = nn.Linear(input_dim, self.n_hid) self.fc2 = nn.Linear(self.n_hid, self.n_hid) self.fc3 = nn.Linear(self.n_hid, output_dim) self.act = nn.ReLU(inplace=True) self.one = None self.a2 = None self.h2 = None self.a1 = None self.h1 = None self.a0 = None def sample_predict(self, x, Nsamples, Qinv1, HHinv1, MAP1, Qinv2, HHinv2, MAP2, Qinv3, HHinv3, MAP3): predictions = x.data.new(Nsamples, x.shape[0], self.output_dim) x = x.view(-1, self.input_dim) for i in range(Nsamples): w1, b1 = sample_K_laplace_MN(MAP1, Qinv1, HHinv1) a = torch.matmul(x, torch.t(w1)) + b1.unsqueeze(0) a = self.act(a) w2, b2 = sample_K_laplace_MN(MAP2, Qinv2, HHinv2) a = torch.matmul(a, torch.t(w2)) + b2.unsqueeze(0) a = self.act(a) w3, b3 = sample_K_laplace_MN(MAP3, Qinv3, HHinv3) y = torch.matmul(a, torch.t(w3)) + b3.unsqueeze(0) predictions[i] = y return predictions def forward(self, input_0): primals_1 = self.fc1.weight primals_3 = self.fc1.bias primals_2 = self.fc2.weight primals_5 = self.fc2.bias primals_4 = self.fc3.weight primals_7 = self.fc3.bias primals_6 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
kw-lee/Bayesian-Neural-Networks
Linear_2L_KFRA
false
7,063
[ "MIT" ]
1
3327fcf85e47c15d86c872211427bff133880c34
https://github.com/kw-lee/Bayesian-Neural-Networks/tree/3327fcf85e47c15d86c872211427bff133880c34
GaussianSubnetBlock
import torch from torch import nn class GaussianSubnetBlock(nn.Module): def __init__(self, in_channels, out_channels, kernel, tanh=False): super().__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel, padding=1 if kernel > 1 else 0) self.activation = nn.Tanh() if tanh else nn.ReLU() if tanh: nn.init.xavier_normal_(self.conv.weight, gain=nn.init. calculate_gain('tanh')) else: nn.init.kaiming_normal_(self.conv.weight, nonlinearity='relu') nn.init.constant_(self.conv.bias, 0) def forward(self, x): x = self.conv(x) return self.activation(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 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 import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 144 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 9 % 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,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 3, 3), (36, 9, 3, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(144)](buf1, primals_2, buf2, 144, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3, buf2 class GaussianSubnetBlockNew(nn.Module): def __init__(self, in_channels, out_channels, kernel, tanh=False): super().__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel, padding=1 if kernel > 1 else 0) self.activation = nn.Tanh() if tanh else nn.ReLU() if tanh: nn.init.xavier_normal_(self.conv.weight, gain=nn.init. calculate_gain('tanh')) else: nn.init.kaiming_normal_(self.conv.weight, nonlinearity='relu') nn.init.constant_(self.conv.bias, 0) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
laitalaj/cvpce
GaussianSubnetBlock
false
7,064
[ "MIT" ]
1
7509e7d7783039f39a88edc6e411333bcf6fb2af
https://github.com/laitalaj/cvpce/tree/7509e7d7783039f39a88edc6e411333bcf6fb2af
Detector
import torch from torch import nn import torch.nn.functional as F class Detector(nn.Module): def __init__(self): super(Detector, self).__init__() self.conv1 = nn.Conv2d(50, 50, 3, 1, 1) self.conv2 = nn.Conv2d(50, 50, 3, 1, 1) self.fc1 = nn.Linear(2 * 2 * 50, 50) self.fc2 = nn.Linear(50, 2) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.max_pool2d(x, 2, 2) x = x.view(-1, 2 * 2 * 50) x = F.relu(self.fc1(x)) x = F.softmax(self.fc2(x), dim=1) return x def get_inputs(): return [torch.rand([4, 50, 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 from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 50 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None, 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, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 50 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__softmax_3(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 x1 = xindex // 2 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + 2 * x1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 2 * x1), None, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp4 = tmp0 - tmp3 tmp5 = tl_math.exp(tmp4) tmp6 = tmp1 - tmp3 tmp7 = tl_math.exp(tmp6) tmp8 = tmp2 - tmp3 tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp11 = tmp5 / tmp10 tl.store(out_ptr0 + x2, tmp11, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (50, 50, 3, 3), (450, 9, 3, 1)) assert_size_stride(primals_2, (50,), (1,)) assert_size_stride(primals_3, (4, 50, 64, 64), (204800, 4096, 64, 1)) assert_size_stride(primals_4, (50, 50, 3, 3), (450, 9, 3, 1)) assert_size_stride(primals_5, (50,), (1,)) assert_size_stride(primals_6, (50, 200), (200, 1)) assert_size_stride(primals_7, (50,), (1,)) assert_size_stride(primals_8, (2, 50), (50, 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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 50, 64, 64), (204800, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(819200)](buf1, primals_2, 819200, XBLOCK=512, num_warps=8, 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, 50, 64, 64), (204800, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(819200)](buf3, primals_5, 819200, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 50, 32, 32), (51200, 1024, 32, 1), torch.int8) buf5 = empty_strided_cuda((4, 50, 32, 32), (51200, 1024, 32, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_1[grid(204800)](buf3, buf4, buf5, 204800, XBLOCK=512, num_warps=8, num_stages=1) buf6 = empty_strided_cuda((1024, 50), (50, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (1024, 200), (200, 1), 0 ), reinterpret_tensor(primals_6, (200, 50), (1, 200), 0), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_relu_2[grid(51200)](buf7, primals_7, 51200, XBLOCK =512, num_warps=4, num_stages=1) del primals_7 buf8 = empty_strided_cuda((1024, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_9, buf7, reinterpret_tensor(primals_8, (50, 2), (1, 50), 0), alpha=1, beta=1, out=buf8) del primals_9 buf9 = empty_strided_cuda((1024, 2), (2, 1), torch.float32) triton_poi_fused__softmax_3[grid(2048)](buf8, buf9, 2048, XBLOCK= 256, num_warps=4, num_stages=1) del buf8 return (buf9, primals_1, primals_3, primals_4, buf1, buf3, buf4, reinterpret_tensor(buf5, (1024, 200), (200, 1), 0), buf7, buf9, primals_8, primals_6) class DetectorNew(nn.Module): def __init__(self): super(DetectorNew, self).__init__() self.conv1 = nn.Conv2d(50, 50, 3, 1, 1) self.conv2 = nn.Conv2d(50, 50, 3, 1, 1) self.fc1 = nn.Linear(2 * 2 * 50, 50) self.fc2 = nn.Linear(50, 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.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
ksivaman/observer-networks
Detector
false
7,065
[ "MIT" ]
1
a0cd540c762751c5500f714dc3979d3a62b9ea77
https://github.com/ksivaman/observer-networks/tree/a0cd540c762751c5500f714dc3979d3a62b9ea77
BahdanauAttention
import math import torch import torch.nn.functional as F import torch.nn as nn import torch.utils.data from typing import * from torch.nn import Parameter import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler class BaseAttention(nn.Module): """Base class for attention layers.""" def __init__(self, query_dim, value_dim, embed_dim=None): super().__init__() self.query_dim = query_dim self.value_dim = value_dim self.embed_dim = embed_dim self.onnx_trace = False def prepare_for_onnx_export_(self): self.onnx_trace = True def reset_parameters(self): pass def forward(self, query, value, key_padding_mask=None, state=None): raise NotImplementedError class BahdanauAttention(BaseAttention): """ Bahdanau Attention.""" def __init__(self, query_dim, value_dim, embed_dim, normalize=True): super().__init__(query_dim, value_dim, embed_dim) self.query_proj = nn.Linear(self.query_dim, embed_dim, bias=False) self.value_proj = nn.Linear(self.value_dim, embed_dim, bias=False) self.v = Parameter(torch.Tensor(embed_dim)) self.normalize = normalize if self.normalize: self.b = Parameter(torch.Tensor(embed_dim)) self.g = Parameter(torch.Tensor(1)) self.reset_parameters() def reset_parameters(self): self.query_proj.weight.data.uniform_(-0.1, 0.1) self.value_proj.weight.data.uniform_(-0.1, 0.1) nn.init.uniform_(self.v, -0.1, 0.1) if self.normalize: nn.init.constant_(self.b, 0.0) nn.init.constant_(self.g, math.sqrt(1.0 / self.embed_dim)) def forward(self, query, value, key_padding_mask=None, state=None): projected_query = self.query_proj(query).unsqueeze(0) key = self.value_proj(value) if self.normalize: normed_v = self.g * self.v / torch.norm(self.v) attn_scores = (normed_v * torch.tanh(projected_query + key + self.b)).sum(dim=2) else: attn_scores = self.v * torch.tanh(projected_query + key).sum(dim=2) if key_padding_mask is not None: attn_scores = attn_scores.float().masked_fill_(key_padding_mask, float('-inf')).type_as(attn_scores) attn_scores = F.softmax(attn_scores, dim=0) context = (attn_scores.unsqueeze(2) * value).sum(dim=0) next_state = attn_scores return context, attn_scores, next_state def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'query_dim': 4, 'value_dim': 4, '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.triton_helpers import libdevice, math as tl_math import math import torch.nn as nn import torch.utils.data from typing import * from torch.nn import Parameter import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler 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_linalg_vector_norm_0(in_ptr0, 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 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp4, None) @triton.jit def triton_poi_fused_add_tanh_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = libdevice.tanh(tmp4) tl.store(in_out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused__softmax_div_linalg_vector_norm_mul_sum_2(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 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex % 16 x3 = xindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp8 = tl.load(in_ptr3 + (x4 + 64 * x2), xmask) tmp10 = tl.load(in_ptr3 + (16 + x4 + 64 * x2), xmask) tmp13 = tl.load(in_ptr3 + (32 + x4 + 64 * x2), xmask) tmp16 = tl.load(in_ptr3 + (48 + x4 + 64 * x2), xmask) tmp3 = tmp1 * tmp2 tmp6 = libdevice.sqrt(tmp5) tmp7 = tmp3 / tmp6 tmp9 = tmp7 * tmp8 tmp11 = tmp7 * tmp10 tmp12 = tmp9 + tmp11 tmp14 = tmp7 * tmp13 tmp15 = tmp12 + tmp14 tmp17 = tmp7 * tmp16 tmp18 = tmp15 + tmp17 tmp19 = tmp18 - tmp18 tmp20 = tl_math.exp(tmp19) tmp21 = tmp20 / tmp20 tl.store(in_out_ptr0 + x3, tmp21, xmask) @triton.jit def triton_poi_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 * tmp1 tl.store(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), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_linalg_vector_norm_0[grid(1)](primals_6, buf2, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf3 = reinterpret_tensor(buf0, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ) del buf0 triton_poi_fused_add_tanh_1[grid(256)](buf3, buf1, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf4 = empty_strided_cuda((1, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf5 = buf4 del buf4 triton_poi_fused__softmax_div_linalg_vector_norm_mul_sum_2[grid(64)]( buf5, primals_5, primals_6, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf2 buf6 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_mul_sum_3[grid(256)](buf5, primals_4, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf6, buf5, primals_4, primals_5, primals_6, reinterpret_tensor( primals_2, (64, 4), (4, 1), 0), buf3, buf5 class BaseAttention(nn.Module): """Base class for attention layers.""" def __init__(self, query_dim, value_dim, embed_dim=None): super().__init__() self.query_dim = query_dim self.value_dim = value_dim self.embed_dim = embed_dim self.onnx_trace = False def prepare_for_onnx_export_(self): self.onnx_trace = True def reset_parameters(self): pass def forward(self, query, value, key_padding_mask=None, state=None): raise NotImplementedError class BahdanauAttentionNew(BaseAttention): """ Bahdanau Attention.""" def __init__(self, query_dim, value_dim, embed_dim, normalize=True): super().__init__(query_dim, value_dim, embed_dim) self.query_proj = nn.Linear(self.query_dim, embed_dim, bias=False) self.value_proj = nn.Linear(self.value_dim, embed_dim, bias=False) self.v = Parameter(torch.Tensor(embed_dim)) self.normalize = normalize if self.normalize: self.b = Parameter(torch.Tensor(embed_dim)) self.g = Parameter(torch.Tensor(1)) self.reset_parameters() def reset_parameters(self): self.query_proj.weight.data.uniform_(-0.1, 0.1) self.value_proj.weight.data.uniform_(-0.1, 0.1) nn.init.uniform_(self.v, -0.1, 0.1) if self.normalize: nn.init.constant_(self.b, 0.0) nn.init.constant_(self.g, math.sqrt(1.0 / self.embed_dim)) def forward(self, input_0, input_1): primals_6 = self.v primals_7 = self.b primals_5 = self.g primals_1 = self.query_proj.weight primals_3 = self.value_proj.weight primals_2 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0], output[1], output[2]
lahiruts/espresso
BahdanauAttention
false
7,066
[ "MIT" ]
1
940a1bf3c2c3d4a057d543b875c329b0515e6b55
https://github.com/lahiruts/espresso/tree/940a1bf3c2c3d4a057d543b875c329b0515e6b55
EncoderNO2
import torch import torch.nn as nn class EncoderNO2(nn.Module): def __init__(self, D, H, M): super().__init__() self.D = D self.M = M self.H = H self.enc1 = nn.Linear(in_features=self.D, out_features=self.H) self.enc2 = nn.Linear(in_features=self.H, out_features=self.M * 2) self.loc_param = nn.Linear(in_features=self.M, out_features=self.M) self.scale_param = nn.Linear(in_features=self.M, out_features=self.M) def forward(self, x): x = self.enc1(x) x = nn.functional.relu(x) x = self.enc2(x) x = x.view(-1, 2, self.M) mu = self.loc_param(x[:, 0, :]) log_var = self.scale_param(x[:, 1, :]) std = torch.exp(log_var / 2) return mu, std def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'D': 4, 'H': 4, 'M': 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_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_div_exp_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 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tl_math.exp(tmp4) tl.store(in_out_ptr0 + x2, tmp5, 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (8, 4), (4, 1)) assert_size_stride(primals_5, (8,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (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((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_2, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 8), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf2, (64, 4), ( 8, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_7 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (8, 1), 4), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_div_exp_1[grid(256)](buf5, primals_9, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_9 return buf3, buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor( buf2, (64, 4), (8, 1), 0), reinterpret_tensor(buf2, (64, 4), (8, 1), 4 ), buf5, primals_8, primals_6, primals_4, buf6 class EncoderNO2New(nn.Module): def __init__(self, D, H, M): super().__init__() self.D = D self.M = M self.H = H self.enc1 = nn.Linear(in_features=self.D, out_features=self.H) self.enc2 = nn.Linear(in_features=self.H, out_features=self.M * 2) self.loc_param = nn.Linear(in_features=self.M, out_features=self.M) self.scale_param = nn.Linear(in_features=self.M, out_features=self.M) def forward(self, input_0): primals_1 = self.enc1.weight primals_2 = self.enc1.bias primals_4 = self.enc2.weight primals_5 = self.enc2.bias primals_6 = self.loc_param.weight primals_7 = self.loc_param.bias primals_8 = self.scale_param.weight primals_9 = self.scale_param.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0], output[1]
le0x99/deep-generative-modeling
EncoderNO2
false
7,067
[ "MIT" ]
1
40ffd1640dc3e5a6a2b4ba16a1d767034f081475
https://github.com/le0x99/deep-generative-modeling/tree/40ffd1640dc3e5a6a2b4ba16a1d767034f081475
Decoder2
import torch import torch.nn as nn class Decoder2(nn.Module): def __init__(self, M, H, D): super().__init__() self.D = D self.M = M self.H = H self.dec1 = nn.Linear(in_features=self.M, out_features=self.H * 2) self.dec2 = nn.Linear(in_features=self.H * 2, out_features=self.H) self.dec3 = nn.Linear(in_features=self.H, out_features=self.D) self.log_scale = nn.Parameter(torch.Tensor([0.0])) def forward(self, Z): Z = self.dec1(Z) Z = nn.functional.relu(Z) Z = self.dec2(Z) Z = nn.functional.relu(Z) mu = self.dec3(Z) mu = nn.functional.tanh(mu) std = torch.exp(self.log_scale) return mu, std def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'M': 4, 'H': 4, 'D': 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_relu_threshold_backward_0(in_out_ptr0, 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 x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_exp_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl_math.exp(tmp1) tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp2, None) 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, (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,)) assert_size_stride(primals_8, (1,), (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 = reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(512)](buf1, primals_2, buf8, 512, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf3, primals_5, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused_tanh_2[grid(256)](buf5, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((1,), (1,), torch.float32) triton_poi_fused_exp_3[grid(1)](primals_8, buf6, 1, XBLOCK=1, num_warps=1, num_stages=1) del primals_8 return buf5, buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 8), (8, 1), 0), reinterpret_tensor( buf3, (64, 4), (4, 1), 0), buf5, buf6, primals_6, buf7, primals_4, buf8 class Decoder2New(nn.Module): def __init__(self, M, H, D): super().__init__() self.D = D self.M = M self.H = H self.dec1 = nn.Linear(in_features=self.M, out_features=self.H * 2) self.dec2 = nn.Linear(in_features=self.H * 2, out_features=self.H) self.dec3 = nn.Linear(in_features=self.H, out_features=self.D) self.log_scale = nn.Parameter(torch.Tensor([0.0])) def forward(self, input_0): primals_8 = self.log_scale primals_1 = self.dec1.weight primals_2 = self.dec1.bias primals_4 = self.dec2.weight primals_5 = self.dec2.bias primals_6 = self.dec3.weight primals_7 = self.dec3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0], output[1]
le0x99/deep-generative-modeling
Decoder2
false
7,068
[ "MIT" ]
1
40ffd1640dc3e5a6a2b4ba16a1d767034f081475
https://github.com/le0x99/deep-generative-modeling/tree/40ffd1640dc3e5a6a2b4ba16a1d767034f081475
InnerProductDecoder
import torch import torch.nn as nn import torch.nn.functional as F class InnerProductDecoder(nn.Module): def __init__(self, activation=torch.sigmoid, dropout=0.1): super().__init__() self.dropout = dropout self.activation = activation def forward(self, z): z = F.dropout(z, self.dropout) adj = self.activation(torch.matmul(z, z.t())) return adj def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sigmoid_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.native_dropout.default(arg0_1, 0.1, True) del arg0_1 buf1 = buf0[0] del buf0 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf3) del buf1 buf4 = buf3 del buf3 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(16)](buf4, 16, XBLOCK=16, num_warps =1, num_stages=1) return buf4, class InnerProductDecoderNew(nn.Module): def __init__(self, activation=torch.sigmoid, dropout=0.1): super().__init__() self.dropout = dropout self.activation = activation def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
leiyu-thunder/gae_dgl
InnerProductDecoder
false
7,069
[ "Apache-2.0" ]
1
c743acc96e24c4ca3ae72d08956381f302b373bd
https://github.com/leiyu-thunder/gae_dgl/tree/c743acc96e24c4ca3ae72d08956381f302b373bd
NN_logsoftmax
import torch from torch import nn import torch.nn.functional as F class NN_logsoftmax(nn.Module): """Build a new class for the network you want to run, returning log softmax""" def set_parameters(self, initializers): """Set the parameter values obtained from vanilla NN as initializers""" with torch.no_grad(): self.fc1.weight.data = torch.from_numpy(initializers[0].copy()) self.fc1.bias.data = torch.from_numpy(initializers[1].copy()) self.fc2.weight.data = torch.from_numpy(initializers[2].copy()) self.fc2.bias.data = torch.from_numpy(initializers[3].copy()) """Single layer network with layer_size nodes""" def __init__(self, d, layer_size, num_classes): super(NN_logsoftmax, self).__init__() self.fc1 = nn.Linear(d, layer_size) self.fc2 = nn.Linear(layer_size, num_classes) """Return the log softmax values for each of the classes""" def forward(self, x): x = F.relu(self.fc1(x)) x = self.fc2(x) return F.log_softmax(x, dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d': 4, 'layer_size': 1, 'num_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = 0.0 tmp7 = tmp5 <= tmp6 tl.store(in_out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 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 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x3, tmp13, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 1), (1, 1)) assert_size_stride(primals_5, (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 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf1, primals_2, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 1), ( 1, 0), 0), reinterpret_tensor(primals_4, (1, 4), (1, 1), 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__log_softmax_1[grid(256)](buf2, buf3, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused__log_softmax_2[grid(256)](buf3, buf4, 256, XBLOCK= 256, num_warps=4, num_stages=1) del buf3 return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 1), (1, 1), 0), buf4, primals_4, buf5 class NN_logsoftmaxNew(nn.Module): """Build a new class for the network you want to run, returning log softmax""" def set_parameters(self, initializers): """Set the parameter values obtained from vanilla NN as initializers""" with torch.no_grad(): self.fc1.weight.data = torch.from_numpy(initializers[0].copy()) self.fc1.bias.data = torch.from_numpy(initializers[1].copy()) self.fc2.weight.data = torch.from_numpy(initializers[2].copy()) self.fc2.bias.data = torch.from_numpy(initializers[3].copy()) """Single layer network with layer_size nodes""" def __init__(self, d, layer_size, num_classes): super(NN_logsoftmaxNew, self).__init__() self.fc1 = nn.Linear(d, layer_size) self.fc2 = nn.Linear(layer_size, num_classes) """Return the log softmax values for each of the classes""" def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
laravomfell/tvd_loss
NN_logsoftmax
false
7,070
[ "MIT" ]
1
b30a925f95985a03ff70bfa40a6ec3662432779d
https://github.com/laravomfell/tvd_loss/tree/b30a925f95985a03ff70bfa40a6ec3662432779d