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
NonAttentiveTacotronLoss
import torch from torch import nn import torch.nn.functional as F class NonAttentiveTacotronLoss(nn.Module): def __init__(self, sample_rate: 'int', hop_size: 'int'): super(NonAttentiveTacotronLoss, self).__init__() self.sample_rate = sample_rate self.hop_size = hop_size def forward(self, prenet_mels, postnet_mels, model_durations, target_durations, target_mels): target_mels.requires_grad = False target_durations.requires_grad = False prenet_l1 = F.l1_loss(prenet_mels, target_mels) prenet_l2 = F.mse_loss(prenet_mels, target_mels) postnet_l1 = F.l1_loss(postnet_mels, target_mels) postnet_l2 = F.mse_loss(postnet_mels, target_mels) loss_prenet = prenet_l1 + prenet_l2 loss_postnet = postnet_l1 + postnet_l2 model_durations = model_durations * self.hop_size / self.sample_rate target_durations = target_durations * self.hop_size / self.sample_rate loss_durations = F.mse_loss(model_durations, target_durations) return loss_prenet, loss_postnet, loss_durations def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'sample_rate': 4, 'hop_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 @triton.jit def triton_per_fused_abs_add_mean_mse_loss_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp11 = tl.load(in_ptr2 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tmp2 * tmp2 tmp8 = tl.broadcast_to(tmp7, [RBLOCK]) tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0)) tmp12 = tmp11 - tmp1 tmp13 = tl_math.abs(tmp12) tmp14 = tl.broadcast_to(tmp13, [RBLOCK]) tmp16 = triton_helpers.promote_to_tensor(tl.sum(tmp14, 0)) tmp17 = tmp12 * tmp12 tmp18 = tl.broadcast_to(tmp17, [RBLOCK]) tmp20 = triton_helpers.promote_to_tensor(tl.sum(tmp18, 0)) tmp21 = 256.0 tmp22 = tmp16 / tmp21 tmp23 = tmp20 / tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp6 / tmp21 tmp26 = tmp10 / tmp21 tmp27 = tmp25 + tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp24, None) tl.debug_barrier() tl.store(in_out_ptr1 + tl.full([1], 0, tl.int32), tmp27, None) @triton.jit def triton_per_fused_div_mse_loss_mul_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp5 = tl.load(in_ptr1 + r0, None) tmp1 = 4.0 tmp2 = tmp0 * tmp1 tmp3 = 0.25 tmp4 = tmp2 * tmp3 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp3 tmp8 = tmp4 - tmp7 tmp9 = tmp8 * tmp8 tmp10 = tl.broadcast_to(tmp9, [RBLOCK]) tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0)) tmp13 = 256.0 tmp14 = tmp12 / tmp13 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp14, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1, arg4_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg4_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = empty_strided_cuda((), (), torch.float32) buf6 = buf2 del buf2 buf5 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_mean_mse_loss_sub_0[grid(1)](buf6, buf5, arg1_1, arg0_1, arg2_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 buf4 = empty_strided_cuda((), (), torch.float32) buf7 = buf4 del buf4 triton_per_fused_div_mse_loss_mul_1[grid(1)](buf7, arg3_1, arg4_1, 1, 256, num_warps=2, num_stages=1) del arg3_1 del arg4_1 return buf5, buf6, buf7 class NonAttentiveTacotronLossNew(nn.Module): def __init__(self, sample_rate: 'int', hop_size: 'int'): super(NonAttentiveTacotronLossNew, self).__init__() self.sample_rate = sample_rate self.hop_size = hop_size def forward(self, input_0, input_1, input_2, input_3, input_4): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 arg4_1 = input_4 output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1]) return output[0], output[1], output[2]
IMDxD/NonAttentiveTacotron
NonAttentiveTacotronLoss
false
17,420
[ "MIT" ]
4
a227fba1bdfa4c5ec63a0f0364313f3ac0fef1ba
https://github.com/IMDxD/NonAttentiveTacotron/tree/a227fba1bdfa4c5ec63a0f0364313f3ac0fef1ba
layer_1_to_2
import torch import numpy as np import torch.nn as nn def contractions_1_to_2(inputs, dim, normalization='inf', normalization_val=1.0 ): sum_all = torch.sum(inputs, dim=2).unsqueeze(dim=2) op1 = torch.diag_embed(inputs, dim1=2, dim2=3) op2 = torch.diag_embed(torch.cat([sum_all for d in range(dim)], dim=2), dim1=2, dim2=3) op3 = torch.cat([torch.unsqueeze(inputs, dim=2) for d in range(dim)], dim=2 ) op4 = torch.cat([torch.unsqueeze(inputs, dim=3) for d in range(dim)], dim=3 ) op5 = torch.cat([sum_all for d in range(dim)], dim=2) op5 = torch.cat([op5.unsqueeze(dim=3) for d in range(dim)], dim=3) if normalization is not None: if normalization == 'inf': op2 = op2 / dim op5 = op5 / dim return [op1, op2, op3, op4, op5] class layer_1_to_2(nn.Module): """ :param name: name of layer :param input_depth: D :param output_depth: S :param inputs: N x D x m tensor :return: output: N x S x m x m tensor """ def __init__(self, input_depth, output_depth, normalization='inf', normalization_val=1.0, device='cpu'): super().__init__() self.input_depth = input_depth self.output_depth = output_depth self.normalization = normalization self.normalization_val = normalization_val self.device = device self.basis_dimension = 5 self.coeffs = torch.nn.Parameter(torch.randn(self.input_depth, self .output_depth, self.basis_dimension) * np.sqrt(2.0) / (self. input_depth + self.output_depth), requires_grad=True) self.bias = torch.nn.Parameter(torch.zeros(1, self.output_depth, 1, 1)) def forward(self, inputs): m = inputs.size(2) ops_out = contractions_1_to_2(inputs, m, normalization=self. normalization) ops_out = torch.stack(ops_out, dim=2) output = torch.einsum('dsb,ndbij->nsij', self.coeffs, ops_out) output = output + self.bias return output def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'input_depth': 1, 'output_depth': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_cat_diag_embed_div_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 16 x3 = xindex % 16 x1 = xindex // 4 % 4 tmp59 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last') tmp60 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp62 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp64 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + 4 * x2, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (1 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr0 + (2 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tmp7 + tmp8 tmp10 = tl.load(in_ptr0 + (3 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tmp15 = tl.full([1], 2, tl.int64) tmp16 = tmp0 < tmp15 tmp17 = tmp14 & tmp16 tmp18 = tl.load(in_ptr0 + 4 * x2, tmp17 & xmask, eviction_policy= 'evict_last', other=0.0) tmp19 = tl.load(in_ptr0 + (1 + 4 * x2), tmp17 & xmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tmp18 + tmp19 tmp21 = tl.load(in_ptr0 + (2 + 4 * x2), tmp17 & xmask, eviction_policy= 'evict_last', other=0.0) tmp22 = tmp20 + tmp21 tmp23 = tl.load(in_ptr0 + (3 + 4 * x2), tmp17 & xmask, eviction_policy= 'evict_last', other=0.0) tmp24 = tmp22 + tmp23 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp17, tmp24, tmp25) tmp27 = tmp0 >= tmp15 tmp28 = tl.full([1], 3, tl.int64) tmp29 = tmp0 < tmp28 tmp30 = tmp27 & tmp29 tmp31 = tl.load(in_ptr0 + 4 * x2, tmp30 & xmask, eviction_policy= 'evict_last', other=0.0) tmp32 = tl.load(in_ptr0 + (1 + 4 * x2), tmp30 & xmask, eviction_policy= 'evict_last', other=0.0) tmp33 = tmp31 + tmp32 tmp34 = tl.load(in_ptr0 + (2 + 4 * x2), tmp30 & xmask, eviction_policy= 'evict_last', other=0.0) tmp35 = tmp33 + tmp34 tmp36 = tl.load(in_ptr0 + (3 + 4 * x2), tmp30 & xmask, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp35 + tmp36 tmp38 = tl.full(tmp37.shape, 0.0, tmp37.dtype) tmp39 = tl.where(tmp30, tmp37, tmp38) tmp40 = tmp0 >= tmp28 tl.full([1], 4, tl.int64) tmp43 = tl.load(in_ptr0 + 4 * x2, tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp44 = tl.load(in_ptr0 + (1 + 4 * x2), tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp45 = tmp43 + tmp44 tmp46 = tl.load(in_ptr0 + (2 + 4 * x2), tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp47 = tmp45 + tmp46 tmp48 = tl.load(in_ptr0 + (3 + 4 * x2), tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp49 = tmp47 + tmp48 tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp40, tmp49, tmp50) tmp52 = tl.where(tmp30, tmp39, tmp51) tmp53 = tl.where(tmp17, tmp26, tmp52) tmp54 = tl.where(tmp4, tmp13, tmp53) tmp55 = 0.25 tmp56 = tmp54 * tmp55 tmp57 = x1 tmp58 = tmp0 == tmp57 tmp61 = tmp59 + tmp60 tmp63 = tmp61 + tmp62 tmp65 = tmp63 + tmp64 tmp66 = 0.0 tmp67 = tl.where(tmp58, tmp65, tmp66) tmp68 = tmp67 * tmp55 tl.store(out_ptr0 + (x3 + 80 * x2), tmp56, xmask) tl.store(out_ptr1 + (x3 + 80 * x2), tmp68, xmask) @triton.jit def triton_poi_fused_cat_diag_embed_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 x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex % 16 tmp3 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp0 = x0 tmp1 = x1 tmp2 = tmp0 == tmp1 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.full([1], 0, tl.int64) tmp8 = tl.full([1], 1, tl.int64) tmp9 = tmp1 < tmp8 tmp10 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp9 & xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp1 >= tmp8 tmp12 = tl.full([1], 2, tl.int64) tmp13 = tmp1 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp14 & xmask, eviction_policy ='evict_last', other=0.0) tmp16 = tmp1 >= tmp12 tmp17 = tl.full([1], 3, tl.int64) tmp18 = tmp1 < tmp17 tmp19 = tmp16 & tmp18 tmp20 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp19 & xmask, eviction_policy ='evict_last', other=0.0) tmp21 = tmp1 >= tmp17 tl.full([1], 4, tl.int64) tmp24 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp21 & xmask, eviction_policy ='evict_last', other=0.0) tmp25 = tl.where(tmp19, tmp20, tmp24) tmp26 = tl.where(tmp14, tmp15, tmp25) tmp27 = tl.where(tmp9, tmp10, tmp26) tl.store(out_ptr0 + (x3 + 80 * x2), tmp5, xmask) tl.store(out_ptr1 + (x3 + 80 * x2), tmp27, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x3 = xindex // 4 x2 = xindex // 16 x4 = xindex % 16 tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 2, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr0 + x3, tmp9 & xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 3, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + x3, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 4, tl.int64) tmp19 = tl.load(in_ptr0 + x3, tmp16 & xmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tl.where(tmp14, tmp15, tmp19) tmp21 = tl.where(tmp9, tmp10, tmp20) tmp22 = tl.where(tmp4, tmp5, tmp21) tl.store(out_ptr0 + (x4 + 80 * x2), tmp22, xmask) @triton.jit def triton_poi_fused_sum_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 20 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 5 y1 = yindex // 5 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y0 + 320 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (80 + x2 + 16 * y0 + 320 * y1), xmask & ymask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (160 + x2 + 16 * y0 + 320 * y1), xmask & ymask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (240 + x2 + 16 * y0 + 320 * y1), xmask & ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tl.store(out_ptr0 + (y0 + 5 * x2 + 80 * y1), tmp6, xmask & ymask) @triton.jit def triton_poi_fused_add_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) 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, (1, 1, 5), (5, 5, 1)) assert_size_stride(primals_3, (1, 1, 1, 1), (1, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf5 = empty_strided_cuda((4, 4, 20, 4), (320, 80, 4, 1), torch.float32 ) buf0 = reinterpret_tensor(buf5, (4, 4, 4, 4), (320, 80, 4, 1), 64) buf2 = reinterpret_tensor(buf5, (4, 4, 4, 4), (320, 80, 4, 1), 16) get_raw_stream(0) triton_poi_fused_cat_diag_embed_div_0[grid(256)](primals_1, buf0, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) buf1 = reinterpret_tensor(buf5, (4, 4, 4, 4), (320, 80, 4, 1), 0) buf3 = reinterpret_tensor(buf5, (4, 4, 4, 4), (320, 80, 4, 1), 32) triton_poi_fused_cat_diag_embed_1[grid(256)](primals_1, buf1, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf5, (4, 4, 4, 4), (320, 80, 4, 1), 48) triton_poi_fused_cat_2[grid(256)](primals_1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf6 = empty_strided_cuda((4, 1, 4, 4, 5, 1), (80, 80, 20, 5, 1, 1), torch.float32) triton_poi_fused_sum_3[grid(20, 16)](buf5, buf6, 20, 16, XBLOCK=16, YBLOCK=32, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 del buf3 del buf4 del buf5 buf7 = empty_strided_cuda((1, 1, 64), (64, 64, 1), torch.float32) extern_kernels.bmm(primals_2, reinterpret_tensor(buf6, (1, 5, 64), (0, 1, 5), 0), out=buf7) del primals_2 buf8 = reinterpret_tensor(buf7, (4, 1, 4, 4), (16, 16, 4, 1), 0) del buf7 triton_poi_fused_add_4[grid(64)](buf8, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf8, reinterpret_tensor(buf6, (1, 64, 5), (5, 5, 1), 0) def contractions_1_to_2(inputs, dim, normalization='inf', normalization_val=1.0 ): sum_all = torch.sum(inputs, dim=2).unsqueeze(dim=2) op1 = torch.diag_embed(inputs, dim1=2, dim2=3) op2 = torch.diag_embed(torch.cat([sum_all for d in range(dim)], dim=2), dim1=2, dim2=3) op3 = torch.cat([torch.unsqueeze(inputs, dim=2) for d in range(dim)], dim=2 ) op4 = torch.cat([torch.unsqueeze(inputs, dim=3) for d in range(dim)], dim=3 ) op5 = torch.cat([sum_all for d in range(dim)], dim=2) op5 = torch.cat([op5.unsqueeze(dim=3) for d in range(dim)], dim=3) if normalization is not None: if normalization == 'inf': op2 = op2 / dim op5 = op5 / dim return [op1, op2, op3, op4, op5] class layer_1_to_2New(nn.Module): """ :param name: name of layer :param input_depth: D :param output_depth: S :param inputs: N x D x m tensor :return: output: N x S x m x m tensor """ def __init__(self, input_depth, output_depth, normalization='inf', normalization_val=1.0, device='cpu'): super().__init__() self.input_depth = input_depth self.output_depth = output_depth self.normalization = normalization self.normalization_val = normalization_val self.device = device self.basis_dimension = 5 self.coeffs = torch.nn.Parameter(torch.randn(self.input_depth, self .output_depth, self.basis_dimension) * np.sqrt(2.0) / (self. input_depth + self.output_depth), requires_grad=True) self.bias = torch.nn.Parameter(torch.zeros(1, self.output_depth, 1, 1)) def forward(self, input_0): primals_2 = self.coeffs primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
HyTruongSon/InvariantGraphNetworks-PyTorch
layer_1_to_2
false
17,421
[ "Apache-2.0" ]
7
da9fdaa4f858d6fcae14b08a59d4b172a2aabaf8
https://github.com/HyTruongSon/InvariantGraphNetworks-PyTorch/tree/da9fdaa4f858d6fcae14b08a59d4b172a2aabaf8
MRAE
import torch import torch.nn as nn class MRAE(nn.Module): def __init__(self): super(MRAE, self).__init__() def forward(self, output, target, mask=None): relative_diff = torch.abs(output - target) / (target + 1.0 / 65535.0) if mask is not None: relative_diff = mask * relative_diff return torch.mean(relative_diff) 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_abs_add_div_mean_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 1.5259021896696422e-05 tmp5 = tmp1 + tmp4 tmp6 = tmp3 / tmp5 tmp7 = tl.broadcast_to(tmp6, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = 256.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([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((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_div_mean_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class MRAENew(nn.Module): def __init__(self): super(MRAENew, 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]
IVRL/Multi-Modal-Spectral-Image-Super-Resolution
MRAE
false
17,422
[ "MIT" ]
9
6afe35c16d4cc2466e5eb51f3ddc39b43f6f765e
https://github.com/IVRL/Multi-Modal-Spectral-Image-Super-Resolution/tree/6afe35c16d4cc2466e5eb51f3ddc39b43f6f765e
GLU
import torch import torch.nn as nn import torch.utils.data import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler class GLU(nn.Module): def __init__(self, dim): super().__init__() self.dim = dim def forward(self, x): out, gate = x.chunk(2, dim=self.dim) return out * gate.sigmoid() def get_inputs(): return [torch.rand([4, 4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils.data 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 @triton.jit def triton_poi_fused_mul_sigmoid_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 % 2 x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1), xmask) tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 2), (128, 32, 8, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(512)](arg0_1, buf0, 512, XBLOCK =128, num_warps=4, num_stages=1) del arg0_1 return buf0, class GLUNew(nn.Module): def __init__(self, dim): super().__init__() self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
IIP-Sogang/Audio-Visual-Speech-Recognition
GLU
false
17,423
[ "MIT" ]
9
bd03be91135acbc6162b83092d462b7fe71dd007
https://github.com/IIP-Sogang/Audio-Visual-Speech-Recognition/tree/bd03be91135acbc6162b83092d462b7fe71dd007
tofp16
import torch import torch.utils.data import torch import torch.nn as nn class tofp16(nn.Module): def __init__(self): super(tofp16, self).__init__() def forward(self, input): return input.half() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.utils.data import torch import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy_0(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 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, 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.float16) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg0_1 return buf0, class tofp16New(nn.Module): def __init__(self): super(tofp16New, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Icep2020/CrowdGAN
tofp16
false
17,424
[ "MIT" ]
7
4adebaa09460f2f8296d368ffeba03f32c963d4d
https://github.com/Icep2020/CrowdGAN/tree/4adebaa09460f2f8296d368ffeba03f32c963d4d
GlobalAveragePooling2d
import torch import torch as pt import torch.nn as nn class GlobalAveragePooling2d(nn.Module): """class for performing global average pooling on 2d feature maps""" def forward(self, x): """ calculates the average of each feature map in the tensor :param x: input tensor of shape [batch, channels, height, width] :return: tensor that containes the average for each channel, [batch, channel_average] """ return pt.mean(pt.mean(x, -1), -1)[..., None, None] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp28 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp32 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp11 = tmp9 + tmp10 tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp16 = tmp15 / tmp7 tmp17 = tmp8 + tmp16 tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp24 / tmp7 tmp26 = tmp17 + tmp25 tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tmp33 = tmp31 + tmp32 tmp34 = tmp33 / tmp7 tmp35 = tmp26 + tmp34 tmp36 = tmp35 / tmp7 tl.store(out_ptr0 + x0, tmp36, xmask) 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) get_raw_stream(0) triton_poi_fused_mean_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0), class GlobalAveragePooling2dNew(nn.Module): """class for performing global average pooling on 2d feature maps""" def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
IljaManakov/Autoencoders
GlobalAveragePooling2d
false
17,425
[ "MIT" ]
4
bd2ccc6decda37a004cc57a41dcd406752c21d61
https://github.com/IljaManakov/Autoencoders/tree/bd2ccc6decda37a004cc57a41dcd406752c21d61
ComplexConvTranspose2d
import torch import torch.nn as nn import torch.utils.data import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler class ComplexConvTranspose2d(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True, **kwargs ): super().__init__() self.tconv_re = nn.ConvTranspose2d(in_channel, out_channel, kernel_size=kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation, **kwargs) self.tconv_im = nn.ConvTranspose2d(in_channel, out_channel, kernel_size=kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation, **kwargs) def forward(self, x): real = self.tconv_re(x[..., 0]) - self.tconv_im(x[..., 1]) imaginary = self.tconv_re(x[..., 1]) + self.tconv_im(x[..., 0]) output = torch.stack((real, imaginary), dim=-1) return output 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 torch.nn as nn import torch.utils.data 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_poi_fused_stack_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 392 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x3 = xindex // 2 x2 = xindex // 98 x4 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr2 + x3, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tl.load(in_ptr3 + x2, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tmp8 + tmp9 tmp11 = tmp7 - tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp17 = tl.load(in_ptr4 + x3, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tl.load(in_ptr1 + x2, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp19 = tmp17 + tmp18 tmp20 = tl.load(in_ptr5 + x3, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.load(in_ptr3 + x2, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp22 = tmp20 + tmp21 tmp23 = tmp19 + tmp22 tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp14, tmp23, tmp24) tmp26 = tl.where(tmp4, tmp13, tmp25) tl.store(out_ptr0 + x4, tmp26, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (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 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 0), primals_2, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0 ), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 7, 7), (196, 49, 7, 1)) buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 1), primals_4, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0 ), groups=1, bias=None) assert_size_stride(buf1, (1, 4, 7, 7), (196, 49, 7, 1)) buf2 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 1), primals_2, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0 ), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 7, 7), (196, 49, 7, 1)) buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 0), primals_4, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0 ), groups=1, bias=None) assert_size_stride(buf3, (1, 4, 7, 7), (196, 49, 7, 1)) buf4 = empty_strided_cuda((4, 7, 7, 2), (98, 14, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(392)](buf0, primals_3, buf1, primals_5, buf2, buf3, buf4, 392, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 del buf3 del primals_3 del primals_5 return buf4, primals_2, primals_4, reinterpret_tensor(primals_1, (1, 4, 4, 4), (256, 64, 16, 4), 0), reinterpret_tensor(primals_1, (1, 4, 4, 4), (256, 64, 16, 4), 1) class ComplexConvTranspose2dNew(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, output_padding=0, dilation=1, groups=1, bias=True, **kwargs ): super().__init__() self.tconv_re = nn.ConvTranspose2d(in_channel, out_channel, kernel_size=kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation, **kwargs) self.tconv_im = nn.ConvTranspose2d(in_channel, out_channel, kernel_size=kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation, **kwargs) def forward(self, input_0): primals_1 = self.tconv_re.weight primals_3 = self.tconv_re.bias primals_2 = self.tconv_im.weight primals_5 = self.tconv_im.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
IIP-Sogang/Audio-Visual-Speech-Recognition
ComplexConvTranspose2d
false
17,426
[ "MIT" ]
9
bd03be91135acbc6162b83092d462b7fe71dd007
https://github.com/IIP-Sogang/Audio-Visual-Speech-Recognition/tree/bd03be91135acbc6162b83092d462b7fe71dd007
FeatureDiscriminator
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class FeatureDiscriminator(nn.Module): def __init__(self): super(FeatureDiscriminator, self).__init__() self.conv1 = nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1) self.conv2 = nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, stride=1) self.conv3 = nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, stride=1) self.conv4 = nn.Conv2d(in_channels=64, out_channels=32, kernel_size =1, stride=1) self.conv5 = nn.Conv2d(in_channels=32, out_channels=1, kernel_size= 1, stride=1) self.sig5 = nn.Sigmoid() self.avg_pool = nn.AvgPool2d(kernel_size=(1, 25), stride=1) self._do_initializer() def _do_initializer(self): for module in self.modules(): if isinstance(module, nn.Conv2d): nn.init.normal_(tensor=module.weight, mean=0, std=0.01) def forward(self, inputs): out = F.leaky_relu(self.conv1(inputs)) out = F.leaky_relu(self.conv2(out)) out = F.leaky_relu(self.conv3(out)) out = F.leaky_relu(self.conv4(out)) out = self.sig5(self.conv5(out)) out = self.avg_pool(out) out = out.view(-1) return out def get_inputs(): return [torch.rand([4, 512, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), None, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 512 * x2 + 2097152 * y1), tmp0, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_sigmoid_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) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, None) @triton.jit def triton_poi_fused_avg_pool2d_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 40 x1 = xindex // 40 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), None) tmp1 = tl.load(in_ptr0 + (1 + x0 + 64 * x1), None) tmp3 = tl.load(in_ptr0 + (2 + x0 + 64 * x1), None) tmp5 = tl.load(in_ptr0 + (3 + x0 + 64 * x1), None) tmp7 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), None) tmp9 = tl.load(in_ptr0 + (5 + x0 + 64 * x1), None) tmp11 = tl.load(in_ptr0 + (6 + x0 + 64 * x1), None) tmp13 = tl.load(in_ptr0 + (7 + x0 + 64 * x1), None) tmp15 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), None) tmp17 = tl.load(in_ptr0 + (9 + x0 + 64 * x1), None) tmp19 = tl.load(in_ptr0 + (10 + x0 + 64 * x1), None) tmp21 = tl.load(in_ptr0 + (11 + x0 + 64 * x1), None) tmp23 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), None) tmp25 = tl.load(in_ptr0 + (13 + x0 + 64 * x1), None) tmp27 = tl.load(in_ptr0 + (14 + x0 + 64 * x1), None) tmp29 = tl.load(in_ptr0 + (15 + x0 + 64 * x1), None) tmp31 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), None) tmp33 = tl.load(in_ptr0 + (17 + x0 + 64 * x1), None) tmp35 = tl.load(in_ptr0 + (18 + x0 + 64 * x1), None) tmp37 = tl.load(in_ptr0 + (19 + x0 + 64 * x1), None) tmp39 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), None) tmp41 = tl.load(in_ptr0 + (21 + x0 + 64 * x1), None) tmp43 = tl.load(in_ptr0 + (22 + x0 + 64 * x1), None) tmp45 = tl.load(in_ptr0 + (23 + x0 + 64 * x1), None) tmp47 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), None) tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp8 = tmp7 + tmp6 tmp10 = tmp9 + tmp8 tmp12 = tmp11 + tmp10 tmp14 = tmp13 + tmp12 tmp16 = tmp15 + tmp14 tmp18 = tmp17 + tmp16 tmp20 = tmp19 + tmp18 tmp22 = tmp21 + tmp20 tmp24 = tmp23 + tmp22 tmp26 = tmp25 + tmp24 tmp28 = tmp27 + tmp26 tmp30 = tmp29 + tmp28 tmp32 = tmp31 + tmp30 tmp34 = tmp33 + tmp32 tmp36 = tmp35 + tmp34 tmp38 = tmp37 + tmp36 tmp40 = tmp39 + tmp38 tmp42 = tmp41 + tmp40 tmp44 = tmp43 + tmp42 tmp46 = tmp45 + tmp44 tmp48 = tmp47 + tmp46 tmp49 = 0.04 tmp50 = tmp48 * tmp49 tl.store(out_ptr0 + x2, tmp50, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (256, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 512, 64, 64), (2097152, 4096, 64, 1)) assert_size_stride(primals_4, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (64, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (32, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_9, (32,), (1,)) assert_size_stride(primals_10, (1, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_11, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 512, 64, 64), (2097152, 1, 32768, 512 ), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(2048, 4096)](primals_3, buf0, 2048, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_3 buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 256, 64, 64), (1048576, 1, 16384, 256)) buf2 = empty_strided_cuda((4, 256, 64, 64), (1048576, 1, 16384, 256 ), torch.bool) buf3 = empty_strided_cuda((4, 256, 64, 64), (1048576, 1, 16384, 256 ), torch.float32) triton_poi_fused_convolution_leaky_relu_1[grid(4194304)](buf1, primals_2, buf2, buf3, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del buf1 del primals_2 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 128, 64, 64), (524288, 1, 8192, 128)) buf5 = empty_strided_cuda((4, 128, 64, 64), (524288, 1, 8192, 128), torch.bool) buf6 = empty_strided_cuda((4, 128, 64, 64), (524288, 1, 8192, 128), torch.float32) triton_poi_fused_convolution_leaky_relu_2[grid(2097152)](buf4, primals_5, buf5, buf6, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del buf4 del primals_5 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, 64, 64, 64), (262144, 1, 4096, 64)) buf8 = empty_strided_cuda((4, 64, 64, 64), (262144, 1, 4096, 64), torch.bool) buf9 = empty_strided_cuda((4, 64, 64, 64), (262144, 1, 4096, 64), torch.float32) triton_poi_fused_convolution_leaky_relu_3[grid(1048576)](buf7, primals_7, buf8, buf9, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf7 del primals_7 buf10 = extern_kernels.convolution(buf9, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 32, 64, 64), (131072, 1, 2048, 32)) buf11 = empty_strided_cuda((4, 32, 64, 64), (131072, 1, 2048, 32), torch.bool) buf12 = empty_strided_cuda((4, 32, 64, 64), (131072, 1, 2048, 32), torch.float32) triton_poi_fused_convolution_leaky_relu_4[grid(524288)](buf10, primals_9, buf11, buf12, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del buf10 del primals_9 buf13 = extern_kernels.convolution(buf12, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (4, 1, 64, 64), (4096, 1, 64, 1)) buf14 = buf13 del buf13 triton_poi_fused_convolution_sigmoid_5[grid(16384)](buf14, primals_11, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf15 = empty_strided_cuda((4, 1, 64, 40), (2560, 2560, 40, 1), torch.float32) triton_poi_fused_avg_pool2d_6[grid(10240)](buf14, buf15, 10240, XBLOCK=128, num_warps=4, num_stages=1) return (reinterpret_tensor(buf15, (10240,), (1,), 0), primals_1, buf0, primals_4, primals_6, primals_8, primals_10, buf2, buf3, buf5, buf6, buf8, buf9, buf11, buf12, buf14) class FeatureDiscriminatorNew(nn.Module): def __init__(self): super(FeatureDiscriminatorNew, self).__init__() self.conv1 = nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1) self.conv2 = nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, stride=1) self.conv3 = nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, stride=1) self.conv4 = nn.Conv2d(in_channels=64, out_channels=32, kernel_size =1, stride=1) self.conv5 = nn.Conv2d(in_channels=32, out_channels=1, kernel_size= 1, stride=1) self.sig5 = nn.Sigmoid() self.avg_pool = nn.AvgPool2d(kernel_size=(1, 25), stride=1) self._do_initializer() def _do_initializer(self): for module in self.modules(): if isinstance(module, nn.Conv2d): nn.init.normal_(tensor=module.weight, mean=0, std=0.01) 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_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]
HotaekHan/Synthetically_Supervised_Text_Recognition
FeatureDiscriminator
false
17,427
[ "MIT" ]
8
a6bb7d3039b1280c6efe177b69d8b985d2e13285
https://github.com/HotaekHan/Synthetically_Supervised_Text_Recognition/tree/a6bb7d3039b1280c6efe177b69d8b985d2e13285
ActorNetwork
import torch import torch.nn as nn import torch.nn.functional as F class ActorNetwork(nn.Module): def __init__(self, input_size, hidden_size, action_size): super(ActorNetwork, self).__init__() self.fc1 = nn.Linear(input_size, hidden_size) self.fc2 = nn.Linear(hidden_size, hidden_size) self.fc3 = nn.Linear(hidden_size, action_size) def forward(self, x): out = F.relu(self.fc1(x)) out = F.relu(self.fc2(out)) out = F.log_softmax(self.fc3(out)) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4, 'action_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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__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, 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, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 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 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_2, buf8, 256, 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, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf3, primals_5, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](buf4, buf5, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused__log_softmax_2[grid(256)](buf5, buf6, 256, XBLOCK= 128, num_warps=4, num_stages=1) del buf5 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor( buf3, (64, 4), (4, 1), 0), buf6, primals_6, buf7, primals_4, buf8 class ActorNetworkNew(nn.Module): def __init__(self, input_size, hidden_size, action_size): super(ActorNetworkNew, self).__init__() self.fc1 = nn.Linear(input_size, hidden_size) self.fc2 = nn.Linear(hidden_size, hidden_size) self.fc3 = nn.Linear(hidden_size, action_size) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
IandRover/meta-gradient_RL
ActorNetwork
false
17,428
[ "MIT" ]
6
5d2539aceb9fa68b1849feac7d37741f9e5f83a3
https://github.com/IandRover/meta-gradient_RL/tree/5d2539aceb9fa68b1849feac7d37741f9e5f83a3
CircleLoss
import torch from typing import * import torch.nn as nn import torch.nn.functional as F class CircleLoss(nn.Module): def __init__(self, gamma, m): super().__init__() self.gamma = gamma self.m = m def forward(self, s_p, s_n): alpha_p = torch.clamp_min(1 + self.m - s_p, 0) alpha_n = torch.clamp_min(self.m + s_n, 0) delta_p = 1 - self.m delta_n = self.m logit_p = -self.gamma * alpha_p * (s_p - delta_p) logit_n = self.gamma * alpha_n * (s_n - delta_n) return F.softplus(torch.logsumexp(logit_p, dim=0) + torch.logsumexp (logit_n, dim=0)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'gamma': 4, 'm': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from typing import * 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_clamp_min_logsumexp_mul_rsub_softplus_sub_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp10 = tl.load(in_ptr0 + (64 + x0), xmask) tmp17 = tl.load(in_ptr0 + (128 + x0), xmask) tmp24 = tl.load(in_ptr0 + (192 + x0), xmask) tmp46 = tl.load(in_ptr1 + x0, xmask) tmp53 = tl.load(in_ptr1 + (64 + x0), xmask) tmp60 = tl.load(in_ptr1 + (128 + x0), xmask) tmp67 = tl.load(in_ptr1 + (192 + x0), xmask) tmp1 = 5.0 tmp2 = tmp1 - tmp0 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = -4.0 tmp6 = tmp4 * tmp5 tmp7 = -3.0 tmp8 = tmp0 - tmp7 tmp9 = tmp6 * tmp8 tmp11 = tmp1 - tmp10 tmp12 = triton_helpers.maximum(tmp11, tmp3) tmp13 = tmp12 * tmp5 tmp14 = tmp10 - tmp7 tmp15 = tmp13 * tmp14 tmp16 = triton_helpers.maximum(tmp9, tmp15) tmp18 = tmp1 - tmp17 tmp19 = triton_helpers.maximum(tmp18, tmp3) tmp20 = tmp19 * tmp5 tmp21 = tmp17 - tmp7 tmp22 = tmp20 * tmp21 tmp23 = triton_helpers.maximum(tmp16, tmp22) tmp25 = tmp1 - tmp24 tmp26 = triton_helpers.maximum(tmp25, tmp3) tmp27 = tmp26 * tmp5 tmp28 = tmp24 - tmp7 tmp29 = tmp27 * tmp28 tmp30 = triton_helpers.maximum(tmp23, tmp29) tmp31 = tl_math.abs(tmp30) tmp32 = float('inf') tmp33 = tmp31 == tmp32 tmp34 = tl.where(tmp33, tmp3, tmp30) tmp35 = tmp9 - tmp34 tmp36 = tl_math.exp(tmp35) tmp37 = tmp15 - tmp34 tmp38 = tl_math.exp(tmp37) tmp39 = tmp36 + tmp38 tmp40 = tmp22 - tmp34 tmp41 = tl_math.exp(tmp40) tmp42 = tmp39 + tmp41 tmp43 = tmp29 - tmp34 tmp44 = tl_math.exp(tmp43) tmp45 = tmp42 + tmp44 tmp47 = 4.0 tmp48 = tmp46 + tmp47 tmp49 = triton_helpers.maximum(tmp48, tmp3) tmp50 = tmp49 * tmp47 tmp51 = tmp46 - tmp47 tmp52 = tmp50 * tmp51 tmp54 = tmp53 + tmp47 tmp55 = triton_helpers.maximum(tmp54, tmp3) tmp56 = tmp55 * tmp47 tmp57 = tmp53 - tmp47 tmp58 = tmp56 * tmp57 tmp59 = triton_helpers.maximum(tmp52, tmp58) tmp61 = tmp60 + tmp47 tmp62 = triton_helpers.maximum(tmp61, tmp3) tmp63 = tmp62 * tmp47 tmp64 = tmp60 - tmp47 tmp65 = tmp63 * tmp64 tmp66 = triton_helpers.maximum(tmp59, tmp65) tmp68 = tmp67 + tmp47 tmp69 = triton_helpers.maximum(tmp68, tmp3) tmp70 = tmp69 * tmp47 tmp71 = tmp67 - tmp47 tmp72 = tmp70 * tmp71 tmp73 = triton_helpers.maximum(tmp66, tmp72) tmp74 = tl_math.abs(tmp73) tmp75 = tmp74 == tmp32 tmp76 = tl.where(tmp75, tmp3, tmp73) tmp77 = tmp52 - tmp76 tmp78 = tl_math.exp(tmp77) tmp79 = tmp58 - tmp76 tmp80 = tl_math.exp(tmp79) tmp81 = tmp78 + tmp80 tmp82 = tmp65 - tmp76 tmp83 = tl_math.exp(tmp82) tmp84 = tmp81 + tmp83 tmp85 = tmp72 - tmp76 tmp86 = tl_math.exp(tmp85) tmp87 = tmp84 + tmp86 tmp88 = tl_math.log(tmp45) tmp89 = tmp88 + tmp34 tmp90 = tl_math.log(tmp87) tmp91 = tmp90 + tmp76 tmp92 = tmp89 + tmp91 tmp93 = 20.0 tmp94 = tmp92 > tmp93 tmp95 = tl_math.exp(tmp92) tmp96 = libdevice.log1p(tmp95) tmp97 = tl.where(tmp94, tmp92, tmp96) tl.store(in_out_ptr0 + x0, tmp97, 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) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf5 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_add_clamp_min_logsumexp_mul_rsub_softplus_sub_0[grid (64)](buf5, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf5, class CircleLossNew(nn.Module): def __init__(self, gamma, m): super().__init__() self.gamma = gamma self.m = m def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
IntelLabs/MICSAS
CircleLoss
false
17,429
[ "MIT", "BSD-3-Clause" ]
7
4124991a683cc10004e403f3f3eb442f58616519
https://github.com/IntelLabs/MICSAS/tree/4124991a683cc10004e403f3f3eb442f58616519
GeneralRelu
import torch from torch import nn import torch.nn.functional as F from typing import * class GeneralRelu(nn.Module): def __init__(self, leak=None, sub=None, maxv=None): super().__init__() self.leak, self.sub, self.maxv = leak, sub, maxv def forward(self, x): x = F.leaky_relu(x, self.leak) if self.leak is not None else F.relu(x) if self.sub is not None: x.sub_(self.sub) if self.maxv is not None: x.clamp_max_(self.maxv) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn from typing 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_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) 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_relu_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class GeneralReluNew(nn.Module): def __init__(self, leak=None, sub=None, maxv=None): super().__init__() self.leak, self.sub, self.maxv = leak, sub, maxv def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ImadDabbura/fastai-courses
GeneralRelu
false
17,430
[ "Apache-2.0" ]
3
053637a2dd3b4ad6c35f97a13f3fba87af1d3940
https://github.com/ImadDabbura/fastai-courses/tree/053637a2dd3b4ad6c35f97a13f3fba87af1d3940
NetVLAD
import torch import numpy as np from torch import nn import torch.nn.functional as F from sklearn.neighbors import NearestNeighbors class NetVLAD(nn.Module): """NetVLAD layer implementation""" def __init__(self, num_clusters=64, dim=128, normalize_input=True, vladv2=False): """ Args: num_clusters : int The number of clusters dim : int Dimension of descriptors alpha : float Parameter of initialization. Larger value is harder assignment. normalize_input : bool If true, descriptor-wise L2 normalization is applied to input. vladv2 : bool If true, use vladv2 otherwise use vladv1 """ super(NetVLAD, self).__init__() self.num_clusters = num_clusters self.dim = dim self.alpha = 0 self.vladv2 = vladv2 self.normalize_input = normalize_input self.conv = nn.Conv2d(dim, num_clusters, kernel_size=(1, 1), bias= vladv2) self.centroids = nn.Parameter(torch.rand(num_clusters, dim)) def init_params(self, clsts, traindescs): if self.vladv2 is False: clstsAssign = clsts / np.linalg.norm(clsts, axis=1, keepdims=True) dots = np.dot(clstsAssign, traindescs.T) dots.sort(0) dots = dots[::-1, :] self.alpha = (-np.log(0.01) / np.mean(dots[0, :] - dots[1, :]) ).item() self.centroids = nn.Parameter(torch.from_numpy(clsts)) self.conv.weight = nn.Parameter(torch.from_numpy(self.alpha * clstsAssign).unsqueeze(2).unsqueeze(3)) self.conv.bias = None else: knn = NearestNeighbors(n_jobs=-1) knn.fit(traindescs) del traindescs dsSq = np.square(knn.kneighbors(clsts, 2)[1]) del knn self.alpha = (-np.log(0.01) / np.mean(dsSq[:, 1] - dsSq[:, 0]) ).item() self.centroids = nn.Parameter(torch.from_numpy(clsts)) del clsts, dsSq self.conv.weight = nn.Parameter((2.0 * self.alpha * self. centroids).unsqueeze(-1).unsqueeze(-1)) self.conv.bias = nn.Parameter(-self.alpha * self.centroids.norm (dim=1)) def forward(self, x): N, C = x.shape[:2] if self.normalize_input: x = F.normalize(x, p=2, dim=1) soft_assign = self.conv(x).view(N, self.num_clusters, -1) soft_assign = F.softmax(soft_assign, dim=1) x_flatten = x.view(N, C, -1) vlad = torch.zeros([N, self.num_clusters, C], dtype=x.dtype, layout =x.layout, device=x.device) for C in range(self.num_clusters): residual = x_flatten.unsqueeze(0).permute(1, 0, 2, 3 ) - self.centroids[C:C + 1, :].expand(x_flatten.size(-1), - 1, -1).permute(1, 2, 0).unsqueeze(0) residual *= soft_assign[:, C:C + 1, :].unsqueeze(2) vlad[:, C:C + 1, :] = residual.sum(dim=-1) vlad = F.normalize(vlad, p=2, dim=2) vlad = vlad.view(x.size(0), -1) vlad = F.normalize(vlad, p=2, dim=1) return vlad def get_inputs(): return [torch.rand([4, 128, 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, math as tl_math import numpy as np from torch import nn from sklearn.neighbors import NearestNeighbors assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_red_fused_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 4096 x1 = xindex // 4096 _tmp3 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) x3 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (x0 + 4096 * r2 + 524288 * x1), rmask, eviction_policy='evict_last', other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = _tmp3 + tmp2 _tmp3 = tl.where(rmask, tmp4, _tmp3) tmp3 = tl.sum(_tmp3, 1)[:, None] tl.store(out_ptr0 + x3, tmp3, None) @triton.jit def triton_poi_fused_div_sub_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, out_ptr11, out_ptr12, out_ptr13, out_ptr14, out_ptr15, out_ptr16, out_ptr17, out_ptr18, out_ptr19, out_ptr20, out_ptr21, out_ptr22, out_ptr23, out_ptr24, out_ptr25, out_ptr26, out_ptr27, out_ptr28, out_ptr29, out_ptr30, out_ptr31, out_ptr32, out_ptr33, out_ptr34, out_ptr35, out_ptr36, out_ptr37, out_ptr38, out_ptr39, out_ptr40, out_ptr41, out_ptr42, out_ptr43, out_ptr44, out_ptr45, out_ptr46, out_ptr47, out_ptr48, out_ptr49, out_ptr50, out_ptr51, out_ptr52, out_ptr53, out_ptr54, out_ptr55, out_ptr56, out_ptr57, out_ptr58, out_ptr59, out_ptr60, out_ptr61, out_ptr62, out_ptr63, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 4096 x2 = xindex // 524288 x1 = xindex // 4096 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr2 + (128 + x1), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr2 + (256 + x1), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + (384 + x1), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr2 + (512 + x1), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr2 + (640 + x1), None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr2 + (768 + x1), None, eviction_policy='evict_last') tmp18 = tl.load(in_ptr2 + (896 + x1), None, eviction_policy='evict_last') tmp20 = tl.load(in_ptr2 + (1024 + x1), None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr2 + (1152 + x1), None, eviction_policy='evict_last') tmp24 = tl.load(in_ptr2 + (1280 + x1), None, eviction_policy='evict_last') tmp26 = tl.load(in_ptr2 + (1408 + x1), None, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + (1536 + x1), None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + (1664 + x1), None, eviction_policy='evict_last') tmp32 = tl.load(in_ptr2 + (1792 + x1), None, eviction_policy='evict_last') tmp34 = tl.load(in_ptr2 + (1920 + x1), None, eviction_policy='evict_last') tmp36 = tl.load(in_ptr2 + (2048 + x1), None, eviction_policy='evict_last') tmp38 = tl.load(in_ptr2 + (2176 + x1), None, eviction_policy='evict_last') tmp40 = tl.load(in_ptr2 + (2304 + x1), None, eviction_policy='evict_last') tmp42 = tl.load(in_ptr2 + (2432 + x1), None, eviction_policy='evict_last') tmp44 = tl.load(in_ptr2 + (2560 + x1), None, eviction_policy='evict_last') tmp46 = tl.load(in_ptr2 + (2688 + x1), None, eviction_policy='evict_last') tmp48 = tl.load(in_ptr2 + (2816 + x1), None, eviction_policy='evict_last') tmp50 = tl.load(in_ptr2 + (2944 + x1), None, eviction_policy='evict_last') tmp52 = tl.load(in_ptr2 + (3072 + x1), None, eviction_policy='evict_last') tmp54 = tl.load(in_ptr2 + (3200 + x1), None, eviction_policy='evict_last') tmp56 = tl.load(in_ptr2 + (3328 + x1), None, eviction_policy='evict_last') tmp58 = tl.load(in_ptr2 + (3456 + x1), None, eviction_policy='evict_last') tmp60 = tl.load(in_ptr2 + (3584 + x1), None, eviction_policy='evict_last') tmp62 = tl.load(in_ptr2 + (3712 + x1), None, eviction_policy='evict_last') tmp64 = tl.load(in_ptr2 + (3840 + x1), None, eviction_policy='evict_last') tmp66 = tl.load(in_ptr2 + (3968 + x1), None, eviction_policy='evict_last') tmp68 = tl.load(in_ptr2 + (4096 + x1), None, eviction_policy='evict_last') tmp70 = tl.load(in_ptr2 + (4224 + x1), None, eviction_policy='evict_last') tmp72 = tl.load(in_ptr2 + (4352 + x1), None, eviction_policy='evict_last') tmp74 = tl.load(in_ptr2 + (4480 + x1), None, eviction_policy='evict_last') tmp76 = tl.load(in_ptr2 + (4608 + x1), None, eviction_policy='evict_last') tmp78 = tl.load(in_ptr2 + (4736 + x1), None, eviction_policy='evict_last') tmp80 = tl.load(in_ptr2 + (4864 + x1), None, eviction_policy='evict_last') tmp82 = tl.load(in_ptr2 + (4992 + x1), None, eviction_policy='evict_last') tmp84 = tl.load(in_ptr2 + (5120 + x1), None, eviction_policy='evict_last') tmp86 = tl.load(in_ptr2 + (5248 + x1), None, eviction_policy='evict_last') tmp88 = tl.load(in_ptr2 + (5376 + x1), None, eviction_policy='evict_last') tmp90 = tl.load(in_ptr2 + (5504 + x1), None, eviction_policy='evict_last') tmp92 = tl.load(in_ptr2 + (5632 + x1), None, eviction_policy='evict_last') tmp94 = tl.load(in_ptr2 + (5760 + x1), None, eviction_policy='evict_last') tmp96 = tl.load(in_ptr2 + (5888 + x1), None, eviction_policy='evict_last') tmp98 = tl.load(in_ptr2 + (6016 + x1), None, eviction_policy='evict_last') tmp100 = tl.load(in_ptr2 + (6144 + x1), None, eviction_policy='evict_last') tmp102 = tl.load(in_ptr2 + (6272 + x1), None, eviction_policy='evict_last') tmp104 = tl.load(in_ptr2 + (6400 + x1), None, eviction_policy='evict_last') tmp106 = tl.load(in_ptr2 + (6528 + x1), None, eviction_policy='evict_last') tmp108 = tl.load(in_ptr2 + (6656 + x1), None, eviction_policy='evict_last') tmp110 = tl.load(in_ptr2 + (6784 + x1), None, eviction_policy='evict_last') tmp112 = tl.load(in_ptr2 + (6912 + x1), None, eviction_policy='evict_last') tmp114 = tl.load(in_ptr2 + (7040 + x1), None, eviction_policy='evict_last') tmp116 = tl.load(in_ptr2 + (7168 + x1), None, eviction_policy='evict_last') tmp118 = tl.load(in_ptr2 + (7296 + x1), None, eviction_policy='evict_last') tmp120 = tl.load(in_ptr2 + (7424 + x1), None, eviction_policy='evict_last') tmp122 = tl.load(in_ptr2 + (7552 + x1), None, eviction_policy='evict_last') tmp124 = tl.load(in_ptr2 + (7680 + x1), None, eviction_policy='evict_last') tmp126 = tl.load(in_ptr2 + (7808 + x1), None, eviction_policy='evict_last') tmp128 = tl.load(in_ptr2 + (7936 + x1), None, eviction_policy='evict_last') tmp130 = tl.load(in_ptr2 + (8064 + x1), None, eviction_policy='evict_last') tmp2 = libdevice.sqrt(tmp1) tmp3 = 1e-12 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = tmp0 / tmp4 tmp7 = tmp5 - tmp6 tmp9 = tmp5 - tmp8 tmp11 = tmp5 - tmp10 tmp13 = tmp5 - tmp12 tmp15 = tmp5 - tmp14 tmp17 = tmp5 - tmp16 tmp19 = tmp5 - tmp18 tmp21 = tmp5 - tmp20 tmp23 = tmp5 - tmp22 tmp25 = tmp5 - tmp24 tmp27 = tmp5 - tmp26 tmp29 = tmp5 - tmp28 tmp31 = tmp5 - tmp30 tmp33 = tmp5 - tmp32 tmp35 = tmp5 - tmp34 tmp37 = tmp5 - tmp36 tmp39 = tmp5 - tmp38 tmp41 = tmp5 - tmp40 tmp43 = tmp5 - tmp42 tmp45 = tmp5 - tmp44 tmp47 = tmp5 - tmp46 tmp49 = tmp5 - tmp48 tmp51 = tmp5 - tmp50 tmp53 = tmp5 - tmp52 tmp55 = tmp5 - tmp54 tmp57 = tmp5 - tmp56 tmp59 = tmp5 - tmp58 tmp61 = tmp5 - tmp60 tmp63 = tmp5 - tmp62 tmp65 = tmp5 - tmp64 tmp67 = tmp5 - tmp66 tmp69 = tmp5 - tmp68 tmp71 = tmp5 - tmp70 tmp73 = tmp5 - tmp72 tmp75 = tmp5 - tmp74 tmp77 = tmp5 - tmp76 tmp79 = tmp5 - tmp78 tmp81 = tmp5 - tmp80 tmp83 = tmp5 - tmp82 tmp85 = tmp5 - tmp84 tmp87 = tmp5 - tmp86 tmp89 = tmp5 - tmp88 tmp91 = tmp5 - tmp90 tmp93 = tmp5 - tmp92 tmp95 = tmp5 - tmp94 tmp97 = tmp5 - tmp96 tmp99 = tmp5 - tmp98 tmp101 = tmp5 - tmp100 tmp103 = tmp5 - tmp102 tmp105 = tmp5 - tmp104 tmp107 = tmp5 - tmp106 tmp109 = tmp5 - tmp108 tmp111 = tmp5 - tmp110 tmp113 = tmp5 - tmp112 tmp115 = tmp5 - tmp114 tmp117 = tmp5 - tmp116 tmp119 = tmp5 - tmp118 tmp121 = tmp5 - tmp120 tmp123 = tmp5 - tmp122 tmp125 = tmp5 - tmp124 tmp127 = tmp5 - tmp126 tmp129 = tmp5 - tmp128 tmp131 = tmp5 - tmp130 tl.store(out_ptr0 + x3, tmp5, None) tl.store(out_ptr1 + x3, tmp7, None) tl.store(out_ptr2 + x3, tmp9, None) tl.store(out_ptr3 + x3, tmp11, None) tl.store(out_ptr4 + x3, tmp13, None) tl.store(out_ptr5 + x3, tmp15, None) tl.store(out_ptr6 + x3, tmp17, None) tl.store(out_ptr7 + x3, tmp19, None) tl.store(out_ptr8 + x3, tmp21, None) tl.store(out_ptr9 + x3, tmp23, None) tl.store(out_ptr10 + x3, tmp25, None) tl.store(out_ptr11 + x3, tmp27, None) tl.store(out_ptr12 + x3, tmp29, None) tl.store(out_ptr13 + x3, tmp31, None) tl.store(out_ptr14 + x3, tmp33, None) tl.store(out_ptr15 + x3, tmp35, None) tl.store(out_ptr16 + x3, tmp37, None) tl.store(out_ptr17 + x3, tmp39, None) tl.store(out_ptr18 + x3, tmp41, None) tl.store(out_ptr19 + x3, tmp43, None) tl.store(out_ptr20 + x3, tmp45, None) tl.store(out_ptr21 + x3, tmp47, None) tl.store(out_ptr22 + x3, tmp49, None) tl.store(out_ptr23 + x3, tmp51, None) tl.store(out_ptr24 + x3, tmp53, None) tl.store(out_ptr25 + x3, tmp55, None) tl.store(out_ptr26 + x3, tmp57, None) tl.store(out_ptr27 + x3, tmp59, None) tl.store(out_ptr28 + x3, tmp61, None) tl.store(out_ptr29 + x3, tmp63, None) tl.store(out_ptr30 + x3, tmp65, None) tl.store(out_ptr31 + x3, tmp67, None) tl.store(out_ptr32 + x3, tmp69, None) tl.store(out_ptr33 + x3, tmp71, None) tl.store(out_ptr34 + x3, tmp73, None) tl.store(out_ptr35 + x3, tmp75, None) tl.store(out_ptr36 + x3, tmp77, None) tl.store(out_ptr37 + x3, tmp79, None) tl.store(out_ptr38 + x3, tmp81, None) tl.store(out_ptr39 + x3, tmp83, None) tl.store(out_ptr40 + x3, tmp85, None) tl.store(out_ptr41 + x3, tmp87, None) tl.store(out_ptr42 + x3, tmp89, None) tl.store(out_ptr43 + x3, tmp91, None) tl.store(out_ptr44 + x3, tmp93, None) tl.store(out_ptr45 + x3, tmp95, None) tl.store(out_ptr46 + x3, tmp97, None) tl.store(out_ptr47 + x3, tmp99, None) tl.store(out_ptr48 + x3, tmp101, None) tl.store(out_ptr49 + x3, tmp103, None) tl.store(out_ptr50 + x3, tmp105, None) tl.store(out_ptr51 + x3, tmp107, None) tl.store(out_ptr52 + x3, tmp109, None) tl.store(out_ptr53 + x3, tmp111, None) tl.store(out_ptr54 + x3, tmp113, None) tl.store(out_ptr55 + x3, tmp115, None) tl.store(out_ptr56 + x3, tmp117, None) tl.store(out_ptr57 + x3, tmp119, None) tl.store(out_ptr58 + x3, tmp121, None) tl.store(out_ptr59 + x3, tmp123, None) tl.store(out_ptr60 + x3, tmp125, None) tl.store(out_ptr61 + x3, tmp127, None) tl.store(out_ptr62 + x3, tmp129, None) tl.store(out_ptr63 + x3, tmp131, None) @triton.jit def triton_per_fused__softmax_2(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 4096 x1 = xindex // 4096 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4096 * r2 + 262144 * x1), None) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = triton_helpers.max2(tmp1, 1)[:, None] tmp4 = tmp0 - tmp3 tmp5 = tl_math.exp(tmp4) tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = tl.sum(tmp6, 1)[:, None] tl.store(out_ptr0 + x3, tmp3, None) tl.store(out_ptr1 + x3, tmp8, None) @triton.jit def triton_red_fused_mul_sub_sum_3(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, in_ptr32, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, out_ptr11, out_ptr12, out_ptr13, out_ptr14, out_ptr15, out_ptr16, out_ptr17, out_ptr18, out_ptr19, out_ptr20, out_ptr21, out_ptr22, out_ptr23, out_ptr24, out_ptr25, out_ptr26, out_ptr27, out_ptr28, xnumel, rnumel, XBLOCK: tl. constexpr, RBLOCK: tl.constexpr): xnumel = 512 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x3 = xindex x0 = xindex % 128 tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') x1 = xindex // 128 _tmp11 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp20 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp29 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp38 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp47 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp56 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp65 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp74 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp83 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp92 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp101 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp110 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp119 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp128 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp137 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp146 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp155 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp164 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp173 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp182 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp191 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp200 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp209 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp218 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp227 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp236 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp245 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp254 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp263 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp3 = tl.load(in_ptr2 + (r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp4 = tl.load(in_ptr3 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.load(in_ptr4 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp13 = tl.load(in_ptr5 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp14 = tl.load(in_ptr2 + (4096 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp22 = tl.load(in_ptr6 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp23 = tl.load(in_ptr2 + (8192 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp31 = tl.load(in_ptr7 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp32 = tl.load(in_ptr2 + (12288 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp40 = tl.load(in_ptr8 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp41 = tl.load(in_ptr2 + (16384 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp49 = tl.load(in_ptr9 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp50 = tl.load(in_ptr2 + (20480 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp58 = tl.load(in_ptr10 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp59 = tl.load(in_ptr2 + (24576 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp67 = tl.load(in_ptr11 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp68 = tl.load(in_ptr2 + (28672 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp76 = tl.load(in_ptr12 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp77 = tl.load(in_ptr2 + (32768 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp85 = tl.load(in_ptr13 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp86 = tl.load(in_ptr2 + (36864 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp94 = tl.load(in_ptr14 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp95 = tl.load(in_ptr2 + (40960 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp103 = tl.load(in_ptr15 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp104 = tl.load(in_ptr2 + (45056 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp112 = tl.load(in_ptr16 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp113 = tl.load(in_ptr2 + (49152 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp121 = tl.load(in_ptr17 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp122 = tl.load(in_ptr2 + (53248 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp130 = tl.load(in_ptr18 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp131 = tl.load(in_ptr2 + (57344 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp139 = tl.load(in_ptr19 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp140 = tl.load(in_ptr2 + (61440 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp148 = tl.load(in_ptr20 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp149 = tl.load(in_ptr2 + (65536 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp157 = tl.load(in_ptr21 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp158 = tl.load(in_ptr2 + (69632 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp166 = tl.load(in_ptr22 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp167 = tl.load(in_ptr2 + (73728 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp175 = tl.load(in_ptr23 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp176 = tl.load(in_ptr2 + (77824 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp184 = tl.load(in_ptr24 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp185 = tl.load(in_ptr2 + (81920 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp193 = tl.load(in_ptr25 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp194 = tl.load(in_ptr2 + (86016 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp202 = tl.load(in_ptr26 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp203 = tl.load(in_ptr2 + (90112 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp211 = tl.load(in_ptr27 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp212 = tl.load(in_ptr2 + (94208 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp220 = tl.load(in_ptr28 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp221 = tl.load(in_ptr2 + (98304 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp229 = tl.load(in_ptr29 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp230 = tl.load(in_ptr2 + (102400 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp238 = tl.load(in_ptr30 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp239 = tl.load(in_ptr2 + (106496 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp247 = tl.load(in_ptr31 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp248 = tl.load(in_ptr2 + (110592 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp256 = tl.load(in_ptr32 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp257 = tl.load(in_ptr2 + (114688 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = tmp0 - tmp1 tmp5 = tmp3 - tmp4 tmp6 = tl_math.exp(tmp5) tmp8 = tmp6 / tmp7 tmp9 = tmp2 * tmp8 tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp12 = _tmp11 + tmp10 _tmp11 = tl.where(rmask & xmask, tmp12, _tmp11) tmp15 = tmp14 - tmp4 tmp16 = tl_math.exp(tmp15) tmp17 = tmp16 / tmp7 tmp18 = tmp13 * tmp17 tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK]) tmp21 = _tmp20 + tmp19 _tmp20 = tl.where(rmask & xmask, tmp21, _tmp20) tmp24 = tmp23 - tmp4 tmp25 = tl_math.exp(tmp24) tmp26 = tmp25 / tmp7 tmp27 = tmp22 * tmp26 tmp28 = tl.broadcast_to(tmp27, [XBLOCK, RBLOCK]) tmp30 = _tmp29 + tmp28 _tmp29 = tl.where(rmask & xmask, tmp30, _tmp29) tmp33 = tmp32 - tmp4 tmp34 = tl_math.exp(tmp33) tmp35 = tmp34 / tmp7 tmp36 = tmp31 * tmp35 tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK]) tmp39 = _tmp38 + tmp37 _tmp38 = tl.where(rmask & xmask, tmp39, _tmp38) tmp42 = tmp41 - tmp4 tmp43 = tl_math.exp(tmp42) tmp44 = tmp43 / tmp7 tmp45 = tmp40 * tmp44 tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK]) tmp48 = _tmp47 + tmp46 _tmp47 = tl.where(rmask & xmask, tmp48, _tmp47) tmp51 = tmp50 - tmp4 tmp52 = tl_math.exp(tmp51) tmp53 = tmp52 / tmp7 tmp54 = tmp49 * tmp53 tmp55 = tl.broadcast_to(tmp54, [XBLOCK, RBLOCK]) tmp57 = _tmp56 + tmp55 _tmp56 = tl.where(rmask & xmask, tmp57, _tmp56) tmp60 = tmp59 - tmp4 tmp61 = tl_math.exp(tmp60) tmp62 = tmp61 / tmp7 tmp63 = tmp58 * tmp62 tmp64 = tl.broadcast_to(tmp63, [XBLOCK, RBLOCK]) tmp66 = _tmp65 + tmp64 _tmp65 = tl.where(rmask & xmask, tmp66, _tmp65) tmp69 = tmp68 - tmp4 tmp70 = tl_math.exp(tmp69) tmp71 = tmp70 / tmp7 tmp72 = tmp67 * tmp71 tmp73 = tl.broadcast_to(tmp72, [XBLOCK, RBLOCK]) tmp75 = _tmp74 + tmp73 _tmp74 = tl.where(rmask & xmask, tmp75, _tmp74) tmp78 = tmp77 - tmp4 tmp79 = tl_math.exp(tmp78) tmp80 = tmp79 / tmp7 tmp81 = tmp76 * tmp80 tmp82 = tl.broadcast_to(tmp81, [XBLOCK, RBLOCK]) tmp84 = _tmp83 + tmp82 _tmp83 = tl.where(rmask & xmask, tmp84, _tmp83) tmp87 = tmp86 - tmp4 tmp88 = tl_math.exp(tmp87) tmp89 = tmp88 / tmp7 tmp90 = tmp85 * tmp89 tmp91 = tl.broadcast_to(tmp90, [XBLOCK, RBLOCK]) tmp93 = _tmp92 + tmp91 _tmp92 = tl.where(rmask & xmask, tmp93, _tmp92) tmp96 = tmp95 - tmp4 tmp97 = tl_math.exp(tmp96) tmp98 = tmp97 / tmp7 tmp99 = tmp94 * tmp98 tmp100 = tl.broadcast_to(tmp99, [XBLOCK, RBLOCK]) tmp102 = _tmp101 + tmp100 _tmp101 = tl.where(rmask & xmask, tmp102, _tmp101) tmp105 = tmp104 - tmp4 tmp106 = tl_math.exp(tmp105) tmp107 = tmp106 / tmp7 tmp108 = tmp103 * tmp107 tmp109 = tl.broadcast_to(tmp108, [XBLOCK, RBLOCK]) tmp111 = _tmp110 + tmp109 _tmp110 = tl.where(rmask & xmask, tmp111, _tmp110) tmp114 = tmp113 - tmp4 tmp115 = tl_math.exp(tmp114) tmp116 = tmp115 / tmp7 tmp117 = tmp112 * tmp116 tmp118 = tl.broadcast_to(tmp117, [XBLOCK, RBLOCK]) tmp120 = _tmp119 + tmp118 _tmp119 = tl.where(rmask & xmask, tmp120, _tmp119) tmp123 = tmp122 - tmp4 tmp124 = tl_math.exp(tmp123) tmp125 = tmp124 / tmp7 tmp126 = tmp121 * tmp125 tmp127 = tl.broadcast_to(tmp126, [XBLOCK, RBLOCK]) tmp129 = _tmp128 + tmp127 _tmp128 = tl.where(rmask & xmask, tmp129, _tmp128) tmp132 = tmp131 - tmp4 tmp133 = tl_math.exp(tmp132) tmp134 = tmp133 / tmp7 tmp135 = tmp130 * tmp134 tmp136 = tl.broadcast_to(tmp135, [XBLOCK, RBLOCK]) tmp138 = _tmp137 + tmp136 _tmp137 = tl.where(rmask & xmask, tmp138, _tmp137) tmp141 = tmp140 - tmp4 tmp142 = tl_math.exp(tmp141) tmp143 = tmp142 / tmp7 tmp144 = tmp139 * tmp143 tmp145 = tl.broadcast_to(tmp144, [XBLOCK, RBLOCK]) tmp147 = _tmp146 + tmp145 _tmp146 = tl.where(rmask & xmask, tmp147, _tmp146) tmp150 = tmp149 - tmp4 tmp151 = tl_math.exp(tmp150) tmp152 = tmp151 / tmp7 tmp153 = tmp148 * tmp152 tmp154 = tl.broadcast_to(tmp153, [XBLOCK, RBLOCK]) tmp156 = _tmp155 + tmp154 _tmp155 = tl.where(rmask & xmask, tmp156, _tmp155) tmp159 = tmp158 - tmp4 tmp160 = tl_math.exp(tmp159) tmp161 = tmp160 / tmp7 tmp162 = tmp157 * tmp161 tmp163 = tl.broadcast_to(tmp162, [XBLOCK, RBLOCK]) tmp165 = _tmp164 + tmp163 _tmp164 = tl.where(rmask & xmask, tmp165, _tmp164) tmp168 = tmp167 - tmp4 tmp169 = tl_math.exp(tmp168) tmp170 = tmp169 / tmp7 tmp171 = tmp166 * tmp170 tmp172 = tl.broadcast_to(tmp171, [XBLOCK, RBLOCK]) tmp174 = _tmp173 + tmp172 _tmp173 = tl.where(rmask & xmask, tmp174, _tmp173) tmp177 = tmp176 - tmp4 tmp178 = tl_math.exp(tmp177) tmp179 = tmp178 / tmp7 tmp180 = tmp175 * tmp179 tmp181 = tl.broadcast_to(tmp180, [XBLOCK, RBLOCK]) tmp183 = _tmp182 + tmp181 _tmp182 = tl.where(rmask & xmask, tmp183, _tmp182) tmp186 = tmp185 - tmp4 tmp187 = tl_math.exp(tmp186) tmp188 = tmp187 / tmp7 tmp189 = tmp184 * tmp188 tmp190 = tl.broadcast_to(tmp189, [XBLOCK, RBLOCK]) tmp192 = _tmp191 + tmp190 _tmp191 = tl.where(rmask & xmask, tmp192, _tmp191) tmp195 = tmp194 - tmp4 tmp196 = tl_math.exp(tmp195) tmp197 = tmp196 / tmp7 tmp198 = tmp193 * tmp197 tmp199 = tl.broadcast_to(tmp198, [XBLOCK, RBLOCK]) tmp201 = _tmp200 + tmp199 _tmp200 = tl.where(rmask & xmask, tmp201, _tmp200) tmp204 = tmp203 - tmp4 tmp205 = tl_math.exp(tmp204) tmp206 = tmp205 / tmp7 tmp207 = tmp202 * tmp206 tmp208 = tl.broadcast_to(tmp207, [XBLOCK, RBLOCK]) tmp210 = _tmp209 + tmp208 _tmp209 = tl.where(rmask & xmask, tmp210, _tmp209) tmp213 = tmp212 - tmp4 tmp214 = tl_math.exp(tmp213) tmp215 = tmp214 / tmp7 tmp216 = tmp211 * tmp215 tmp217 = tl.broadcast_to(tmp216, [XBLOCK, RBLOCK]) tmp219 = _tmp218 + tmp217 _tmp218 = tl.where(rmask & xmask, tmp219, _tmp218) tmp222 = tmp221 - tmp4 tmp223 = tl_math.exp(tmp222) tmp224 = tmp223 / tmp7 tmp225 = tmp220 * tmp224 tmp226 = tl.broadcast_to(tmp225, [XBLOCK, RBLOCK]) tmp228 = _tmp227 + tmp226 _tmp227 = tl.where(rmask & xmask, tmp228, _tmp227) tmp231 = tmp230 - tmp4 tmp232 = tl_math.exp(tmp231) tmp233 = tmp232 / tmp7 tmp234 = tmp229 * tmp233 tmp235 = tl.broadcast_to(tmp234, [XBLOCK, RBLOCK]) tmp237 = _tmp236 + tmp235 _tmp236 = tl.where(rmask & xmask, tmp237, _tmp236) tmp240 = tmp239 - tmp4 tmp241 = tl_math.exp(tmp240) tmp242 = tmp241 / tmp7 tmp243 = tmp238 * tmp242 tmp244 = tl.broadcast_to(tmp243, [XBLOCK, RBLOCK]) tmp246 = _tmp245 + tmp244 _tmp245 = tl.where(rmask & xmask, tmp246, _tmp245) tmp249 = tmp248 - tmp4 tmp250 = tl_math.exp(tmp249) tmp251 = tmp250 / tmp7 tmp252 = tmp247 * tmp251 tmp253 = tl.broadcast_to(tmp252, [XBLOCK, RBLOCK]) tmp255 = _tmp254 + tmp253 _tmp254 = tl.where(rmask & xmask, tmp255, _tmp254) tmp258 = tmp257 - tmp4 tmp259 = tl_math.exp(tmp258) tmp260 = tmp259 / tmp7 tmp261 = tmp256 * tmp260 tmp262 = tl.broadcast_to(tmp261, [XBLOCK, RBLOCK]) tmp264 = _tmp263 + tmp262 _tmp263 = tl.where(rmask & xmask, tmp264, _tmp263) tmp11 = tl.sum(_tmp11, 1)[:, None] tl.store(out_ptr0 + x3, tmp11, xmask) tmp20 = tl.sum(_tmp20, 1)[:, None] tl.store(out_ptr1 + x3, tmp20, xmask) tmp29 = tl.sum(_tmp29, 1)[:, None] tl.store(out_ptr2 + x3, tmp29, xmask) tmp38 = tl.sum(_tmp38, 1)[:, None] tl.store(out_ptr3 + x3, tmp38, xmask) tmp47 = tl.sum(_tmp47, 1)[:, None] tl.store(out_ptr4 + x3, tmp47, xmask) tmp56 = tl.sum(_tmp56, 1)[:, None] tl.store(out_ptr5 + x3, tmp56, xmask) tmp65 = tl.sum(_tmp65, 1)[:, None] tl.store(out_ptr6 + x3, tmp65, xmask) tmp74 = tl.sum(_tmp74, 1)[:, None] tl.store(out_ptr7 + x3, tmp74, xmask) tmp83 = tl.sum(_tmp83, 1)[:, None] tl.store(out_ptr8 + x3, tmp83, xmask) tmp92 = tl.sum(_tmp92, 1)[:, None] tl.store(out_ptr9 + x3, tmp92, xmask) tmp101 = tl.sum(_tmp101, 1)[:, None] tl.store(out_ptr10 + x3, tmp101, xmask) tmp110 = tl.sum(_tmp110, 1)[:, None] tl.store(out_ptr11 + x3, tmp110, xmask) tmp119 = tl.sum(_tmp119, 1)[:, None] tl.store(out_ptr12 + x3, tmp119, xmask) tmp128 = tl.sum(_tmp128, 1)[:, None] tl.store(out_ptr13 + x3, tmp128, xmask) tmp137 = tl.sum(_tmp137, 1)[:, None] tl.store(out_ptr14 + x3, tmp137, xmask) tmp146 = tl.sum(_tmp146, 1)[:, None] tl.store(out_ptr15 + x3, tmp146, xmask) tmp155 = tl.sum(_tmp155, 1)[:, None] tl.store(out_ptr16 + x3, tmp155, xmask) tmp164 = tl.sum(_tmp164, 1)[:, None] tl.store(out_ptr17 + x3, tmp164, xmask) tmp173 = tl.sum(_tmp173, 1)[:, None] tl.store(out_ptr18 + x3, tmp173, xmask) tmp182 = tl.sum(_tmp182, 1)[:, None] tl.store(out_ptr19 + x3, tmp182, xmask) tmp191 = tl.sum(_tmp191, 1)[:, None] tl.store(out_ptr20 + x3, tmp191, xmask) tmp200 = tl.sum(_tmp200, 1)[:, None] tl.store(out_ptr21 + x3, tmp200, xmask) tmp209 = tl.sum(_tmp209, 1)[:, None] tl.store(out_ptr22 + x3, tmp209, xmask) tmp218 = tl.sum(_tmp218, 1)[:, None] tl.store(out_ptr23 + x3, tmp218, xmask) tmp227 = tl.sum(_tmp227, 1)[:, None] tl.store(out_ptr24 + x3, tmp227, xmask) tmp236 = tl.sum(_tmp236, 1)[:, None] tl.store(out_ptr25 + x3, tmp236, xmask) tmp245 = tl.sum(_tmp245, 1)[:, None] tl.store(out_ptr26 + x3, tmp245, xmask) tmp254 = tl.sum(_tmp254, 1)[:, None] tl.store(out_ptr27 + x3, tmp254, xmask) tmp263 = tl.sum(_tmp263, 1)[:, None] tl.store(out_ptr28 + x3, tmp263, xmask) @triton.jit def triton_red_fused_mul_sum_4(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, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, out_ptr11, out_ptr12, out_ptr13, out_ptr14, out_ptr15, out_ptr16, out_ptr17, out_ptr18, out_ptr19, out_ptr20, out_ptr21, out_ptr22, out_ptr23, out_ptr24, out_ptr25, out_ptr26, out_ptr27, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 512 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x3 = xindex x1 = xindex // 128 _tmp9 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp18 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp27 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp36 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp45 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp54 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp63 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp72 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp81 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp90 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp99 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp108 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp117 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp126 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp135 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp144 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp153 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp162 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp171 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp180 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp189 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp198 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp207 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp216 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp225 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp234 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp243 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp252 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr1 + (118784 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = tl.load(in_ptr2 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp5 = tl.load(in_ptr3 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tl.load(in_ptr4 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp12 = tl.load(in_ptr1 + (122880 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tl.load(in_ptr5 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp21 = tl.load(in_ptr1 + (126976 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp29 = tl.load(in_ptr6 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp30 = tl.load(in_ptr1 + (131072 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp38 = tl.load(in_ptr7 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp39 = tl.load(in_ptr1 + (135168 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp47 = tl.load(in_ptr8 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp48 = tl.load(in_ptr1 + (139264 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp56 = tl.load(in_ptr9 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp57 = tl.load(in_ptr1 + (143360 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp65 = tl.load(in_ptr10 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp66 = tl.load(in_ptr1 + (147456 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp74 = tl.load(in_ptr11 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp75 = tl.load(in_ptr1 + (151552 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp83 = tl.load(in_ptr12 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp84 = tl.load(in_ptr1 + (155648 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp92 = tl.load(in_ptr13 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp93 = tl.load(in_ptr1 + (159744 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp101 = tl.load(in_ptr14 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp102 = tl.load(in_ptr1 + (163840 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp110 = tl.load(in_ptr15 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp111 = tl.load(in_ptr1 + (167936 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp119 = tl.load(in_ptr16 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp120 = tl.load(in_ptr1 + (172032 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp128 = tl.load(in_ptr17 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp129 = tl.load(in_ptr1 + (176128 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp137 = tl.load(in_ptr18 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp138 = tl.load(in_ptr1 + (180224 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp146 = tl.load(in_ptr19 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp147 = tl.load(in_ptr1 + (184320 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp155 = tl.load(in_ptr20 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp156 = tl.load(in_ptr1 + (188416 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp164 = tl.load(in_ptr21 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp165 = tl.load(in_ptr1 + (192512 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp173 = tl.load(in_ptr22 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp174 = tl.load(in_ptr1 + (196608 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp182 = tl.load(in_ptr23 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp183 = tl.load(in_ptr1 + (200704 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp191 = tl.load(in_ptr24 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp192 = tl.load(in_ptr1 + (204800 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp200 = tl.load(in_ptr25 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp201 = tl.load(in_ptr1 + (208896 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp209 = tl.load(in_ptr26 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp210 = tl.load(in_ptr1 + (212992 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp218 = tl.load(in_ptr27 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp219 = tl.load(in_ptr1 + (217088 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp227 = tl.load(in_ptr28 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp228 = tl.load(in_ptr1 + (221184 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp236 = tl.load(in_ptr29 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp237 = tl.load(in_ptr1 + (225280 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp245 = tl.load(in_ptr30 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp246 = tl.load(in_ptr1 + (229376 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp3 = tmp1 - tmp2 tmp4 = tl_math.exp(tmp3) tmp6 = tmp4 / tmp5 tmp7 = tmp0 * tmp6 tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = _tmp9 + tmp8 _tmp9 = tl.where(rmask & xmask, tmp10, _tmp9) tmp13 = tmp12 - tmp2 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 * tmp15 tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK]) tmp19 = _tmp18 + tmp17 _tmp18 = tl.where(rmask & xmask, tmp19, _tmp18) tmp22 = tmp21 - tmp2 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp25 = tmp20 * tmp24 tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK]) tmp28 = _tmp27 + tmp26 _tmp27 = tl.where(rmask & xmask, tmp28, _tmp27) tmp31 = tmp30 - tmp2 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp34 = tmp29 * tmp33 tmp35 = tl.broadcast_to(tmp34, [XBLOCK, RBLOCK]) tmp37 = _tmp36 + tmp35 _tmp36 = tl.where(rmask & xmask, tmp37, _tmp36) tmp40 = tmp39 - tmp2 tmp41 = tl_math.exp(tmp40) tmp42 = tmp41 / tmp5 tmp43 = tmp38 * tmp42 tmp44 = tl.broadcast_to(tmp43, [XBLOCK, RBLOCK]) tmp46 = _tmp45 + tmp44 _tmp45 = tl.where(rmask & xmask, tmp46, _tmp45) tmp49 = tmp48 - tmp2 tmp50 = tl_math.exp(tmp49) tmp51 = tmp50 / tmp5 tmp52 = tmp47 * tmp51 tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK]) tmp55 = _tmp54 + tmp53 _tmp54 = tl.where(rmask & xmask, tmp55, _tmp54) tmp58 = tmp57 - tmp2 tmp59 = tl_math.exp(tmp58) tmp60 = tmp59 / tmp5 tmp61 = tmp56 * tmp60 tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK]) tmp64 = _tmp63 + tmp62 _tmp63 = tl.where(rmask & xmask, tmp64, _tmp63) tmp67 = tmp66 - tmp2 tmp68 = tl_math.exp(tmp67) tmp69 = tmp68 / tmp5 tmp70 = tmp65 * tmp69 tmp71 = tl.broadcast_to(tmp70, [XBLOCK, RBLOCK]) tmp73 = _tmp72 + tmp71 _tmp72 = tl.where(rmask & xmask, tmp73, _tmp72) tmp76 = tmp75 - tmp2 tmp77 = tl_math.exp(tmp76) tmp78 = tmp77 / tmp5 tmp79 = tmp74 * tmp78 tmp80 = tl.broadcast_to(tmp79, [XBLOCK, RBLOCK]) tmp82 = _tmp81 + tmp80 _tmp81 = tl.where(rmask & xmask, tmp82, _tmp81) tmp85 = tmp84 - tmp2 tmp86 = tl_math.exp(tmp85) tmp87 = tmp86 / tmp5 tmp88 = tmp83 * tmp87 tmp89 = tl.broadcast_to(tmp88, [XBLOCK, RBLOCK]) tmp91 = _tmp90 + tmp89 _tmp90 = tl.where(rmask & xmask, tmp91, _tmp90) tmp94 = tmp93 - tmp2 tmp95 = tl_math.exp(tmp94) tmp96 = tmp95 / tmp5 tmp97 = tmp92 * tmp96 tmp98 = tl.broadcast_to(tmp97, [XBLOCK, RBLOCK]) tmp100 = _tmp99 + tmp98 _tmp99 = tl.where(rmask & xmask, tmp100, _tmp99) tmp103 = tmp102 - tmp2 tmp104 = tl_math.exp(tmp103) tmp105 = tmp104 / tmp5 tmp106 = tmp101 * tmp105 tmp107 = tl.broadcast_to(tmp106, [XBLOCK, RBLOCK]) tmp109 = _tmp108 + tmp107 _tmp108 = tl.where(rmask & xmask, tmp109, _tmp108) tmp112 = tmp111 - tmp2 tmp113 = tl_math.exp(tmp112) tmp114 = tmp113 / tmp5 tmp115 = tmp110 * tmp114 tmp116 = tl.broadcast_to(tmp115, [XBLOCK, RBLOCK]) tmp118 = _tmp117 + tmp116 _tmp117 = tl.where(rmask & xmask, tmp118, _tmp117) tmp121 = tmp120 - tmp2 tmp122 = tl_math.exp(tmp121) tmp123 = tmp122 / tmp5 tmp124 = tmp119 * tmp123 tmp125 = tl.broadcast_to(tmp124, [XBLOCK, RBLOCK]) tmp127 = _tmp126 + tmp125 _tmp126 = tl.where(rmask & xmask, tmp127, _tmp126) tmp130 = tmp129 - tmp2 tmp131 = tl_math.exp(tmp130) tmp132 = tmp131 / tmp5 tmp133 = tmp128 * tmp132 tmp134 = tl.broadcast_to(tmp133, [XBLOCK, RBLOCK]) tmp136 = _tmp135 + tmp134 _tmp135 = tl.where(rmask & xmask, tmp136, _tmp135) tmp139 = tmp138 - tmp2 tmp140 = tl_math.exp(tmp139) tmp141 = tmp140 / tmp5 tmp142 = tmp137 * tmp141 tmp143 = tl.broadcast_to(tmp142, [XBLOCK, RBLOCK]) tmp145 = _tmp144 + tmp143 _tmp144 = tl.where(rmask & xmask, tmp145, _tmp144) tmp148 = tmp147 - tmp2 tmp149 = tl_math.exp(tmp148) tmp150 = tmp149 / tmp5 tmp151 = tmp146 * tmp150 tmp152 = tl.broadcast_to(tmp151, [XBLOCK, RBLOCK]) tmp154 = _tmp153 + tmp152 _tmp153 = tl.where(rmask & xmask, tmp154, _tmp153) tmp157 = tmp156 - tmp2 tmp158 = tl_math.exp(tmp157) tmp159 = tmp158 / tmp5 tmp160 = tmp155 * tmp159 tmp161 = tl.broadcast_to(tmp160, [XBLOCK, RBLOCK]) tmp163 = _tmp162 + tmp161 _tmp162 = tl.where(rmask & xmask, tmp163, _tmp162) tmp166 = tmp165 - tmp2 tmp167 = tl_math.exp(tmp166) tmp168 = tmp167 / tmp5 tmp169 = tmp164 * tmp168 tmp170 = tl.broadcast_to(tmp169, [XBLOCK, RBLOCK]) tmp172 = _tmp171 + tmp170 _tmp171 = tl.where(rmask & xmask, tmp172, _tmp171) tmp175 = tmp174 - tmp2 tmp176 = tl_math.exp(tmp175) tmp177 = tmp176 / tmp5 tmp178 = tmp173 * tmp177 tmp179 = tl.broadcast_to(tmp178, [XBLOCK, RBLOCK]) tmp181 = _tmp180 + tmp179 _tmp180 = tl.where(rmask & xmask, tmp181, _tmp180) tmp184 = tmp183 - tmp2 tmp185 = tl_math.exp(tmp184) tmp186 = tmp185 / tmp5 tmp187 = tmp182 * tmp186 tmp188 = tl.broadcast_to(tmp187, [XBLOCK, RBLOCK]) tmp190 = _tmp189 + tmp188 _tmp189 = tl.where(rmask & xmask, tmp190, _tmp189) tmp193 = tmp192 - tmp2 tmp194 = tl_math.exp(tmp193) tmp195 = tmp194 / tmp5 tmp196 = tmp191 * tmp195 tmp197 = tl.broadcast_to(tmp196, [XBLOCK, RBLOCK]) tmp199 = _tmp198 + tmp197 _tmp198 = tl.where(rmask & xmask, tmp199, _tmp198) tmp202 = tmp201 - tmp2 tmp203 = tl_math.exp(tmp202) tmp204 = tmp203 / tmp5 tmp205 = tmp200 * tmp204 tmp206 = tl.broadcast_to(tmp205, [XBLOCK, RBLOCK]) tmp208 = _tmp207 + tmp206 _tmp207 = tl.where(rmask & xmask, tmp208, _tmp207) tmp211 = tmp210 - tmp2 tmp212 = tl_math.exp(tmp211) tmp213 = tmp212 / tmp5 tmp214 = tmp209 * tmp213 tmp215 = tl.broadcast_to(tmp214, [XBLOCK, RBLOCK]) tmp217 = _tmp216 + tmp215 _tmp216 = tl.where(rmask & xmask, tmp217, _tmp216) tmp220 = tmp219 - tmp2 tmp221 = tl_math.exp(tmp220) tmp222 = tmp221 / tmp5 tmp223 = tmp218 * tmp222 tmp224 = tl.broadcast_to(tmp223, [XBLOCK, RBLOCK]) tmp226 = _tmp225 + tmp224 _tmp225 = tl.where(rmask & xmask, tmp226, _tmp225) tmp229 = tmp228 - tmp2 tmp230 = tl_math.exp(tmp229) tmp231 = tmp230 / tmp5 tmp232 = tmp227 * tmp231 tmp233 = tl.broadcast_to(tmp232, [XBLOCK, RBLOCK]) tmp235 = _tmp234 + tmp233 _tmp234 = tl.where(rmask & xmask, tmp235, _tmp234) tmp238 = tmp237 - tmp2 tmp239 = tl_math.exp(tmp238) tmp240 = tmp239 / tmp5 tmp241 = tmp236 * tmp240 tmp242 = tl.broadcast_to(tmp241, [XBLOCK, RBLOCK]) tmp244 = _tmp243 + tmp242 _tmp243 = tl.where(rmask & xmask, tmp244, _tmp243) tmp247 = tmp246 - tmp2 tmp248 = tl_math.exp(tmp247) tmp249 = tmp248 / tmp5 tmp250 = tmp245 * tmp249 tmp251 = tl.broadcast_to(tmp250, [XBLOCK, RBLOCK]) tmp253 = _tmp252 + tmp251 _tmp252 = tl.where(rmask & xmask, tmp253, _tmp252) tmp9 = tl.sum(_tmp9, 1)[:, None] tl.store(out_ptr0 + x3, tmp9, xmask) tmp18 = tl.sum(_tmp18, 1)[:, None] tl.store(out_ptr1 + x3, tmp18, xmask) tmp27 = tl.sum(_tmp27, 1)[:, None] tl.store(out_ptr2 + x3, tmp27, xmask) tmp36 = tl.sum(_tmp36, 1)[:, None] tl.store(out_ptr3 + x3, tmp36, xmask) tmp45 = tl.sum(_tmp45, 1)[:, None] tl.store(out_ptr4 + x3, tmp45, xmask) tmp54 = tl.sum(_tmp54, 1)[:, None] tl.store(out_ptr5 + x3, tmp54, xmask) tmp63 = tl.sum(_tmp63, 1)[:, None] tl.store(out_ptr6 + x3, tmp63, xmask) tmp72 = tl.sum(_tmp72, 1)[:, None] tl.store(out_ptr7 + x3, tmp72, xmask) tmp81 = tl.sum(_tmp81, 1)[:, None] tl.store(out_ptr8 + x3, tmp81, xmask) tmp90 = tl.sum(_tmp90, 1)[:, None] tl.store(out_ptr9 + x3, tmp90, xmask) tmp99 = tl.sum(_tmp99, 1)[:, None] tl.store(out_ptr10 + x3, tmp99, xmask) tmp108 = tl.sum(_tmp108, 1)[:, None] tl.store(out_ptr11 + x3, tmp108, xmask) tmp117 = tl.sum(_tmp117, 1)[:, None] tl.store(out_ptr12 + x3, tmp117, xmask) tmp126 = tl.sum(_tmp126, 1)[:, None] tl.store(out_ptr13 + x3, tmp126, xmask) tmp135 = tl.sum(_tmp135, 1)[:, None] tl.store(out_ptr14 + x3, tmp135, xmask) tmp144 = tl.sum(_tmp144, 1)[:, None] tl.store(out_ptr15 + x3, tmp144, xmask) tmp153 = tl.sum(_tmp153, 1)[:, None] tl.store(out_ptr16 + x3, tmp153, xmask) tmp162 = tl.sum(_tmp162, 1)[:, None] tl.store(out_ptr17 + x3, tmp162, xmask) tmp171 = tl.sum(_tmp171, 1)[:, None] tl.store(out_ptr18 + x3, tmp171, xmask) tmp180 = tl.sum(_tmp180, 1)[:, None] tl.store(out_ptr19 + x3, tmp180, xmask) tmp189 = tl.sum(_tmp189, 1)[:, None] tl.store(out_ptr20 + x3, tmp189, xmask) tmp198 = tl.sum(_tmp198, 1)[:, None] tl.store(out_ptr21 + x3, tmp198, xmask) tmp207 = tl.sum(_tmp207, 1)[:, None] tl.store(out_ptr22 + x3, tmp207, xmask) tmp216 = tl.sum(_tmp216, 1)[:, None] tl.store(out_ptr23 + x3, tmp216, xmask) tmp225 = tl.sum(_tmp225, 1)[:, None] tl.store(out_ptr24 + x3, tmp225, xmask) tmp234 = tl.sum(_tmp234, 1)[:, None] tl.store(out_ptr25 + x3, tmp234, xmask) tmp243 = tl.sum(_tmp243, 1)[:, None] tl.store(out_ptr26 + x3, tmp243, xmask) tmp252 = tl.sum(_tmp252, 1)[:, None] tl.store(out_ptr27 + x3, tmp252, xmask) @triton.jit def triton_red_fused_mul_sum_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 512 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x3 = xindex x1 = xindex // 128 _tmp9 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp18 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp27 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp36 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp45 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp54 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp63 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr1 + (233472 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = tl.load(in_ptr2 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp5 = tl.load(in_ptr3 + (r2 + 4096 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tl.load(in_ptr4 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp12 = tl.load(in_ptr1 + (237568 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tl.load(in_ptr5 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp21 = tl.load(in_ptr1 + (241664 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp29 = tl.load(in_ptr6 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp30 = tl.load(in_ptr1 + (245760 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp38 = tl.load(in_ptr7 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp39 = tl.load(in_ptr1 + (249856 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp47 = tl.load(in_ptr8 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp48 = tl.load(in_ptr1 + (253952 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp56 = tl.load(in_ptr9 + (r2 + 4096 * x3), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp57 = tl.load(in_ptr1 + (258048 + r2 + 262144 * x1), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp3 = tmp1 - tmp2 tmp4 = tl_math.exp(tmp3) tmp6 = tmp4 / tmp5 tmp7 = tmp0 * tmp6 tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = _tmp9 + tmp8 _tmp9 = tl.where(rmask & xmask, tmp10, _tmp9) tmp13 = tmp12 - tmp2 tmp14 = tl_math.exp(tmp13) tmp15 = tmp14 / tmp5 tmp16 = tmp11 * tmp15 tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK]) tmp19 = _tmp18 + tmp17 _tmp18 = tl.where(rmask & xmask, tmp19, _tmp18) tmp22 = tmp21 - tmp2 tmp23 = tl_math.exp(tmp22) tmp24 = tmp23 / tmp5 tmp25 = tmp20 * tmp24 tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK]) tmp28 = _tmp27 + tmp26 _tmp27 = tl.where(rmask & xmask, tmp28, _tmp27) tmp31 = tmp30 - tmp2 tmp32 = tl_math.exp(tmp31) tmp33 = tmp32 / tmp5 tmp34 = tmp29 * tmp33 tmp35 = tl.broadcast_to(tmp34, [XBLOCK, RBLOCK]) tmp37 = _tmp36 + tmp35 _tmp36 = tl.where(rmask & xmask, tmp37, _tmp36) tmp40 = tmp39 - tmp2 tmp41 = tl_math.exp(tmp40) tmp42 = tmp41 / tmp5 tmp43 = tmp38 * tmp42 tmp44 = tl.broadcast_to(tmp43, [XBLOCK, RBLOCK]) tmp46 = _tmp45 + tmp44 _tmp45 = tl.where(rmask & xmask, tmp46, _tmp45) tmp49 = tmp48 - tmp2 tmp50 = tl_math.exp(tmp49) tmp51 = tmp50 / tmp5 tmp52 = tmp47 * tmp51 tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK]) tmp55 = _tmp54 + tmp53 _tmp54 = tl.where(rmask & xmask, tmp55, _tmp54) tmp58 = tmp57 - tmp2 tmp59 = tl_math.exp(tmp58) tmp60 = tmp59 / tmp5 tmp61 = tmp56 * tmp60 tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK]) tmp64 = _tmp63 + tmp62 _tmp63 = tl.where(rmask & xmask, tmp64, _tmp63) tmp9 = tl.sum(_tmp9, 1)[:, None] tl.store(out_ptr0 + x3, tmp9, xmask) tmp18 = tl.sum(_tmp18, 1)[:, None] tl.store(out_ptr1 + x3, tmp18, xmask) tmp27 = tl.sum(_tmp27, 1)[:, None] tl.store(out_ptr2 + x3, tmp27, xmask) tmp36 = tl.sum(_tmp36, 1)[:, None] tl.store(out_ptr3 + x3, tmp36, xmask) tmp45 = tl.sum(_tmp45, 1)[:, None] tl.store(out_ptr4 + x3, tmp45, xmask) tmp54 = tl.sum(_tmp54, 1)[:, None] tl.store(out_ptr5 + x3, tmp54, xmask) tmp63 = tl.sum(_tmp63, 1)[:, None] tl.store(out_ptr6 + x3, tmp63, xmask) @triton.jit def triton_per_fused_copy_linalg_vector_norm_zeros_6(in_out_ptr0, in_out_ptr1, 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, in_ptr32, in_ptr33, in_ptr34, in_ptr35, in_ptr36, in_ptr37, in_ptr38, in_ptr39, in_ptr40, in_ptr41, in_ptr42, in_ptr43, in_ptr44, in_ptr45, in_ptr46, in_ptr47, in_ptr48, in_ptr49, in_ptr50, in_ptr51, in_ptr52, in_ptr53, in_ptr54, in_ptr55, in_ptr56, in_ptr57, in_ptr58, in_ptr59, in_ptr60, in_ptr61, in_ptr62, in_ptr63, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) x0 = xindex % 64 r2 = rindex x1 = xindex // 64 x3 = xindex tmp0 = x0 tmp1 = tl.full([1, 1], 4, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1, 1], 5, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (r2 + 128 * x1), tmp5 & xmask, eviction_policy ='evict_last', other=0.0) tmp7 = tl.full([1, 1], 3, tl.int64) tmp8 = tmp0 >= tmp7 tmp9 = tmp0 < tmp1 tmp10 = tmp8 & tmp9 tmp11 = tl.load(in_ptr1 + (r2 + 128 * x1), tmp10 & xmask, eviction_policy='evict_last', other=0.0) tmp12 = tl.full([1, 1], 2, tl.int64) tmp13 = tmp0 >= tmp12 tmp14 = tmp0 < tmp7 tmp15 = tmp13 & tmp14 tmp16 = tl.load(in_ptr2 + (r2 + 128 * x1), tmp15 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tl.full([1, 1], 1, tl.int64) tmp18 = tmp0 >= tmp17 tmp19 = tmp0 < tmp12 tmp20 = tmp18 & tmp19 tmp21 = tl.load(in_ptr3 + (r2 + 128 * x1), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp22 = tmp0 < tmp17 tmp23 = tl.load(in_ptr4 + (r2 + 128 * x1), tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = 0.0 tmp25 = tl.where(tmp22, tmp23, tmp24) tmp26 = tl.where(tmp20, tmp21, tmp25) tmp27 = tl.where(tmp15, tmp16, tmp26) tmp28 = tl.where(tmp10, tmp11, tmp27) tmp29 = tl.where(tmp5, tmp6, tmp28) tmp30 = tl.full([1, 1], 8, tl.int64) tmp31 = tmp0 >= tmp30 tmp32 = tl.full([1, 1], 9, tl.int64) tmp33 = tmp0 < tmp32 tmp34 = tmp31 & tmp33 tmp35 = tl.load(in_ptr5 + (r2 + 128 * x1), tmp34 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tl.full([1, 1], 7, tl.int64) tmp37 = tmp0 >= tmp36 tmp38 = tmp0 < tmp30 tmp39 = tmp37 & tmp38 tmp40 = tl.load(in_ptr6 + (r2 + 128 * x1), tmp39 & xmask, eviction_policy='evict_last', other=0.0) tmp41 = tl.full([1, 1], 6, tl.int64) tmp42 = tmp0 >= tmp41 tmp43 = tmp0 < tmp36 tmp44 = tmp42 & tmp43 tmp45 = tl.load(in_ptr7 + (r2 + 128 * x1), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp46 = tmp0 >= tmp3 tmp47 = tmp0 < tmp41 tmp48 = tmp46 & tmp47 tmp49 = tl.load(in_ptr8 + (r2 + 128 * x1), tmp48 & xmask, eviction_policy='evict_last', other=0.0) tmp50 = tl.where(tmp48, tmp49, tmp29) tmp51 = tl.where(tmp44, tmp45, tmp50) tmp52 = tl.where(tmp39, tmp40, tmp51) tmp53 = tl.where(tmp34, tmp35, tmp52) tmp54 = tl.full([1, 1], 12, tl.int64) tmp55 = tmp0 >= tmp54 tmp56 = tl.full([1, 1], 13, tl.int64) tmp57 = tmp0 < tmp56 tmp58 = tmp55 & tmp57 tmp59 = tl.load(in_ptr9 + (r2 + 128 * x1), tmp58 & xmask, eviction_policy='evict_last', other=0.0) tmp60 = tl.full([1, 1], 11, tl.int64) tmp61 = tmp0 >= tmp60 tmp62 = tmp0 < tmp54 tmp63 = tmp61 & tmp62 tmp64 = tl.load(in_ptr10 + (r2 + 128 * x1), tmp63 & xmask, eviction_policy='evict_last', other=0.0) tmp65 = tl.full([1, 1], 10, tl.int64) tmp66 = tmp0 >= tmp65 tmp67 = tmp0 < tmp60 tmp68 = tmp66 & tmp67 tmp69 = tl.load(in_ptr11 + (r2 + 128 * x1), tmp68 & xmask, eviction_policy='evict_last', other=0.0) tmp70 = tmp0 >= tmp32 tmp71 = tmp0 < tmp65 tmp72 = tmp70 & tmp71 tmp73 = tl.load(in_ptr12 + (r2 + 128 * x1), tmp72 & xmask, eviction_policy='evict_last', other=0.0) tmp74 = tl.where(tmp72, tmp73, tmp53) tmp75 = tl.where(tmp68, tmp69, tmp74) tmp76 = tl.where(tmp63, tmp64, tmp75) tmp77 = tl.where(tmp58, tmp59, tmp76) tmp78 = tl.full([1, 1], 16, tl.int64) tmp79 = tmp0 >= tmp78 tmp80 = tl.full([1, 1], 17, tl.int64) tmp81 = tmp0 < tmp80 tmp82 = tmp79 & tmp81 tmp83 = tl.load(in_ptr13 + (r2 + 128 * x1), tmp82 & xmask, eviction_policy='evict_last', other=0.0) tmp84 = tl.full([1, 1], 15, tl.int64) tmp85 = tmp0 >= tmp84 tmp86 = tmp0 < tmp78 tmp87 = tmp85 & tmp86 tmp88 = tl.load(in_ptr14 + (r2 + 128 * x1), tmp87 & xmask, eviction_policy='evict_last', other=0.0) tmp89 = tl.full([1, 1], 14, tl.int64) tmp90 = tmp0 >= tmp89 tmp91 = tmp0 < tmp84 tmp92 = tmp90 & tmp91 tmp93 = tl.load(in_ptr15 + (r2 + 128 * x1), tmp92 & xmask, eviction_policy='evict_last', other=0.0) tmp94 = tmp0 >= tmp56 tmp95 = tmp0 < tmp89 tmp96 = tmp94 & tmp95 tmp97 = tl.load(in_ptr16 + (r2 + 128 * x1), tmp96 & xmask, eviction_policy='evict_last', other=0.0) tmp98 = tl.where(tmp96, tmp97, tmp77) tmp99 = tl.where(tmp92, tmp93, tmp98) tmp100 = tl.where(tmp87, tmp88, tmp99) tmp101 = tl.where(tmp82, tmp83, tmp100) tmp102 = tl.full([1, 1], 20, tl.int64) tmp103 = tmp0 >= tmp102 tmp104 = tl.full([1, 1], 21, tl.int64) tmp105 = tmp0 < tmp104 tmp106 = tmp103 & tmp105 tmp107 = tl.load(in_ptr17 + (r2 + 128 * x1), tmp106 & xmask, eviction_policy='evict_last', other=0.0) tmp108 = tl.full([1, 1], 19, tl.int64) tmp109 = tmp0 >= tmp108 tmp110 = tmp0 < tmp102 tmp111 = tmp109 & tmp110 tmp112 = tl.load(in_ptr18 + (r2 + 128 * x1), tmp111 & xmask, eviction_policy='evict_last', other=0.0) tmp113 = tl.full([1, 1], 18, tl.int64) tmp114 = tmp0 >= tmp113 tmp115 = tmp0 < tmp108 tmp116 = tmp114 & tmp115 tmp117 = tl.load(in_ptr19 + (r2 + 128 * x1), tmp116 & xmask, eviction_policy='evict_last', other=0.0) tmp118 = tmp0 >= tmp80 tmp119 = tmp0 < tmp113 tmp120 = tmp118 & tmp119 tmp121 = tl.load(in_ptr20 + (r2 + 128 * x1), tmp120 & xmask, eviction_policy='evict_last', other=0.0) tmp122 = tl.where(tmp120, tmp121, tmp101) tmp123 = tl.where(tmp116, tmp117, tmp122) tmp124 = tl.where(tmp111, tmp112, tmp123) tmp125 = tl.where(tmp106, tmp107, tmp124) tmp126 = tl.full([1, 1], 24, tl.int64) tmp127 = tmp0 >= tmp126 tmp128 = tl.full([1, 1], 25, tl.int64) tmp129 = tmp0 < tmp128 tmp130 = tmp127 & tmp129 tmp131 = tl.load(in_ptr21 + (r2 + 128 * x1), tmp130 & xmask, eviction_policy='evict_last', other=0.0) tmp132 = tl.full([1, 1], 23, tl.int64) tmp133 = tmp0 >= tmp132 tmp134 = tmp0 < tmp126 tmp135 = tmp133 & tmp134 tmp136 = tl.load(in_ptr22 + (r2 + 128 * x1), tmp135 & xmask, eviction_policy='evict_last', other=0.0) tmp137 = tl.full([1, 1], 22, tl.int64) tmp138 = tmp0 >= tmp137 tmp139 = tmp0 < tmp132 tmp140 = tmp138 & tmp139 tmp141 = tl.load(in_ptr23 + (r2 + 128 * x1), tmp140 & xmask, eviction_policy='evict_last', other=0.0) tmp142 = tmp0 >= tmp104 tmp143 = tmp0 < tmp137 tmp144 = tmp142 & tmp143 tmp145 = tl.load(in_ptr24 + (r2 + 128 * x1), tmp144 & xmask, eviction_policy='evict_last', other=0.0) tmp146 = tl.where(tmp144, tmp145, tmp125) tmp147 = tl.where(tmp140, tmp141, tmp146) tmp148 = tl.where(tmp135, tmp136, tmp147) tmp149 = tl.where(tmp130, tmp131, tmp148) tmp150 = tl.full([1, 1], 28, tl.int64) tmp151 = tmp0 >= tmp150 tmp152 = tl.full([1, 1], 29, tl.int64) tmp153 = tmp0 < tmp152 tmp154 = tmp151 & tmp153 tmp155 = tl.load(in_ptr25 + (r2 + 128 * x1), tmp154 & xmask, eviction_policy='evict_last', other=0.0) tmp156 = tl.full([1, 1], 27, tl.int64) tmp157 = tmp0 >= tmp156 tmp158 = tmp0 < tmp150 tmp159 = tmp157 & tmp158 tmp160 = tl.load(in_ptr26 + (r2 + 128 * x1), tmp159 & xmask, eviction_policy='evict_last', other=0.0) tmp161 = tl.full([1, 1], 26, tl.int64) tmp162 = tmp0 >= tmp161 tmp163 = tmp0 < tmp156 tmp164 = tmp162 & tmp163 tmp165 = tl.load(in_ptr27 + (r2 + 128 * x1), tmp164 & xmask, eviction_policy='evict_last', other=0.0) tmp166 = tmp0 >= tmp128 tmp167 = tmp0 < tmp161 tmp168 = tmp166 & tmp167 tmp169 = tl.load(in_ptr28 + (r2 + 128 * x1), tmp168 & xmask, eviction_policy='evict_last', other=0.0) tmp170 = tl.where(tmp168, tmp169, tmp149) tmp171 = tl.where(tmp164, tmp165, tmp170) tmp172 = tl.where(tmp159, tmp160, tmp171) tmp173 = tl.where(tmp154, tmp155, tmp172) tmp174 = tl.full([1, 1], 32, tl.int64) tmp175 = tmp0 >= tmp174 tmp176 = tl.full([1, 1], 33, tl.int64) tmp177 = tmp0 < tmp176 tmp178 = tmp175 & tmp177 tmp179 = tl.load(in_ptr29 + (r2 + 128 * x1), tmp178 & xmask, eviction_policy='evict_last', other=0.0) tmp180 = tl.full([1, 1], 31, tl.int64) tmp181 = tmp0 >= tmp180 tmp182 = tmp0 < tmp174 tmp183 = tmp181 & tmp182 tmp184 = tl.load(in_ptr30 + (r2 + 128 * x1), tmp183 & xmask, eviction_policy='evict_last', other=0.0) tmp185 = tl.full([1, 1], 30, tl.int64) tmp186 = tmp0 >= tmp185 tmp187 = tmp0 < tmp180 tmp188 = tmp186 & tmp187 tmp189 = tl.load(in_ptr31 + (r2 + 128 * x1), tmp188 & xmask, eviction_policy='evict_last', other=0.0) tmp190 = tmp0 >= tmp152 tmp191 = tmp0 < tmp185 tmp192 = tmp190 & tmp191 tmp193 = tl.load(in_ptr32 + (r2 + 128 * x1), tmp192 & xmask, eviction_policy='evict_last', other=0.0) tmp194 = tl.where(tmp192, tmp193, tmp173) tmp195 = tl.where(tmp188, tmp189, tmp194) tmp196 = tl.where(tmp183, tmp184, tmp195) tmp197 = tl.where(tmp178, tmp179, tmp196) tmp198 = tl.full([1, 1], 36, tl.int64) tmp199 = tmp0 >= tmp198 tmp200 = tl.full([1, 1], 37, tl.int64) tmp201 = tmp0 < tmp200 tmp202 = tmp199 & tmp201 tmp203 = tl.load(in_ptr33 + (r2 + 128 * x1), tmp202 & xmask, eviction_policy='evict_last', other=0.0) tmp204 = tl.full([1, 1], 35, tl.int64) tmp205 = tmp0 >= tmp204 tmp206 = tmp0 < tmp198 tmp207 = tmp205 & tmp206 tmp208 = tl.load(in_ptr34 + (r2 + 128 * x1), tmp207 & xmask, eviction_policy='evict_last', other=0.0) tmp209 = tl.full([1, 1], 34, tl.int64) tmp210 = tmp0 >= tmp209 tmp211 = tmp0 < tmp204 tmp212 = tmp210 & tmp211 tmp213 = tl.load(in_ptr35 + (r2 + 128 * x1), tmp212 & xmask, eviction_policy='evict_last', other=0.0) tmp214 = tmp0 >= tmp176 tmp215 = tmp0 < tmp209 tmp216 = tmp214 & tmp215 tmp217 = tl.load(in_ptr36 + (r2 + 128 * x1), tmp216 & xmask, eviction_policy='evict_last', other=0.0) tmp218 = tl.where(tmp216, tmp217, tmp197) tmp219 = tl.where(tmp212, tmp213, tmp218) tmp220 = tl.where(tmp207, tmp208, tmp219) tmp221 = tl.where(tmp202, tmp203, tmp220) tmp222 = tl.full([1, 1], 40, tl.int64) tmp223 = tmp0 >= tmp222 tmp224 = tl.full([1, 1], 41, tl.int64) tmp225 = tmp0 < tmp224 tmp226 = tmp223 & tmp225 tmp227 = tl.load(in_ptr37 + (r2 + 128 * x1), tmp226 & xmask, eviction_policy='evict_last', other=0.0) tmp228 = tl.full([1, 1], 39, tl.int64) tmp229 = tmp0 >= tmp228 tmp230 = tmp0 < tmp222 tmp231 = tmp229 & tmp230 tmp232 = tl.load(in_ptr38 + (r2 + 128 * x1), tmp231 & xmask, eviction_policy='evict_last', other=0.0) tmp233 = tl.full([1, 1], 38, tl.int64) tmp234 = tmp0 >= tmp233 tmp235 = tmp0 < tmp228 tmp236 = tmp234 & tmp235 tmp237 = tl.load(in_ptr39 + (r2 + 128 * x1), tmp236 & xmask, eviction_policy='evict_last', other=0.0) tmp238 = tmp0 >= tmp200 tmp239 = tmp0 < tmp233 tmp240 = tmp238 & tmp239 tmp241 = tl.load(in_ptr40 + (r2 + 128 * x1), tmp240 & xmask, eviction_policy='evict_last', other=0.0) tmp242 = tl.where(tmp240, tmp241, tmp221) tmp243 = tl.where(tmp236, tmp237, tmp242) tmp244 = tl.where(tmp231, tmp232, tmp243) tmp245 = tl.where(tmp226, tmp227, tmp244) tmp246 = tl.full([1, 1], 44, tl.int64) tmp247 = tmp0 >= tmp246 tmp248 = tl.full([1, 1], 45, tl.int64) tmp249 = tmp0 < tmp248 tmp250 = tmp247 & tmp249 tmp251 = tl.load(in_ptr41 + (r2 + 128 * x1), tmp250 & xmask, eviction_policy='evict_last', other=0.0) tmp252 = tl.full([1, 1], 43, tl.int64) tmp253 = tmp0 >= tmp252 tmp254 = tmp0 < tmp246 tmp255 = tmp253 & tmp254 tmp256 = tl.load(in_ptr42 + (r2 + 128 * x1), tmp255 & xmask, eviction_policy='evict_last', other=0.0) tmp257 = tl.full([1, 1], 42, tl.int64) tmp258 = tmp0 >= tmp257 tmp259 = tmp0 < tmp252 tmp260 = tmp258 & tmp259 tmp261 = tl.load(in_ptr43 + (r2 + 128 * x1), tmp260 & xmask, eviction_policy='evict_last', other=0.0) tmp262 = tmp0 >= tmp224 tmp263 = tmp0 < tmp257 tmp264 = tmp262 & tmp263 tmp265 = tl.load(in_ptr44 + (r2 + 128 * x1), tmp264 & xmask, eviction_policy='evict_last', other=0.0) tmp266 = tl.where(tmp264, tmp265, tmp245) tmp267 = tl.where(tmp260, tmp261, tmp266) tmp268 = tl.where(tmp255, tmp256, tmp267) tmp269 = tl.where(tmp250, tmp251, tmp268) tmp270 = tl.full([1, 1], 48, tl.int64) tmp271 = tmp0 >= tmp270 tmp272 = tl.full([1, 1], 49, tl.int64) tmp273 = tmp0 < tmp272 tmp274 = tmp271 & tmp273 tmp275 = tl.load(in_ptr45 + (r2 + 128 * x1), tmp274 & xmask, eviction_policy='evict_last', other=0.0) tmp276 = tl.full([1, 1], 47, tl.int64) tmp277 = tmp0 >= tmp276 tmp278 = tmp0 < tmp270 tmp279 = tmp277 & tmp278 tmp280 = tl.load(in_ptr46 + (r2 + 128 * x1), tmp279 & xmask, eviction_policy='evict_last', other=0.0) tmp281 = tl.full([1, 1], 46, tl.int64) tmp282 = tmp0 >= tmp281 tmp283 = tmp0 < tmp276 tmp284 = tmp282 & tmp283 tmp285 = tl.load(in_ptr47 + (r2 + 128 * x1), tmp284 & xmask, eviction_policy='evict_last', other=0.0) tmp286 = tmp0 >= tmp248 tmp287 = tmp0 < tmp281 tmp288 = tmp286 & tmp287 tmp289 = tl.load(in_ptr48 + (r2 + 128 * x1), tmp288 & xmask, eviction_policy='evict_last', other=0.0) tmp290 = tl.where(tmp288, tmp289, tmp269) tmp291 = tl.where(tmp284, tmp285, tmp290) tmp292 = tl.where(tmp279, tmp280, tmp291) tmp293 = tl.where(tmp274, tmp275, tmp292) tmp294 = tl.full([1, 1], 52, tl.int64) tmp295 = tmp0 >= tmp294 tmp296 = tl.full([1, 1], 53, tl.int64) tmp297 = tmp0 < tmp296 tmp298 = tmp295 & tmp297 tmp299 = tl.load(in_ptr49 + (r2 + 128 * x1), tmp298 & xmask, eviction_policy='evict_last', other=0.0) tmp300 = tl.full([1, 1], 51, tl.int64) tmp301 = tmp0 >= tmp300 tmp302 = tmp0 < tmp294 tmp303 = tmp301 & tmp302 tmp304 = tl.load(in_ptr50 + (r2 + 128 * x1), tmp303 & xmask, eviction_policy='evict_last', other=0.0) tmp305 = tl.full([1, 1], 50, tl.int64) tmp306 = tmp0 >= tmp305 tmp307 = tmp0 < tmp300 tmp308 = tmp306 & tmp307 tmp309 = tl.load(in_ptr51 + (r2 + 128 * x1), tmp308 & xmask, eviction_policy='evict_last', other=0.0) tmp310 = tmp0 >= tmp272 tmp311 = tmp0 < tmp305 tmp312 = tmp310 & tmp311 tmp313 = tl.load(in_ptr52 + (r2 + 128 * x1), tmp312 & xmask, eviction_policy='evict_last', other=0.0) tmp314 = tl.where(tmp312, tmp313, tmp293) tmp315 = tl.where(tmp308, tmp309, tmp314) tmp316 = tl.where(tmp303, tmp304, tmp315) tmp317 = tl.where(tmp298, tmp299, tmp316) tmp318 = tl.full([1, 1], 56, tl.int64) tmp319 = tmp0 >= tmp318 tmp320 = tl.full([1, 1], 57, tl.int64) tmp321 = tmp0 < tmp320 tmp322 = tmp319 & tmp321 tmp323 = tl.load(in_ptr53 + (r2 + 128 * x1), tmp322 & xmask, eviction_policy='evict_last', other=0.0) tmp324 = tl.full([1, 1], 55, tl.int64) tmp325 = tmp0 >= tmp324 tmp326 = tmp0 < tmp318 tmp327 = tmp325 & tmp326 tmp328 = tl.load(in_ptr54 + (r2 + 128 * x1), tmp327 & xmask, eviction_policy='evict_last', other=0.0) tmp329 = tl.full([1, 1], 54, tl.int64) tmp330 = tmp0 >= tmp329 tmp331 = tmp0 < tmp324 tmp332 = tmp330 & tmp331 tmp333 = tl.load(in_ptr55 + (r2 + 128 * x1), tmp332 & xmask, eviction_policy='evict_last', other=0.0) tmp334 = tmp0 >= tmp296 tmp335 = tmp0 < tmp329 tmp336 = tmp334 & tmp335 tmp337 = tl.load(in_ptr56 + (r2 + 128 * x1), tmp336 & xmask, eviction_policy='evict_last', other=0.0) tmp338 = tl.where(tmp336, tmp337, tmp317) tmp339 = tl.where(tmp332, tmp333, tmp338) tmp340 = tl.where(tmp327, tmp328, tmp339) tmp341 = tl.where(tmp322, tmp323, tmp340) tmp342 = tl.full([1, 1], 60, tl.int64) tmp343 = tmp0 >= tmp342 tmp344 = tl.full([1, 1], 61, tl.int64) tmp345 = tmp0 < tmp344 tmp346 = tmp343 & tmp345 tmp347 = tl.load(in_ptr57 + (r2 + 128 * x1), tmp346 & xmask, eviction_policy='evict_last', other=0.0) tmp348 = tl.full([1, 1], 59, tl.int64) tmp349 = tmp0 >= tmp348 tmp350 = tmp0 < tmp342 tmp351 = tmp349 & tmp350 tmp352 = tl.load(in_ptr58 + (r2 + 128 * x1), tmp351 & xmask, eviction_policy='evict_last', other=0.0) tmp353 = tl.full([1, 1], 58, tl.int64) tmp354 = tmp0 >= tmp353 tmp355 = tmp0 < tmp348 tmp356 = tmp354 & tmp355 tmp357 = tl.load(in_ptr59 + (r2 + 128 * x1), tmp356 & xmask, eviction_policy='evict_last', other=0.0) tmp358 = tmp0 >= tmp320 tmp359 = tmp0 < tmp353 tmp360 = tmp358 & tmp359 tmp361 = tl.load(in_ptr60 + (r2 + 128 * x1), tmp360 & xmask, eviction_policy='evict_last', other=0.0) tmp362 = tl.where(tmp360, tmp361, tmp341) tmp363 = tl.where(tmp356, tmp357, tmp362) tmp364 = tl.where(tmp351, tmp352, tmp363) tmp365 = tl.where(tmp346, tmp347, tmp364) tmp366 = tl.full([1, 1], 63, tl.int64) tmp367 = tmp0 >= tmp366 tmp368 = tl.load(in_ptr61 + (r2 + 128 * x1), tmp367 & xmask, eviction_policy='evict_last', other=0.0) tmp369 = tl.full([1, 1], 62, tl.int64) tmp370 = tmp0 >= tmp369 tmp371 = tmp0 < tmp366 tmp372 = tmp370 & tmp371 tmp373 = tl.load(in_ptr62 + (r2 + 128 * x1), tmp372 & xmask, eviction_policy='evict_last', other=0.0) tmp374 = tmp0 >= tmp344 tmp375 = tmp0 < tmp369 tmp376 = tmp374 & tmp375 tmp377 = tl.load(in_ptr63 + (r2 + 128 * x1), tmp376 & xmask, eviction_policy='evict_last', other=0.0) tmp378 = tl.where(tmp376, tmp377, tmp365) tmp379 = tl.where(tmp372, tmp373, tmp378) tmp380 = tl.where(tmp367, tmp368, tmp379) tmp381 = tmp380 * tmp380 tmp382 = tl.broadcast_to(tmp381, [XBLOCK, RBLOCK]) tmp384 = tl.where(xmask, tmp382, 0) tmp385 = tl.sum(tmp384, 1)[:, None] tmp386 = libdevice.sqrt(tmp385) tl.store(in_out_ptr0 + (r2 + 128 * x3), tmp380, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp386, xmask) @triton.jit def triton_red_fused_div_linalg_vector_norm_7(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 4 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 _tmp7 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tl.load(in_ptr1 + (64 * x0 + r1 // 128), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = 1e-12 tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp4 = tmp0 / tmp3 tmp5 = tmp4 * tmp4 tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = _tmp7 + tmp6 _tmp7 = tl.where(rmask & xmask, tmp8, _tmp7) tmp7 = tl.sum(_tmp7, 1)[:, None] tmp9 = libdevice.sqrt(tmp7) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, xmask) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp11 = tl.load(in_ptr1 + (64 * x0 + r1 // 128), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp12 = 1e-12 tmp13 = triton_helpers.maximum(tmp11, tmp12) tmp14 = tmp10 / tmp13 tmp15 = triton_helpers.maximum(tmp9, tmp12) tmp16 = tmp14 / tmp15 tl.store(out_ptr0 + (r1 + 8192 * x0), tmp16, rmask & xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 128, 64, 64), (524288, 4096, 64, 1)) assert_size_stride(primals_2, (64, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_3, (64, 128), (128, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) get_raw_stream(0) triton_red_fused_linalg_vector_norm_0[grid(16384)](primals_1, buf0, 16384, 128, XBLOCK=64, RBLOCK=4, num_warps=8, num_stages=1) buf1 = empty_strided_cuda((4, 128, 64, 64), (524288, 4096, 64, 1), torch.float32) buf6 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf8 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf10 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf12 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf15 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf17 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf19 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf21 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf24 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf26 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf28 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf30 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf33 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf35 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf37 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf39 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf42 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf44 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf46 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf48 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf51 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf53 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf55 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf57 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf60 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf62 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf64 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf66 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf69 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf71 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf73 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf75 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf78 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf80 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf82 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf84 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf87 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf89 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf91 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf93 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf96 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf98 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf100 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf102 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf105 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf107 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf109 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf111 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf114 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf116 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf118 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf120 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf123 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf125 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf127 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf129 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf132 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf134 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf136 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf138 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf141 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf143 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) buf145 = empty_strided_cuda((4, 1, 128, 4096), (524288, 2097152, 4096, 1), torch.float32) triton_poi_fused_div_sub_1[grid(2097152)](primals_1, buf0, primals_3, buf1, buf6, buf8, buf10, buf12, buf15, buf17, buf19, buf21, buf24, buf26, buf28, buf30, buf33, buf35, buf37, buf39, buf42, buf44, buf46, buf48, buf51, buf53, buf55, buf57, buf60, buf62, buf64, buf66, buf69, buf71, buf73, buf75, buf78, buf80, buf82, buf84, buf87, buf89, buf91, buf93, buf96, buf98, buf100, buf102, buf105, buf107, buf109, buf111, buf114, buf116, buf118, buf120, buf123, buf125, buf127, buf129, buf132, buf134, buf136, buf138, buf141, buf143, buf145, 2097152, XBLOCK=512, num_warps= 8, num_stages=1) del primals_1 buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = reinterpret_tensor(buf0, (4, 1, 4096), (4096, 4096, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 1, 4096), (4096, 4096, 1), torch.float32) triton_per_fused__softmax_2[grid(16384)](buf2, buf3, buf4, 16384, 64, XBLOCK=8, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf7 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf9 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf11 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf13 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf16 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf18 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf20 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf22 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf25 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf27 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf29 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf31 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf34 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf36 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf38 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf40 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf43 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf45 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf47 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf49 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf52 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf54 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf56 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf58 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf61 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf63 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf65 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf67 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) triton_red_fused_mul_sub_sum_3[grid(512)](buf1, primals_3, buf2, buf3, buf4, buf6, buf8, buf10, buf12, buf15, buf17, buf19, buf21, buf24, buf26, buf28, buf30, buf33, buf35, buf37, buf39, buf42, buf44, buf46, buf48, buf51, buf53, buf55, buf57, buf60, buf62, buf64, buf66, buf5, buf7, buf9, buf11, buf13, buf16, buf18, buf20, buf22, buf25, buf27, buf29, buf31, buf34, buf36, buf38, buf40, buf43, buf45, buf47, buf49, buf52, buf54, buf56, buf58, buf61, buf63, buf65, buf67, 512, 4096, XBLOCK=1, RBLOCK= 2048, num_warps=16, num_stages=1) buf70 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf72 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf74 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf76 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf79 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf81 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf83 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf85 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf88 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf90 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf92 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf94 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf97 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf99 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf101 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf103 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf106 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf108 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf110 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf112 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf115 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf117 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf119 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf121 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf124 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf126 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf128 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf130 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) triton_red_fused_mul_sum_4[grid(512)](buf69, buf2, buf3, buf4, buf71, buf73, buf75, buf78, buf80, buf82, buf84, buf87, buf89, buf91, buf93, buf96, buf98, buf100, buf102, buf105, buf107, buf109, buf111, buf114, buf116, buf118, buf120, buf123, buf125, buf127, buf129, buf70, buf72, buf74, buf76, buf79, buf81, buf83, buf85, buf88, buf90, buf92, buf94, buf97, buf99, buf101, buf103, buf106, buf108, buf110, buf112, buf115, buf117, buf119, buf121, buf124, buf126, buf128, buf130, 512, 4096, XBLOCK=1, RBLOCK= 2048, num_warps=16, num_stages=1) buf133 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf135 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf137 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf139 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf142 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf144 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) buf146 = empty_strided_cuda((4, 1, 128), (128, 512, 1), torch.float32) triton_red_fused_mul_sum_5[grid(512)](buf132, buf2, buf3, buf4, buf134, buf136, buf138, buf141, buf143, buf145, buf133, buf135, buf137, buf139, buf142, buf144, buf146, 512, 4096, XBLOCK=1, RBLOCK=1024, num_warps=16, num_stages=1) buf14 = empty_strided_cuda((4, 64, 128), (8192, 128, 1), torch.float32) buf23 = buf14 del buf14 buf32 = buf23 del buf23 buf41 = buf32 del buf32 buf50 = buf41 del buf41 buf59 = buf50 del buf50 buf68 = buf59 del buf59 buf77 = buf68 del buf68 buf86 = buf77 del buf77 buf95 = buf86 del buf86 buf104 = buf95 del buf95 buf113 = buf104 del buf104 buf122 = buf113 del buf113 buf131 = buf122 del buf122 buf140 = buf131 del buf131 buf147 = buf140 del buf140 buf148 = empty_strided_cuda((4, 64, 1), (64, 1, 256), torch.float32) buf149 = reinterpret_tensor(buf148, (4, 64, 1), (64, 1, 1), 0) del buf148 triton_per_fused_copy_linalg_vector_norm_zeros_6[grid(256)](buf147, buf149, buf13, buf11, buf9, buf7, buf5, buf22, buf20, buf18, buf16, buf31, buf29, buf27, buf25, buf40, buf38, buf36, buf34, buf49, buf47, buf45, buf43, buf58, buf56, buf54, buf52, buf67, buf65, buf63, buf61, buf76, buf74, buf72, buf70, buf85, buf83, buf81, buf79, buf94, buf92, buf90, buf88, buf103, buf101, buf99, buf97, buf112, buf110, buf108, buf106, buf121, buf119, buf117, buf115, buf130, buf128, buf126, buf124, buf139, buf137, buf135, buf133, buf146, buf144, buf142, 256, 128, XBLOCK=1, num_warps=2, num_stages=1) del buf101 del buf103 del buf106 del buf108 del buf11 del buf110 del buf112 del buf115 del buf117 del buf119 del buf121 del buf124 del buf126 del buf128 del buf13 del buf130 del buf133 del buf135 del buf137 del buf139 del buf142 del buf144 del buf146 del buf16 del buf18 del buf20 del buf22 del buf25 del buf27 del buf29 del buf31 del buf34 del buf36 del buf38 del buf40 del buf43 del buf45 del buf47 del buf49 del buf5 del buf52 del buf54 del buf56 del buf58 del buf61 del buf63 del buf65 del buf67 del buf7 del buf70 del buf72 del buf74 del buf76 del buf79 del buf81 del buf83 del buf85 del buf88 del buf9 del buf90 del buf92 del buf94 del buf97 del buf99 buf150 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf151 = reinterpret_tensor(buf150, (4, 1), (1, 1), 0) del buf150 buf152 = empty_strided_cuda((4, 8192), (8192, 1), torch.float32) triton_red_fused_div_linalg_vector_norm_7[grid(4)](buf151, buf147, buf149, buf152, 4, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) return (buf152, primals_2, buf1, buf2, buf3, buf4, reinterpret_tensor( primals_3, (1, 128), (128, 1), 0), buf6, buf8, buf10, buf12, buf15, buf17, buf19, buf21, buf24, buf26, buf28, buf30, buf33, buf35, buf37, buf39, buf42, buf44, buf46, buf48, buf51, buf53, buf55, buf57, buf60, buf62, buf64, buf66, buf69, buf71, buf73, buf75, buf78, buf80, buf82, buf84, buf87, buf89, buf91, buf93, buf96, buf98, buf100, buf102, buf105, buf107, buf109, buf111, buf114, buf116, buf118, buf120, buf123, buf125, buf127, buf129, buf132, buf134, buf136, buf138, buf141, buf143, buf145, buf147, buf149, buf151) class NetVLADNew(nn.Module): """NetVLAD layer implementation""" def __init__(self, num_clusters=64, dim=128, normalize_input=True, vladv2=False): """ Args: num_clusters : int The number of clusters dim : int Dimension of descriptors alpha : float Parameter of initialization. Larger value is harder assignment. normalize_input : bool If true, descriptor-wise L2 normalization is applied to input. vladv2 : bool If true, use vladv2 otherwise use vladv1 """ super(NetVLADNew, self).__init__() self.num_clusters = num_clusters self.dim = dim self.alpha = 0 self.vladv2 = vladv2 self.normalize_input = normalize_input self.conv = nn.Conv2d(dim, num_clusters, kernel_size=(1, 1), bias= vladv2) self.centroids = nn.Parameter(torch.rand(num_clusters, dim)) def init_params(self, clsts, traindescs): if self.vladv2 is False: clstsAssign = clsts / np.linalg.norm(clsts, axis=1, keepdims=True) dots = np.dot(clstsAssign, traindescs.T) dots.sort(0) dots = dots[::-1, :] self.alpha = (-np.log(0.01) / np.mean(dots[0, :] - dots[1, :]) ).item() self.centroids = nn.Parameter(torch.from_numpy(clsts)) self.conv.weight = nn.Parameter(torch.from_numpy(self.alpha * clstsAssign).unsqueeze(2).unsqueeze(3)) self.conv.bias = None else: knn = NearestNeighbors(n_jobs=-1) knn.fit(traindescs) del traindescs dsSq = np.square(knn.kneighbors(clsts, 2)[1]) del knn self.alpha = (-np.log(0.01) / np.mean(dsSq[:, 1] - dsSq[:, 0]) ).item() self.centroids = nn.Parameter(torch.from_numpy(clsts)) del clsts, dsSq self.conv.weight = nn.Parameter((2.0 * self.alpha * self. centroids).unsqueeze(-1).unsqueeze(-1)) self.conv.bias = nn.Parameter(-self.alpha * self.centroids.norm (dim=1)) def forward(self, input_0): primals_3 = self.centroids primals_2 = self.conv.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ByungHeeCha/visual_localization
NetVLAD
false
17,431
[ "BSD-3-Clause" ]
3
787fb8f6ee5c6e69ece9e83a016d15596e5524bc
https://github.com/ByungHeeCha/visual_localization/tree/787fb8f6ee5c6e69ece9e83a016d15596e5524bc
SELayer
import math import torch from torch import nn from torch.nn import functional as F import torch.onnx from torch.optim.lr_scheduler import * def composite_swish(inputs_1, inputs_2): return inputs_1 * torch.sigmoid(inputs_2) def swish(x): return torch.sigmoid(x) * x class _Conv2dSamePadding(nn.Conv2d): """ Class implementing 2d adaptively padded convolutions """ def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): super().__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) self.stride = self.stride if len(self.stride) == 2 else [self.stride[0] ] * 2 def forward(self, x): ih, iw = x.size()[-2:] kh, kw = self.weight.size()[-2:] sh, sw = self.stride oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) if pad_h > 0 or pad_w > 0: x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) return F.conv2d(x, self.weight, self.bias, self.stride, self. padding, self.dilation, self.groups) class SELayer(nn.Module): """ Class impements the squeeze and excitation layer """ def __init__(self, in_channels, se_ratio): super(SELayer, self).__init__() assert se_ratio <= 1.0 and se_ratio >= 0.0, 'se_ratio should be in [0,1]' num_squeezed_channels = max(1, int(in_channels * se_ratio)) self._se_reduce = _Conv2dSamePadding(in_channels, num_squeezed_channels, 1) self._se_expand = _Conv2dSamePadding(num_squeezed_channels, in_channels, 1) def forward(self, inputs): inputs_squeezed = F.adaptive_avg_pool2d(inputs, 1) inputs_squeezed = self._se_expand(swish(self._se_reduce( inputs_squeezed))) return composite_swish(inputs, inputs_squeezed) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'se_ratio': 0}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math from torch import nn from torch.nn import functional as F import torch.onnx 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_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_mul_sigmoid_1(in_out_ptr0, 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_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tmp5 = tmp4 * tmp3 tl.store(in_out_ptr0 + x0, tmp3, xmask) tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (4, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 1, 1), (1, 1, 1, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32) triton_poi_fused_convolution_mul_sigmoid_1[grid(4)](buf3, primals_3, buf4, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf5 = extern_kernels.convolution(buf4, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 1, 1), (4, 1, 1, 1)) buf6 = buf5 del buf5 triton_poi_fused_convolution_2[grid(16)](buf6, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf7, primals_1, primals_2, primals_4, buf1, buf3, buf4, buf6 def composite_swish(inputs_1, inputs_2): return inputs_1 * torch.sigmoid(inputs_2) def swish(x): return torch.sigmoid(x) * x class _Conv2dSamePadding(nn.Conv2d): """ Class implementing 2d adaptively padded convolutions """ def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): super().__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) self.stride = self.stride if len(self.stride) == 2 else [self.stride[0] ] * 2 def forward(self, x): ih, iw = x.size()[-2:] kh, kw = self.weight.size()[-2:] sh, sw = self.stride oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) if pad_h > 0 or pad_w > 0: x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) return F.conv2d(x, self.weight, self.bias, self.stride, self. padding, self.dilation, self.groups) class SELayerNew(nn.Module): """ Class impements the squeeze and excitation layer """ def __init__(self, in_channels, se_ratio): super(SELayerNew, self).__init__() assert se_ratio <= 1.0 and se_ratio >= 0.0, 'se_ratio should be in [0,1]' num_squeezed_channels = max(1, int(in_channels * se_ratio)) self._se_reduce = _Conv2dSamePadding(in_channels, num_squeezed_channels, 1) self._se_expand = _Conv2dSamePadding(num_squeezed_channels, in_channels, 1) def forward(self, input_0): primals_2 = self._se_reduce.weight primals_3 = self._se_reduce.bias primals_4 = self._se_expand.weight primals_5 = self._se_expand.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
IST-DASLab/ACDC
SELayer
false
17,432
[ "Apache-2.0" ]
6
ac53210b6adc1f2506ff909de08172ed9cad25d5
https://github.com/IST-DASLab/ACDC/tree/ac53210b6adc1f2506ff909de08172ed9cad25d5
LayerNorm
import torch from torch import nn from typing import * class LayerNorm(nn.Module): """Normalize by channels, height and width for images.""" __constants__ = ['eps'] def __init__(self, eps): super().__init__() self.eps = eps self.gamma = nn.Parameter(torch.ones(1)) self.beta = nn.Parameter(torch.zeros(1)) def forward(self, x): mean = x.mean((1, 2, 3), keepdim=True) var = x.var((1, 2, 3), keepdim=True) x = (x - mean) / (var + self.eps).sqrt() return self.gamma * x + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'eps': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn from typing 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_add_div_mean_mul_sqrt_sub_var_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr1 + 0) tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK]) tmp31 = tl.load(in_ptr2 + 0) tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK]) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp4 / tmp19 tmp21 = 63.0 tmp22 = tmp18 / tmp21 tmp23 = 4.0 tmp24 = tmp22 + tmp23 tmp25 = libdevice.sqrt(tmp24) tmp28 = tmp0 - tmp20 tmp29 = tmp28 / tmp25 tmp30 = tmp27 * tmp29 tmp33 = tmp30 + tmp32 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp33, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf3 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf0 buf5 = reinterpret_tensor(buf3, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_sqrt_sub_var_0[grid(4)](buf1, buf5, primals_1, primals_2, primals_3, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf6, primals_1, buf1, buf5 class LayerNormNew(nn.Module): """Normalize by channels, height and width for images.""" __constants__ = ['eps'] def __init__(self, eps): super().__init__() self.eps = eps self.gamma = nn.Parameter(torch.ones(1)) self.beta = nn.Parameter(torch.zeros(1)) def forward(self, input_0): primals_2 = self.gamma primals_3 = self.beta primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ImadDabbura/fastai-courses
LayerNorm
false
17,433
[ "Apache-2.0" ]
3
053637a2dd3b4ad6c35f97a13f3fba87af1d3940
https://github.com/ImadDabbura/fastai-courses/tree/053637a2dd3b4ad6c35f97a13f3fba87af1d3940
InstanceNorm
import torch from torch import nn from typing import * class InstanceNorm(nn.Module): """Normalize by height and width for images.""" __constants__ = ['eps'] def __init__(self, nf, mom, eps): super().__init__() self.eps = eps self.gamma = nn.Parameter(torch.ones(nf, 1, 1)) self.beta = nn.Parameter(torch.zeros(nf, 1, 1)) def forward(self, x): mean = x.mean((2, 3), keepdim=True) var = x.var((2, 3), keepdim=True) x = (x - mean) / (var + self.eps).sqrt() return self.gamma * x + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'nf': 4, 'mom': 4, 'eps': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn from typing 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_add_div_mean_mul_sqrt_sub_var_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp4 / tmp19 tmp21 = 15.0 tmp22 = tmp18 / tmp21 tmp23 = 4.0 tmp24 = tmp22 + tmp23 tmp25 = libdevice.sqrt(tmp24) tmp27 = tmp0 - tmp20 tmp28 = tmp27 / tmp25 tmp29 = tmp26 * tmp28 tmp31 = tmp29 + tmp30 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp31, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 1, 1), (1, 1, 1)) assert_size_stride(primals_3, (4, 1, 1), (1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf3 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 buf5 = reinterpret_tensor(buf3, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_sqrt_sub_var_0[grid(16)](buf1, buf5, primals_1, primals_2, primals_3, buf6, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf6, primals_1, buf1, buf5 class InstanceNormNew(nn.Module): """Normalize by height and width for images.""" __constants__ = ['eps'] def __init__(self, nf, mom, eps): super().__init__() self.eps = eps self.gamma = nn.Parameter(torch.ones(nf, 1, 1)) self.beta = nn.Parameter(torch.zeros(nf, 1, 1)) def forward(self, input_0): primals_2 = self.gamma primals_3 = self.beta primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ImadDabbura/fastai-courses
InstanceNorm
false
17,434
[ "Apache-2.0" ]
3
053637a2dd3b4ad6c35f97a13f3fba87af1d3940
https://github.com/ImadDabbura/fastai-courses/tree/053637a2dd3b4ad6c35f97a13f3fba87af1d3940
layer_basic
import torch import numpy as np import torch.nn as nn class layer_basic(nn.Module): """ :param name: name of layer :param input_depth: D :param output_depth: S :param inputs: N x D x m x m tensor :return: output: N x S x m x m tensor """ def __init__(self, input_depth, output_depth, normalization='inf', normalization_val=1.0, device='cpu'): super().__init__() self.input_depth = input_depth self.output_depth = output_depth self.normalization = normalization self.normalization_val = normalization_val self.device = device self.basis_dimension = 4 self.coeffs = torch.nn.Parameter(torch.randn(self.input_depth, self .output_depth, self.basis_dimension) * np.sqrt(2.0) / (self. input_depth + self.output_depth), requires_grad=True) self.bias = torch.nn.Parameter(torch.zeros(1, self.output_depth, 1, 1)) def forward(self, inputs): m = inputs.size(3) float_dim = np.float32(m) ops_out = [] ops_out.append(inputs) sum_of_cols = torch.sum(inputs, dim=2) / float_dim ops_out.append(torch.cat([sum_of_cols.unsqueeze(dim=2) for i in range(m)], dim=2)) sum_of_rows = torch.sum(inputs, dim=3) / float_dim ops_out.append(torch.cat([sum_of_rows.unsqueeze(dim=3) for i in range(m)], dim=3)) sum_all = torch.sum(sum_of_rows, dim=2) / float_dim ** 2 out = torch.cat([sum_all.unsqueeze(dim=2) for i in range(m)], dim=2) ops_out.append(torch.cat([out.unsqueeze(dim=3) for i in range(m)], dim=3)) ops_out = torch.stack(ops_out, dim=2) output = torch.einsum('dsb,ndbij->nsij', self.coeffs, ops_out) output = output + self.bias return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_depth': 1, 'output_depth': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 x3 = xindex % 16 tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tmp7 + tmp8 tmp10 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = 0.25 tmp13 = tmp11 * tmp12 tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp4, tmp13, tmp14) tmp16 = tmp0 >= tmp3 tmp17 = tl.full([1], 2, tl.int64) tmp18 = tmp0 < tmp17 tmp19 = tmp16 & tmp18 tmp20 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp21 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp22 = tmp20 + tmp21 tmp23 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tmp22 + tmp23 tmp25 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp26 = tmp24 + tmp25 tmp27 = tmp26 * tmp12 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp19, tmp27, tmp28) tmp30 = tmp0 >= tmp17 tmp31 = tl.full([1], 3, tl.int64) tmp32 = tmp0 < tmp31 tmp33 = tmp30 & tmp32 tmp34 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp33 & xmask, eviction_policy='evict_last', other=0.0) tmp35 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), tmp33 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tmp34 + tmp35 tmp37 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), tmp33 & xmask, eviction_policy='evict_last', other=0.0) tmp38 = tmp36 + tmp37 tmp39 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), tmp33 & xmask, eviction_policy='evict_last', other=0.0) tmp40 = tmp38 + tmp39 tmp41 = tmp40 * tmp12 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp33, tmp41, tmp42) tmp44 = tmp0 >= tmp31 tl.full([1], 4, tl.int64) tmp47 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp48 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp49 = tmp47 + tmp48 tmp50 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp51 = tmp49 + tmp50 tmp52 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp53 = tmp51 + tmp52 tmp54 = tmp53 * tmp12 tmp55 = tl.full(tmp54.shape, 0.0, tmp54.dtype) tmp56 = tl.where(tmp44, tmp54, tmp55) tmp57 = tl.where(tmp33, tmp43, tmp56) tmp58 = tl.where(tmp19, tmp29, tmp57) tmp59 = tl.where(tmp4, tmp15, tmp58) tl.store(out_ptr0 + (x3 + 64 * x2), tmp59, 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 x0 = xindex % 4 x3 = xindex // 4 x2 = xindex // 16 x4 = xindex % 16 tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + 4 * x3, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (1 + 4 * x3), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr0 + (2 + 4 * x3), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tmp7 + tmp8 tmp10 = tl.load(in_ptr0 + (3 + 4 * x3), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = 0.25 tmp13 = tmp11 * tmp12 tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp4, tmp13, tmp14) tmp16 = tmp0 >= tmp3 tmp17 = tl.full([1], 2, tl.int64) tmp18 = tmp0 < tmp17 tmp19 = tmp16 & tmp18 tmp20 = tl.load(in_ptr0 + 4 * x3, tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.load(in_ptr0 + (1 + 4 * x3), tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp22 = tmp20 + tmp21 tmp23 = tl.load(in_ptr0 + (2 + 4 * x3), tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp24 = tmp22 + tmp23 tmp25 = tl.load(in_ptr0 + (3 + 4 * x3), tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp26 = tmp24 + tmp25 tmp27 = tmp26 * tmp12 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp19, tmp27, tmp28) tmp30 = tmp0 >= tmp17 tmp31 = tl.full([1], 3, tl.int64) tmp32 = tmp0 < tmp31 tmp33 = tmp30 & tmp32 tmp34 = tl.load(in_ptr0 + 4 * x3, tmp33 & xmask, eviction_policy= 'evict_last', other=0.0) tmp35 = tl.load(in_ptr0 + (1 + 4 * x3), tmp33 & xmask, eviction_policy= 'evict_last', other=0.0) tmp36 = tmp34 + tmp35 tmp37 = tl.load(in_ptr0 + (2 + 4 * x3), tmp33 & xmask, eviction_policy= 'evict_last', other=0.0) tmp38 = tmp36 + tmp37 tmp39 = tl.load(in_ptr0 + (3 + 4 * x3), tmp33 & xmask, eviction_policy= 'evict_last', other=0.0) tmp40 = tmp38 + tmp39 tmp41 = tmp40 * tmp12 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp33, tmp41, tmp42) tmp44 = tmp0 >= tmp31 tl.full([1], 4, tl.int64) tmp47 = tl.load(in_ptr0 + 4 * x3, tmp44 & xmask, eviction_policy= 'evict_last', other=0.0) tmp48 = tl.load(in_ptr0 + (1 + 4 * x3), tmp44 & xmask, eviction_policy= 'evict_last', other=0.0) tmp49 = tmp47 + tmp48 tmp50 = tl.load(in_ptr0 + (2 + 4 * x3), tmp44 & xmask, eviction_policy= 'evict_last', other=0.0) tmp51 = tmp49 + tmp50 tmp52 = tl.load(in_ptr0 + (3 + 4 * x3), tmp44 & xmask, eviction_policy= 'evict_last', other=0.0) tmp53 = tmp51 + tmp52 tmp54 = tmp53 * tmp12 tmp55 = tl.full(tmp54.shape, 0.0, tmp54.dtype) tmp56 = tl.where(tmp44, tmp54, tmp55) tmp57 = tl.where(tmp33, tmp43, tmp56) tmp58 = tl.where(tmp19, tmp29, tmp57) tmp59 = tl.where(tmp4, tmp15, tmp58) tl.store(out_ptr0 + (x4 + 64 * x2), tmp59, xmask) @triton.jit def triton_poi_fused__to_copy_div_sum_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp10 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp28 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp32 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 0.25 tmp8 = tmp6 * tmp7 tmp11 = tmp9 + tmp10 tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp16 = tmp15 * tmp7 tmp17 = tmp8 + tmp16 tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp24 * tmp7 tmp26 = tmp17 + tmp25 tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tmp33 = tmp31 + tmp32 tmp34 = tmp33 * tmp7 tmp35 = tmp26 + tmp34 tl.store(out_ptr0 + x0, tmp35, xmask) @triton.jit def triton_poi_fused_cat_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex % 16 tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = x1 tmp7 = tmp5 < tmp3 tmp8 = tmp7 & tmp4 tmp9 = tl.load(in_ptr0 + x2, tmp8 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = 0.0625 tmp11 = tmp9 * tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp8, tmp11, tmp12) tmp14 = tmp5 >= tmp3 tmp15 = tl.full([1], 2, tl.int64) tmp16 = tmp5 < tmp15 tmp17 = tmp14 & tmp16 tmp18 = tmp17 & tmp4 tmp19 = tl.load(in_ptr0 + x2, tmp18 & xmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tmp19 * tmp10 tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp18, tmp20, tmp21) tmp23 = tmp5 >= tmp15 tmp24 = tl.full([1], 3, tl.int64) tmp25 = tmp5 < tmp24 tmp26 = tmp23 & tmp25 tmp27 = tmp26 & tmp4 tmp28 = tl.load(in_ptr0 + x2, tmp27 & xmask, eviction_policy= 'evict_last', other=0.0) tmp29 = tmp28 * tmp10 tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp27, tmp29, tmp30) tmp32 = tmp5 >= tmp24 tl.full([1], 4, tl.int64) tmp35 = tmp32 & tmp4 tmp36 = tl.load(in_ptr0 + x2, tmp35 & xmask, eviction_policy= 'evict_last', other=0.0) tmp37 = tmp36 * tmp10 tmp38 = tl.full(tmp37.shape, 0.0, tmp37.dtype) tmp39 = tl.where(tmp35, tmp37, tmp38) tmp40 = tl.where(tmp26, tmp31, tmp39) tmp41 = tl.where(tmp17, tmp22, tmp40) tmp42 = tl.where(tmp7, tmp13, tmp41) tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype) tmp44 = tl.where(tmp4, tmp42, tmp43) tmp45 = tmp0 >= tmp3 tmp46 = tmp0 < tmp15 tmp47 = tmp45 & tmp46 tmp48 = tmp7 & tmp47 tmp49 = tl.load(in_ptr0 + x2, tmp48 & xmask, eviction_policy= 'evict_last', other=0.0) tmp50 = tmp49 * tmp10 tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype) tmp52 = tl.where(tmp48, tmp50, tmp51) tmp53 = tmp17 & tmp47 tmp54 = tl.load(in_ptr0 + x2, tmp53 & xmask, eviction_policy= 'evict_last', other=0.0) tmp55 = tmp54 * tmp10 tmp56 = tl.full(tmp55.shape, 0.0, tmp55.dtype) tmp57 = tl.where(tmp53, tmp55, tmp56) tmp58 = tmp26 & tmp47 tmp59 = tl.load(in_ptr0 + x2, tmp58 & xmask, eviction_policy= 'evict_last', other=0.0) tmp60 = tmp59 * tmp10 tmp61 = tl.full(tmp60.shape, 0.0, tmp60.dtype) tmp62 = tl.where(tmp58, tmp60, tmp61) tmp63 = tmp32 & tmp47 tmp64 = tl.load(in_ptr0 + x2, tmp63 & xmask, eviction_policy= 'evict_last', other=0.0) tmp65 = tmp64 * tmp10 tmp66 = tl.full(tmp65.shape, 0.0, tmp65.dtype) tmp67 = tl.where(tmp63, tmp65, tmp66) tmp68 = tl.where(tmp26, tmp62, tmp67) tmp69 = tl.where(tmp17, tmp57, tmp68) tmp70 = tl.where(tmp7, tmp52, tmp69) tmp71 = tl.full(tmp70.shape, 0.0, tmp70.dtype) tmp72 = tl.where(tmp47, tmp70, tmp71) tmp73 = tmp0 >= tmp15 tmp74 = tmp0 < tmp24 tmp75 = tmp73 & tmp74 tmp76 = tmp7 & tmp75 tmp77 = tl.load(in_ptr0 + x2, tmp76 & xmask, eviction_policy= 'evict_last', other=0.0) tmp78 = tmp77 * tmp10 tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype) tmp80 = tl.where(tmp76, tmp78, tmp79) tmp81 = tmp17 & tmp75 tmp82 = tl.load(in_ptr0 + x2, tmp81 & xmask, eviction_policy= 'evict_last', other=0.0) tmp83 = tmp82 * tmp10 tmp84 = tl.full(tmp83.shape, 0.0, tmp83.dtype) tmp85 = tl.where(tmp81, tmp83, tmp84) tmp86 = tmp26 & tmp75 tmp87 = tl.load(in_ptr0 + x2, tmp86 & xmask, eviction_policy= 'evict_last', other=0.0) tmp88 = tmp87 * tmp10 tmp89 = tl.full(tmp88.shape, 0.0, tmp88.dtype) tmp90 = tl.where(tmp86, tmp88, tmp89) tmp91 = tmp32 & tmp75 tmp92 = tl.load(in_ptr0 + x2, tmp91 & xmask, eviction_policy= 'evict_last', other=0.0) tmp93 = tmp92 * tmp10 tmp94 = tl.full(tmp93.shape, 0.0, tmp93.dtype) tmp95 = tl.where(tmp91, tmp93, tmp94) tmp96 = tl.where(tmp26, tmp90, tmp95) tmp97 = tl.where(tmp17, tmp85, tmp96) tmp98 = tl.where(tmp7, tmp80, tmp97) tmp99 = tl.full(tmp98.shape, 0.0, tmp98.dtype) tmp100 = tl.where(tmp75, tmp98, tmp99) tmp101 = tmp0 >= tmp24 tmp103 = tmp7 & tmp101 tmp104 = tl.load(in_ptr0 + x2, tmp103 & xmask, eviction_policy= 'evict_last', other=0.0) tmp105 = tmp104 * tmp10 tmp106 = tl.full(tmp105.shape, 0.0, tmp105.dtype) tmp107 = tl.where(tmp103, tmp105, tmp106) tmp108 = tmp17 & tmp101 tmp109 = tl.load(in_ptr0 + x2, tmp108 & xmask, eviction_policy= 'evict_last', other=0.0) tmp110 = tmp109 * tmp10 tmp111 = tl.full(tmp110.shape, 0.0, tmp110.dtype) tmp112 = tl.where(tmp108, tmp110, tmp111) tmp113 = tmp26 & tmp101 tmp114 = tl.load(in_ptr0 + x2, tmp113 & xmask, eviction_policy= 'evict_last', other=0.0) tmp115 = tmp114 * tmp10 tmp116 = tl.full(tmp115.shape, 0.0, tmp115.dtype) tmp117 = tl.where(tmp113, tmp115, tmp116) tmp118 = tmp32 & tmp101 tmp119 = tl.load(in_ptr0 + x2, tmp118 & xmask, eviction_policy= 'evict_last', other=0.0) tmp120 = tmp119 * tmp10 tmp121 = tl.full(tmp120.shape, 0.0, tmp120.dtype) tmp122 = tl.where(tmp118, tmp120, tmp121) tmp123 = tl.where(tmp26, tmp117, tmp122) tmp124 = tl.where(tmp17, tmp112, tmp123) tmp125 = tl.where(tmp7, tmp107, tmp124) tmp126 = tl.full(tmp125.shape, 0.0, tmp125.dtype) tmp127 = tl.where(tmp101, tmp125, tmp126) tmp128 = tl.where(tmp75, tmp100, tmp127) tmp129 = tl.where(tmp47, tmp72, tmp128) tmp130 = tl.where(tmp4, tmp44, tmp129) tl.store(out_ptr0 + (x3 + 64 * x2), tmp130, xmask) @triton.jit def triton_poi_fused_stack_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 64 * x1), tmp0, xmask) @triton.jit def triton_poi_fused_sum_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y0 + 256 * y1), xmask & ymask) tmp1 = tl.load(in_ptr0 + (64 + x2 + 16 * y0 + 256 * y1), xmask & ymask) tmp3 = tl.load(in_ptr0 + (128 + x2 + 16 * y0 + 256 * y1), xmask & ymask) tmp5 = tl.load(in_ptr0 + (192 + x2 + 16 * y0 + 256 * y1), xmask & ymask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp6, xmask & ymask) @triton.jit def triton_poi_fused_add_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 1, 4), (4, 4, 1)) assert_size_stride(primals_3, (1, 1, 1, 1), (1, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf5 = empty_strided_cuda((4, 4, 16, 4), (256, 64, 4, 1), torch.float32 ) buf0 = reinterpret_tensor(buf5, (4, 4, 4, 4), (256, 64, 4, 1), 16) get_raw_stream(0) triton_poi_fused_cat_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = reinterpret_tensor(buf5, (4, 4, 4, 4), (256, 64, 4, 1), 32) triton_poi_fused_cat_1[grid(256)](primals_1, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__to_copy_div_sum_2[grid(16)](primals_1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf5, (4, 4, 4, 4), (256, 64, 4, 1), 48) triton_poi_fused_cat_3[grid(256)](buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf2 buf4 = reinterpret_tensor(buf5, (4, 4, 4, 4), (256, 64, 4, 1), 0) triton_poi_fused_stack_4[grid(256)](primals_1, buf4, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_1 buf6 = empty_strided_cuda((4, 1, 4, 4, 4, 1), (64, 64, 16, 4, 1, 1), torch.float32) triton_poi_fused_sum_5[grid(16, 16)](buf5, buf6, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del buf0 del buf1 del buf3 del buf4 del buf5 buf7 = empty_strided_cuda((1, 1, 64), (64, 64, 1), torch.float32) extern_kernels.bmm(primals_2, reinterpret_tensor(buf6, (1, 4, 64), (0, 1, 4), 0), out=buf7) del primals_2 buf8 = reinterpret_tensor(buf7, (4, 1, 4, 4), (16, 16, 4, 1), 0) del buf7 triton_poi_fused_add_6[grid(64)](buf8, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf8, reinterpret_tensor(buf6, (1, 64, 4), (4, 4, 1), 0) class layer_basicNew(nn.Module): """ :param name: name of layer :param input_depth: D :param output_depth: S :param inputs: N x D x m x m tensor :return: output: N x S x m x m tensor """ def __init__(self, input_depth, output_depth, normalization='inf', normalization_val=1.0, device='cpu'): super().__init__() self.input_depth = input_depth self.output_depth = output_depth self.normalization = normalization self.normalization_val = normalization_val self.device = device self.basis_dimension = 4 self.coeffs = torch.nn.Parameter(torch.randn(self.input_depth, self .output_depth, self.basis_dimension) * np.sqrt(2.0) / (self. input_depth + self.output_depth), requires_grad=True) self.bias = torch.nn.Parameter(torch.zeros(1, self.output_depth, 1, 1)) def forward(self, input_0): primals_2 = self.coeffs primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
HyTruongSon/InvariantGraphNetworks-PyTorch
layer_basic
false
17,435
[ "Apache-2.0" ]
7
da9fdaa4f858d6fcae14b08a59d4b172a2aabaf8
https://github.com/HyTruongSon/InvariantGraphNetworks-PyTorch/tree/da9fdaa4f858d6fcae14b08a59d4b172a2aabaf8
SamePad2dStrong
import math import torch import torch.nn.functional as F import torch.nn as nn class SamePad2dStrong(nn.Module): """Mimics tensorflow's 'SAME' padding. """ def __init__(self, kernel_size, stride): super(SamePad2dStrong, self).__init__() self.kernel_size = torch.nn.modules.utils._pair(kernel_size) self.stride = torch.nn.modules.utils._pair(stride) def forward(self, input): in_width = input.size()[2] in_height = input.size()[3] out_width = math.ceil(float(in_width) / float(self.stride[0])) out_height = math.ceil(float(in_height) / float(self.stride[1])) pad_along_width = (out_width - 1) * self.stride[0] + self.kernel_size[0 ] - in_width pad_along_height = (out_height - 1) * self.stride[1 ] + self.kernel_size[1] - in_height pad_left = math.floor(pad_along_width / 2) pad_top = math.floor(pad_along_height / 2) pad_right = pad_along_width - pad_left pad_bottom = pad_along_height - pad_top return F.pad(input, (pad_left, pad_right, pad_top, pad_bottom), 'constant', 0) def __repr__(self): return self.__class__.__name__ def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4, 'stride': 1}]
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_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 7 % 7 x0 = xindex % 7 x2 = xindex // 49 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp11, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(784)](arg0_1, buf0, 784, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SamePad2dStrongNew(nn.Module): """Mimics tensorflow's 'SAME' padding. """ def __init__(self, kernel_size, stride): super(SamePad2dStrongNew, self).__init__() self.kernel_size = torch.nn.modules.utils._pair(kernel_size) self.stride = torch.nn.modules.utils._pair(stride) def __repr__(self): return self.__class__.__name__ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
IssamLaradji/wisenet
SamePad2dStrong
false
17,436
[ "Apache-2.0" ]
7
881457f5168815f5e9d03f110244842d539747a0
https://github.com/IssamLaradji/wisenet/tree/881457f5168815f5e9d03f110244842d539747a0
InstrShifting
import torch import torch.nn as nn class InstrShifting(nn.Module): """ Sub-Instruction Shifting Module. Decide whether the current subinstruction will be completed by the next action or not. """ def __init__(self, rnn_hidden_size, shift_hidden_size, action_emb_size, max_subinstr_size, drop_ratio): super(InstrShifting, self).__init__() self.drop = nn.Dropout(p=drop_ratio) self.linear0 = nn.Linear(rnn_hidden_size, shift_hidden_size, bias=False ) self.linear1 = nn.Linear(rnn_hidden_size + shift_hidden_size + action_emb_size, shift_hidden_size, bias=False) self.linear2 = nn.Linear(max_subinstr_size, shift_hidden_size, bias =False) self.linear3 = nn.Linear(2 * shift_hidden_size, 1, bias=False) def forward(self, h_t, m_t, a_t_cur, weighted_ctx, e_t): """ Propogate through the network. :param h_t: torch.Tensor, batch x rnn_hidden_size :param m_t: torch.Tensor, batch x rnn_hidden_size :param a_t_cur: torch.Tensor, batch x action_emb_size :param weighted_ctx: torch.Tensor, batch x rnn_hidden_size :param e_t: torch.Tensor, batch x max_subinstr_size """ proj_h = self.linear0(self.drop(h_t)) concat_input = torch.cat((proj_h, a_t_cur, weighted_ctx), 1) h_t_c = torch.sigmoid(self.linear1(concat_input)) * torch.tanh(m_t) proj_e = self.linear2(e_t) concat_input = torch.cat((proj_e, self.drop(h_t_c)), 1) p_t_s = torch.sigmoid(self.linear3(concat_input)) return p_t_s.squeeze() def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'rnn_hidden_size': 4, 'shift_hidden_size': 4, 'action_emb_size': 4, 'max_subinstr_size': 4, 'drop_ratio': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels from torch._C import _cuda_getCurrentRawStream as get_raw_stream import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_for_fused_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1): pid = tl.program_id(0) XBLOCK: tl.constexpr = 1024 num_xblocks_0 = tl.cdiv(16, XBLOCK) num_xblocks_1 = num_xblocks_0 + tl.cdiv(16, XBLOCK) if pid < num_xblocks_0: pid_offset = pid xnumel = 16 xoffset = pid_offset * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, xmask) elif pid < num_xblocks_1: pid_offset = pid - num_xblocks_0 xnumel = 16 xoffset = pid_offset * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x5 = xindex x3 = xindex % 4 x4 = xindex // 4 tmp1 = tl.load(in_ptr1 + x5, xmask) tl.store(out_ptr1 + (x3 + 12 * x4), tmp1, xmask) else: pass @triton.jit def triton_poi_fused_mul_sigmoid_tanh_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x2, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = libdevice.tanh(tmp2) tmp4 = tmp1 * tmp3 tl.store(out_ptr0 + (x0 + 8 * x1), tmp4, xmask) @triton.jit def triton_poi_fused_sigmoid_sigmoid_backward_2(in_out_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_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, 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, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4, 12), (12, 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, 4), (4, 1)) assert_size_stride(primals_9, (1, 8), (8, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf3 = empty_strided_cuda((4, 12), (12, 1), torch.float32) buf0 = reinterpret_tensor(buf3, (4, 4), (12, 1), 0) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf3, (4, 4), (12, 1), 4) buf2 = reinterpret_tensor(buf3, (4, 4), (12, 1), 8) get_raw_stream(0) triton_for_fused_0[2, 1, 1](primals_3, primals_4, buf1, buf2, num_warps=8, num_stages=1) del primals_3 del primals_4 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_5, (12, 4), (1, 12), 0), out=buf4) buf7 = empty_strided_cuda((4, 8), (8, 1), torch.float32) buf5 = reinterpret_tensor(buf7, (4, 4), (8, 1), 0) extern_kernels.mm(primals_8, reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf5) del primals_7 buf6 = reinterpret_tensor(buf7, (4, 4), (8, 1), 4) triton_poi_fused_mul_sigmoid_tanh_1[grid(16)](buf4, primals_6, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.mm(buf7, reinterpret_tensor(primals_9, (8, 1), (1, 8 ), 0), out=buf8) buf9 = buf8 del buf8 buf10 = empty_strided_cuda((4, 1), (1, 1), torch.float32) triton_poi_fused_sigmoid_sigmoid_backward_2[grid(4)](buf9, buf10, 4, XBLOCK=4, num_warps=1, num_stages=1) return (reinterpret_tensor(buf9, (4,), (1,), 0), primals_1, primals_6, primals_8, buf3, buf4, buf7, buf10, primals_9, primals_5) class InstrShiftingNew(nn.Module): """ Sub-Instruction Shifting Module. Decide whether the current subinstruction will be completed by the next action or not. """ def __init__(self, rnn_hidden_size, shift_hidden_size, action_emb_size, max_subinstr_size, drop_ratio): super(InstrShiftingNew, self).__init__() self.drop = nn.Dropout(p=drop_ratio) self.linear0 = nn.Linear(rnn_hidden_size, shift_hidden_size, bias=False ) self.linear1 = nn.Linear(rnn_hidden_size + shift_hidden_size + action_emb_size, shift_hidden_size, bias=False) self.linear2 = nn.Linear(max_subinstr_size, shift_hidden_size, bias =False) self.linear3 = nn.Linear(2 * shift_hidden_size, 1, bias=False) def forward(self, input_0, input_1, input_2, input_3, input_4): primals_1 = self.linear0.weight primals_5 = self.linear1.weight primals_2 = self.linear2.weight primals_9 = self.linear3.weight primals_3 = input_0 primals_4 = input_1 primals_6 = input_2 primals_7 = input_3 primals_8 = input_4 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
IMNearth/Curriculum-Learning-For-VLN
InstrShifting
false
17,437
[ "MIT" ]
8
d2fe1286eb295dc8c63a0c886b35883f32481d85
https://github.com/IMNearth/Curriculum-Learning-For-VLN/tree/d2fe1286eb295dc8c63a0c886b35883f32481d85
DiceLoss
import collections import torch import warnings from typing import Optional from typing import Union from typing import Callable from typing import Any from typing import Tuple import torch.nn from torch.nn.modules.loss import _Loss from enum import Enum import collections.abc def issequenceiterable(obj: 'Any') ->bool: """ Determine if the object is an iterable sequence and is not a string. """ if torch.is_tensor(obj): return int(obj.dim()) > 0 return isinstance(obj, collections.abc.Iterable) and not isinstance(obj, str) def ensure_tuple(vals: 'Any') ->Tuple[Any, ...]: """ Returns a tuple of `vals`. """ if not issequenceiterable(vals): vals = vals, return tuple(vals) def ensure_tuple_size(tup: 'Any', dim: 'int', pad_val: 'Any'=0) ->Tuple[Any, ...]: """ Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. """ tup = ensure_tuple(tup) + (pad_val,) * dim return tuple(tup[:dim]) def one_hot(labels: 'torch.Tensor', num_classes: 'int', dtype: 'torch.dtype'=torch.float, dim: 'int'=1) ->torch.Tensor: """ For a tensor `labels` of dimensions B1[spatial_dims], return a tensor of dimensions `BN[spatial_dims]` for `num_classes` N number of classes. Example: For every value v = labels[b,1,h,w], the value in the result at [b,v,h,w] will be 1 and all others 0. Note that this will include the background label, thus a binary mask should be treated as having 2 classes. """ assert labels.dim() > 0, 'labels should have dim of 1 or more.' if labels.ndimension() < dim + 1: shape = ensure_tuple_size(labels.shape, dim + 1, 1) labels = labels.reshape(*shape) sh = list(labels.shape) assert sh[dim ] == 1, 'labels should have a channel with length equals to one.' sh[dim] = num_classes o = torch.zeros(size=sh, dtype=dtype, device=labels.device) labels = o.scatter_(dim=dim, index=labels.long(), value=1) return labels class LossReduction(Enum): """ See also: - :py:class:`monai.losses.dice.DiceLoss` - :py:class:`monai.losses.dice.GeneralizedDiceLoss` - :py:class:`monai.losses.focal_loss.FocalLoss` - :py:class:`monai.losses.tversky.TverskyLoss` """ NONE = 'none' MEAN = 'mean' SUM = 'sum' class DiceLoss(_Loss): """ Compute average Dice loss between two tensors. It can support both multi-classes and multi-labels tasks. Input logits `input` (BNHW[D] where N is number of classes) is compared with ground truth `target` (BNHW[D]). Axis N of `input` is expected to have logit predictions for each class rather than being image channels, while the same axis of `target` can be 1 or N (one-hot format). The `smooth_nr` and `smooth_dr` parameters are values added to the intersection and union components of the inter-over-union calculation to smooth results respectively, these values should be small. The `include_background` class attribute can be set to False for an instance of DiceLoss to exclude the first category (channel index 0) which is by convention assumed to be background. If the non-background segmentations are small compared to the total image size they can get overwhelmed by the signal from the background so excluding it in such cases helps convergence. Milletari, F. et. al. (2016) V-Net: Fully Convolutional Neural Networks forVolumetric Medical Image Segmentation, 3DV, 2016. """ def __init__(self, include_background: 'bool'=True, to_onehot_y: 'bool' =False, sigmoid: 'bool'=False, softmax: 'bool'=False, other_act: 'Optional[Callable]'=None, squared_pred: 'bool'=False, jaccard: 'bool'=False, reduction: 'Union[LossReduction, str]'=LossReduction. MEAN, smooth_nr: 'float'=1e-05, smooth_dr: 'float'=1e-05, batch: 'bool'=False) ->None: """ Args: include_background: if False channel index 0 (background category) is excluded from the calculation. to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. sigmoid: if True, apply a sigmoid function to the prediction. softmax: if True, apply a softmax function to the prediction. other_act: if don't want to use `sigmoid` or `softmax`, use other callable function to execute other activation layers, Defaults to ``None``. for example: `other_act = torch.tanh`. squared_pred: use squared versions of targets and predictions in the denominator or not. jaccard: compute Jaccard Index (soft IoU) instead of dice or not. reduction: {``"none"``, ``"mean"``, ``"sum"``} Specifies the reduction to apply to the output. Defaults to ``"mean"``. - ``"none"``: no reduction will be applied. - ``"mean"``: the sum of the output will be divided by the number of elements in the output. - ``"sum"``: the output will be summed. smooth_nr: a small constant added to the numerator to avoid zero. smooth_dr: a small constant added to the denominator to avoid nan. batch: whether to sum the intersection and union areas over the batch dimension before the dividing. Defaults to False, a Dice loss value is computed independently from each item in the batch before any `reduction`. Raises: TypeError: When ``other_act`` is not an ``Optional[Callable]``. ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``]. Incompatible values. """ super().__init__(reduction=LossReduction(reduction).value) if other_act is not None and not callable(other_act): raise TypeError( f'other_act must be None or callable but is {type(other_act).__name__}.' ) if int(sigmoid) + int(softmax) + int(other_act is not None) > 1: raise ValueError( 'Incompatible values: more than 1 of [sigmoid=True, softmax=True, other_act is not None].' ) self.include_background = include_background self.to_onehot_y = to_onehot_y self.sigmoid = sigmoid self.softmax = softmax self.other_act = other_act self.squared_pred = squared_pred self.jaccard = jaccard self.smooth_nr = float(smooth_nr) self.smooth_dr = float(smooth_dr) self.batch = batch def forward(self, input: 'torch.Tensor', target: 'torch.Tensor' ) ->torch.Tensor: """ Args: input: the shape should be BNH[WD]. target: the shape should be BNH[WD]. Raises: ValueError: When ``self.reduction`` is not one of ["mean", "sum", "none"]. """ if self.sigmoid: input = torch.sigmoid(input) n_pred_ch = input.shape[1] if self.softmax: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `softmax=True` ignored.') else: input = torch.softmax(input, 1) if self.other_act is not None: input = self.other_act(input) if self.to_onehot_y: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `to_onehot_y=True` ignored.') else: target = one_hot(target, num_classes=n_pred_ch) if not self.include_background: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `include_background=False` ignored.' ) else: target = target[:, 1:] input = input[:, 1:] assert target.shape == input.shape, f'ground truth has differing shape ({target.shape}) from input ({input.shape})' reduce_axis = list(range(2, len(input.shape))) if self.batch: reduce_axis = [0] + reduce_axis intersection = torch.sum(target * input, dim=reduce_axis) if self.squared_pred: target = torch.pow(target, 2) input = torch.pow(input, 2) ground_o = torch.sum(target, dim=reduce_axis) pred_o = torch.sum(input, dim=reduce_axis) denominator = ground_o + pred_o if self.jaccard: denominator = 2.0 * (denominator - intersection) f: 'torch.Tensor' = 1.0 - (2.0 * intersection + self.smooth_nr) / ( denominator + self.smooth_dr) if self.reduction == LossReduction.MEAN.value: f = torch.mean(f) elif self.reduction == LossReduction.SUM.value: f = torch.sum(f) elif self.reduction == LossReduction.NONE.value: pass else: raise ValueError( f'Unsupported reduction: {self.reduction}, available options are ["mean", "sum", "none"].' ) return f 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 collections from typing import Optional from typing import Union from typing import Callable from typing import Any from typing import Tuple import torch.nn from torch.nn.modules.loss import _Loss from enum import Enum import collections.abc 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_mul_sum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp13 = tl.where(xmask, tmp11, 0) tmp14 = tl.sum(tmp13, 1)[:, None] tl.store(out_ptr0 + x0, tmp6, xmask) tl.store(out_ptr1 + x0, tmp10, xmask) tl.store(out_ptr2 + x0, tmp14, xmask) @triton.jit def triton_per_fused_add_div_mean_mul_rsub_1(in_out_ptr0, in_ptr0, in_ptr1, in_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 tmp0 = tl.load(in_ptr0 + r0, None) tmp5 = tl.load(in_ptr1 + r0, None) tmp6 = tl.load(in_ptr2 + r0, None) tmp1 = 2.0 tmp2 = tmp0 * tmp1 tmp3 = 1e-05 tmp4 = tmp2 + tmp3 tmp7 = tmp5 + tmp6 tmp8 = tmp7 + tmp3 tmp9 = tmp4 / tmp8 tmp10 = 1.0 tmp11 = tmp10 - tmp9 tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK]) tmp14 = tl.sum(tmp12, 1)[:, None] tmp15 = 16.0 tmp16 = tmp14 / tmp15 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp16, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused_mul_sum_0[grid(16)](arg1_1, arg0_1, buf0, buf1, buf2, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused_add_div_mean_mul_rsub_1[grid(1)](buf4, buf0, buf1, buf2, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 del buf2 return buf4, def issequenceiterable(obj: 'Any') ->bool: """ Determine if the object is an iterable sequence and is not a string. """ if torch.is_tensor(obj): return int(obj.dim()) > 0 return isinstance(obj, collections.abc.Iterable) and not isinstance(obj, str) def ensure_tuple(vals: 'Any') ->Tuple[Any, ...]: """ Returns a tuple of `vals`. """ if not issequenceiterable(vals): vals = vals, return tuple(vals) def ensure_tuple_size(tup: 'Any', dim: 'int', pad_val: 'Any'=0) ->Tuple[Any, ...]: """ Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. """ tup = ensure_tuple(tup) + (pad_val,) * dim return tuple(tup[:dim]) def one_hot(labels: 'torch.Tensor', num_classes: 'int', dtype: 'torch.dtype'=torch.float, dim: 'int'=1) ->torch.Tensor: """ For a tensor `labels` of dimensions B1[spatial_dims], return a tensor of dimensions `BN[spatial_dims]` for `num_classes` N number of classes. Example: For every value v = labels[b,1,h,w], the value in the result at [b,v,h,w] will be 1 and all others 0. Note that this will include the background label, thus a binary mask should be treated as having 2 classes. """ assert labels.dim() > 0, 'labels should have dim of 1 or more.' if labels.ndimension() < dim + 1: shape = ensure_tuple_size(labels.shape, dim + 1, 1) labels = labels.reshape(*shape) sh = list(labels.shape) assert sh[dim ] == 1, 'labels should have a channel with length equals to one.' sh[dim] = num_classes o = torch.zeros(size=sh, dtype=dtype, device=labels.device) labels = o.scatter_(dim=dim, index=labels.long(), value=1) return labels class LossReduction(Enum): """ See also: - :py:class:`monai.losses.dice.DiceLoss` - :py:class:`monai.losses.dice.GeneralizedDiceLoss` - :py:class:`monai.losses.focal_loss.FocalLoss` - :py:class:`monai.losses.tversky.TverskyLoss` """ NONE = 'none' MEAN = 'mean' SUM = 'sum' class DiceLossNew(_Loss): """ Compute average Dice loss between two tensors. It can support both multi-classes and multi-labels tasks. Input logits `input` (BNHW[D] where N is number of classes) is compared with ground truth `target` (BNHW[D]). Axis N of `input` is expected to have logit predictions for each class rather than being image channels, while the same axis of `target` can be 1 or N (one-hot format). The `smooth_nr` and `smooth_dr` parameters are values added to the intersection and union components of the inter-over-union calculation to smooth results respectively, these values should be small. The `include_background` class attribute can be set to False for an instance of DiceLoss to exclude the first category (channel index 0) which is by convention assumed to be background. If the non-background segmentations are small compared to the total image size they can get overwhelmed by the signal from the background so excluding it in such cases helps convergence. Milletari, F. et. al. (2016) V-Net: Fully Convolutional Neural Networks forVolumetric Medical Image Segmentation, 3DV, 2016. """ def __init__(self, include_background: 'bool'=True, to_onehot_y: 'bool' =False, sigmoid: 'bool'=False, softmax: 'bool'=False, other_act: 'Optional[Callable]'=None, squared_pred: 'bool'=False, jaccard: 'bool'=False, reduction: 'Union[LossReduction, str]'=LossReduction. MEAN, smooth_nr: 'float'=1e-05, smooth_dr: 'float'=1e-05, batch: 'bool'=False) ->None: """ Args: include_background: if False channel index 0 (background category) is excluded from the calculation. to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. sigmoid: if True, apply a sigmoid function to the prediction. softmax: if True, apply a softmax function to the prediction. other_act: if don't want to use `sigmoid` or `softmax`, use other callable function to execute other activation layers, Defaults to ``None``. for example: `other_act = torch.tanh`. squared_pred: use squared versions of targets and predictions in the denominator or not. jaccard: compute Jaccard Index (soft IoU) instead of dice or not. reduction: {``"none"``, ``"mean"``, ``"sum"``} Specifies the reduction to apply to the output. Defaults to ``"mean"``. - ``"none"``: no reduction will be applied. - ``"mean"``: the sum of the output will be divided by the number of elements in the output. - ``"sum"``: the output will be summed. smooth_nr: a small constant added to the numerator to avoid zero. smooth_dr: a small constant added to the denominator to avoid nan. batch: whether to sum the intersection and union areas over the batch dimension before the dividing. Defaults to False, a Dice loss value is computed independently from each item in the batch before any `reduction`. Raises: TypeError: When ``other_act`` is not an ``Optional[Callable]``. ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``]. Incompatible values. """ super().__init__(reduction=LossReduction(reduction).value) if other_act is not None and not callable(other_act): raise TypeError( f'other_act must be None or callable but is {type(other_act).__name__}.' ) if int(sigmoid) + int(softmax) + int(other_act is not None) > 1: raise ValueError( 'Incompatible values: more than 1 of [sigmoid=True, softmax=True, other_act is not None].' ) self.include_background = include_background self.to_onehot_y = to_onehot_y self.sigmoid = sigmoid self.softmax = softmax self.other_act = other_act self.squared_pred = squared_pred self.jaccard = jaccard self.smooth_nr = float(smooth_nr) self.smooth_dr = float(smooth_dr) self.batch = batch def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Irme/MONAI
DiceLoss
false
17,438
[ "Apache-2.0" ]
3
dc4bf661831b14f4231cb325cc1b15d38c1e406c
https://github.com/Irme/MONAI/tree/dc4bf661831b14f4231cb325cc1b15d38c1e406c
BCEFocalLoss
import torch import torch.utils.data from sklearn import * class BCEFocalLoss(torch.nn.Module): """ 二分类的Focalloss alpha 固定 """ def __init__(self, gamma=2, alpha=0.25, reduction='elementwise_mean'): super().__init__() self.gamma = gamma self.alpha = alpha self.reduction = reduction def forward(self, _input, target): pt = _input alpha = self.alpha loss = -alpha * (1 - pt) ** self.gamma * target * torch.log(pt) - ( 1 - alpha) * pt ** self.gamma * (1 - target) * torch.log(1 - pt) if self.reduction == 'elementwise_mean': loss = torch.mean(loss) elif self.reduction == 'sum': loss = torch.sum(loss) elif self.reduction == 'pos': loss = torch.sum(loss) / (2 * pos) 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.utils.data from sklearn 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_log_mean_mul_pow_rsub_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp6 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp3 = tmp2 * tmp2 tmp4 = -0.25 tmp5 = tmp3 * tmp4 tmp7 = tmp5 * tmp6 tmp8 = tl_math.log(tmp0) tmp9 = tmp7 * tmp8 tmp10 = tmp0 * tmp0 tmp11 = 0.75 tmp12 = tmp10 * tmp11 tmp13 = tmp1 - tmp6 tmp14 = tmp12 * tmp13 tmp15 = tl_math.log(tmp2) tmp16 = tmp14 * tmp15 tmp17 = tmp9 - tmp16 tmp18 = tl.broadcast_to(tmp17, [RBLOCK]) tmp20 = triton_helpers.promote_to_tensor(tl.sum(tmp18, 0)) tmp21 = 256.0 tmp22 = tmp20 / tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp22, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_log_mean_mul_pow_rsub_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class BCEFocalLossNew(torch.nn.Module): """ 二分类的Focalloss alpha 固定 """ def __init__(self, gamma=2, alpha=0.25, reduction='elementwise_mean'): super().__init__() self.gamma = gamma self.alpha = alpha self.reduction = reduction def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
CityU-AIM-Group/SIGMA
BCEFocalLoss
false
17,439
[ "MIT" ]
5
19f89777db8d42f750a9b87756d3326c7efd18f5
https://github.com/CityU-AIM-Group/SIGMA/tree/19f89777db8d42f750a9b87756d3326c7efd18f5
BiAttention
import torch from torchvision.transforms import functional as F import torch.utils.data import torch.nn as nn import torch.nn.functional as F from torch.nn.utils import weight_norm import torch.nn.modules.module class FCNet(nn.Module): def __init__(self, in_size, out_size, activate=None, drop=0.0): super(FCNet, self).__init__() self.lin = weight_norm(nn.Linear(in_size, out_size), dim=None) self.drop_value = drop self.drop = nn.Dropout(drop) self.activate = activate.lower() if activate is not None else None if activate == 'relu': self.ac_fn = nn.ReLU() elif activate == 'sigmoid': self.ac_fn = nn.Sigmoid() elif activate == 'tanh': self.ac_fn = nn.Tanh() def forward(self, x): if self.drop_value > 0: x = self.drop(x) x = self.lin(x) if self.activate is not None: x = self.ac_fn(x) return x class BiAttention(nn.Module): def __init__(self, v_features, q_features, mid_features, glimpses, drop=0.0 ): super(BiAttention, self).__init__() self.hidden_aug = 3 self.glimpses = glimpses self.lin_v = FCNet(v_features, int(mid_features * self.hidden_aug), activate='relu', drop=drop / 2.5) self.lin_q = FCNet(q_features, int(mid_features * self.hidden_aug), activate='relu', drop=drop / 2.5) self.h_weight = nn.Parameter(torch.Tensor(1, glimpses, 1, int( mid_features * self.hidden_aug)).normal_()) self.h_bias = nn.Parameter(torch.Tensor(1, glimpses, 1, 1).normal_()) self.drop = nn.Dropout(drop) def forward(self, v, q): """ v = batch, num_obj, dim q = batch, que_len, dim """ v_num = v.size(1) q_num = q.size(1) v_ = self.lin_v(v).unsqueeze(1) q_ = self.lin_q(q).unsqueeze(1) v_ = self.drop(v_) h_ = v_ * self.h_weight logits = torch.matmul(h_, q_.transpose(2, 3)) logits = logits + self.h_bias atten = F.softmax(logits.view(-1, self.glimpses, v_num * q_num), 2) return atten.view(-1, self.glimpses, v_num, q_num) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'v_features': 4, 'q_features': 4, 'mid_features': 4, 'glimpses': 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.utils.data import torch.nn as nn from torch.nn.utils import weight_norm import torch.nn.modules.module assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_div_mul_norm_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, 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 + r0, rmask, other=0.0) tmp7 = tl.load(in_ptr1 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(rmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = libdevice.sqrt(tmp5) tmp9 = tmp8 / tmp6 tmp10 = tmp0 * tmp9 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp10, rmask) @triton.jit def triton_poi_fused_clone_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex // 768 x5 = xindex % 192 x0 = xindex % 12 x2 = xindex // 48 % 4 x7 = xindex tmp0 = tl.load(in_ptr0 + (x5 + 192 * x4), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr1 + (x0 + 12 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x7, tmp4, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 12 x3 = xindex // 192 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (x1 + 12 * x0 + 48 * x3), xmask, eviction_policy='evict_last') 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 + x5, tmp4, xmask) @triton.jit def triton_per_fused__softmax_3(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tmp7 = tmp2 - tmp6 tmp8 = tl_math.exp(tmp7) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.where(xmask, tmp9, 0) tmp12 = tl.sum(tmp11, 1)[:, None] tmp13 = tmp8 / tmp12 tl.store(out_ptr2 + (r2 + 16 * x3), tmp13, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 12 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp6, xmask) 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), (16, 4, 1)) assert_size_stride(primals_3, (), ()) assert_size_stride(primals_4, (12, 4), (4, 1)) assert_size_stride(primals_5, (12,), (1,)) assert_size_stride(primals_6, (), ()) assert_size_stride(primals_7, (12, 4), (4, 1)) assert_size_stride(primals_8, (12,), (1,)) assert_size_stride(primals_9, (1, 4, 1, 12), (48, 12, 12, 1)) assert_size_stride(primals_10, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((12, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused_div_mul_norm_0[grid(1)](buf1, primals_4, primals_3, buf2, 1, 48, XBLOCK=1, num_warps=2, num_stages=1) buf3 = empty_strided_cuda((64, 12), (12, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(buf2, (4, 12), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((12, 4), (4, 1), torch.float32) triton_per_fused_div_mul_norm_0[grid(1)](buf5, primals_7, primals_6, buf6, 1, 48, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), reinterpret_tensor(buf6, (4, 12), (1, 4), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 4, 4, 12), (768, 192, 48, 12, 1), torch.float32) triton_poi_fused_clone_1[grid(3072)](buf3, primals_9, buf8, 3072, XBLOCK=128, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((4, 4, 4, 12, 4), (768, 192, 48, 4, 1), torch.float32) triton_poi_fused_clone_2[grid(3072)](buf7, primals_8, buf9, 3072, XBLOCK=256, num_warps=4, num_stages=1) buf10 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf8, (64, 4, 12), (48, 12, 1 ), 0), reinterpret_tensor(buf9, (64, 12, 4), (48, 4, 1), 0), out=buf10) buf13 = empty_strided_cuda((16, 4, 16), (64, 16, 1), torch.float32) triton_per_fused__softmax_3[grid(64)](buf10, primals_10, buf13, 64, 16, XBLOCK=32, num_warps=4, num_stages=1) del buf10 del primals_10 buf14 = empty_strided_cuda((4, 4, 12), (48, 12, 1), torch.bool) triton_poi_fused_relu_threshold_backward_4[grid(192)](buf7, primals_8, buf14, 192, XBLOCK=128, num_warps=4, num_stages=1) del buf7 del primals_8 return (reinterpret_tensor(buf13, (16, 4, 4, 4), (64, 16, 4, 1), 0), buf2, buf6, primals_3, primals_4, primals_6, primals_7, primals_9, buf1, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), buf3, buf5, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0), buf13, reinterpret_tensor(buf8, (64, 12, 4), (48, 1, 12), 0), reinterpret_tensor(buf9, (64, 4, 12), (48, 1, 4), 0), buf14) class FCNet(nn.Module): def __init__(self, in_size, out_size, activate=None, drop=0.0): super(FCNet, self).__init__() self.lin = weight_norm(nn.Linear(in_size, out_size), dim=None) self.drop_value = drop self.drop = nn.Dropout(drop) self.activate = activate.lower() if activate is not None else None if activate == 'relu': self.ac_fn = nn.ReLU() elif activate == 'sigmoid': self.ac_fn = nn.Sigmoid() elif activate == 'tanh': self.ac_fn = nn.Tanh() def forward(self, x): if self.drop_value > 0: x = self.drop(x) x = self.lin(x) if self.activate is not None: x = self.ac_fn(x) return x class BiAttentionNew(nn.Module): def __init__(self, v_features, q_features, mid_features, glimpses, drop=0.0 ): super(BiAttentionNew, self).__init__() self.hidden_aug = 3 self.glimpses = glimpses self.lin_v = FCNet(v_features, int(mid_features * self.hidden_aug), activate='relu', drop=drop / 2.5) self.lin_q = FCNet(q_features, int(mid_features * self.hidden_aug), activate='relu', drop=drop / 2.5) self.h_weight = nn.Parameter(torch.Tensor(1, glimpses, 1, int( mid_features * self.hidden_aug)).normal_()) self.h_bias = nn.Parameter(torch.Tensor(1, glimpses, 1, 1).normal_()) self.drop = nn.Dropout(drop) def forward(self, input_0, input_1): primals_9 = self.h_weight primals_10 = self.h_bias primals_5 = self.lin_v.lin.bias primals_3 = self.lin_v.lin.weight_g primals_4 = self.lin_v.lin.weight_v primals_8 = self.lin_q.lin.bias primals_6 = self.lin_q.lin.weight_g primals_7 = self.lin_q.lin.weight_v 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]
ChCh1999/RTPB
BiAttention
false
17,440
[ "MIT" ]
8
1066a3bfe4fe1b41eff74fd152936880302a60a2
https://github.com/ChCh1999/RTPB/tree/1066a3bfe4fe1b41eff74fd152936880302a60a2
ScaledDotProductAttention
import torch from torch import nn from typing import Optional class ScaledDotProductAttention(nn.Module): def __init__(self, dropout: 'Optional[float]'=None, scale: 'bool'=True): super(ScaledDotProductAttention, self).__init__() if dropout is not None: self.dropout = nn.Dropout(p=dropout) else: self.dropout = dropout self.softmax = nn.Softmax(dim=2) self.scale = scale def forward(self, q, k, v, mask=None): attn = torch.bmm(q, k.permute(0, 2, 1)) if self.scale: dimension = torch.sqrt(torch.tensor(k.shape[-1])) attn = attn / dimension if mask is not None: attn = attn.masked_fill(mask, -1000000000.0) attn = self.softmax(attn) if self.dropout is not None: attn = self.dropout(attn) output = torch.bmm(attn, v) return output, attn def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn from typing import Optional assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_sqrt_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp8 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 2.0 tmp2 = 0.0 tmp3 = tmp1 >= tmp2 tmp4 = 1.0 tmp5 = -1.0 tmp6 = tl.where(tmp3, tmp4, tmp5) tmp7 = tmp0 * tmp6 tmp9 = tmp8 * tmp6 tmp11 = tmp10 * tmp6 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp14 = tmp13 * tmp6 tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp17 = tmp16 * tmp6 tmp18 = triton_helpers.maximum(tmp15, tmp17) tmp19 = tmp7 - tmp18 tmp20 = tmp6 * tmp1 tmp21 = tmp19 / tmp20 tmp22 = tl_math.exp(tmp21) tl.store(out_ptr0 + x2, tmp22, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), ( 16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_sqrt_0[grid(64)](buf0, buf1, 64, XBLOCK= 64, num_warps=1, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf1 del buf1 extern_kernels.bmm(buf2, arg2_1, out=buf3) del arg2_1 return buf3, buf2 class ScaledDotProductAttentionNew(nn.Module): def __init__(self, dropout: 'Optional[float]'=None, scale: 'bool'=True): super(ScaledDotProductAttentionNew, self).__init__() if dropout is not None: self.dropout = nn.Dropout(p=dropout) else: self.dropout = dropout self.softmax = nn.Softmax(dim=2) self.scale = scale def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0], output[1]
IusztinPaul/yacht
ScaledDotProductAttention
false
17,441
[ "Apache-2.0" ]
5
c68ab7c66bde860bb91534c29e97772ba328adb5
https://github.com/IusztinPaul/yacht/tree/c68ab7c66bde860bb91534c29e97772ba328adb5
ResBlock
import torch from torch import nn import torch.distributed class ResBlock(nn.Module): def __init__(self, feature_size, action_size): super(ResBlock, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.lin_2 = nn.Linear(feature_size + action_size, feature_size) def forward(self, x, action): res = nn.functional.leaky_relu(self.lin_1(torch.cat([x, action], 2))) res = self.lin_2(torch.cat([res, action], 2)) return res + x def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'feature_size': 4, 'action_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_leaky_relu_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 x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0).to(tl.int1) tmp6 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = 0.01 tmp10 = tmp8 * tmp9 tmp11 = tl.where(tmp5, tmp8, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp17 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tl.where(tmp4, tmp13, tmp17) tl.store(out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_add_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 8), (8, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_1, primals_2, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf1, primals_4, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf2, buf1, primals_4, primals_2, buf3, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_4 buf4 = buf1 del buf1 extern_kernels.mm(reinterpret_tensor(buf3, (16, 8), (8, 1), 0), reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0) del buf4 triton_poi_fused_add_3[grid(64)](buf5, primals_6, primals_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 del primals_6 return buf5, reinterpret_tensor(buf0, (16, 8), (8, 1), 0 ), buf2, reinterpret_tensor(buf3, (16, 8), (8, 1), 0), primals_5 class ResBlockNew(nn.Module): def __init__(self, feature_size, action_size): super(ResBlockNew, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.lin_2 = nn.Linear(feature_size + action_size, feature_size) def forward(self, input_0, input_1): primals_3 = self.lin_1.weight primals_4 = self.lin_1.bias primals_5 = self.lin_2.weight primals_6 = self.lin_2.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
Improbable-AI/curiosity_baselines
ResBlock
false
17,442
[ "MIT" ]
5
42dca92b2fb66c0790a72206bf48595d3b5b487f
https://github.com/Improbable-AI/curiosity_baselines/tree/42dca92b2fb66c0790a72206bf48595d3b5b487f
ZReLU
import numpy import torch import numpy as np import torch.nn as nn import numpy.matlib def cylindricalToPolarConversion(input1, input2=None): if input2 is None: """input1 is tensor of [B,C,H,W,D,2] contains both real and imaginary channels in the last dims""" ndims = input1.ndimension() real_input = input1.narrow(ndims - 1, 0, 1).squeeze(ndims - 1) imag_input = input1.narrow(ndims - 1, 1, 1).squeeze(ndims - 1) mag = (real_input ** 2 + imag_input ** 2) ** 0.5 phase = torch.atan2(imag_input, real_input) phase[phase.ne(phase)] = 0.0 return torch.stack((mag, phase), dim=input1.ndimension() - 1) else: """input1 is real part and input2 is imaginary part; both of size [B,C,H,W,D]""" mag = (input1 ** 2 + input2 ** 2) ** 0.5 phase = torch.atan2(input2, input1) phase[phase.ne(phase)] = 0.0 return mag, phase class ZReLU(nn.Module): def __init__(self, polar=False): super(ZReLU, self).__init__() self.polar = polar def forward(self, input): ndims = input.ndimension() input_real = input.narrow(ndims - 1, 0, 1).squeeze(ndims - 1) input_imag = input.narrow(ndims - 1, 1, 1).squeeze(ndims - 1) if not self.polar: _mag, phase = cylindricalToPolarConversion(input_real, input_imag) else: phase = input_imag phase = phase.unsqueeze(-1) phase = torch.cat([phase, phase], ndims - 1) output = torch.where(phase >= 0.0, input, torch.tensor(0.0)) output = torch.where(phase <= np.pi / 2, output, torch.tensor(0.0)) return output def get_inputs(): return [torch.rand([4, 4, 4, 2])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_atan2_index_put_lift_fresh_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 + (1 + 2 * x0), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last') tmp2 = libdevice.atan2(tmp0, tmp1) tmp3 = tmp2 != tmp2 tmp4 = 0.0 tmp5 = tl.where(tmp3, tmp4, tmp2) tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_cat_ge_le_lift_fresh_where_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x2, xmask) tmp1 = 1.5707963267948966 tmp2 = tmp0 <= tmp1 tmp3 = 0.0 tmp4 = tmp0 >= tmp3 tmp6 = tl.where(tmp4, tmp5, tmp3) tmp7 = tl.where(tmp2, tmp6, tmp3) tl.store(out_ptr0 + x2, tmp7, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 2), (32, 8, 2, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_atan2_index_put_lift_fresh_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32) triton_poi_fused_cat_ge_le_lift_fresh_where_1[grid(128)](buf0, arg0_1, buf1, 128, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del buf0 return buf1, def cylindricalToPolarConversion(input1, input2=None): if input2 is None: """input1 is tensor of [B,C,H,W,D,2] contains both real and imaginary channels in the last dims""" ndims = input1.ndimension() real_input = input1.narrow(ndims - 1, 0, 1).squeeze(ndims - 1) imag_input = input1.narrow(ndims - 1, 1, 1).squeeze(ndims - 1) mag = (real_input ** 2 + imag_input ** 2) ** 0.5 phase = torch.atan2(imag_input, real_input) phase[phase.ne(phase)] = 0.0 return torch.stack((mag, phase), dim=input1.ndimension() - 1) else: """input1 is real part and input2 is imaginary part; both of size [B,C,H,W,D]""" mag = (input1 ** 2 + input2 ** 2) ** 0.5 phase = torch.atan2(input2, input1) phase[phase.ne(phase)] = 0.0 return mag, phase class ZReLUNew(nn.Module): def __init__(self, polar=False): super(ZReLUNew, self).__init__() self.polar = polar def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
HMS-CardiacMR/MyoMapNet-Myocardial-Parametric-Mapping
ZReLU
false
17,443
[ "MIT" ]
4
1e2dee8d6d1f97722eba91618462537faf9efba7
https://github.com/HMS-CardiacMR/MyoMapNet-Myocardial-Parametric-Mapping/tree/1e2dee8d6d1f97722eba91618462537faf9efba7
Dense
import torch import torch.nn as nn import torch.nn.functional as functions class Dense(nn.Module): def __init__(self): super(Dense, self).__init__() self.fc1 = nn.Linear(6 * 7, 32) self.fc2 = nn.Linear(32, 16) self.probhead = nn.Linear(16, 7) self.valuehead = nn.Linear(16, 1) self.soft = nn.Softmax(dim=1) self.tanh = nn.Tanh() def forward(self, x): x = x.view(-1, 6 * 7) x = functions.relu(self.fc1(x)) x = functions.relu(self.fc2(x)) P = self.soft(self.probhead(x)) v = self.tanh(self.valuehead(x)) return P, v def get_inputs(): return [torch.rand([4, 42])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__softmax_2(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 + 7 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 7 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 7 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 7 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (4 + 7 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (5 + 7 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (6 + 7 * x0), xmask, eviction_policy='evict_last' ) tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp10 = triton_helpers.maximum(tmp8, tmp9) tmp12 = triton_helpers.maximum(tmp10, tmp11) tmp13 = tmp0 - tmp12 tmp14 = tl_math.exp(tmp13) tmp15 = tmp1 - tmp12 tmp16 = tl_math.exp(tmp15) tmp17 = tmp14 + tmp16 tmp18 = tmp3 - tmp12 tmp19 = tl_math.exp(tmp18) tmp20 = tmp17 + tmp19 tmp21 = tmp5 - tmp12 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tmp7 - tmp12 tmp25 = tl_math.exp(tmp24) tmp26 = tmp23 + tmp25 tmp27 = tmp9 - tmp12 tmp28 = tl_math.exp(tmp27) tmp29 = tmp26 + tmp28 tmp30 = tmp11 - tmp12 tmp31 = tl_math.exp(tmp30) tmp32 = tmp29 + tmp31 tl.store(out_ptr0 + x0, tmp12, xmask) tl.store(out_ptr1 + x0, tmp32, xmask) @triton.jit def triton_poi_fused__softmax_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 28 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 7 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = tl_math.exp(tmp2) tmp5 = tmp3 / tmp4 tl.store(in_out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_tanh_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = libdevice.tanh(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, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 42), (42, 1)) assert_size_stride(primals_2, (32, 42), (42, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (16, 32), (32, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (7, 16), (16, 1)) assert_size_stride(primals_7, (7,), (1,)) assert_size_stride(primals_8, (1, 16), (16, 1)) assert_size_stride(primals_9, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (42, 32), (1, 42), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(128)](buf1, primals_3, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (32, 16), (1, 32), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(64)](buf3, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 7), (7, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (16, 7), (1, 16), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf6 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused__softmax_2[grid(4)](buf4, buf5, buf6, 4, XBLOCK=4, num_warps=1, num_stages=1) buf7 = buf4 del buf4 triton_poi_fused__softmax_3[grid(28)](buf7, buf5, buf6, 28, XBLOCK= 32, num_warps=1, num_stages=1) del buf5 buf8 = reinterpret_tensor(buf6, (4, 1), (1, 1), 0) del buf6 extern_kernels.mm(buf3, reinterpret_tensor(primals_8, (16, 1), (1, 16), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_tanh_4[grid(4)](buf9, primals_9, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_9 return (buf7, buf9, primals_1, buf1, buf3, buf7, buf9, primals_8, primals_6, primals_4) class DenseNew(nn.Module): def __init__(self): super(DenseNew, self).__init__() self.fc1 = nn.Linear(6 * 7, 32) self.fc2 = nn.Linear(32, 16) self.probhead = nn.Linear(16, 7) self.valuehead = nn.Linear(16, 1) self.soft = nn.Softmax(dim=1) self.tanh = nn.Tanh() 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.probhead.weight primals_7 = self.probhead.bias primals_8 = self.valuehead.weight primals_9 = self.valuehead.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0], output[1]
IvLabs/model-based-RL
Dense
false
17,444
[ "MIT" ]
7
8d22eabf7bf2601629015ef6c869e3850c306d6f
https://github.com/IvLabs/model-based-RL/tree/8d22eabf7bf2601629015ef6c869e3850c306d6f
ActorCritic
import torch import torch.nn as nn import torch.nn.functional as F class ActorCritic(nn.Module): """ Actor Critic neural network with shared body. The Actor maps states (actions) to action, log_probs, entropy. The Critic maps states to values. """ def __init__(self, state_size, action_size, seed=0): """ Initialize the neural net. Params ====== state_size: dimension of each input state action_size: dimension of each output seed: random seed """ super().__init__() self.seed = torch.manual_seed(seed) self.fc1_body = nn.Linear(state_size, 64) self.fc2_body = nn.Linear(64, 64) self.fc3_actor = nn.Linear(64, action_size) self.std = nn.Parameter(torch.ones(1, action_size)) self.fc3_critic = nn.Linear(64, 1) def forward(self, state, action=None): x = torch.Tensor(state) x = F.relu(self.fc1_body(x)) x = F.relu(self.fc2_body(x)) mean = torch.tanh(self.fc3_actor(x)) dist = torch.distributions.Normal(mean, F.softplus(self.std)) if action is None: action = dist.sample() log_prob = dist.log_prob(action) log_prob = torch.sum(log_prob, dim=1, keepdim=True) entropy = dist.entropy() entropy = torch.sum(entropy, dim=1, keepdim=True) value = self.fc3_critic(x) return action, log_prob, entropy, value def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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): 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) @triton.jit def triton_poi_fused_tanh_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_softplus_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 + x0, xmask) tmp1 = 20.0 tmp2 = tmp0 > tmp1 tmp3 = tl_math.exp(tmp0) tmp4 = libdevice.log1p(tmp3) tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_sub_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 x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_out_ptr0 + x0, xmask) tmp2 = tmp0 - tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_mul_pow_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp2 = 2.0 tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_add_div_log_neg_pow_sub_sum_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 x4 = xindex % 16 x0 = xindex % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (x4 + 64 * x2), xmask) tmp3 = tl.load(in_ptr1 + (x4 + 64 * x2), xmask) tmp5 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (16 + x4 + 64 * x2), xmask) tmp13 = tl.load(in_ptr1 + (16 + x4 + 64 * x2), xmask) tmp18 = tl.load(in_ptr0 + (32 + x4 + 64 * x2), xmask) tmp21 = tl.load(in_ptr1 + (32 + x4 + 64 * x2), xmask) tmp26 = tl.load(in_ptr0 + (48 + x4 + 64 * x2), xmask) tmp29 = tl.load(in_ptr1 + (48 + x4 + 64 * x2), xmask) tmp1 = tmp0 * tmp0 tmp2 = -tmp1 tmp4 = tmp2 / tmp3 tmp6 = tl_math.log(tmp5) tmp7 = tmp4 - tmp6 tmp8 = 0.9189385332046727 tmp9 = tmp7 - tmp8 tmp11 = tmp10 * tmp10 tmp12 = -tmp11 tmp14 = tmp12 / tmp13 tmp15 = tmp14 - tmp6 tmp16 = tmp15 - tmp8 tmp17 = tmp9 + tmp16 tmp19 = tmp18 * tmp18 tmp20 = -tmp19 tmp22 = tmp20 / tmp21 tmp23 = tmp22 - tmp6 tmp24 = tmp23 - tmp8 tmp25 = tmp17 + tmp24 tmp27 = tmp26 * tmp26 tmp28 = -tmp27 tmp30 = tmp28 / tmp29 tmp31 = tmp30 - tmp6 tmp32 = tmp31 - tmp8 tmp33 = tmp25 + tmp32 tmp34 = 1.4189385332046727 tmp35 = tmp6 + tmp34 tmp36 = tmp35 + tmp35 tmp37 = tmp36 + tmp35 tmp38 = tmp37 + tmp35 tl.store(out_ptr0 + x5, tmp33, xmask) tl.store(out_ptr1 + x5, tmp38, 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, (64, 4), (4, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64), (64, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (1, 4), (4, 1)) assert_size_stride(primals_9, (1, 64), (64, 1)) assert_size_stride(primals_10, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 64), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf0 buf16 = 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_3, buf16, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 64), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf2 buf15 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch .bool) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf3, primals_5, buf15, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_tanh_1[grid(256)](buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((1, 4), (4, 1), torch.float32) triton_poi_fused_softplus_2[grid(4)](primals_8, buf6, 4, XBLOCK=4, num_warps=1, num_stages=1) buf7 = torch.ops.aten.normal.Tensor_Tensor(buf5, reinterpret_tensor (buf6, (4, 4, 4, 4), (0, 0, 0, 1), 0)) buf8 = buf7 del buf7 buf9 = buf5 del buf5 triton_poi_fused_sub_3[grid(256)](buf9, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_pow_4[grid(256)](buf6, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) buf11 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) buf12 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) triton_poi_fused_add_div_log_neg_pow_sub_sum_5[grid(64)](buf9, buf10, buf6, buf11, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1 ) del buf6 buf14 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_10, reinterpret_tensor(buf3, (64, 64), (64, 1), 0), reinterpret_tensor(primals_9, (64, 1), (1, 64), 0), alpha=1, beta=1, out=buf14) del primals_10 return buf8, buf11, buf12, reinterpret_tensor(buf14, (4, 4, 4, 1), (16, 4, 1, 1), 0), primals_8, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (64, 64), (64, 1), 0 ), reinterpret_tensor(buf3, (64, 64), (64, 1), 0 ), buf4, buf9, buf10, primals_9, primals_6, buf15, primals_4, buf16 class ActorCriticNew(nn.Module): """ Actor Critic neural network with shared body. The Actor maps states (actions) to action, log_probs, entropy. The Critic maps states to values. """ def __init__(self, state_size, action_size, seed=0): """ Initialize the neural net. Params ====== state_size: dimension of each input state action_size: dimension of each output seed: random seed """ super().__init__() self.seed = torch.manual_seed(seed) self.fc1_body = nn.Linear(state_size, 64) self.fc2_body = nn.Linear(64, 64) self.fc3_actor = nn.Linear(64, action_size) self.std = nn.Parameter(torch.ones(1, action_size)) self.fc3_critic = nn.Linear(64, 1) def forward(self, input_0): primals_8 = self.std primals_2 = self.fc1_body.weight primals_3 = self.fc1_body.bias primals_4 = self.fc2_body.weight primals_5 = self.fc2_body.bias primals_6 = self.fc3_actor.weight primals_7 = self.fc3_actor.bias primals_9 = self.fc3_critic.weight primals_10 = self.fc3_critic.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]) return output[0], output[1], output[2], output[3]
ImmanuelXIV/ppo-self-play
ActorCritic
false
17,445
[ "MIT" ]
7
21c000492b2450628b5a506d4101b7b12e5755e0
https://github.com/ImmanuelXIV/ppo-self-play/tree/21c000492b2450628b5a506d4101b7b12e5755e0
ResidualSequential
import torch import torch.optim import torch.nn as nn import torch import torch.nn.init class ResidualSequential(nn.Sequential): def __init__(self, *args): super(ResidualSequential, self).__init__(*args) def forward(self, x): out = super(ResidualSequential, self).forward(x) x_ = None if out.size(2) != x.size(2) or out.size(3) != x.size(3): diff2 = x.size(2) - out.size(2) diff3 = x.size(3) - out.size(3) x_ = x[:, :, diff2 / 2:out.size(2) + diff2 / 2, diff3 / 2:out. size(3) + diff3 / 2] else: x_ = x return out + x_ def eval(self): None for m in self.modules(): m.eval() exit() 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.optim import torch.nn as nn import torch import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, 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_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class ResidualSequentialNew(nn.Sequential): def __init__(self, *args): super(ResidualSequentialNew, self).__init__(*args) def eval(self): None for m in self.modules(): m.eval() exit() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Jay-Lewis/phase_retrieval
ResidualSequential
false
17,446
[ "MIT" ]
4
799cef92852c53e62e2a548f605652923e979456
https://github.com/Jay-Lewis/phase_retrieval/tree/799cef92852c53e62e2a548f605652923e979456
ConvLayer
import torch class ConvLayer(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = torch.nn.Conv2d(in_channels, out_channels, kernel_size, 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 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 = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') 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=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(400)](buf2, primals_3, 400, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class ConvLayerNew(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayerNew, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = torch.nn.Conv2d(in_channels, out_channels, kernel_size, 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]
JEF1056/Reconstruction-Style
ConvLayer
false
17,447
[ "MIT" ]
6
3430d9e9f05c6980ae251cf15b619148a2c899d6
https://github.com/JEF1056/Reconstruction-Style/tree/3430d9e9f05c6980ae251cf15b619148a2c899d6
Decoder
import torch import torch.nn as nn class Decoder(nn.Module): def __init__(self, dim_encoding, vocab_size): super().__init__() self.E = nn.Embedding(dim_encoding, vocab_size) self.b = nn.Parameter(torch.zeros(1, vocab_size)) def forward(self, Z, targets): scores = Z @ self.E.weight + self.b log_probs = scores.log_softmax(dim=1) log_likelihood = (log_probs * targets).sum(1).mean() return log_likelihood def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim_encoding': 4, 'vocab_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn 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__log_softmax_add_mean_mul_sum_0(in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex // 16 r4 = rindex % 16 r0 = rindex % 4 tmp0 = tl.load(in_ptr0 + (r4 + 64 * r2), None) tmp1 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (16 + r4 + 64 * r2), None) tmp6 = tl.load(in_ptr0 + (32 + r4 + 64 * r2), None) tmp9 = tl.load(in_ptr0 + (48 + r4 + 64 * r2), None) tmp25 = tl.load(in_ptr2 + (r4 + 64 * r2), None) tmp28 = tl.load(in_ptr2 + (16 + r4 + 64 * r2), None) tmp32 = tl.load(in_ptr2 + (32 + r4 + 64 * r2), None) tmp36 = tl.load(in_ptr2 + (48 + r4 + 64 * r2), None) tmp2 = tmp0 + tmp1 tmp4 = tmp3 + tmp1 tmp5 = triton_helpers.maximum(tmp2, tmp4) tmp7 = tmp6 + tmp1 tmp8 = triton_helpers.maximum(tmp5, tmp7) tmp10 = tmp9 + tmp1 tmp11 = triton_helpers.maximum(tmp8, tmp10) tmp12 = tmp2 - tmp11 tmp13 = tl_math.exp(tmp12) tmp14 = tmp4 - tmp11 tmp15 = tl_math.exp(tmp14) tmp16 = tmp13 + tmp15 tmp17 = tmp7 - tmp11 tmp18 = tl_math.exp(tmp17) tmp19 = tmp16 + tmp18 tmp20 = tmp10 - tmp11 tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp23 = tl_math.log(tmp22) tmp24 = tmp12 - tmp23 tmp26 = tmp24 * tmp25 tmp27 = tmp14 - tmp23 tmp29 = tmp27 * tmp28 tmp30 = tmp26 + tmp29 tmp31 = tmp17 - tmp23 tmp33 = tmp31 * tmp32 tmp34 = tmp30 + tmp33 tmp35 = tmp20 - tmp23 tmp37 = tmp35 * tmp36 tmp38 = tmp34 + 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_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (1, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), primals_1, out=buf0) del primals_1 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 get_raw_stream(0) triton_per_fused__log_softmax_add_mean_mul_sum_0[grid(1)](buf5, buf0, primals_3, primals_4, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) return buf5, primals_3, primals_4, buf0, reinterpret_tensor(primals_2, (4, 64), (1, 4), 0) class DecoderNew(nn.Module): def __init__(self, dim_encoding, vocab_size): super().__init__() self.E = nn.Embedding(dim_encoding, vocab_size) self.b = nn.Parameter(torch.zeros(1, vocab_size)) def forward(self, input_0, input_1): primals_3 = self.b primals_1 = self.E.weight primals_2 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
J-zin/SNUH
Decoder
false
17,448
[ "MIT" ]
4
e4bde66609e1480f890b8386046431d488b825bd
https://github.com/J-zin/SNUH/tree/e4bde66609e1480f890b8386046431d488b825bd
Resample
import torch from torch import nn from typing import Optional class LinearStack(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', activation_fn: 'Optional[nn.Module]'=None, n: 'int'=1, hidden_features: 'Optional[int]'=None, dropout: 'Optional[float]'=None ): super().__init__() if hidden_features is None or n == 1: hidden_features = out_features modules = [] for i in range(n): if i == 0: modules.append(nn.Linear(in_features=in_features, out_features=hidden_features)) elif 1 < i < n - 1: modules.append(nn.Linear(in_features=hidden_features, out_features=hidden_features)) else: modules.append(nn.Linear(in_features=hidden_features, out_features=out_features)) if activation_fn is not None: modules.append(activation_fn()) if dropout is not None and dropout > 0: modules.append(nn.Dropout(p=dropout)) self.net = nn.Sequential(*modules) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'weight' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x: 'torch.Tensor') ->torch.Tensor: return self.net(x) class Resample(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', activation_fn: 'nn.Module', trainable_add: 'bool'=True, dropout: 'Optional[float]'=None): super().__init__() self.in_features = in_features self.trainable_add = trainable_add self.out_features = out_features self.dropout = dropout if self.in_features != self.out_features: self.resample = LinearStack(in_features=self.in_features, out_features=self.out_features, activation_fn=activation_fn, dropout=self.dropout) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.out_features, dtype= torch.float)) self.gate = nn.Sigmoid() def forward(self, x: 'torch.Tensor') ->torch.Tensor: if self.in_features != self.out_features: x = self.resample(x) if self.trainable_add: x = x * self.gate(self.mask) * 2.0 return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4, 'activation_fn': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn from typing import Optional assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = 2.0 tmp5 = tmp3 * tmp4 tl.store(out_ptr0 + x2, tmp5, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf0, primals_1, primals_2 class LinearStack(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', activation_fn: 'Optional[nn.Module]'=None, n: 'int'=1, hidden_features: 'Optional[int]'=None, dropout: 'Optional[float]'=None ): super().__init__() if hidden_features is None or n == 1: hidden_features = out_features modules = [] for i in range(n): if i == 0: modules.append(nn.Linear(in_features=in_features, out_features=hidden_features)) elif 1 < i < n - 1: modules.append(nn.Linear(in_features=hidden_features, out_features=hidden_features)) else: modules.append(nn.Linear(in_features=hidden_features, out_features=out_features)) if activation_fn is not None: modules.append(activation_fn()) if dropout is not None and dropout > 0: modules.append(nn.Dropout(p=dropout)) self.net = nn.Sequential(*modules) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'weight' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x: 'torch.Tensor') ->torch.Tensor: return self.net(x) class ResampleNew(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', activation_fn: 'nn.Module', trainable_add: 'bool'=True, dropout: 'Optional[float]'=None): super().__init__() self.in_features = in_features self.trainable_add = trainable_add self.out_features = out_features self.dropout = dropout if self.in_features != self.out_features: self.resample = LinearStack(in_features=self.in_features, out_features=self.out_features, activation_fn=activation_fn, dropout=self.dropout) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.out_features, dtype= torch.float)) self.gate = nn.Sigmoid() def forward(self, input_0): primals_1 = self.mask primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
IusztinPaul/yacht
Resample
false
17,449
[ "Apache-2.0" ]
5
c68ab7c66bde860bb91534c29e97772ba328adb5
https://github.com/IusztinPaul/yacht/tree/c68ab7c66bde860bb91534c29e97772ba328adb5
ResampleNorm
import torch from torch import nn import torch.nn.functional as F class LearnableInterpolation(nn.Module): def __init__(self, input_size: 'int', output_size: 'int', trainable: 'bool'=False): super().__init__() self.input_size = input_size self.output_size = output_size self.trainable = trainable self.lin = nn.Linear(in_features=self.input_size, out_features=self .output_size) self.init_weights() if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def init_weights(self): for name, p in self.named_parameters(): if 'bias' not in name: torch.nn.init.xavier_uniform_(p) else: torch.nn.init.zeros_(p) def forward(self, x): upsampled = self.lin(x) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled class TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class ResampleNorm(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True, residual_upsampling: 'str'= 'interpolation', drop_normalization: 'bool'=False): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size self.residual_upsampling = residual_upsampling self.drop_normalization = drop_normalization if self.input_size != self.output_size: if self.residual_upsampling == 'interpolation': self.resample = TimeDistributedInterpolation(self. output_size, batch_first=True, trainable=False) elif self.residual_upsampling == 'learnable': self.resample = LearnableInterpolation(self.input_size, self.output_size, trainable=False) else: raise RuntimeError( f'Wrong residual_upsampling method: {self.residual_upsampling}' ) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() if self.drop_normalization is False: self.norm = nn.LayerNorm(self.output_size) def forward(self, x: 'torch.Tensor') ->torch.Tensor: if self.input_size != self.output_size: x = self.resample(x) if self.trainable_add: x = x * self.gate(self.mask) * 2.0 if self.drop_normalization is False: output = self.norm(x) else: output = x return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_native_layer_norm_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + 1) tmp9 = tl.broadcast_to(tmp8, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + 2) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + 3) tmp23 = tl.broadcast_to(tmp22, [XBLOCK]) tmp3 = tl.sigmoid(tmp2) tmp4 = tmp0 * tmp3 tmp5 = 2.0 tmp6 = tmp4 * tmp5 tmp10 = tl.sigmoid(tmp9) tmp11 = tmp7 * tmp10 tmp12 = tmp11 * tmp5 tmp13 = tmp6 + tmp12 tmp17 = tl.sigmoid(tmp16) tmp18 = tmp14 * tmp17 tmp19 = tmp18 * tmp5 tmp20 = tmp13 + tmp19 tmp24 = tl.sigmoid(tmp23) tmp25 = tmp21 * tmp24 tmp26 = tmp25 * tmp5 tmp27 = tmp20 + tmp26 tmp28 = 4.0 tmp29 = tmp27 / tmp28 tmp30 = tmp6 - tmp29 tmp31 = tmp30 * tmp30 tmp32 = tmp12 - tmp29 tmp33 = tmp32 * tmp32 tmp34 = tmp31 + tmp33 tmp35 = tmp19 - tmp29 tmp36 = tmp35 * tmp35 tmp37 = tmp34 + tmp36 tmp38 = tmp26 - tmp29 tmp39 = tmp38 * tmp38 tmp40 = tmp37 + tmp39 tmp41 = tmp40 / tmp28 tl.store(out_ptr0 + x0, tmp29, xmask) tl.store(out_ptr1 + x0, tmp41, xmask) @triton.jit def triton_poi_fused_mul_native_layer_norm_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = 2.0 tmp5 = tmp3 * tmp4 tmp7 = tmp5 - tmp6 tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = libdevice.rsqrt(tmp10) tmp12 = tmp7 * tmp11 tmp14 = tmp12 * tmp13 tmp16 = tmp14 + tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_mul_native_layer_norm_sigmoid_0[grid(64)](primals_2, primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_native_layer_norm_sigmoid_1[grid(256)](primals_2, primals_1, buf0, buf1, primals_3, primals_4, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del buf0 del buf1 del primals_4 return buf2, primals_1, primals_2, primals_3 class LearnableInterpolation(nn.Module): def __init__(self, input_size: 'int', output_size: 'int', trainable: 'bool'=False): super().__init__() self.input_size = input_size self.output_size = output_size self.trainable = trainable self.lin = nn.Linear(in_features=self.input_size, out_features=self .output_size) self.init_weights() if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def init_weights(self): for name, p in self.named_parameters(): if 'bias' not in name: torch.nn.init.xavier_uniform_(p) else: torch.nn.init.zeros_(p) def forward(self, x): upsampled = self.lin(x) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled class TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class ResampleNormNew(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True, residual_upsampling: 'str'= 'interpolation', drop_normalization: 'bool'=False): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size self.residual_upsampling = residual_upsampling self.drop_normalization = drop_normalization if self.input_size != self.output_size: if self.residual_upsampling == 'interpolation': self.resample = TimeDistributedInterpolation(self. output_size, batch_first=True, trainable=False) elif self.residual_upsampling == 'learnable': self.resample = LearnableInterpolation(self.input_size, self.output_size, trainable=False) else: raise RuntimeError( f'Wrong residual_upsampling method: {self.residual_upsampling}' ) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() if self.drop_normalization is False: self.norm = nn.LayerNorm(self.output_size) def forward(self, input_0): primals_1 = self.mask primals_3 = self.norm.weight primals_4 = self.norm.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
IusztinPaul/yacht
ResampleNorm
false
17,450
[ "Apache-2.0" ]
5
c68ab7c66bde860bb91534c29e97772ba328adb5
https://github.com/IusztinPaul/yacht/tree/c68ab7c66bde860bb91534c29e97772ba328adb5
IntervalObservationEncoder
import torch from torch import nn class IntervalObservationEncoder(nn.Module): def __init__(self, num_input_channel: 'int', num_output_channel: 'int', kernel_size: 'int', initial_output_weight_value: 'float'): super().__init__() assert initial_output_weight_value <= 1 self.conv_1d = nn.Conv1d(in_channels=num_input_channel, out_channels=num_output_channel, kernel_size=kernel_size, stride=1) self.weight = nn.Parameter(torch.tensor(initial_output_weight_value ).type(torch.FloatTensor), requires_grad=True) def forward(self, observation: 'torch.Tensor') ->torch.Tensor: batch_size, _window_size, channel_size, _ = observation.shape interval_feature = torch.transpose(observation, 1, 2) interval_feature = interval_feature.reshape(batch_size, channel_size, -1) interval_feature = self.conv_1d(interval_feature) interval_feature = torch.squeeze(interval_feature, dim=-1) interval_feature = interval_feature * self.weight return interval_feature def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_input_channel': 4, 'num_output_channel': 4, 'kernel_size': 4, 'initial_output_weight_value': 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 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 = 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_convolution_mul_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 208 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 13 % 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 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 * tmp4 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (), ()) 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= 256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (4, 4, 16), (64, 16, 1), 0), primals_2, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 13), (52, 13, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 13), (52, 13, 1), torch.float32) triton_poi_fused_convolution_mul_1[grid(208)](buf2, primals_3, primals_4, buf3, 208, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf3, primals_2, primals_4, reinterpret_tensor(buf0, (4, 4, 16), (64, 16, 1), 0), buf2 class IntervalObservationEncoderNew(nn.Module): def __init__(self, num_input_channel: 'int', num_output_channel: 'int', kernel_size: 'int', initial_output_weight_value: 'float'): super().__init__() assert initial_output_weight_value <= 1 self.conv_1d = nn.Conv1d(in_channels=num_input_channel, out_channels=num_output_channel, kernel_size=kernel_size, stride=1) self.weight = nn.Parameter(torch.tensor(initial_output_weight_value ).type(torch.FloatTensor), requires_grad=True) def forward(self, input_0): primals_4 = self.weight primals_2 = self.conv_1d.weight primals_3 = self.conv_1d.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
IusztinPaul/yacht
IntervalObservationEncoder
false
17,451
[ "Apache-2.0" ]
5
c68ab7c66bde860bb91534c29e97772ba328adb5
https://github.com/IusztinPaul/yacht/tree/c68ab7c66bde860bb91534c29e97772ba328adb5
ComplexConv2d
import torch import torch.nn as nn import torch.utils.data import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler class ComplexConv2d(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, **kwargs): super().__init__() self.conv_re = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias, **kwargs) self.conv_im = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias, **kwargs) def forward(self, x): real = self.conv_re(x[..., 0]) - self.conv_im(x[..., 1]) imaginary = self.conv_re(x[..., 1]) + self.conv_im(x[..., 0]) output = torch.stack((real, imaginary), dim=-1) return output 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 torch.nn as nn import torch.utils.data 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_poi_fused_stack_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr2 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tl.load(in_ptr3 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tmp8 + tmp9 tmp11 = tmp7 - tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp17 = tl.load(in_ptr4 + x1, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tl.load(in_ptr1 + x1, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp19 = tmp17 + tmp18 tmp20 = tl.load(in_ptr5 + x1, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.load(in_ptr3 + x1, tmp14 & xmask, eviction_policy= 'evict_last', other=0.0) tmp22 = tmp20 + tmp21 tmp23 = tmp19 + tmp22 tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp14, tmp23, tmp24) tmp26 = tl.where(tmp4, tmp13, tmp25) tl.store(out_ptr0 + x2, tmp26, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (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 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 0), primals_2, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 1, 1), (4, 1, 1, 1)) buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 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(buf1, (1, 4, 1, 1), (4, 1, 1, 1)) buf2 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 1), primals_2, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 1, 1), (4, 1, 1, 1)) buf3 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1, 4, 4, 4), (0, 64, 16, 4), 0), primals_4, stride=(1, 1), padding =(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (1, 4, 1, 1), (4, 1, 1, 1)) buf4 = empty_strided_cuda((4, 1, 1, 2), (2, 2, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(8)](buf0, primals_3, buf1, primals_5, buf2, buf3, buf4, 8, XBLOCK=8, num_warps=1, num_stages=1) del buf0 del buf1 del buf2 del buf3 del primals_3 del primals_5 return buf4, primals_2, primals_4, reinterpret_tensor(primals_1, (1, 4, 4, 4), (256, 64, 16, 4), 0), reinterpret_tensor(primals_1, (1, 4, 4, 4), (256, 64, 16, 4), 1) class ComplexConv2dNew(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, **kwargs): super().__init__() self.conv_re = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias, **kwargs) self.conv_im = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias, **kwargs) def forward(self, input_0): primals_1 = self.conv_re.weight primals_3 = self.conv_re.bias primals_2 = self.conv_im.weight primals_5 = self.conv_im.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
IIP-Sogang/Audio-Visual-Speech-Recognition
ComplexConv2d
false
17,452
[ "MIT" ]
9
bd03be91135acbc6162b83092d462b7fe71dd007
https://github.com/IIP-Sogang/Audio-Visual-Speech-Recognition/tree/bd03be91135acbc6162b83092d462b7fe71dd007
SquashingCosine_Classifier
import math import torch import torch.nn as nn from torch.nn.parameter import Parameter class SquashingCosine_Classifier(nn.Module): def __init__(self, in_dims, out_dims, scale=16, margin=0.5, init_std=0.001 ): super(SquashingCosine_Classifier, self).__init__() self.in_dims = in_dims self.out_dims = out_dims self.scale = scale self.margin = margin self.weight = Parameter(torch.Tensor(out_dims, in_dims), requires_grad=True) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) def forward(self, input, *args): norm_x = torch.norm(input, 2, 1, keepdim=True) ex = norm_x / (self.margin + norm_x) * (input / norm_x) ew = self.weight / torch.norm(self.weight, 2, 1, keepdim=True) return torch.mm(self.scale * ex, ew.t()) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_dims': 4, 'out_dims': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_linalg_vector_norm_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 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr0 + x2, xmask) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = libdevice.sqrt(tmp10) tmp12 = 0.5 tmp13 = tmp11 + tmp12 tmp14 = tmp11 / tmp13 tmp16 = tmp15 / tmp11 tmp17 = tmp14 * tmp16 tmp18 = 16.0 tmp19 = tmp17 * tmp18 tl.store(out_ptr0 + x2, tmp19, xmask) @triton.jit def triton_poi_fused_div_linalg_vector_norm_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp0 / tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_linalg_vector_norm_mul_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_linalg_vector_norm_1[grid(16)](primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2) del buf1 return buf2, primals_2, buf0 class SquashingCosine_ClassifierNew(nn.Module): def __init__(self, in_dims, out_dims, scale=16, margin=0.5, init_std=0.001 ): super(SquashingCosine_ClassifierNew, self).__init__() self.in_dims = in_dims self.out_dims = out_dims self.scale = scale self.margin = margin self.weight = Parameter(torch.Tensor(out_dims, in_dims), requires_grad=True) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) def forward(self, input_0): primals_1 = self.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
JKozerawski/BLT
SquashingCosine_Classifier
false
17,453
[ "MIT" ]
5
6f3a6f4dc3c832b62c4ac3f3baf34b6a0bd6e181
https://github.com/JKozerawski/BLT/tree/6f3a6f4dc3c832b62c4ac3f3baf34b6a0bd6e181
FscoreMetric
import torch import torch.nn as nn def f_score(pr, gt, beta=1, eps=1e-07, threshold=0.5): """dice score(also referred to as F1-score)""" if threshold is not None: pr = (pr > threshold).float() tp = torch.sum(gt * pr) fp = torch.sum(pr) - tp fn = torch.sum(gt) - tp score = ((1 + beta ** 2) * tp + eps) / ((1 + beta ** 2) * tp + beta ** 2 * fn + fp + eps) return score class FscoreMetric(nn.Module): __name__ = 'f-score' def __init__(self, beta=1, eps=1e-07, threshold=0.5): super().__init__() self.eps = eps self.threshold = threshold self.beta = beta def forward(self, y_pr, y_gt): return f_score(y_pr, y_gt, self.beta, self.eps, self.threshold) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused__to_copy_add_div_gt_mul_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 = 0.5 tmp3 = tmp1 > tmp2 tmp4 = tmp3.to(tl.float32) tmp5 = tmp0 * tmp4 tmp6 = tl.broadcast_to(tmp5, [RBLOCK]) tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0)) tmp9 = tl.broadcast_to(tmp0, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = tl.broadcast_to(tmp4, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 2.0 tmp16 = tmp8 * tmp15 tmp17 = 1e-07 tmp18 = tmp16 + tmp17 tmp19 = tmp11 - tmp8 tmp20 = 1.0 tmp21 = tmp19 * tmp20 tmp22 = tmp16 + tmp21 tmp23 = tmp14 - tmp8 tmp24 = tmp22 + tmp23 tmp25 = tmp24 + tmp17 tmp26 = tmp18 / tmp25 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp26, 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) buf3 = buf0 del buf0 get_raw_stream(0) triton_per_fused__to_copy_add_div_gt_mul_sub_sum_0[grid(1)](buf3, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf3, def f_score(pr, gt, beta=1, eps=1e-07, threshold=0.5): """dice score(also referred to as F1-score)""" if threshold is not None: pr = (pr > threshold).float() tp = torch.sum(gt * pr) fp = torch.sum(pr) - tp fn = torch.sum(gt) - tp score = ((1 + beta ** 2) * tp + eps) / ((1 + beta ** 2) * tp + beta ** 2 * fn + fp + eps) return score class FscoreMetricNew(nn.Module): __name__ = 'f-score' def __init__(self, beta=1, eps=1e-07, threshold=0.5): super().__init__() self.eps = eps self.threshold = threshold self.beta = beta def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
JACKYLUO1991/HybridNet
FscoreMetric
false
17,454
[ "Apache-2.0" ]
6
eb97d8a048ca4bb4087bc542360172e169a08dbf
https://github.com/JACKYLUO1991/HybridNet/tree/eb97d8a048ca4bb4087bc542360172e169a08dbf
MnistMLP
import torch from torch import nn from torch.nn import functional as F import torch.onnx from torch.optim.lr_scheduler import * class MnistMLP(nn.Module): def __init__(self, hidden_size=500): super(MnistMLP, self).__init__() self.hidden_size = hidden_size self.fc1 = nn.Linear(784, hidden_size) self.fc2 = nn.Linear(hidden_size, 10) def forward(self, x): x = x.view(-1, 784) x = self.fc1(x) x = F.relu(x) x = self.fc2(x) return 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 from torch import nn import torch.onnx 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_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 2000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 500 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 = args args.clear() assert_size_stride(primals_1, (4, 784), (784, 1)) assert_size_stride(primals_2, (500, 784), (784, 1)) assert_size_stride(primals_3, (500,), (1,)) assert_size_stride(primals_4, (10, 500), (500, 1)) assert_size_stride(primals_5, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 500), (500, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (784, 500), (1, 784), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(2000)](buf1, primals_3, 2000, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_5, buf1, reinterpret_tensor(primals_4, (500, 10), (1, 500), 0), alpha=1, beta=1, out=buf2) del primals_5 return buf2, primals_1, buf1, primals_4 class MnistMLPNew(nn.Module): def __init__(self, hidden_size=500): super(MnistMLPNew, self).__init__() self.hidden_size = hidden_size self.fc1 = nn.Linear(784, hidden_size) self.fc2 = nn.Linear(hidden_size, 10) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
IST-DASLab/ACDC
MnistMLP
false
17,455
[ "Apache-2.0" ]
6
ac53210b6adc1f2506ff909de08172ed9cad25d5
https://github.com/IST-DASLab/ACDC/tree/ac53210b6adc1f2506ff909de08172ed9cad25d5
SqueezeAndExcite
import torch import torch.nn as nn class SqueezeAndExcite(nn.Module): def __init__(self, channels, squeeze_channels, se_ratio): super(SqueezeAndExcite, self).__init__() squeeze_channels = squeeze_channels * se_ratio if not squeeze_channels.is_integer(): raise ValueError('channels must be divisible by 1 / ratio') squeeze_channels = int(squeeze_channels) self.se_reduce = nn.Conv2d(channels, squeeze_channels, 1, 1, 0, bias=True) self.non_linear1 = nn.ReLU(inplace=True) self.se_expand = nn.Conv2d(squeeze_channels, channels, 1, 1, 0, bias=True) self.non_linear2 = nn.Sigmoid() def forward(self, x): y = torch.mean(x, (2, 3), keepdim=True) y = self.non_linear1(self.se_reduce(y)) y = self.non_linear2(self.se_expand(y)) y = x * y return y def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4, 'squeeze_channels': 4, 'se_ratio': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (16, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (4, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 16, 1, 1), (16, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(64)](buf3, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(16)](buf5, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf5, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf6, primals_1, primals_2, primals_4, buf1, buf3, buf5 class SqueezeAndExciteNew(nn.Module): def __init__(self, channels, squeeze_channels, se_ratio): super(SqueezeAndExciteNew, self).__init__() squeeze_channels = squeeze_channels * se_ratio if not squeeze_channels.is_integer(): raise ValueError('channels must be divisible by 1 / ratio') squeeze_channels = int(squeeze_channels) self.se_reduce = nn.Conv2d(channels, squeeze_channels, 1, 1, 0, bias=True) self.non_linear1 = nn.ReLU(inplace=True) self.se_expand = nn.Conv2d(squeeze_channels, channels, 1, 1, 0, bias=True) self.non_linear2 = nn.Sigmoid() def forward(self, input_0): primals_2 = self.se_reduce.weight primals_3 = self.se_reduce.bias primals_4 = self.se_expand.weight primals_5 = self.se_expand.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JACKYLUO1991/HybridNet
SqueezeAndExcite
false
17,456
[ "Apache-2.0" ]
6
eb97d8a048ca4bb4087bc542360172e169a08dbf
https://github.com/JACKYLUO1991/HybridNet/tree/eb97d8a048ca4bb4087bc542360172e169a08dbf
ResForward
import torch from torch import nn import torch.distributed class ResBlock(nn.Module): def __init__(self, feature_size, action_size): super(ResBlock, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.lin_2 = nn.Linear(feature_size + action_size, feature_size) def forward(self, x, action): res = nn.functional.leaky_relu(self.lin_1(torch.cat([x, action], 2))) res = self.lin_2(torch.cat([res, action], 2)) return res + x class ResForward(nn.Module): def __init__(self, feature_size, action_size): super(ResForward, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.res_block_1 = ResBlock(feature_size, action_size) self.res_block_2 = ResBlock(feature_size, action_size) self.res_block_3 = ResBlock(feature_size, action_size) self.res_block_4 = ResBlock(feature_size, action_size) self.lin_last = nn.Linear(feature_size + action_size, feature_size) def forward(self, phi1, action): x = nn.functional.leaky_relu(self.lin_1(torch.cat([phi1, action], 2))) x = self.res_block_1(x, action) x = self.res_block_2(x, action) x = self.res_block_3(x, action) x = self.res_block_4(x, action) x = self.lin_last(torch.cat([x, action], 2)) return x def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'feature_size': 4, 'action_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_leaky_relu_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 x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0).to(tl.int1) tmp6 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = 0.01 tmp10 = tmp8 * tmp9 tmp11 = tl.where(tmp5, tmp8, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp17 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tl.where(tmp4, tmp13, tmp17) tl.store(out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_add_leaky_relu_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask).to(tl.int1) tmp4 = tl.load(in_ptr3 + x2, xmask) tmp5 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp6 = tmp4 + tmp5 tmp7 = 0.01 tmp8 = tmp6 * tmp7 tmp9 = tl.where(tmp3, tmp6, tmp8) tmp10 = tmp2 + tmp9 tl.store(out_ptr0 + (x0 + 8 * x1), tmp10, xmask) @triton.jit def triton_poi_fused_cat_4(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 8 * x1), tmp0, xmask) tl.store(out_ptr1 + (x0 + 8 * x1), tmp0, xmask) @triton.jit def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr2 + (8 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tmp7 + tmp8 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp15 = tl.load(in_ptr3 + (4 * x1 + (-4 + x0)), tmp12 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.where(tmp4, tmp11, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_add_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr4 + (x0 + 8 * x1), xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp2 + tmp7 tl.store(out_ptr0 + (x0 + 8 * x1), tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 8), (8, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 8), (8, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 8), (8, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 8), (8, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 8), (8, 1)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (4, 8), (8, 1)) assert_size_stride(primals_16, (4,), (1,)) assert_size_stride(primals_17, (4, 8), (8, 1)) assert_size_stride(primals_18, (4,), (1,)) assert_size_stride(primals_19, (4, 8), (8, 1)) assert_size_stride(primals_20, (4,), (1,)) assert_size_stride(primals_21, (4, 8), (8, 1)) assert_size_stride(primals_22, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_1, primals_2, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf1, primals_4, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf2, buf1, primals_4, primals_2, buf3, 128, XBLOCK=128, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (16, 8), (8, 1), 0), reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), out=buf4) buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf4, primals_6, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf5, buf4, primals_6, primals_2, buf6, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_6 buf7 = buf4 del buf4 extern_kernels.mm(reinterpret_tensor(buf6, (16, 8), (8, 1), 0), reinterpret_tensor(primals_7, (8, 4), (1, 8), 0), out=buf7) buf10 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf8 = reinterpret_tensor(buf10, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_add_leaky_relu_3[grid(64)](buf7, primals_8, buf2, buf1, primals_4, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_4 del primals_8 buf9 = reinterpret_tensor(buf10, (4, 4, 4), (32, 8, 1), 4) buf22 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf21 = reinterpret_tensor(buf22, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_4[grid(64)](primals_2, buf9, buf21, 64, XBLOCK =64, num_warps=1, num_stages=1) buf11 = buf7 del buf7 extern_kernels.mm(reinterpret_tensor(buf10, (16, 8), (8, 1), 0), reinterpret_tensor(primals_9, (8, 4), (1, 8), 0), out=buf11) buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf11, primals_10, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf12, buf11, primals_10, primals_2, buf13, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_10 buf14 = buf11 del buf11 extern_kernels.mm(reinterpret_tensor(buf13, (16, 8), (8, 1), 0), reinterpret_tensor(primals_11, (8, 4), (1, 8), 0), out=buf14) buf15 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_5[grid(128)](buf14, primals_12, buf8, primals_2, buf15, 128, XBLOCK=128, num_warps=4, num_stages=1) buf16 = buf1 del buf1 extern_kernels.mm(reinterpret_tensor(buf15, (16, 8), (8, 1), 0), reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf16) buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf16, primals_14, buf17, 64, XBLOCK=64, num_warps=1, num_stages=1) buf18 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf17, buf16, primals_14, primals_2, buf18, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_14 buf19 = buf16 del buf16 extern_kernels.mm(reinterpret_tensor(buf18, (16, 8), (8, 1), 0), reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf19) buf20 = reinterpret_tensor(buf22, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_add_6[grid(64)](buf19, primals_16, buf14, primals_12, buf8, buf20, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf14 del primals_12 del primals_16 buf23 = buf19 del buf19 extern_kernels.mm(reinterpret_tensor(buf22, (16, 8), (8, 1), 0), reinterpret_tensor(primals_17, (8, 4), (1, 8), 0), out=buf23) buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_1[grid(64)](buf23, primals_18, buf24, 64, XBLOCK=64, num_warps=1, num_stages=1) buf25 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf24, buf23, primals_18, primals_2, buf25, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_18 buf26 = buf23 del buf23 extern_kernels.mm(reinterpret_tensor(buf25, (16, 8), (8, 1), 0), reinterpret_tensor(primals_19, (8, 4), (1, 8), 0), out=buf26) buf27 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_5[grid(128)](buf26, primals_20, buf20, primals_2, buf27, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_20 buf28 = buf26 del buf26 extern_kernels.addmm(primals_22, reinterpret_tensor(buf27, (16, 8), (8, 1), 0), reinterpret_tensor(primals_21, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf28) del primals_22 return (reinterpret_tensor(buf28, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf0, (16, 8), (8, 1), 0), buf2, reinterpret_tensor(buf3, (16, 8), (8, 1), 0), buf5, reinterpret_tensor(buf6, (16, 8), (8, 1), 0), reinterpret_tensor( buf10, (16, 8), (8, 1), 0), buf12, reinterpret_tensor(buf13, (16, 8 ), (8, 1), 0), reinterpret_tensor(buf15, (16, 8), (8, 1), 0), buf17, reinterpret_tensor(buf18, (16, 8), (8, 1), 0), reinterpret_tensor( buf22, (16, 8), (8, 1), 0), buf24, reinterpret_tensor(buf25, (16, 8 ), (8, 1), 0), reinterpret_tensor(buf27, (16, 8), (8, 1), 0), primals_21, primals_19, primals_17, primals_15, primals_13, primals_11, primals_9, primals_7, primals_5) class ResBlock(nn.Module): def __init__(self, feature_size, action_size): super(ResBlock, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.lin_2 = nn.Linear(feature_size + action_size, feature_size) def forward(self, x, action): res = nn.functional.leaky_relu(self.lin_1(torch.cat([x, action], 2))) res = self.lin_2(torch.cat([res, action], 2)) return res + x class ResForwardNew(nn.Module): def __init__(self, feature_size, action_size): super(ResForwardNew, self).__init__() self.lin_1 = nn.Linear(feature_size + action_size, feature_size) self.res_block_1 = ResBlock(feature_size, action_size) self.res_block_2 = ResBlock(feature_size, action_size) self.res_block_3 = ResBlock(feature_size, action_size) self.res_block_4 = ResBlock(feature_size, action_size) self.lin_last = nn.Linear(feature_size + action_size, feature_size) def forward(self, input_0, input_1): primals_3 = self.lin_1.weight primals_4 = self.lin_1.bias primals_5 = self.res_block_1.lin_1.weight primals_6 = self.res_block_1.lin_1.bias primals_7 = self.res_block_1.lin_2.weight primals_8 = self.res_block_1.lin_2.bias primals_9 = self.res_block_2.lin_1.weight primals_10 = self.res_block_2.lin_1.bias primals_11 = self.res_block_2.lin_2.weight primals_12 = self.res_block_2.lin_2.bias primals_13 = self.res_block_3.lin_1.weight primals_14 = self.res_block_3.lin_1.bias primals_15 = self.res_block_3.lin_2.weight primals_16 = self.res_block_3.lin_2.bias primals_17 = self.res_block_4.lin_1.weight primals_18 = self.res_block_4.lin_1.bias primals_19 = self.res_block_4.lin_2.weight primals_20 = self.res_block_4.lin_2.bias primals_21 = self.lin_last.weight primals_22 = self.lin_last.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22]) return output[0]
Improbable-AI/curiosity_baselines
ResForward
false
17,457
[ "MIT" ]
5
42dca92b2fb66c0790a72206bf48595d3b5b487f
https://github.com/Improbable-AI/curiosity_baselines/tree/42dca92b2fb66c0790a72206bf48595d3b5b487f
Autoencoder
import torch from torch import nn class Autoencoder(nn.Module): def __init__(self, input_dim, output_dim, n_hid, n_bottleneck): super(Autoencoder, self).__init__() self.fc1 = nn.Linear(input_dim, n_hid) self.fc2 = nn.Linear(n_hid, n_bottleneck) self.fc3 = nn.Linear(n_bottleneck, n_hid) self.fc4 = nn.Linear(n_hid, output_dim) self.act = nn.ReLU(inplace=True) def forward(self, x): None x = self.fc1(x) x = self.act(x) x = self.fc2(x) x = self.act(x) x = self.fc3(x) x = self.act(x) y = self.fc4(x) return y def get_features(self, x): return None def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4, 'n_hid': 4, 'n_bottleneck': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_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 x4 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = 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 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * (x1 % 4 // 4) + 64 * ((4 * (x1 // 4 % 4) + x1 % 4) // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_2, buf12, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused_view_1[grid(256)](buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) buf3 = reinterpret_tensor(buf1, (64, 4), (4, 1), 0) del buf1 extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf4, primals_5, buf11, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused_view_1[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (64, 4), (4, 1), 0) del buf4 extern_kernels.mm(buf5, reinterpret_tensor(primals_6, (4, 4), (1, 4 ), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf7, primals_7, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf8 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused_view_1[grid(256)](buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = reinterpret_tensor(buf7, (64, 4), (4, 1), 0) del buf7 extern_kernels.addmm(primals_9, buf8, reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf9) del primals_9 return reinterpret_tensor(buf9, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, buf5, buf8, primals_8, buf10, primals_6, buf11, primals_4, buf12 class AutoencoderNew(nn.Module): def __init__(self, input_dim, output_dim, n_hid, n_bottleneck): super(AutoencoderNew, self).__init__() self.fc1 = nn.Linear(input_dim, n_hid) self.fc2 = nn.Linear(n_hid, n_bottleneck) self.fc3 = nn.Linear(n_bottleneck, n_hid) self.fc4 = nn.Linear(n_hid, output_dim) self.act = nn.ReLU(inplace=True) def get_features(self, x): return None def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_8 = self.fc4.weight primals_9 = self.fc4.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]
JavierAntoran/tiger-costume
Autoencoder
false
17,458
[ "MIT" ]
10
975661dfab2c435281f74c6be86529b16881ebcb
https://github.com/JavierAntoran/tiger-costume/tree/975661dfab2c435281f74c6be86529b16881ebcb
DQfDNetwork
import torch import torch.nn as nn import torch.nn.functional as F class DQfDNetwork(nn.Module): def __init__(self, in_size, out_size): super(DQfDNetwork, self).__init__() HIDDEN_SIZE = 30 self.f1 = nn.Linear(in_size, HIDDEN_SIZE) self.f2 = nn.Linear(HIDDEN_SIZE, HIDDEN_SIZE) self.f3 = nn.Linear(HIDDEN_SIZE, out_size) nn.init.xavier_uniform_(self.f1.weight) nn.init.xavier_uniform_(self.f2.weight) nn.init.xavier_uniform_(self.f3.weight) self.opt = torch.optim.Adam(self.parameters()) self.loss = torch.nn.MSELoss() def forward(self, x): x1 = F.relu(self.f1(x)) x2 = F.relu(self.f2(x1)) x3 = self.f3(x2) res = F.softmax(x3) return res def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'out_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn 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 = 1920 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 30 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.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__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) 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, (30, 4), (4, 1)) assert_size_stride(primals_2, (30,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (30, 30), (30, 1)) assert_size_stride(primals_5, (30,), (1,)) assert_size_stride(primals_6, (4, 30), (30, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 30), (30, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 30), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 30), (480, 120, 30, 1), 0) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 30), (480, 120, 30, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(1920)](buf1, primals_2, buf8, 1920, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 30), (30, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 30), (30, 1), 0), reinterpret_tensor(primals_4, (30, 30), (1, 30), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 30), (480, 120, 30, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 30), (480, 120, 30, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(1920)](buf3, primals_5, buf7, 1920, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 30), (30, 1), 0), reinterpret_tensor(primals_6, (30, 4), (1, 30), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[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__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf5 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 30), (30, 1), 0), reinterpret_tensor( buf3, (64, 30), (30, 1), 0), buf6, primals_6, buf7, primals_4, buf8 class DQfDNetworkNew(nn.Module): def __init__(self, in_size, out_size): super(DQfDNetworkNew, self).__init__() HIDDEN_SIZE = 30 self.f1 = nn.Linear(in_size, HIDDEN_SIZE) self.f2 = nn.Linear(HIDDEN_SIZE, HIDDEN_SIZE) self.f3 = nn.Linear(HIDDEN_SIZE, out_size) nn.init.xavier_uniform_(self.f1.weight) nn.init.xavier_uniform_(self.f2.weight) nn.init.xavier_uniform_(self.f3.weight) self.opt = torch.optim.Adam(self.parameters()) self.loss = torch.nn.MSELoss() def forward(self, input_0): primals_1 = self.f1.weight primals_2 = self.f1.bias primals_4 = self.f2.weight primals_5 = self.f2.bias primals_6 = self.f3.weight primals_7 = self.f3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
DPS0340/DQNDemo
DQfDNetwork
false
17,459
[ "MIT" ]
8
5b57159ea8ff8a6b127cb18ff28da6696b40665b
https://github.com/DPS0340/DQNDemo/tree/5b57159ea8ff8a6b127cb18ff28da6696b40665b
NeuralClassifier
import torch import torch.nn as nn import torch.utils.data class NeuralClassifier(nn.Module): def __init__(self, input_size, n_classes): super(NeuralClassifier, self).__init__() self.input_size = input_size self.mapping1 = nn.Linear(input_size, input_size) self.mapping2 = nn.Linear(input_size, n_classes) self.f = torch.sigmoid def forward(self, x): x = self.f(self.mapping1(x)) return self.f(self.mapping2(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'n_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 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_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(256)](buf1, primals_2, 256, 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, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_sigmoid_0[grid(256)](buf3, primals_5, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf3, primals_4 class NeuralClassifierNew(nn.Module): def __init__(self, input_size, n_classes): super(NeuralClassifierNew, self).__init__() self.input_size = input_size self.mapping1 = nn.Linear(input_size, input_size) self.mapping2 = nn.Linear(input_size, n_classes) self.f = torch.sigmoid def forward(self, input_0): primals_1 = self.mapping1.weight primals_2 = self.mapping1.bias primals_4 = self.mapping2.weight primals_5 = self.mapping2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JayWalker512/PacketGAN
NeuralClassifier
false
17,460
[ "MIT" ]
5
93d4266ab9299c25ffd1f0aedf68fa4639f66572
https://github.com/JayWalker512/PacketGAN/tree/93d4266ab9299c25ffd1f0aedf68fa4639f66572
Sinkhorn
import torch import torch.utils.data import torch.nn as nn from sklearn import * class Sinkhorn(nn.Module): """ BiStochastic Layer turns the input matrix into a bi-stochastic matrix. Parameter: maximum iterations max_iter a small number for numerical stability epsilon Input: input matrix s Output: bi-stochastic matrix s """ def __init__(self, max_iter=10, epsilon=0.0001): super(Sinkhorn, self).__init__() self.max_iter = max_iter self.epsilon = epsilon def forward(self, s, nrows=None, ncols=None, exp=False, exp_alpha=20, dummy_row=False, dtype=torch.float32): batch_size = s.shape[0] if dummy_row: dummy_shape = list(s.shape) dummy_shape[1] = s.shape[2] - s.shape[1] s = torch.cat((s, torch.full(dummy_shape, 0.0)), dim=1) new_nrows = ncols for b in range(batch_size): s[b, nrows[b]:new_nrows[b], :ncols[b]] = self.epsilon nrows = new_nrows row_norm_ones = torch.zeros(batch_size, s.shape[1], s.shape[1], device=s.device) col_norm_ones = torch.zeros(batch_size, s.shape[2], s.shape[2], device=s.device) for b in range(batch_size): row_slice = slice(0, nrows[b] if nrows is not None else s.shape[2]) col_slice = slice(0, ncols[b] if ncols is not None else s.shape[1]) row_norm_ones[b, row_slice, row_slice] = 1 col_norm_ones[b, col_slice, col_slice] = 1 if len(s.shape) == 4: row_norm_ones = row_norm_ones.unsqueeze(-1) col_norm_ones = col_norm_ones.unsqueeze(-1) s += self.epsilon for i in range(self.max_iter): if exp: s = torch.exp(exp_alpha * s) if i % 2 == 1: sum = torch.sum(torch.mul(s.unsqueeze(3), col_norm_ones. unsqueeze(1)), dim=2) else: sum = torch.sum(torch.mul(row_norm_ones.unsqueeze(3), s. unsqueeze(1)), dim=2) tmp = torch.zeros_like(s) for b in range(batch_size): row_slice = slice(0, nrows[b] if nrows is not None else s. shape[2]) col_slice = slice(0, ncols[b] if ncols is not None else s. shape[1]) tmp[b, row_slice, col_slice] = 1 / sum[b, row_slice, col_slice] s = s * tmp if dummy_row and dummy_shape[1] > 0: s = s[:, :-dummy_shape[1]] return s def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.utils.data import torch.nn as nn from sklearn 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_mul_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 64 x0 = xindex % 16 x3 = xindex tmp15 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp0 = x2 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tl.full([1], 2, tl.int32) tmp4 = tmp0 == tmp3 tmp5 = tl.full([1], 1, tl.int32) tmp6 = tmp0 == tmp5 tmp7 = tl.full([1], 0, tl.int32) tmp8 = tmp0 == tmp7 tmp9 = 1.0 tmp10 = 0.0 tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = tl.where(tmp6, tmp9, tmp11) tmp13 = tl.where(tmp4, tmp9, tmp12) tmp14 = tl.where(tmp2, tmp9, tmp13) tmp16 = 0.0001 tmp17 = tmp15 + tmp16 tmp18 = tmp14 * tmp17 tmp20 = tmp19 + tmp16 tmp21 = tmp14 * tmp20 tmp22 = tmp18 + tmp21 tmp24 = tmp23 + tmp16 tmp25 = tmp14 * tmp24 tmp26 = tmp22 + tmp25 tmp28 = tmp27 + tmp16 tmp29 = tmp14 * tmp28 tmp30 = tmp26 + tmp29 tl.store(out_ptr0 + x3, tmp30, xmask) @triton.jit def triton_poi_fused_add_mul_reciprocal_zeros_like_1(in_ptr0, in_ptr1, out_ptr0, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 64 x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr1 + (192 + x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (128 + x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (64 + x0), xmask, eviction_policy='evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp1 = 0.0001 tmp2 = tmp0 + tmp1 tmp3 = x1 tmp4 = tl.full([1], 3, tl.int32) tmp5 = tmp3 == tmp4 tmp7 = tl.full([1], 1, tl.int32) tmp8 = tmp7 / tmp6 tmp9 = 1.0 tmp10 = tmp8 * tmp9 tmp11 = tl.full([1], 2, tl.int32) tmp12 = tmp3 == tmp11 tmp14 = tmp7 / tmp13 tmp15 = tmp14 * tmp9 tmp16 = tmp3 == tmp7 tmp18 = tmp7 / tmp17 tmp19 = tmp18 * tmp9 tmp20 = tl.full([1], 0, tl.int32) tmp21 = tmp3 == tmp20 tmp23 = tmp7 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = 0.0 tmp26 = tl.where(tmp21, tmp24, tmp25) tmp27 = tl.where(tmp16, tmp19, tmp26) tmp28 = tl.where(tmp12, tmp15, tmp27) tmp29 = tl.where(tmp5, tmp10, tmp28) tmp30 = tmp2 * tmp29 tl.store(out_ptr0 + x2, tmp30, xmask) tl.store(out_ptr2 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_mul_reciprocal_zeros_like_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 // 64 x0 = xindex % 4 x2 = xindex // 16 % 4 x4 = xindex tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp24 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp31 = tl.load(in_ptr0 + (64 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp41 = tl.load(in_ptr0 + (68 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp44 = tl.load(in_ptr0 + (72 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp47 = tl.load(in_ptr0 + (76 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp54 = tl.load(in_ptr0 + (128 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp64 = tl.load(in_ptr0 + (132 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp67 = tl.load(in_ptr0 + (136 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp70 = tl.load(in_ptr0 + (140 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp77 = tl.load(in_ptr0 + (192 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp87 = tl.load(in_ptr0 + (196 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp90 = tl.load(in_ptr0 + (200 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp93 = tl.load(in_ptr0 + (204 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp0 = x3 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl.full([1], 3, tl.int32) tmp5 = tmp1 == tmp4 tmp6 = tl.full([1], 2, tl.int32) tmp7 = tmp1 == tmp6 tmp8 = tl.full([1], 1, tl.int32) tmp9 = tmp1 == tmp8 tmp10 = tmp1 == tmp1 tmp11 = 1.0 tmp12 = 0.0 tmp13 = tl.where(tmp10, tmp11, tmp12) tmp14 = tl.where(tmp9, tmp11, tmp13) tmp15 = tl.where(tmp7, tmp11, tmp14) tmp16 = tl.where(tmp5, tmp11, tmp15) tmp17 = tmp3 * tmp16 tmp19 = tmp18 * tmp16 tmp20 = tmp17 + tmp19 tmp22 = tmp21 * tmp16 tmp23 = tmp20 + tmp22 tmp25 = tmp24 * tmp16 tmp26 = tmp23 + tmp25 tmp27 = tmp8 / tmp26 tmp28 = tmp27 * tmp11 tmp29 = tl.where(tmp2, tmp28, tmp12) tmp30 = tmp0 == tmp8 tmp32 = tmp8 == tmp4 tmp33 = tmp8 == tmp6 tmp34 = tmp8 == tmp8 tmp35 = tmp8 == tmp1 tmp36 = tl.where(tmp35, tmp11, tmp12) tmp37 = tl.where(tmp34, tmp11, tmp36) tmp38 = tl.where(tmp33, tmp11, tmp37) tmp39 = tl.where(tmp32, tmp11, tmp38) tmp40 = tmp31 * tmp39 tmp42 = tmp41 * tmp39 tmp43 = tmp40 + tmp42 tmp45 = tmp44 * tmp39 tmp46 = tmp43 + tmp45 tmp48 = tmp47 * tmp39 tmp49 = tmp46 + tmp48 tmp50 = tmp8 / tmp49 tmp51 = tmp50 * tmp11 tmp52 = tl.where(tmp30, tmp51, tmp29) tmp53 = tmp0 == tmp6 tmp55 = tmp6 == tmp4 tmp56 = tmp6 == tmp6 tmp57 = tmp6 == tmp8 tmp58 = tmp6 == tmp1 tmp59 = tl.where(tmp58, tmp11, tmp12) tmp60 = tl.where(tmp57, tmp11, tmp59) tmp61 = tl.where(tmp56, tmp11, tmp60) tmp62 = tl.where(tmp55, tmp11, tmp61) tmp63 = tmp54 * tmp62 tmp65 = tmp64 * tmp62 tmp66 = tmp63 + tmp65 tmp68 = tmp67 * tmp62 tmp69 = tmp66 + tmp68 tmp71 = tmp70 * tmp62 tmp72 = tmp69 + tmp71 tmp73 = tmp8 / tmp72 tmp74 = tmp73 * tmp11 tmp75 = tl.where(tmp53, tmp74, tmp52) tmp76 = tmp0 == tmp4 tmp78 = tmp4 == tmp4 tmp79 = tmp4 == tmp6 tmp80 = tmp4 == tmp8 tmp81 = tmp4 == tmp1 tmp82 = tl.where(tmp81, tmp11, tmp12) tmp83 = tl.where(tmp80, tmp11, tmp82) tmp84 = tl.where(tmp79, tmp11, tmp83) tmp85 = tl.where(tmp78, tmp11, tmp84) tmp86 = tmp77 * tmp85 tmp88 = tmp87 * tmp85 tmp89 = tmp86 + tmp88 tmp91 = tmp90 * tmp85 tmp92 = tmp89 + tmp91 tmp94 = tmp93 * tmp85 tmp95 = tmp92 + tmp94 tmp96 = tmp8 / tmp95 tmp97 = tmp96 * tmp11 tmp98 = tl.where(tmp76, tmp97, tmp75) tl.store(in_out_ptr0 + x4, tmp98, 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 x2 = xindex // 64 x0 = xindex % 16 x3 = xindex tmp15 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp24 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp0 = x2 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tl.full([1], 2, tl.int32) tmp4 = tmp0 == tmp3 tmp5 = tl.full([1], 1, tl.int32) tmp6 = tmp0 == tmp5 tmp7 = tl.full([1], 0, tl.int32) tmp8 = tmp0 == tmp7 tmp9 = 1.0 tmp10 = 0.0 tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = tl.where(tmp6, tmp9, tmp11) tmp13 = tl.where(tmp4, tmp9, tmp12) tmp14 = tl.where(tmp2, tmp9, tmp13) tmp17 = tmp15 * tmp16 tmp18 = tmp14 * tmp17 tmp21 = tmp19 * tmp20 tmp22 = tmp14 * tmp21 tmp23 = tmp18 + tmp22 tmp26 = tmp24 * tmp25 tmp27 = tmp14 * tmp26 tmp28 = tmp23 + tmp27 tmp31 = tmp29 * tmp30 tmp32 = tmp14 * tmp31 tmp33 = tmp28 + tmp32 tl.store(out_ptr0 + x3, tmp33, xmask) @triton.jit def triton_poi_fused_mul_reciprocal_zeros_like_4(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 x1 = xindex // 64 x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr1 + (192 + x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (128 + x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (64 + x0), xmask, eviction_policy='evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp3 = x1 tmp4 = tl.full([1], 3, tl.int32) tmp5 = tmp3 == tmp4 tmp7 = tl.full([1], 1, tl.int32) tmp8 = tmp7 / tmp6 tmp9 = 1.0 tmp10 = tmp8 * tmp9 tmp11 = tl.full([1], 2, tl.int32) tmp12 = tmp3 == tmp11 tmp14 = tmp7 / tmp13 tmp15 = tmp14 * tmp9 tmp16 = tmp3 == tmp7 tmp18 = tmp7 / tmp17 tmp19 = tmp18 * tmp9 tmp20 = tl.full([1], 0, tl.int32) tmp21 = tmp3 == tmp20 tmp23 = tmp7 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = 0.0 tmp26 = tl.where(tmp21, tmp24, tmp25) tmp27 = tl.where(tmp16, tmp19, tmp26) tmp28 = tl.where(tmp12, tmp15, tmp27) tmp29 = tl.where(tmp5, tmp10, tmp28) tmp30 = tmp2 * tmp29 tl.store(in_out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_mul_reciprocal_zeros_like_5(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 x1 = xindex // 64 x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_out_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr1 + (192 + x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (128 + x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (64 + x0), xmask, eviction_policy='evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp3 = x1 tmp4 = tl.full([1], 3, tl.int32) tmp5 = tmp3 == tmp4 tmp7 = tl.full([1], 1, tl.int32) tmp8 = tmp7 / tmp6 tmp9 = 1.0 tmp10 = tmp8 * tmp9 tmp11 = tl.full([1], 2, tl.int32) tmp12 = tmp3 == tmp11 tmp14 = tmp7 / tmp13 tmp15 = tmp14 * tmp9 tmp16 = tmp3 == tmp7 tmp18 = tmp7 / tmp17 tmp19 = tmp18 * tmp9 tmp20 = tl.full([1], 0, tl.int32) tmp21 = tmp3 == tmp20 tmp23 = tmp7 / tmp22 tmp24 = tmp23 * tmp9 tmp25 = 0.0 tmp26 = tl.where(tmp21, tmp24, tmp25) tmp27 = tl.where(tmp16, tmp19, tmp26) tmp28 = tl.where(tmp12, tmp15, tmp27) tmp29 = tl.where(tmp5, tmp10, tmp28) tmp30 = tmp2 * tmp29 tl.store(in_out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_mul_reciprocal_zeros_like_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex // 64 x0 = xindex % 4 x2 = xindex // 16 % 4 x4 = xindex tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp24 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp31 = tl.load(in_ptr0 + (64 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp41 = tl.load(in_ptr0 + (68 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp44 = tl.load(in_ptr0 + (72 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp47 = tl.load(in_ptr0 + (76 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp54 = tl.load(in_ptr0 + (128 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp64 = tl.load(in_ptr0 + (132 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp67 = tl.load(in_ptr0 + (136 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp70 = tl.load(in_ptr0 + (140 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp77 = tl.load(in_ptr0 + (192 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp87 = tl.load(in_ptr0 + (196 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp90 = tl.load(in_ptr0 + (200 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp93 = tl.load(in_ptr0 + (204 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp99 = tl.load(in_ptr0 + x4, xmask) tmp0 = x3 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl.full([1], 3, tl.int32) tmp5 = tmp1 == tmp4 tmp6 = tl.full([1], 2, tl.int32) tmp7 = tmp1 == tmp6 tmp8 = tl.full([1], 1, tl.int32) tmp9 = tmp1 == tmp8 tmp10 = tmp1 == tmp1 tmp11 = 1.0 tmp12 = 0.0 tmp13 = tl.where(tmp10, tmp11, tmp12) tmp14 = tl.where(tmp9, tmp11, tmp13) tmp15 = tl.where(tmp7, tmp11, tmp14) tmp16 = tl.where(tmp5, tmp11, tmp15) tmp17 = tmp3 * tmp16 tmp19 = tmp18 * tmp16 tmp20 = tmp17 + tmp19 tmp22 = tmp21 * tmp16 tmp23 = tmp20 + tmp22 tmp25 = tmp24 * tmp16 tmp26 = tmp23 + tmp25 tmp27 = tmp8 / tmp26 tmp28 = tmp27 * tmp11 tmp29 = tl.where(tmp2, tmp28, tmp12) tmp30 = tmp0 == tmp8 tmp32 = tmp8 == tmp4 tmp33 = tmp8 == tmp6 tmp34 = tmp8 == tmp8 tmp35 = tmp8 == tmp1 tmp36 = tl.where(tmp35, tmp11, tmp12) tmp37 = tl.where(tmp34, tmp11, tmp36) tmp38 = tl.where(tmp33, tmp11, tmp37) tmp39 = tl.where(tmp32, tmp11, tmp38) tmp40 = tmp31 * tmp39 tmp42 = tmp41 * tmp39 tmp43 = tmp40 + tmp42 tmp45 = tmp44 * tmp39 tmp46 = tmp43 + tmp45 tmp48 = tmp47 * tmp39 tmp49 = tmp46 + tmp48 tmp50 = tmp8 / tmp49 tmp51 = tmp50 * tmp11 tmp52 = tl.where(tmp30, tmp51, tmp29) tmp53 = tmp0 == tmp6 tmp55 = tmp6 == tmp4 tmp56 = tmp6 == tmp6 tmp57 = tmp6 == tmp8 tmp58 = tmp6 == tmp1 tmp59 = tl.where(tmp58, tmp11, tmp12) tmp60 = tl.where(tmp57, tmp11, tmp59) tmp61 = tl.where(tmp56, tmp11, tmp60) tmp62 = tl.where(tmp55, tmp11, tmp61) tmp63 = tmp54 * tmp62 tmp65 = tmp64 * tmp62 tmp66 = tmp63 + tmp65 tmp68 = tmp67 * tmp62 tmp69 = tmp66 + tmp68 tmp71 = tmp70 * tmp62 tmp72 = tmp69 + tmp71 tmp73 = tmp8 / tmp72 tmp74 = tmp73 * tmp11 tmp75 = tl.where(tmp53, tmp74, tmp52) tmp76 = tmp0 == tmp4 tmp78 = tmp4 == tmp4 tmp79 = tmp4 == tmp6 tmp80 = tmp4 == tmp8 tmp81 = tmp4 == tmp1 tmp82 = tl.where(tmp81, tmp11, tmp12) tmp83 = tl.where(tmp80, tmp11, tmp82) tmp84 = tl.where(tmp79, tmp11, tmp83) tmp85 = tl.where(tmp78, tmp11, tmp84) tmp86 = tmp77 * tmp85 tmp88 = tmp87 * tmp85 tmp89 = tmp86 + tmp88 tmp91 = tmp90 * tmp85 tmp92 = tmp89 + tmp91 tmp94 = tmp93 * tmp85 tmp95 = tmp92 + tmp94 tmp96 = tmp8 / tmp95 tmp97 = tmp96 * tmp11 tmp98 = tl.where(tmp76, tmp97, tmp75) tmp100 = tmp99 * tmp98 tl.store(in_out_ptr0 + x4, tmp100, 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_sum_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_reciprocal_zeros_like_1[grid(256)](arg0_1, buf0, buf1, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf2 = buf0 del buf0 buf3 = buf2 del buf2 buf4 = buf3 del buf3 buf5 = buf4 del buf4 triton_poi_fused_mul_reciprocal_zeros_like_2[grid(256)](buf5, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sum_3[grid(256)](buf1, buf5, buf6, 256, XBLOCK =256, num_warps=4, num_stages=1) buf7 = buf1 del buf1 triton_poi_fused_mul_reciprocal_zeros_like_4[grid(256)](buf7, buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf8 = buf6 del buf6 buf9 = buf8 del buf8 buf10 = buf9 del buf9 buf11 = buf10 del buf10 triton_poi_fused_mul_reciprocal_zeros_like_2[grid(256)](buf11, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) buf12 = buf5 del buf5 triton_poi_fused_mul_sum_3[grid(256)](buf7, buf11, buf12, 256, XBLOCK=256, num_warps=4, num_stages=1) buf13 = buf11 del buf11 triton_poi_fused_mul_reciprocal_zeros_like_5[grid(256)](buf13, buf7, buf12, 256, XBLOCK=256, num_warps=4, num_stages=1) buf14 = buf7 del buf7 buf15 = buf14 del buf14 buf16 = buf15 del buf15 buf17 = buf16 del buf16 triton_poi_fused_mul_reciprocal_zeros_like_2[grid(256)](buf17, buf13, 256, XBLOCK=128, num_warps=4, num_stages=1) buf18 = buf12 del buf12 triton_poi_fused_mul_sum_3[grid(256)](buf13, buf17, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1) buf19 = buf13 del buf13 triton_poi_fused_mul_reciprocal_zeros_like_4[grid(256)](buf19, buf17, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1) buf20 = buf18 del buf18 buf21 = buf20 del buf20 buf22 = buf21 del buf21 buf23 = buf22 del buf22 triton_poi_fused_mul_reciprocal_zeros_like_2[grid(256)](buf23, buf19, 256, XBLOCK=128, num_warps=4, num_stages=1) buf24 = buf17 del buf17 triton_poi_fused_mul_sum_3[grid(256)](buf19, buf23, buf24, 256, XBLOCK=256, num_warps=4, num_stages=1) buf25 = buf19 del buf19 triton_poi_fused_mul_reciprocal_zeros_like_4[grid(256)](buf25, buf23, buf24, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf23 buf26 = buf24 del buf24 buf27 = buf26 del buf26 buf28 = buf27 del buf27 buf29 = buf28 del buf28 buf30 = buf29 del buf29 triton_poi_fused_mul_reciprocal_zeros_like_6[grid(256)](buf30, buf25, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf25 return buf30, class SinkhornNew(nn.Module): """ BiStochastic Layer turns the input matrix into a bi-stochastic matrix. Parameter: maximum iterations max_iter a small number for numerical stability epsilon Input: input matrix s Output: bi-stochastic matrix s """ def __init__(self, max_iter=10, epsilon=0.0001): super(SinkhornNew, self).__init__() self.max_iter = max_iter self.epsilon = epsilon def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
CityU-AIM-Group/SIGMA
Sinkhorn
false
17,461
[ "MIT" ]
5
19f89777db8d42f750a9b87756d3326c7efd18f5
https://github.com/CityU-AIM-Group/SIGMA/tree/19f89777db8d42f750a9b87756d3326c7efd18f5
TotalVariations
import torch from torch.nn.modules.loss import _Loss class TotalVariations(_Loss): def forward(self, img1): return torch.sum(torch.abs(img1[:, :, :-1] - img1[:, :, 1:]) ) + torch.sum(torch.abs(img1[:, :-1, :] - img1[:, 1:, :])) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math from torch.nn.modules.loss import _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_abs_add_sub_sum_0(in_out_ptr0, in_ptr0, 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 % 12 r1 = rindex // 12 r2 = rindex % 48 r3 = rindex // 48 tmp0 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0) tmp1 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), rmask, other=0.0) tmp8 = tl.load(in_ptr0 + (r2 + 64 * r3), rmask, other=0.0) tmp9 = tl.load(in_ptr0 + (16 + r2 + 64 * r3), rmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.where(rmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp10 = tmp8 - tmp9 tmp11 = tl_math.abs(tmp10) tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK]) tmp14 = tl.where(rmask, tmp12, 0) tmp15 = tl.sum(tmp14, 1)[:, None] tmp16 = tmp7 + tmp15 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp16, 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) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_sub_sum_0[grid(1)](buf2, arg0_1, 1, 192, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf2, class TotalVariationsNew(_Loss): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
HMS-CardiacMR/MyoMapNet-Myocardial-Parametric-Mapping
TotalVariations
false
17,462
[ "MIT" ]
4
1e2dee8d6d1f97722eba91618462537faf9efba7
https://github.com/HMS-CardiacMR/MyoMapNet-Myocardial-Parametric-Mapping/tree/1e2dee8d6d1f97722eba91618462537faf9efba7
Nloss_GD
import torch import numpy as np from torch import nn class Nloss_GD(nn.Module): def __init__(self, dim): super(Nloss_GD, self).__init__() self.dim = dim torch.manual_seed(0) def get_likelihoods(self, X, Y, Beta, eps=1e-06): inv_det = Beta.prod(dim=1) if (inv_det < eps).any(): inv_det += (inv_det < eps).type(torch.FloatTensor) * eps det = 1 / inv_det None norm_term = 1 / torch.sqrt((2 * np.pi) ** self.dim * torch.abs(det)) inv_covars = Beta dist = (Y - X).pow(2) exponent = (-0.5 * dist * inv_covars).sum(dim=1) pk = norm_term * exponent.exp() return pk def get_log_likelihoods(self, X, Y, sq_Beta, eps=1e-06): Beta = sq_Beta ** 2 log_det_term = 0.5 * Beta.log().sum(dim=1) norm_term = -0.5 * np.log(2 * np.pi) * self.dim inv_covars = Beta dist = (Y - X).pow(2) exponent = (-0.5 * dist * inv_covars).sum(dim=1) log_p = log_det_term + exponent + norm_term return log_p def forward(self, x, y, Beta): p = self.get_log_likelihoods(x, y, Beta) E = torch.sum(-p) / x.shape[0] return E def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 numpy as np from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_div_log_mul_neg_pow_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp6 = tl.load(in_ptr2 + (r0 + 64 * r1), None) tmp9 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp10 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp14 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None) tmp18 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp19 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp23 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None) tmp27 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp28 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp32 = tl.load(in_ptr2 + (48 + r0 + 64 * r1), None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = -0.5 tmp5 = tmp3 * tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 * tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp12 * tmp4 tmp15 = tmp14 * tmp14 tmp16 = tmp13 * tmp15 tmp17 = tmp8 + tmp16 tmp20 = tmp18 - tmp19 tmp21 = tmp20 * tmp20 tmp22 = tmp21 * tmp4 tmp24 = tmp23 * tmp23 tmp25 = tmp22 * tmp24 tmp26 = tmp17 + tmp25 tmp29 = tmp27 - tmp28 tmp30 = tmp29 * tmp29 tmp31 = tmp30 * tmp4 tmp33 = tmp32 * tmp32 tmp34 = tmp31 * tmp33 tmp35 = tmp26 + tmp34 tmp36 = tl_math.log(tmp7) tmp37 = tl_math.log(tmp15) tmp38 = tmp36 + tmp37 tmp39 = tl_math.log(tmp24) tmp40 = tmp38 + tmp39 tmp41 = tl_math.log(tmp33) tmp42 = tmp40 + tmp41 tmp43 = 0.5 tmp44 = tmp42 * tmp43 tmp45 = tmp44 + tmp35 tmp46 = -3.6757541328186907 tmp47 = tmp45 + tmp46 tmp48 = -tmp47 tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK]) tmp51 = tl.sum(tmp49, 1)[:, None] tmp52 = 0.25 tmp53 = tmp51 * tmp52 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp53, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_div_log_mul_neg_pow_sub_sum_0[grid(1)](buf2, arg1_1, arg2_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class Nloss_GDNew(nn.Module): def __init__(self, dim): super(Nloss_GDNew, self).__init__() self.dim = dim torch.manual_seed(0) def get_likelihoods(self, X, Y, Beta, eps=1e-06): inv_det = Beta.prod(dim=1) if (inv_det < eps).any(): inv_det += (inv_det < eps).type(torch.FloatTensor) * eps det = 1 / inv_det None norm_term = 1 / torch.sqrt((2 * np.pi) ** self.dim * torch.abs(det)) inv_covars = Beta dist = (Y - X).pow(2) exponent = (-0.5 * dist * inv_covars).sum(dim=1) pk = norm_term * exponent.exp() return pk def get_log_likelihoods(self, X, Y, sq_Beta, eps=1e-06): Beta = sq_Beta ** 2 log_det_term = 0.5 * Beta.log().sum(dim=1) norm_term = -0.5 * np.log(2 * np.pi) * self.dim inv_covars = Beta dist = (Y - X).pow(2) exponent = (-0.5 * dist * inv_covars).sum(dim=1) log_p = log_det_term + exponent + norm_term return log_p def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
JavierAntoran/tiger-costume
Nloss_GD
false
17,463
[ "MIT" ]
10
975661dfab2c435281f74c6be86529b16881ebcb
https://github.com/JavierAntoran/tiger-costume/tree/975661dfab2c435281f74c6be86529b16881ebcb
LogisticRegressionBinaryClassifier
import torch import torch.nn as nn import torch.utils.data class LogisticRegressionBinaryClassifier(nn.Module): def __init__(self, input_size): super(LogisticRegressionBinaryClassifier, self).__init__() self.input_size = input_size self.mapping = nn.Linear(input_size, 1) def forward(self, x): return torch.sigmoid(self.mapping(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 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_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (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, 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 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(64)](buf1, primals_2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1 class LogisticRegressionBinaryClassifierNew(nn.Module): def __init__(self, input_size): super(LogisticRegressionBinaryClassifierNew, self).__init__() self.input_size = input_size self.mapping = nn.Linear(input_size, 1) def forward(self, input_0): primals_1 = self.mapping.weight primals_2 = self.mapping.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JayWalker512/PacketGAN
LogisticRegressionBinaryClassifier
false
17,464
[ "MIT" ]
5
93d4266ab9299c25ffd1f0aedf68fa4639f66572
https://github.com/JayWalker512/PacketGAN/tree/93d4266ab9299c25ffd1f0aedf68fa4639f66572
TVLoss
import torch import torch as th import torch.utils.data import torch import torch.autograd class TVLoss(th.nn.Module): def __init__(self, strength=1.0): super(TVLoss, self).__init__() self.strength = strength def forward(self, input): self.x_diff = input[:, :, 1:, :] - input[:, :, :-1, :] self.y_diff = input[:, :, :, 1:] - input[:, :, :, :-1] self.loss = (th.sum(th.abs(self.x_diff)) + th.sum(th.abs(self.y_diff)) ) * self.strength return input def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch as th import torch.utils.data import torch import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_mul_sub_sum_0(in_out_ptr0, in_ptr0, out_ptr0, out_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 % 12 r1 = rindex // 12 r2 = rindex r3 = rindex % 3 r4 = rindex // 3 tmp0 = tl.load(in_ptr0 + (4 + r0 + 16 * r1), rmask, other=0.0) tmp1 = tl.load(in_ptr0 + (r0 + 16 * r1), rmask, other=0.0) tmp8 = tl.load(in_ptr0 + (1 + r3 + 4 * r4), rmask, other=0.0) tmp9 = tl.load(in_ptr0 + (r3 + 4 * r4), rmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.where(rmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp10 = tmp8 - tmp9 tmp11 = tl_math.abs(tmp10) tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK]) tmp14 = tl.where(rmask, tmp12, 0) tmp15 = tl.sum(tmp14, 1)[:, None] tmp16 = tmp7 + tmp15 tmp17 = 1.0 tmp18 = tmp16 * tmp17 tl.store(out_ptr0 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp2, rmask) tl.store(out_ptr1 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp10, rmask) 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((4, 4, 3, 4), (48, 12, 4, 1), torch.float32) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 3), (48, 12, 3, 1), torch.float32) buf4 = buf1 del buf1 get_raw_stream(0) triton_per_fused_abs_add_mul_sub_sum_0[grid(1)](buf4, arg0_1, buf0, buf2, 1, 192, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf4, buf2, buf0 class TVLossNew(th.nn.Module): def __init__(self, strength=1.0): super(TVLossNew, self).__init__() self.strength = strength def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
JCBrouwer/maua
TVLoss
false
17,465
[ "BSD-2-Clause" ]
9
4208023020bc56dd81f6933347f9c4e7c1853318
https://github.com/JCBrouwer/maua/tree/4208023020bc56dd81f6933347f9c4e7c1853318
StridedNet
import torch import torch.nn.functional as F import torch.nn as nn class StridedNet(nn.Module): def __init__(self): super(StridedNet, self).__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size= 6, stride=1, dilation=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=1, dilation=1) self.conv2 = nn.Conv2d(in_channels=10, out_channels=20, kernel_size =4, stride=1, dilation=2) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=1, dilation=2) self.fc1 = nn.Conv2d(in_channels=20, out_channels=32, kernel_size=2, stride=1, dilation=4) self.fc2 = nn.Conv2d(in_channels=32, out_channels=16, kernel_size=1, stride=1, dilation=1) self.fc3 = nn.Conv2d(in_channels=16, out_channels=1, kernel_size=1, stride=1, dilation=1) def forward(self, x): out = F.gelu(self.pool1(self.conv1(x))) out = F.gelu(self.pool2(self.conv2(out))) out = F.gelu(self.fc1(out)) out = F.gelu(self.fc2(out)) out = self.fc3(out) return out 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, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 139240 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3481 % 10 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_gelu_gelu_backward_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 134560 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 58 x1 = xindex // 58 % 58 x2 = xindex // 3364 x3 = xindex % 3364 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 59 * x1 + 3481 * x2), xmask) tmp1 = tl.load(in_ptr0 + (1 + x0 + 59 * x1 + 3481 * x2), xmask) tmp7 = tl.load(in_ptr0 + (59 + x0 + 59 * x1 + 3481 * x2), xmask) tmp12 = tl.load(in_ptr0 + (60 + x0 + 59 * x1 + 3481 * x2), xmask) 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 = 0.5 tmp18 = tmp16 * tmp17 tmp19 = 0.7071067811865476 tmp20 = tmp16 * tmp19 tmp21 = libdevice.erf(tmp20) tmp22 = 1.0 tmp23 = tmp21 + tmp22 tmp24 = tmp18 * tmp23 tmp25 = tmp23 * tmp17 tmp26 = tmp16 * tmp16 tmp27 = -0.5 tmp28 = tmp26 * tmp27 tmp29 = tl_math.exp(tmp28) tmp30 = 0.3989422804014327 tmp31 = tmp29 * tmp30 tmp32 = tmp16 * tmp31 tmp33 = tmp25 + tmp32 tl.store(out_ptr0 + (x3 + 3456 * x2), tmp15, xmask) tl.store(out_ptr1 + x4, tmp24, xmask) tl.store(out_ptr2 + (x3 + 3392 * x2), tmp33, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 216320 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 2704 % 20 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_gelu_gelu_backward_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 200000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex x1 = xindex % 2500 x2 = xindex // 2500 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 tmp9 = tmp7 * tmp1 tmp10 = tmp0 * tmp0 tmp11 = -0.5 tmp12 = tmp10 * tmp11 tmp13 = tl_math.exp(tmp12) tmp14 = 0.3989422804014327 tmp15 = tmp13 * tmp14 tmp16 = tmp0 * tmp15 tmp17 = tmp9 + tmp16 tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + (x1 + 2528 * x2), tmp17, xmask) @triton.jit def triton_poi_fused_convolution_gelu_4(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 270848 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 2116 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = 0.7071067811865476 tmp6 = tmp2 * tmp5 tmp7 = libdevice.erf(tmp6) tmp8 = 1.0 tmp9 = tmp7 + tmp8 tmp10 = tmp4 * tmp9 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_gelu_5(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 135424 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 2116 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = 0.7071067811865476 tmp6 = tmp2 * tmp5 tmp7 = libdevice.erf(tmp6) tmp8 = 1.0 tmp9 = tmp7 + tmp8 tmp10 = tmp4 * tmp9 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 8464 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) 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, (10, 1, 6, 6), (36, 36, 6, 1)) assert_size_stride(primals_2, (10,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (20, 10, 4, 4), (160, 16, 4, 1)) assert_size_stride(primals_5, (20,), (1,)) assert_size_stride(primals_6, (32, 20, 2, 2), (80, 4, 2, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (16, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (1, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_11, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 10, 59, 59), (34810, 3481, 59, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(139240)](buf1, primals_2, 139240, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 10, 58, 58), (34560, 3456, 58, 1), torch.int8) buf3 = empty_strided_cuda((4, 10, 58, 58), (33640, 3364, 58, 1), torch.float32) buf19 = empty_strided_cuda((4, 10, 58, 58), (33920, 3392, 58, 1), torch.float32) triton_poi_fused_gelu_gelu_backward_max_pool2d_with_indices_1[grid( 134560)](buf1, buf2, buf3, buf19, 134560, XBLOCK=512, num_warps =8, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(2, 2), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 20, 52, 52), (54080, 2704, 52, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(216320)](buf5, primals_5, 216320, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf6 = torch.ops.aten.max_pool2d_with_indices.default(buf5, [2, 2], [1, 1], [0, 0], [2, 2]) buf7 = buf6[0] buf8 = buf6[1] del buf6 buf9 = empty_strided_cuda((4, 20, 50, 50), (50000, 2500, 50, 1), torch.float32) buf18 = empty_strided_cuda((4, 20, 50, 50), (50560, 2528, 50, 1), torch.float32) triton_poi_fused_gelu_gelu_backward_3[grid(200000)](buf7, buf9, buf18, 200000, XBLOCK=1024, num_warps=4, num_stages=1) del buf7 buf10 = extern_kernels.convolution(buf9, primals_6, stride=(1, 1), padding=(0, 0), dilation=(4, 4), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 32, 46, 46), (67712, 2116, 46, 1)) buf11 = buf10 del buf10 buf12 = empty_strided_cuda((4, 32, 46, 46), (67712, 2116, 46, 1), torch.float32) triton_poi_fused_convolution_gelu_4[grid(270848)](buf11, primals_7, buf12, 270848, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf13 = extern_kernels.convolution(buf12, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (4, 16, 46, 46), (33856, 2116, 46, 1)) buf14 = buf13 del buf13 buf15 = empty_strided_cuda((4, 16, 46, 46), (33856, 2116, 46, 1), torch.float32) triton_poi_fused_convolution_gelu_5[grid(135424)](buf14, primals_9, buf15, 135424, XBLOCK=512, num_warps=8, num_stages=1) del primals_9 buf16 = extern_kernels.convolution(buf15, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 1, 46, 46), (2116, 2116, 46, 1)) buf17 = buf16 del buf16 triton_poi_fused_convolution_6[grid(8464)](buf17, primals_11, 8464, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 return (buf17, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, buf1, buf2, buf3, buf5, buf8, buf9, buf11, buf12, buf14, buf15, buf18, buf19) class StridedNetNew(nn.Module): def __init__(self): super(StridedNetNew, self).__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size= 6, stride=1, dilation=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=1, dilation=1) self.conv2 = nn.Conv2d(in_channels=10, out_channels=20, kernel_size =4, stride=1, dilation=2) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=1, dilation=2) self.fc1 = nn.Conv2d(in_channels=20, out_channels=32, kernel_size=2, stride=1, dilation=4) self.fc2 = nn.Conv2d(in_channels=32, out_channels=16, kernel_size=1, stride=1, dilation=1) self.fc3 = nn.Conv2d(in_channels=16, out_channels=1, kernel_size=1, stride=1, dilation=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.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_10 = self.fc3.weight primals_11 = 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]) return output[0]
JHorcasitas/cnn_document_binarization
StridedNet
false
17,466
[ "MIT" ]
9
075f76aed375ca14a53011f4dfeb12379debb5b3
https://github.com/JHorcasitas/cnn_document_binarization/tree/075f76aed375ca14a53011f4dfeb12379debb5b3
ResidualBlock
import torch from torch.nn import functional as F class ConvLayer(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = torch.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(torch.nn.Module): def __init__(self, channels): super(ResidualBlock, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.in1 = torch.nn.InstanceNorm2d(channels, affine=True) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.in2 = torch.nn.InstanceNorm2d(channels, affine=True) self.relu = torch.nn.ReLU() def forward(self, x, in_weights=None): residual = x if in_weights is None: out = self.relu(self.in1(self.conv1(x))) out = self.in2(self.conv2(out)) else: out = self.conv1(x) out = F.instance_norm(out, weight=in_weights['in1.weight'], bias=in_weights['in1.bias']) out = self.relu(out) out = self.conv2(out) out = F.instance_norm(out, weight=in_weights['in2.weight'], bias=in_weights['in2.bias']) out = 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 import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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_per_fused__native_batch_norm_legit_convolution_1(in_out_ptr0, in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp23, xmask) tl.store(out_ptr0 + x3, tmp12, xmask) @triton.jit def triton_poi_fused_repeat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0 % 4, xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_reflection_pad2d_relu_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x2, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 0, tl.int32) tmp10 = triton_helpers.maximum(tmp9, tmp8) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_add_convolution_repeat_4( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, out_ptr3, out_ptr4, 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) x0 = xindex r3 = rindex x1 = xindex % 4 tmp0 = tl.load(in_ptr0 + x0 % 4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_out_ptr0 + (r3 + 16 * x0), xmask, other=0.0) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr3 + (r3 + 16 * x0), xmask, other=0.0) tmp3 = tmp1 + tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tl.where(xmask, tmp4, 0) tmp7 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tl.full([XBLOCK, 1], 16, tl.int32) tmp12 = tmp11.to(tl.float32) tmp13 = tmp10 / tmp12 tmp14 = tmp4 - tmp13 tmp15 = tmp14 * tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = tl.where(xmask, tmp16, 0) tmp19 = tl.sum(tmp18, 1)[:, None] tmp20 = tmp3 - tmp13 tmp21 = 16.0 tmp22 = tmp19 / tmp21 tmp23 = 1e-05 tmp24 = tmp22 + tmp23 tmp25 = libdevice.rsqrt(tmp24) tmp26 = tmp20 * tmp25 tmp27 = tmp26 * tmp0 tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + (r3 + 16 * x0), tmp3, xmask) tl.store(out_ptr3 + (r3 + 16 * x0), tmp31, xmask) tl.store(out_ptr4 + x0, tmp25, xmask) tl.store(out_ptr1 + x0, tmp13, 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, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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 buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32) buf6 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf8 = reinterpret_tensor(buf6, (1, 16, 1, 1), (16, 1, 1, 1), 0) del buf6 triton_per_fused__native_batch_norm_legit_convolution_1[grid(16)](buf2, buf8, primals_3, buf5, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_3 buf3 = empty_strided_cuda((16,), (1,), torch.float32) triton_poi_fused_repeat_2[grid(16)](primals_4, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf4 = empty_strided_cuda((16,), (1,), torch.float32) triton_poi_fused_repeat_2[grid(16)](primals_5, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf9 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused_reflection_pad2d_relu_3[grid(576)](buf2, buf5, buf8, buf3, buf4, buf9, 576, XBLOCK=128, num_warps=4, num_stages=1) buf10 = extern_kernels.convolution(buf9, primals_6, 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)) buf12 = empty_strided_cuda((16,), (1,), torch.float32) buf11 = buf10 del buf10 buf13 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf16 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_add_convolution_repeat_4[grid (16)](buf11, primals_8, primals_7, primals_9, primals_1, buf12, buf13, buf17, buf16, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_1 del primals_7 del primals_8 del primals_9 return (buf17, primals_2, primals_6, buf0, buf2, buf3, buf4, buf5, buf8, buf9, buf11, buf12, reinterpret_tensor(buf16, (16,), (1,), 0), reinterpret_tensor(buf13, (1, 16, 1, 1), (16, 1, 1, 1), 0)) class ConvLayer(torch.nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = torch.nn.ReflectionPad2d(reflection_padding) self.conv2d = torch.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(torch.nn.Module): def __init__(self, channels): super(ResidualBlockNew, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.in1 = torch.nn.InstanceNorm2d(channels, affine=True) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1) self.in2 = torch.nn.InstanceNorm2d(channels, affine=True) self.relu = torch.nn.ReLU() def forward(self, input_0): primals_2 = self.conv1.conv2d.weight primals_3 = self.conv1.conv2d.bias primals_4 = self.in1.weight primals_5 = self.in1.bias primals_6 = self.conv2.conv2d.weight primals_7 = self.conv2.conv2d.bias primals_8 = self.in2.weight primals_9 = self.in2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
JEF1056/Reconstruction-Style
ResidualBlock
false
17,467
[ "MIT" ]
6
3430d9e9f05c6980ae251cf15b619148a2c899d6
https://github.com/JEF1056/Reconstruction-Style/tree/3430d9e9f05c6980ae251cf15b619148a2c899d6
BoundaryDiscriminator
import torch import torch.nn as nn class BoundaryDiscriminator(nn.Module): def __init__(self): super(BoundaryDiscriminator, self).__init__() filter_num_list = [64, 128, 256, 512, 1] self.conv1 = nn.Conv2d(1, filter_num_list[0], kernel_size=4, stride =2, padding=2, bias=False) self.conv2 = nn.Conv2d(filter_num_list[0], filter_num_list[1], kernel_size=4, stride=2, padding=2, bias=False) self.conv3 = nn.Conv2d(filter_num_list[1], filter_num_list[2], kernel_size=4, stride=2, padding=2, bias=False) self.conv4 = nn.Conv2d(filter_num_list[2], filter_num_list[3], kernel_size=4, stride=2, padding=2, bias=False) self.conv5 = nn.Conv2d(filter_num_list[3], filter_num_list[4], kernel_size=4, stride=2, padding=2, bias=False) self.leakyrelu = nn.LeakyReLU(negative_slope=0.2) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): m.weight.data.normal_(0.0, 0.02) if m.bias is not None: m.bias.data.zero_() def forward(self, x): x = self.leakyrelu(self.conv1(x)) x = self.leakyrelu(self.conv2(x)) x = self.leakyrelu(self.conv3(x)) x = self.leakyrelu(self.conv4(x)) x = self.conv5(x) return x def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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): xnumel = 278784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 147968 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (64, 1, 4, 4), (16, 16, 4, 1)) assert_size_stride(primals_2, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_3, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_4, (256, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_5, (512, 256, 4, 4), (4096, 16, 4, 1)) assert_size_stride(primals_6, (1, 512, 4, 4), (8192, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 33, 33), (69696, 1089, 33, 1)) buf1 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.bool) buf2 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(278784)](buf0, buf1, buf2, 278784, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 buf3 = extern_kernels.convolution(buf2, primals_3, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 128, 17, 17), (36992, 289, 17, 1)) buf4 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.bool) buf5 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(147968)](buf3, buf4, buf5, 147968, XBLOCK=1024, num_warps=4, num_stages=1) del buf3 buf6 = extern_kernels.convolution(buf5, primals_4, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 256, 9, 9), (20736, 81, 9, 1)) buf7 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch.bool ) buf8 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch. float32) triton_poi_fused_leaky_relu_2[grid(82944)](buf6, buf7, buf8, 82944, XBLOCK=1024, num_warps=4, num_stages=1) del buf6 buf9 = extern_kernels.convolution(buf8, primals_5, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 512, 5, 5), (12800, 25, 5, 1)) buf10 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .bool) buf11 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .float32) triton_poi_fused_leaky_relu_3[grid(51200)](buf9, buf10, buf11, 51200, XBLOCK=512, num_warps=4, num_stages=1) del buf9 buf12 = extern_kernels.convolution(buf11, primals_6, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 1, 3, 3), (9, 9, 3, 1)) return (buf12, primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, buf1, buf2, buf4, buf5, buf7, buf8, buf10, buf11) class BoundaryDiscriminatorNew(nn.Module): def __init__(self): super(BoundaryDiscriminatorNew, self).__init__() filter_num_list = [64, 128, 256, 512, 1] self.conv1 = nn.Conv2d(1, filter_num_list[0], kernel_size=4, stride =2, padding=2, bias=False) self.conv2 = nn.Conv2d(filter_num_list[0], filter_num_list[1], kernel_size=4, stride=2, padding=2, bias=False) self.conv3 = nn.Conv2d(filter_num_list[1], filter_num_list[2], kernel_size=4, stride=2, padding=2, bias=False) self.conv4 = nn.Conv2d(filter_num_list[2], filter_num_list[3], kernel_size=4, stride=2, padding=2, bias=False) self.conv5 = nn.Conv2d(filter_num_list[3], filter_num_list[4], kernel_size=4, stride=2, padding=2, bias=False) self.leakyrelu = nn.LeakyReLU(negative_slope=0.2) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): m.weight.data.normal_(0.0, 0.02) if m.bias is not None: m.bias.data.zero_() 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_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
JACKYLUO1991/DCBNet
BoundaryDiscriminator
false
17,468
[ "MIT" ]
6
b797584b66ad99fe984f58268befb12ec60ccfae
https://github.com/JACKYLUO1991/DCBNet/tree/b797584b66ad99fe984f58268befb12ec60ccfae
MaskDiscriminator
import torch import torch.nn as nn class MaskDiscriminator(nn.Module): def __init__(self): super(MaskDiscriminator, self).__init__() filter_num_list = [64, 128, 256, 512, 2] self.conv1 = nn.Conv2d(2, filter_num_list[0], kernel_size=4, stride =2, padding=2, bias=False) self.conv2 = nn.Conv2d(filter_num_list[0], filter_num_list[1], kernel_size=4, stride=2, padding=2, bias=False) self.conv3 = nn.Conv2d(filter_num_list[1], filter_num_list[2], kernel_size=4, stride=2, padding=2, bias=False) self.conv4 = nn.Conv2d(filter_num_list[2], filter_num_list[3], kernel_size=4, stride=2, padding=2, bias=False) self.conv5 = nn.Conv2d(filter_num_list[3], filter_num_list[4], kernel_size=4, stride=2, padding=2, bias=False) self.leakyrelu = nn.LeakyReLU(negative_slope=0.2) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): m.weight.data.normal_(0.0, 0.02) if m.bias is not None: m.bias.data.zero_() def forward(self, x): x = self.leakyrelu(self.conv1(x)) x = self.leakyrelu(self.conv2(x)) x = self.leakyrelu(self.conv3(x)) x = self.leakyrelu(self.conv4(x)) x = self.conv5(x) return x def get_inputs(): return [torch.rand([4, 2, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 278784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 147968 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp5, xmask) @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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (64, 2, 4, 4), (32, 16, 4, 1)) assert_size_stride(primals_2, (4, 2, 64, 64), (8192, 4096, 64, 1)) assert_size_stride(primals_3, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_4, (256, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_5, (512, 256, 4, 4), (4096, 16, 4, 1)) assert_size_stride(primals_6, (2, 512, 4, 4), (8192, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 33, 33), (69696, 1089, 33, 1)) buf1 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.bool) buf2 = empty_strided_cuda((4, 64, 33, 33), (69696, 1089, 33, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(278784)](buf0, buf1, buf2, 278784, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 buf3 = extern_kernels.convolution(buf2, primals_3, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 128, 17, 17), (36992, 289, 17, 1)) buf4 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.bool) buf5 = empty_strided_cuda((4, 128, 17, 17), (36992, 289, 17, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(147968)](buf3, buf4, buf5, 147968, XBLOCK=1024, num_warps=4, num_stages=1) del buf3 buf6 = extern_kernels.convolution(buf5, primals_4, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 256, 9, 9), (20736, 81, 9, 1)) buf7 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch.bool ) buf8 = empty_strided_cuda((4, 256, 9, 9), (20736, 81, 9, 1), torch. float32) triton_poi_fused_leaky_relu_2[grid(82944)](buf6, buf7, buf8, 82944, XBLOCK=1024, num_warps=4, num_stages=1) del buf6 buf9 = extern_kernels.convolution(buf8, primals_5, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 512, 5, 5), (12800, 25, 5, 1)) buf10 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .bool) buf11 = empty_strided_cuda((4, 512, 5, 5), (12800, 25, 5, 1), torch .float32) triton_poi_fused_leaky_relu_3[grid(51200)](buf9, buf10, buf11, 51200, XBLOCK=512, num_warps=4, num_stages=1) del buf9 buf12 = extern_kernels.convolution(buf11, primals_6, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 2, 3, 3), (18, 9, 3, 1)) return (buf12, primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, buf1, buf2, buf4, buf5, buf7, buf8, buf10, buf11) class MaskDiscriminatorNew(nn.Module): def __init__(self): super(MaskDiscriminatorNew, self).__init__() filter_num_list = [64, 128, 256, 512, 2] self.conv1 = nn.Conv2d(2, filter_num_list[0], kernel_size=4, stride =2, padding=2, bias=False) self.conv2 = nn.Conv2d(filter_num_list[0], filter_num_list[1], kernel_size=4, stride=2, padding=2, bias=False) self.conv3 = nn.Conv2d(filter_num_list[1], filter_num_list[2], kernel_size=4, stride=2, padding=2, bias=False) self.conv4 = nn.Conv2d(filter_num_list[2], filter_num_list[3], kernel_size=4, stride=2, padding=2, bias=False) self.conv5 = nn.Conv2d(filter_num_list[3], filter_num_list[4], kernel_size=4, stride=2, padding=2, bias=False) self.leakyrelu = nn.LeakyReLU(negative_slope=0.2) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): m.weight.data.normal_(0.0, 0.02) if m.bias is not None: m.bias.data.zero_() 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_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
JACKYLUO1991/DCBNet
MaskDiscriminator
false
17,469
[ "MIT" ]
6
b797584b66ad99fe984f58268befb12ec60ccfae
https://github.com/JACKYLUO1991/DCBNet/tree/b797584b66ad99fe984f58268befb12ec60ccfae
StrongMask
import math import torch import torch.nn.functional as F import torch.nn as nn class SamePad2dStrong(nn.Module): """Mimics tensorflow's 'SAME' padding. """ def __init__(self, kernel_size, stride): super(SamePad2dStrong, self).__init__() self.kernel_size = torch.nn.modules.utils._pair(kernel_size) self.stride = torch.nn.modules.utils._pair(stride) def forward(self, input): in_width = input.size()[2] in_height = input.size()[3] out_width = math.ceil(float(in_width) / float(self.stride[0])) out_height = math.ceil(float(in_height) / float(self.stride[1])) pad_along_width = (out_width - 1) * self.stride[0] + self.kernel_size[0 ] - in_width pad_along_height = (out_height - 1) * self.stride[1 ] + self.kernel_size[1] - in_height pad_left = math.floor(pad_along_width / 2) pad_top = math.floor(pad_along_height / 2) pad_right = pad_along_width - pad_left pad_bottom = pad_along_height - pad_top return F.pad(input, (pad_left, pad_right, pad_top, pad_bottom), 'constant', 0) def __repr__(self): return self.__class__.__name__ class StrongMask(nn.Module): def __init__(self, depth=256, pool_size=14, num_classes=21): super(StrongMask, self).__init__() self.depth = depth self.pool_size = pool_size self.num_classes = num_classes self.padding = SamePad2dStrong(kernel_size=3, stride=1) self.conv1 = nn.Conv2d(self.depth, 256, kernel_size=3, stride=1) self.conv2 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.conv3 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.conv4 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.deconv = nn.ConvTranspose2d(256, 256, kernel_size=2, stride=2) self.conv5 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU(inplace=True) def forward(self, x): x = self.conv1(self.padding(x)) x = self.relu(x) x = self.conv2(self.padding(x)) x = self.relu(x) x = self.conv3(self.padding(x)) x = self.relu(x) x = self.conv4(self.padding(x)) x = self.relu(x) x = self.deconv(x) x = self.relu(x) x = self.conv5(x) x = self.sigmoid(x) return x def get_inputs(): return [torch.rand([4, 256, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import 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 @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 4 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 256 * x2 + 1024 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 36 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x3 = xindex // 6 x2 = xindex % 6 y4 = yindex x5 = xindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = -1 + x3 tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1, 1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x2 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x2 + 4 * x3 + 16 * y4), tmp10 & xmask, eviction_policy='evict_last', other=0.0) tl.store(out_ptr0 + (y0 + 256 * x5 + 9216 * y1), tmp11, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_convolution_relu_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 1536 % 6 x1 = xindex // 256 % 6 x3 = xindex // 9216 x4 = xindex % 1536 x0 = xindex % 256 x6 = xindex tmp0 = -1 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x1 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-1280 + x4 + 1024 * x2 + 4096 * x3), tmp10, other=0.0) tmp12 = tl.load(in_ptr1 + x0, tmp10, eviction_policy='evict_last', other=0.0) tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp10, tmp15, tmp16) tl.store(out_ptr0 + x6, tmp17, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_sigmoid_6(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 84 xnumel = 64 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 % 21 y1 = yindex // 21 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 21 * x2 + 1344 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(out_ptr0 + (x2 + 64 * y3), tmp3, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 256, 4, 4), (4096, 16, 4, 1)) assert_size_stride(primals_2, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_3, (256,), (1,)) assert_size_stride(primals_4, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (256, 256, 2, 2), (1024, 4, 2, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (21, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_13, (21,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(65536, 9)](primals_2, buf0, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_0[grid(65536, 9)](primals_4, buf1, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_0[grid(65536, 9)](primals_6, buf2, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_0[grid(65536, 9)](primals_8, buf3, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf4 = empty_strided_cuda((256, 256, 2, 2), (1024, 1, 512, 256), torch.float32) triton_poi_fused_1[grid(65536, 4)](primals_10, buf4, 65536, 4, XBLOCK=4, YBLOCK=256, num_warps=4, num_stages=1) del primals_10 buf5 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256), torch.float32) triton_poi_fused_constant_pad_nd_2[grid(1024, 36)](primals_1, buf5, 1024, 36, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_1 buf6 = extern_kernels.convolution(buf5, buf0, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf7 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256), torch.float32) triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf6, primals_3, buf7, 36864, XBLOCK=256, num_warps=4, num_stages=1) buf8 = extern_kernels.convolution(buf7, buf1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf9 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256), torch.float32) triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf8, primals_5, buf9, 36864, XBLOCK=256, num_warps=4, num_stages=1) buf10 = extern_kernels.convolution(buf9, buf2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf11 = empty_strided_cuda((4, 256, 6, 6), (9216, 1, 1536, 256), torch.float32) triton_poi_fused_constant_pad_nd_convolution_relu_3[grid(36864)](buf10, primals_7, buf11, 36864, XBLOCK=256, num_warps=4, num_stages=1) buf12 = extern_kernels.convolution(buf11, buf3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_4[grid(16384)](buf13, primals_9, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf14 = extern_kernels.convolution(buf13, buf4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 8, 8), (16384, 1, 2048, 256)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_5[grid(65536)](buf15, primals_11, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf16 = extern_kernels.convolution(buf15, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 21, 8, 8), (1344, 1, 168, 21)) buf17 = empty_strided_cuda((4, 21, 8, 8), (1344, 64, 8, 1), torch. float32) triton_poi_fused_convolution_sigmoid_6[grid(84, 64)](buf16, primals_13, buf17, 84, 64, XBLOCK=64, YBLOCK=4, num_warps=4, num_stages=1) del buf16 del primals_13 buf18 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)]( buf10, primals_7, buf18, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf10 del primals_7 buf19 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)]( buf8, primals_5, buf19, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf8 del primals_5 buf20 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_7[grid(16384)]( buf6, primals_3, buf20, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del primals_3 return (buf17, buf0, buf1, buf2, buf3, buf4, primals_12, buf5, buf7, buf9, buf11, buf13, buf15, buf17, buf18, buf19, buf20) class SamePad2dStrong(nn.Module): """Mimics tensorflow's 'SAME' padding. """ def __init__(self, kernel_size, stride): super(SamePad2dStrong, self).__init__() self.kernel_size = torch.nn.modules.utils._pair(kernel_size) self.stride = torch.nn.modules.utils._pair(stride) def forward(self, input): in_width = input.size()[2] in_height = input.size()[3] out_width = math.ceil(float(in_width) / float(self.stride[0])) out_height = math.ceil(float(in_height) / float(self.stride[1])) pad_along_width = (out_width - 1) * self.stride[0] + self.kernel_size[0 ] - in_width pad_along_height = (out_height - 1) * self.stride[1 ] + self.kernel_size[1] - in_height pad_left = math.floor(pad_along_width / 2) pad_top = math.floor(pad_along_height / 2) pad_right = pad_along_width - pad_left pad_bottom = pad_along_height - pad_top return F.pad(input, (pad_left, pad_right, pad_top, pad_bottom), 'constant', 0) def __repr__(self): return self.__class__.__name__ class StrongMaskNew(nn.Module): def __init__(self, depth=256, pool_size=14, num_classes=21): super(StrongMaskNew, self).__init__() self.depth = depth self.pool_size = pool_size self.num_classes = num_classes self.padding = SamePad2dStrong(kernel_size=3, stride=1) self.conv1 = nn.Conv2d(self.depth, 256, kernel_size=3, stride=1) self.conv2 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.conv3 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.conv4 = nn.Conv2d(256, 256, kernel_size=3, stride=1) self.deconv = nn.ConvTranspose2d(256, 256, kernel_size=2, stride=2) self.conv5 = nn.Conv2d(256, num_classes, kernel_size=1, stride=1) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU(inplace=True) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.deconv.weight primals_11 = self.deconv.bias primals_12 = self.conv5.weight primals_13 = self.conv5.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0]
IssamLaradji/wisenet
StrongMask
false
17,470
[ "Apache-2.0" ]
7
881457f5168815f5e9d03f110244842d539747a0
https://github.com/IssamLaradji/wisenet/tree/881457f5168815f5e9d03f110244842d539747a0
GramMatrix
import torch import torch.nn as nn class GramMatrix(nn.Module): def forward(self, input): a, b, c, d = input.size() features = input.view(a, b, c * d) G = torch.bmm(features, features.transpose(1, 2)) return G.div(b * c * d) 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = 0.015625 tmp2 = tmp0 * tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(arg0_1, (4, 16, 4), (64, 1, 16), 0), out=buf0) del arg0_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_div_0[grid(64)](buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf1, class GramMatrixNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Jay2020-01/TextureGAN--Flask
GramMatrix
false
17,471
[ "MIT" ]
5
cddea505b0d66b58d58fb24435f8bae42fd5a852
https://github.com/Jay2020-01/TextureGAN--Flask/tree/cddea505b0d66b58d58fb24435f8bae42fd5a852
GeneralizedDiceLoss
import collections import torch import warnings from typing import Optional from typing import Union from typing import Callable from typing import Any from typing import Tuple import torch.nn from torch.nn.modules.loss import _Loss from enum import Enum import collections.abc def issequenceiterable(obj: 'Any') ->bool: """ Determine if the object is an iterable sequence and is not a string. """ if torch.is_tensor(obj): return int(obj.dim()) > 0 return isinstance(obj, collections.abc.Iterable) and not isinstance(obj, str) def ensure_tuple(vals: 'Any') ->Tuple[Any, ...]: """ Returns a tuple of `vals`. """ if not issequenceiterable(vals): vals = vals, return tuple(vals) def ensure_tuple_size(tup: 'Any', dim: 'int', pad_val: 'Any'=0) ->Tuple[Any, ...]: """ Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. """ tup = ensure_tuple(tup) + (pad_val,) * dim return tuple(tup[:dim]) def one_hot(labels: 'torch.Tensor', num_classes: 'int', dtype: 'torch.dtype'=torch.float, dim: 'int'=1) ->torch.Tensor: """ For a tensor `labels` of dimensions B1[spatial_dims], return a tensor of dimensions `BN[spatial_dims]` for `num_classes` N number of classes. Example: For every value v = labels[b,1,h,w], the value in the result at [b,v,h,w] will be 1 and all others 0. Note that this will include the background label, thus a binary mask should be treated as having 2 classes. """ assert labels.dim() > 0, 'labels should have dim of 1 or more.' if labels.ndimension() < dim + 1: shape = ensure_tuple_size(labels.shape, dim + 1, 1) labels = labels.reshape(*shape) sh = list(labels.shape) assert sh[dim ] == 1, 'labels should have a channel with length equals to one.' sh[dim] = num_classes o = torch.zeros(size=sh, dtype=dtype, device=labels.device) labels = o.scatter_(dim=dim, index=labels.long(), value=1) return labels class LossReduction(Enum): """ See also: - :py:class:`monai.losses.dice.DiceLoss` - :py:class:`monai.losses.dice.GeneralizedDiceLoss` - :py:class:`monai.losses.focal_loss.FocalLoss` - :py:class:`monai.losses.tversky.TverskyLoss` """ NONE = 'none' MEAN = 'mean' SUM = 'sum' class Weight(Enum): """ See also: :py:class:`monai.losses.dice.GeneralizedDiceLoss` """ SQUARE = 'square' SIMPLE = 'simple' UNIFORM = 'uniform' class GeneralizedDiceLoss(_Loss): """ Compute the generalised Dice loss defined in: Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning loss function for highly unbalanced segmentations. DLMIA 2017. Adapted from: https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/layer/loss_segmentation.py#L279 """ def __init__(self, include_background: 'bool'=True, to_onehot_y: 'bool' =False, sigmoid: 'bool'=False, softmax: 'bool'=False, other_act: 'Optional[Callable]'=None, w_type: 'Union[Weight, str]'=Weight. SQUARE, reduction: 'Union[LossReduction, str]'=LossReduction.MEAN, smooth_nr: 'float'=1e-05, smooth_dr: 'float'=1e-05, batch: 'bool'=False ) ->None: """ Args: include_background: If False channel index 0 (background category) is excluded from the calculation. to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. sigmoid: If True, apply a sigmoid function to the prediction. softmax: If True, apply a softmax function to the prediction. other_act: if don't want to use `sigmoid` or `softmax`, use other callable function to execute other activation layers, Defaults to ``None``. for example: `other_act = torch.tanh`. squared_pred: use squared versions of targets and predictions in the denominator or not. w_type: {``"square"``, ``"simple"``, ``"uniform"``} Type of function to transform ground truth volume to a weight factor. Defaults to ``"square"``. reduction: {``"none"``, ``"mean"``, ``"sum"``} Specifies the reduction to apply to the output. Defaults to ``"mean"``. - ``"none"``: no reduction will be applied. - ``"mean"``: the sum of the output will be divided by the number of elements in the output. - ``"sum"``: the output will be summed. smooth_nr: a small constant added to the numerator to avoid zero. smooth_dr: a small constant added to the denominator to avoid nan. batch: whether to sum the intersection and union areas over the batch dimension before the dividing. Defaults to False, intersection over union is computed from each item in the batch. Raises: TypeError: When ``other_act`` is not an ``Optional[Callable]``. ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``]. Incompatible values. """ super().__init__(reduction=LossReduction(reduction).value) if other_act is not None and not callable(other_act): raise TypeError( f'other_act must be None or callable but is {type(other_act).__name__}.' ) if int(sigmoid) + int(softmax) + int(other_act is not None) > 1: raise ValueError( 'Incompatible values: more than 1 of [sigmoid=True, softmax=True, other_act is not None].' ) self.include_background = include_background self.to_onehot_y = to_onehot_y self.sigmoid = sigmoid self.softmax = softmax self.other_act = other_act w_type = Weight(w_type) self.w_func: 'Callable' = torch.ones_like if w_type == Weight.SIMPLE: self.w_func = torch.reciprocal elif w_type == Weight.SQUARE: self.w_func = lambda x: torch.reciprocal(x * x) self.smooth_nr = float(smooth_nr) self.smooth_dr = float(smooth_dr) self.batch = batch def forward(self, input: 'torch.Tensor', target: 'torch.Tensor' ) ->torch.Tensor: """ Args: input: the shape should be BNH[WD]. target: the shape should be BNH[WD]. Raises: ValueError: When ``self.reduction`` is not one of ["mean", "sum", "none"]. """ if self.sigmoid: input = torch.sigmoid(input) n_pred_ch = input.shape[1] if self.softmax: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `softmax=True` ignored.') else: input = torch.softmax(input, 1) if self.other_act is not None: input = self.other_act(input) if self.to_onehot_y: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `to_onehot_y=True` ignored.') else: target = one_hot(target, num_classes=n_pred_ch) if not self.include_background: if n_pred_ch == 1: warnings.warn( 'single channel prediction, `include_background=False` ignored.' ) else: target = target[:, 1:] input = input[:, 1:] assert target.shape == input.shape, f'ground truth has differing shape ({target.shape}) from input ({input.shape})' reduce_axis = list(range(2, len(input.shape))) if self.batch: reduce_axis = [0] + reduce_axis intersection = torch.sum(target * input, reduce_axis) ground_o = torch.sum(target, reduce_axis) pred_o = torch.sum(input, reduce_axis) denominator = ground_o + pred_o w = self.w_func(ground_o.float()) for b in w: infs = torch.isinf(b) b[infs] = 0.0 b[infs] = torch.max(b) f: 'torch.Tensor' = 1.0 - (2.0 * (intersection * w).sum(1) + self. smooth_nr) / ((denominator * w).sum(1) + self.smooth_dr) if self.reduction == LossReduction.MEAN.value: f = torch.mean(f) elif self.reduction == LossReduction.SUM.value: f = torch.sum(f) elif self.reduction == LossReduction.NONE.value: pass else: raise ValueError( f'Unsupported reduction: {self.reduction}, available options are ["mean", "sum", "none"].' ) return f 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 import collections from typing import Optional from typing import Union from typing import Callable from typing import Any from typing import Tuple import torch.nn from torch.nn.modules.loss import _Loss from enum import Enum import collections.abc 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_mul_sum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp13 = tl.where(xmask, tmp11, 0) tmp14 = tl.sum(tmp13, 1)[:, None] tl.store(out_ptr0 + x0, tmp6, xmask) tl.store(out_ptr1 + x0, tmp10, xmask) tl.store(out_ptr2 + x0, tmp14, xmask) @triton.jit def triton_poi_fused_index_put_lift_fresh_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 = tmp0 * tmp0 tmp2 = tl.full([1], 1, tl.int32) tmp3 = tmp2 / tmp1 tmp4 = libdevice.isinf(tmp3).to(tl.int1) tmp5 = 0.0 tmp6 = tl.where(tmp4, tmp5, tmp3) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_mul_reciprocal_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tmp4 * tmp4 tmp6 = tl.full([1], 1, tl.int32) tmp7 = tmp6 / tmp5 tmp8 = tl.where(tmp2, tmp3, tmp7) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_per_fused_index_put_max_3(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp2 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp0 = tl.full([1, 1], 0, tl.int32) tmp1 = tmp0 == tmp0 tmp4 = tmp3 * tmp3 tmp5 = tl.full([1, 1], 1, tl.int32) tmp6 = tmp5 / tmp4 tmp7 = tl.where(tmp1, tmp2, tmp6) tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = triton_helpers.max2(tmp8, 1)[:, None] tmp11 = libdevice.isinf(tmp6).to(tl.int1) tmp12 = tl.where(tmp11, tmp10, tmp7) tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp12, None) @triton.jit def triton_poi_fused_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 x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_index_put_lift_fresh_5(in_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 tmp3 = tl.load(in_ptr0 + x0, xmask) tmp4 = tl.load(in_ptr0 + (4 + x0), xmask) tmp0 = tl.full([1], 1, tl.int32) tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = libdevice.isinf(tmp5).to(tl.int1) tmp7 = 0.0 tmp8 = tl.where(tmp6, tmp7, tmp5) tl.store(out_ptr1 + (4 + x0), tmp8, xmask) @triton.jit def triton_poi_fused_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 x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 1, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_per_fused_index_put_max_7(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp2 = tl.load(in_ptr0 + (4 + r0), None) tmp9 = tl.load(in_ptr1 + r0, None) tmp10 = tl.load(in_ptr1 + (4 + r0), None) tmp0 = tl.full([1, 1], 1, tl.int32) tmp1 = tmp0 == tmp0 tmp3 = tl.where(tmp1, tmp2, tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = triton_helpers.max2(tmp4, 1)[:, None] tmp7 = tl.full([1, 1], 0, tl.int32) tmp8 = tmp0 == tmp7 tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = libdevice.isinf(tmp11).to(tl.int1) tmp13 = tl.where(tmp12, tmp6, tmp3) tl.store(out_ptr2 + tl.broadcast_to(4 + r0, [XBLOCK, RBLOCK]), tmp13, None) @triton.jit def triton_poi_fused_index_put_lift_fresh_8(in_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 tmp3 = tl.load(in_ptr0 + (4 + x0), xmask) tmp4 = tl.load(in_ptr0 + (8 + x0), xmask) tmp0 = tl.full([1], 2, tl.int32) tmp1 = tl.full([1], 1, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = libdevice.isinf(tmp5).to(tl.int1) tmp7 = 0.0 tmp8 = tl.where(tmp6, tmp7, tmp5) tl.store(out_ptr1 + (8 + x0), tmp8, xmask) @triton.jit def triton_poi_fused_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 2, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_per_fused_index_put_max_10(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp2 = tl.load(in_ptr0 + (8 + r0), None) tmp9 = tl.load(in_ptr1 + (4 + r0), None) tmp10 = tl.load(in_ptr1 + (8 + r0), None) tmp0 = tl.full([1, 1], 2, tl.int32) tmp1 = tmp0 == tmp0 tmp3 = tl.where(tmp1, tmp2, tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = triton_helpers.max2(tmp4, 1)[:, None] tmp7 = tl.full([1, 1], 1, tl.int32) tmp8 = tmp0 == tmp7 tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = libdevice.isinf(tmp11).to(tl.int1) tmp13 = tl.where(tmp12, tmp6, tmp3) tl.store(out_ptr2 + tl.broadcast_to(8 + r0, [XBLOCK, RBLOCK]), tmp13, None) @triton.jit def triton_poi_fused_index_put_lift_fresh_11(in_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 tmp3 = tl.load(in_ptr0 + (8 + x0), xmask) tmp4 = tl.load(in_ptr0 + (12 + x0), xmask) tmp0 = tl.full([1], 3, tl.int32) tmp1 = tl.full([1], 2, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = libdevice.isinf(tmp5).to(tl.int1) tmp7 = 0.0 tmp8 = tl.where(tmp6, tmp7, tmp5) tl.store(out_ptr1 + (12 + x0), tmp8, xmask) @triton.jit def triton_poi_fused_12(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp5 = tl.where(tmp2, tmp3, tmp4) tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_per_fused_index_put_max_13(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp2 = tl.load(in_ptr0 + (12 + r0), None) tmp9 = tl.load(in_ptr1 + (8 + r0), None) tmp10 = tl.load(in_ptr1 + (12 + r0), None) tmp0 = tl.full([1, 1], 3, tl.int32) tmp1 = tmp0 == tmp0 tmp3 = tl.where(tmp1, tmp2, tmp2) tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = triton_helpers.max2(tmp4, 1)[:, None] tmp7 = tl.full([1, 1], 2, tl.int32) tmp8 = tmp0 == tmp7 tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = libdevice.isinf(tmp11).to(tl.int1) tmp13 = tl.where(tmp12, tmp6, tmp3) tl.store(out_ptr2 + tl.broadcast_to(12 + r0, [XBLOCK, RBLOCK]), tmp13, None ) @triton.jit def triton_per_fused_add_div_mean_mul_rsub_sum_14(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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') tmp4 = tl.load(in_ptr1 + 12) tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK]) tmp6 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + 13) tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp12 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + 14) tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK]) tmp19 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp23 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp24 = tl.load(in_ptr1 + 15) tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK]) tmp26 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last') tmp31 = tl.load(in_ptr3 + 4 * r0, None, eviction_policy='evict_last') tmp34 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp35 = tl.load(in_ptr3 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp39 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp40 = tl.load(in_ptr3 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp44 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp45 = tl.load(in_ptr3 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp1 = r0 tmp2 = tl.full([1, 1], 3, tl.int32) tmp3 = tmp1 == tmp2 tmp7 = tl.where(tmp3, tmp5, tmp6) tmp8 = tmp0 * tmp7 tmp13 = tl.where(tmp3, tmp11, tmp12) tmp14 = tmp9 * tmp13 tmp15 = tmp8 + tmp14 tmp20 = tl.where(tmp3, tmp18, tmp19) tmp21 = tmp16 * tmp20 tmp22 = tmp15 + tmp21 tmp27 = tl.where(tmp3, tmp25, tmp26) tmp28 = tmp23 * tmp27 tmp29 = tmp22 + tmp28 tmp32 = tmp30 + tmp31 tmp33 = tmp32 * tmp7 tmp36 = tmp34 + tmp35 tmp37 = tmp36 * tmp13 tmp38 = tmp33 + tmp37 tmp41 = tmp39 + tmp40 tmp42 = tmp41 * tmp20 tmp43 = tmp38 + tmp42 tmp46 = tmp44 + tmp45 tmp47 = tmp46 * tmp27 tmp48 = tmp43 + tmp47 tmp49 = 2.0 tmp50 = tmp29 * tmp49 tmp51 = 1e-05 tmp52 = tmp50 + tmp51 tmp53 = tmp48 + tmp51 tmp54 = tmp52 / tmp53 tmp55 = 1.0 tmp56 = tmp55 - tmp54 tmp57 = tl.broadcast_to(tmp56, [XBLOCK, RBLOCK]) tmp59 = tl.sum(tmp57, 1)[:, None] tmp60 = 4.0 tmp61 = tmp59 / tmp60 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp61, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf29 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused_mul_sum_0[grid(16)](arg1_1, arg0_1, buf0, buf1, buf29, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf2 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_index_put_lift_fresh_1[grid(4)](buf1, buf2, 4, XBLOCK=4, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_mul_reciprocal_2[grid(16)](buf2, buf1, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) triton_per_fused_index_put_max_3[grid(1)](buf2, buf1, buf4, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf2 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_4[grid(16)](buf4, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) triton_poi_fused_index_put_lift_fresh_5[grid(4)](buf4, buf7, 4, XBLOCK=4, num_warps=1, num_stages=1) buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_6[grid(16)](buf7, buf11, 16, XBLOCK=16, num_warps= 1, num_stages=1) triton_per_fused_index_put_max_7[grid(1)](buf7, buf4, buf11, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf14 = buf7 del buf7 triton_poi_fused_6[grid(16)](buf11, buf14, 16, XBLOCK=16, num_warps =1, num_stages=1) triton_poi_fused_index_put_lift_fresh_8[grid(4)](buf11, buf14, 4, XBLOCK=4, num_warps=1, num_stages=1) buf18 = buf4 del buf4 triton_poi_fused_9[grid(16)](buf14, buf18, 16, XBLOCK=16, num_warps =1, num_stages=1) triton_per_fused_index_put_max_10[grid(1)](buf14, buf11, buf18, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf21 = buf14 del buf14 triton_poi_fused_9[grid(16)](buf18, buf21, 16, XBLOCK=16, num_warps =1, num_stages=1) triton_poi_fused_index_put_lift_fresh_11[grid(4)](buf18, buf21, 4, XBLOCK=4, num_warps=1, num_stages=1) buf25 = buf11 del buf11 triton_poi_fused_12[grid(16)](buf21, buf25, 16, XBLOCK=16, num_warps=1, num_stages=1) triton_per_fused_index_put_max_13[grid(1)](buf21, buf18, buf25, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf18 del buf21 buf31 = empty_strided_cuda((), (), torch.float32) buf32 = buf31 del buf31 triton_per_fused_add_div_mean_mul_rsub_sum_14[grid(1)](buf32, buf0, buf25, buf1, buf29, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 del buf25 del buf29 return buf32, def issequenceiterable(obj: 'Any') ->bool: """ Determine if the object is an iterable sequence and is not a string. """ if torch.is_tensor(obj): return int(obj.dim()) > 0 return isinstance(obj, collections.abc.Iterable) and not isinstance(obj, str) def ensure_tuple(vals: 'Any') ->Tuple[Any, ...]: """ Returns a tuple of `vals`. """ if not issequenceiterable(vals): vals = vals, return tuple(vals) def ensure_tuple_size(tup: 'Any', dim: 'int', pad_val: 'Any'=0) ->Tuple[Any, ...]: """ Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. """ tup = ensure_tuple(tup) + (pad_val,) * dim return tuple(tup[:dim]) def one_hot(labels: 'torch.Tensor', num_classes: 'int', dtype: 'torch.dtype'=torch.float, dim: 'int'=1) ->torch.Tensor: """ For a tensor `labels` of dimensions B1[spatial_dims], return a tensor of dimensions `BN[spatial_dims]` for `num_classes` N number of classes. Example: For every value v = labels[b,1,h,w], the value in the result at [b,v,h,w] will be 1 and all others 0. Note that this will include the background label, thus a binary mask should be treated as having 2 classes. """ assert labels.dim() > 0, 'labels should have dim of 1 or more.' if labels.ndimension() < dim + 1: shape = ensure_tuple_size(labels.shape, dim + 1, 1) labels = labels.reshape(*shape) sh = list(labels.shape) assert sh[dim ] == 1, 'labels should have a channel with length equals to one.' sh[dim] = num_classes o = torch.zeros(size=sh, dtype=dtype, device=labels.device) labels = o.scatter_(dim=dim, index=labels.long(), value=1) return labels class LossReduction(Enum): """ See also: - :py:class:`monai.losses.dice.DiceLoss` - :py:class:`monai.losses.dice.GeneralizedDiceLoss` - :py:class:`monai.losses.focal_loss.FocalLoss` - :py:class:`monai.losses.tversky.TverskyLoss` """ NONE = 'none' MEAN = 'mean' SUM = 'sum' class Weight(Enum): """ See also: :py:class:`monai.losses.dice.GeneralizedDiceLoss` """ SQUARE = 'square' SIMPLE = 'simple' UNIFORM = 'uniform' class GeneralizedDiceLossNew(_Loss): """ Compute the generalised Dice loss defined in: Sudre, C. et. al. (2017) Generalised Dice overlap as a deep learning loss function for highly unbalanced segmentations. DLMIA 2017. Adapted from: https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/layer/loss_segmentation.py#L279 """ def __init__(self, include_background: 'bool'=True, to_onehot_y: 'bool' =False, sigmoid: 'bool'=False, softmax: 'bool'=False, other_act: 'Optional[Callable]'=None, w_type: 'Union[Weight, str]'=Weight. SQUARE, reduction: 'Union[LossReduction, str]'=LossReduction.MEAN, smooth_nr: 'float'=1e-05, smooth_dr: 'float'=1e-05, batch: 'bool'=False ) ->None: """ Args: include_background: If False channel index 0 (background category) is excluded from the calculation. to_onehot_y: whether to convert `y` into the one-hot format. Defaults to False. sigmoid: If True, apply a sigmoid function to the prediction. softmax: If True, apply a softmax function to the prediction. other_act: if don't want to use `sigmoid` or `softmax`, use other callable function to execute other activation layers, Defaults to ``None``. for example: `other_act = torch.tanh`. squared_pred: use squared versions of targets and predictions in the denominator or not. w_type: {``"square"``, ``"simple"``, ``"uniform"``} Type of function to transform ground truth volume to a weight factor. Defaults to ``"square"``. reduction: {``"none"``, ``"mean"``, ``"sum"``} Specifies the reduction to apply to the output. Defaults to ``"mean"``. - ``"none"``: no reduction will be applied. - ``"mean"``: the sum of the output will be divided by the number of elements in the output. - ``"sum"``: the output will be summed. smooth_nr: a small constant added to the numerator to avoid zero. smooth_dr: a small constant added to the denominator to avoid nan. batch: whether to sum the intersection and union areas over the batch dimension before the dividing. Defaults to False, intersection over union is computed from each item in the batch. Raises: TypeError: When ``other_act`` is not an ``Optional[Callable]``. ValueError: When more than 1 of [``sigmoid=True``, ``softmax=True``, ``other_act is not None``]. Incompatible values. """ super().__init__(reduction=LossReduction(reduction).value) if other_act is not None and not callable(other_act): raise TypeError( f'other_act must be None or callable but is {type(other_act).__name__}.' ) if int(sigmoid) + int(softmax) + int(other_act is not None) > 1: raise ValueError( 'Incompatible values: more than 1 of [sigmoid=True, softmax=True, other_act is not None].' ) self.include_background = include_background self.to_onehot_y = to_onehot_y self.sigmoid = sigmoid self.softmax = softmax self.other_act = other_act w_type = Weight(w_type) self.w_func: 'Callable' = torch.ones_like if w_type == Weight.SIMPLE: self.w_func = torch.reciprocal elif w_type == Weight.SQUARE: self.w_func = lambda x: torch.reciprocal(x * x) self.smooth_nr = float(smooth_nr) self.smooth_dr = float(smooth_dr) self.batch = batch def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Irme/MONAI
GeneralizedDiceLoss
false
17,472
[ "Apache-2.0" ]
3
dc4bf661831b14f4231cb325cc1b15d38c1e406c
https://github.com/Irme/MONAI/tree/dc4bf661831b14f4231cb325cc1b15d38c1e406c
MedianPool2d
import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.utils import _pair from torch.nn.modules.utils import _quadruple class MedianPool2d(nn.Module): """Median pool (usable as median filter when stride=1) module. Args: kernel_size: size of pooling kernel, int or 2-tuple stride: pool stride, int or 2-tuple padding: pool padding, int or 4-tuple (l, r, t, b) as in pytorch F.pad same: override padding and enforce same padding, boolean """ def __init__(self, kernel_size=3, stride=1, padding=0, same=True): """Initialize with kernel_size, stride, padding.""" super().__init__() self.k = _pair(kernel_size) self.stride = _pair(stride) self.padding = _quadruple(padding) self.same = same def _padding(self, x): if self.same: ih, iw = x.size()[2:] if ih % self.stride[0] == 0: ph = max(self.k[0] - self.stride[0], 0) else: ph = max(self.k[0] - ih % self.stride[0], 0) if iw % self.stride[1] == 0: pw = max(self.k[1] - self.stride[1], 0) else: pw = max(self.k[1] - iw % self.stride[1], 0) pl = pw // 2 pr = pw - pl pt = ph // 2 pb = ph - pt padding = pl, pr, pt, pb else: padding = self.padding return padding def forward(self, x): x = F.pad(x, self._padding(x), mode='reflect') x = x.unfold(2, self.k[0], self.stride[0]).unfold(3, self.k[1], self.stride[1]) x = x.contiguous().view(x.size()[:4] + (-1,)).median(dim=-1)[0] return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn from torch.nn.modules.utils import _pair from torch.nn.modules.utils import _quadruple 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 = 2304 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 3 x1 = xindex // 3 % 3 x2 = xindex // 9 % 4 x3 = xindex // 36 % 4 x4 = xindex // 144 x5 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0 + x2)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1 + x3)) + 16 * x4), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x5, tmp0, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 3, 3), (576, 144, 36, 9, 3, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(2304)](arg0_1, buf0, 2304, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf1 = torch.ops.aten.median.dim(reinterpret_tensor(buf0, (4, 4, 4, 4, 9), (576, 144, 36, 9, 1), 0), -1) del buf0 buf2 = buf1[0] del buf1 return buf2, class MedianPool2dNew(nn.Module): """Median pool (usable as median filter when stride=1) module. Args: kernel_size: size of pooling kernel, int or 2-tuple stride: pool stride, int or 2-tuple padding: pool padding, int or 4-tuple (l, r, t, b) as in pytorch F.pad same: override padding and enforce same padding, boolean """ def __init__(self, kernel_size=3, stride=1, padding=0, same=True): """Initialize with kernel_size, stride, padding.""" super().__init__() self.k = _pair(kernel_size) self.stride = _pair(stride) self.padding = _quadruple(padding) self.same = same def _padding(self, x): if self.same: ih, iw = x.size()[2:] if ih % self.stride[0] == 0: ph = max(self.k[0] - self.stride[0], 0) else: ph = max(self.k[0] - ih % self.stride[0], 0) if iw % self.stride[1] == 0: pw = max(self.k[1] - self.stride[1], 0) else: pw = max(self.k[1] - iw % self.stride[1], 0) pl = pw // 2 pr = pw - pl pt = ph // 2 pb = ph - pt padding = pl, pr, pt, pb else: padding = self.padding return padding def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Jiaqi0602/adversarial-attack-from-leakage
MedianPool2d
false
17,473
[ "BSD-3-Clause" ]
9
90db721bed10094ac7d458b232ad5b1573884338
https://github.com/Jiaqi0602/adversarial-attack-from-leakage/tree/90db721bed10094ac7d458b232ad5b1573884338
SlideNet
import torch import torch.nn.functional as F import torch.nn as nn class SlideNet(nn.Module): """ Slided window network """ def __init__(self): super().__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size=6) self.conv2 = nn.Conv2d(in_channels=10, out_channels=20, kernel_size=4) self.fc1 = nn.Linear(in_features=80, out_features=32) self.fc2 = nn.Linear(in_features=32, out_features=16) self.fc3 = nn.Linear(in_features=16, out_features=1) def forward(self, x): out = F.relu(F.max_pool2d(self.conv1(x), kernel_size=2)) out = F.relu(F.max_pool2d(self.conv2(out), kernel_size=2)) out = out.view(-1, 80) out = F.relu(self.fc1(out)) out = F.relu(self.fc2(out)) return self.fc3(out) def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 139240 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3481 % 10 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_relu_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 33640 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 29 x1 = xindex // 29 % 29 x4 = xindex // 841 x3 = xindex // 8410 x5 = xindex % 8410 x6 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 118 * x1 + 3481 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 118 * x1 + 3481 * x4), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (59 + 2 * x0 + 118 * x1 + 3481 * x4), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (60 + 2 * x0 + 118 * x1 + 3481 * x4), 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.full([1], 0, tl.int32) tmp18 = triton_helpers.maximum(tmp17, tmp16) tl.store(out_ptr0 + (x5 + 8448 * x3), tmp15, xmask) tl.store(out_ptr1 + x6, tmp18, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 54080 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 676 % 20 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_relu_threshold_backward_3(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 13520 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 13 x4 = xindex // 13 x2 = xindex // 3380 x3 = xindex % 3380 tmp0 = tl.load(in_ptr0 + (2 * x0 + 52 * x4), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 52 * x4), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (26 + 2 * x0 + 52 * x4), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (27 + 2 * x0 + 52 * x4), 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.full([1], 0, tl.int32) tmp18 = triton_helpers.maximum(tmp17, tmp16) tmp19 = 0.0 tmp20 = tmp18 <= tmp19 tl.store(out_ptr0 + (x3 + 3456 * x2), tmp15, xmask) tl.store(out_ptr1 + (x3 + 3392 * x2), tmp18, xmask) tl.store(out_ptr2 + (x3 + 3456 * x2), tmp20, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_relu_view_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 13520 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (3392 * (x0 // 3380) + x0 % 3380), xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 5408 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 2704 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) 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, (10, 1, 6, 6), (36, 36, 6, 1)) assert_size_stride(primals_2, (10,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (20, 10, 4, 4), (160, 16, 4, 1)) assert_size_stride(primals_5, (20,), (1,)) assert_size_stride(primals_6, (32, 80), (80, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (16, 32), (32, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (1, 16), (16, 1)) assert_size_stride(primals_11, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 10, 59, 59), (34810, 3481, 59, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(139240)](buf1, primals_2, 139240, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 10, 29, 29), (8448, 841, 29, 1), torch.int8) buf3 = empty_strided_cuda((4, 10, 29, 29), (8410, 841, 29, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_relu_1[grid(33640)](buf1, buf2, buf3, 33640, XBLOCK=256, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 20, 26, 26), (13520, 676, 26, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(54080)](buf5, primals_5, 54080, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 20, 13, 13), (3456, 169, 13, 1), torch.int8) buf7 = empty_strided_cuda((4, 20, 13, 13), (3392, 169, 13, 1), torch.float32) buf15 = empty_strided_cuda((4, 20, 13, 13), (3456, 169, 13, 1), torch.bool) triton_poi_fused_max_pool2d_with_indices_relu_threshold_backward_3[grid (13520)](buf5, buf6, buf7, buf15, 13520, XBLOCK=128, num_warps= 4, num_stages=1) buf8 = empty_strided_cuda((169, 80), (80, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_relu_view_4[grid(13520)](buf7, buf8, 13520, XBLOCK=256, num_warps=4, num_stages=1) del buf7 buf9 = empty_strided_cuda((169, 32), (32, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_6, (80, 32), (1, 80), 0), out=buf9) buf10 = buf9 del buf9 triton_poi_fused_relu_5[grid(5408)](buf10, primals_7, 5408, XBLOCK= 256, num_warps=4, num_stages=1) del primals_7 buf11 = empty_strided_cuda((169, 16), (16, 1), torch.float32) extern_kernels.mm(buf10, reinterpret_tensor(primals_8, (32, 16), (1, 32), 0), out=buf11) buf12 = buf11 del buf11 triton_poi_fused_relu_6[grid(2704)](buf12, primals_9, 2704, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 buf14 = empty_strided_cuda((169, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_11, buf12, reinterpret_tensor( primals_10, (16, 1), (1, 16), 0), alpha=1, beta=1, out=buf14) del primals_11 return (buf14, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, buf8, buf10, buf12, primals_10, primals_8, primals_6, buf15) class SlideNetNew(nn.Module): """ Slided window network """ def __init__(self): super().__init__() self.conv1 = nn.Conv2d(in_channels=1, out_channels=10, kernel_size=6) self.conv2 = nn.Conv2d(in_channels=10, out_channels=20, kernel_size=4) self.fc1 = nn.Linear(in_features=80, out_features=32) self.fc2 = nn.Linear(in_features=32, out_features=16) self.fc3 = nn.Linear(in_features=16, out_features=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.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_10 = self.fc3.weight primals_11 = 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]) return output[0]
JHorcasitas/cnn_document_binarization
SlideNet
false
17,474
[ "MIT" ]
9
075f76aed375ca14a53011f4dfeb12379debb5b3
https://github.com/JHorcasitas/cnn_document_binarization/tree/075f76aed375ca14a53011f4dfeb12379debb5b3
ActionScoring
import torch import torch.nn as nn class ActionScoring(nn.Module): """ Linearly mapping h and v to the same dimension, and do a elementwise multiplication and a linear scoring. """ def __init__(self, action_size, hidden_size, dot_size: 'int'=256): super(ActionScoring, self).__init__() self.linear_act = nn.Linear(action_size, dot_size, bias=True) self.linear_hid = nn.Linear(hidden_size, dot_size, bias=True) self.linear_out = nn.Linear(dot_size, 1, bias=True) def forward(self, act_cands, h_tilde): """ Compute logits of action candidates :param act_cands: torch.Tensor(batch, num_candidates, action_emb_size) :param h_tilde: torch.Tensor(batch, hidden_size) Return -> torch.Tensor(batch, num_candidates) """ target = self.linear_hid(h_tilde).unsqueeze(1) context = self.linear_act(act_cands) product = torch.mul(context, target) logits = self.linear_out(product).squeeze(2) return logits def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'action_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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, 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 % 16384 x0 = xindex % 4096 x2 = xindex // 16384 x4 = xindex tmp0 = tl.load(in_ptr0 + x3, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x4, 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, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 4), (4, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_7, (1, 256), (256, 1)) assert_size_stride(primals_8, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 256), (1, 4), 0), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((4, 4, 4, 4, 256), (16384, 4096, 1024, 256, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(65536)](buf1, buf0, buf2, 65536, XBLOCK =256, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((256, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, reinterpret_tensor(buf2, (256, 256), (256, 1), 0), reinterpret_tensor(primals_7, (256, 1), (1, 256), 0), alpha=1, beta=1, out=buf4) del primals_8 return reinterpret_tensor(buf4, (4, 4, 4, 4, 1), (64, 16, 4, 1, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (256, 256), (256, 1), 0), primals_7 class ActionScoringNew(nn.Module): """ Linearly mapping h and v to the same dimension, and do a elementwise multiplication and a linear scoring. """ def __init__(self, action_size, hidden_size, dot_size: 'int'=256): super(ActionScoringNew, self).__init__() self.linear_act = nn.Linear(action_size, dot_size, bias=True) self.linear_hid = nn.Linear(hidden_size, dot_size, bias=True) self.linear_out = nn.Linear(dot_size, 1, bias=True) def forward(self, input_0, input_1): primals_1 = self.linear_act.weight primals_2 = self.linear_act.bias primals_4 = self.linear_hid.weight primals_5 = self.linear_hid.bias primals_7 = self.linear_out.weight primals_8 = self.linear_out.bias primals_3 = input_0 primals_6 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
IMNearth/Curriculum-Learning-For-VLN
ActionScoring
false
17,475
[ "MIT" ]
8
d2fe1286eb295dc8c63a0c886b35883f32481d85
https://github.com/IMNearth/Curriculum-Learning-For-VLN/tree/d2fe1286eb295dc8c63a0c886b35883f32481d85
GraphConv
import torch import torch.nn as nn import torch.utils.data from torch.nn import init import torch.nn.functional as F class MLP(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim, act=nn.ReLU(), normalize_input=True): super(MLP, self).__init__() self.linear_1 = nn.Linear(input_dim, hidden_dim) self.linear_2 = nn.Linear(hidden_dim, output_dim) self.act = act self.normalize_input = normalize_input for m in self.modules(): if isinstance(m, nn.Linear): m.weight.data = init.xavier_uniform_(m.weight.data, gain=nn .init.calculate_gain('relu')) if m.bias is not None: m.bias.data = init.constant_(m.bias.data, 0.0) def forward(self, x): if self.normalize_input: x = (x - torch.mean(x, dim=0)) / torch.std(x, dim=0) x = self.act(self.linear_1(x)) return self.linear_2(x) class GraphConv(nn.Module): def __init__(self, input_dim, output_dim, hidden_dim, normalize_embedding=False, normalize_embedding_l2=False, att=False, mpnn=False, graphsage=False): super(GraphConv, self).__init__() self.normalize_embedding = normalize_embedding self.normalize_embedding_l2 = normalize_embedding_l2 self.input_dim = input_dim self.output_dim = output_dim self.att = att self.mpnn = mpnn self.graphsage = graphsage if self.graphsage: self.out_compute = MLP(input_dim=input_dim * 2, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) elif self.mpnn: self.out_compute = MLP(input_dim=hidden_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) else: self.out_compute = MLP(input_dim=input_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) if self.att: self.att_compute = MLP(input_dim=input_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.LeakyReLU(0.2), normalize_input=False) if self.mpnn: self.mpnn_compute = MLP(input_dim=input_dim * 2, hidden_dim= hidden_dim, output_dim=hidden_dim, act=nn.ReLU(), normalize_input=False) self.softmax = nn.Softmax(dim=-1) def forward(self, x, adj): if self.att: x_att = self.att_compute(x) att = x_att @ x_att.permute(1, 0) att = self.softmax(att) pred = torch.matmul(adj * att, x) elif self.mpnn: x1 = x.unsqueeze(0).repeat(x.shape[0], 1, 1) x2 = x.unsqueeze(1).repeat(1, x.shape[0], 1) e = torch.cat((x1, x2), dim=-1) e = self.mpnn_compute(e) pred = torch.mean(adj.unsqueeze(-1) * e, dim=1) else: pred = torch.matmul(adj, x) if self.graphsage: pred = torch.cat((pred, x), dim=-1) pred = self.out_compute(pred) if self.normalize_embedding: pred = (pred - torch.mean(pred, dim=0)) / torch.std(pred, dim=0) if self.normalize_embedding_l2: pred = F.normalize(pred, p=2, dim=-1) return pred def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4, 'hidden_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data from torch.nn import 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, 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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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 del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf1) del primals_3 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 buf4 = 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, primals_4, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(buf2, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_6 return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor( buf2, (64, 4), (4, 1), 0), primals_5, buf4 class MLP(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim, act=nn.ReLU(), normalize_input=True): super(MLP, self).__init__() self.linear_1 = nn.Linear(input_dim, hidden_dim) self.linear_2 = nn.Linear(hidden_dim, output_dim) self.act = act self.normalize_input = normalize_input for m in self.modules(): if isinstance(m, nn.Linear): m.weight.data = init.xavier_uniform_(m.weight.data, gain=nn .init.calculate_gain('relu')) if m.bias is not None: m.bias.data = init.constant_(m.bias.data, 0.0) def forward(self, x): if self.normalize_input: x = (x - torch.mean(x, dim=0)) / torch.std(x, dim=0) x = self.act(self.linear_1(x)) return self.linear_2(x) class GraphConvNew(nn.Module): def __init__(self, input_dim, output_dim, hidden_dim, normalize_embedding=False, normalize_embedding_l2=False, att=False, mpnn=False, graphsage=False): super(GraphConvNew, self).__init__() self.normalize_embedding = normalize_embedding self.normalize_embedding_l2 = normalize_embedding_l2 self.input_dim = input_dim self.output_dim = output_dim self.att = att self.mpnn = mpnn self.graphsage = graphsage if self.graphsage: self.out_compute = MLP(input_dim=input_dim * 2, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) elif self.mpnn: self.out_compute = MLP(input_dim=hidden_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) else: self.out_compute = MLP(input_dim=input_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.ReLU(), normalize_input=False) if self.att: self.att_compute = MLP(input_dim=input_dim, hidden_dim= hidden_dim, output_dim=output_dim, act=nn.LeakyReLU(0.2), normalize_input=False) if self.mpnn: self.mpnn_compute = MLP(input_dim=input_dim * 2, hidden_dim= hidden_dim, output_dim=hidden_dim, act=nn.ReLU(), normalize_input=False) self.softmax = nn.Softmax(dim=-1) def forward(self, input_0, input_1): primals_3 = self.out_compute.linear_1.weight primals_4 = self.out_compute.linear_1.bias primals_5 = self.out_compute.linear_2.weight primals_6 = self.out_compute.linear_2.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
JiaxuanYou/graph-pooling
GraphConv
false
17,476
[ "MIT" ]
5
e6237f03a72ac55d8a10192ca36fa596973461f5
https://github.com/JiaxuanYou/graph-pooling/tree/e6237f03a72ac55d8a10192ca36fa596973461f5
SALayer
import torch import torch.nn as nn import torch.utils.model_zoo class SALayer(nn.Module): def __init__(self, kernel_size=7): super(SALayer, self).__init__() padding = 3 if kernel_size == 7 else 1 self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): avg_out = torch.mean(x, dim=1, keepdim=True) max_out, _ = torch.max(x, dim=1, keepdim=True) a = torch.cat([avg_out, max_out], dim=1) a = self.conv1(a) a = self.sigmoid(a) return a * x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.model_zoo assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 2 x0 = xindex % 16 x2 = xindex // 32 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tmp7 + tmp8 tmp10 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = 4.0 tmp13 = tmp11 / tmp12 tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp4, tmp13, tmp14) tmp16 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp19 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp21 = triton_helpers.maximum(tmp19, tmp20) tmp22 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp23 = triton_helpers.maximum(tmp21, tmp22) tmp24 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = triton_helpers.maximum(tmp23, tmp24) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp16, tmp25, tmp26) tmp28 = tl.where(tmp4, tmp15, tmp27) tl.store(out_ptr0 + x3, tmp28, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr1 + x3, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x3, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 2, 7, 7), (98, 49, 7, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_1, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 1, 4, 4), (16, 16, 4, 1)) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_1[grid(256)](buf1, primals_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf2, primals_1, primals_2, buf0, buf1 class SALayerNew(nn.Module): def __init__(self, kernel_size=7): super(SALayerNew, self).__init__() padding = 3 if kernel_size == 7 else 1 self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_2 = self.conv1.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
JiahangGu/RFN
SALayer
false
17,477
[ "MIT" ]
4
8f7b33e22bb0a9f4057476720e05cc694a46ec00
https://github.com/JiahangGu/RFN/tree/8f7b33e22bb0a9f4057476720e05cc694a46ec00
NN
import torch from torch import nn import torch.nn.functional as F class NN(nn.Module): def __init__(self): super().__init__() self.fc1 = nn.Linear(4, 16) self.fc2 = nn.Linear(16, 3) def forward(self, x): x = F.relu(self.fc1(x)) x = self.fc2(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda 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 = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (16, 4), (4, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (3, 16), (16, 1)) assert_size_stride(primals_5, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(1024)](buf1, primals_2, buf3, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 3), (3, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 16), (16, 1), 0), reinterpret_tensor(primals_4, (16, 3), (1, 16), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 3), (48, 12, 3, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 16), (16, 1), 0), primals_4, buf3 class NNNew(nn.Module): def __init__(self): super().__init__() self.fc1 = nn.Linear(4, 16) self.fc2 = nn.Linear(16, 3) 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]
Jie-Yuan/Deeps
NN
false
17,478
[ "MIT" ]
4
b4acbb8e16b8ff5d181e70c3b549df0d818d0d76
https://github.com/Jie-Yuan/Deeps/tree/b4acbb8e16b8ff5d181e70c3b549df0d818d0d76
WeightedCrossEntropyLoss
import torch import torch.nn as nn import torch.nn.functional as F class WeightedCrossEntropyLoss(nn.Module): """ Transform input to fit the fomation of PyTorch offical cross entropy loss with anchor-wise weighting. """ def __init__(self): super(WeightedCrossEntropyLoss, self).__init__() def forward(self, input: 'torch.Tensor', target: 'torch.Tensor', weights: 'torch.Tensor'): """ Args: input: (B, #anchors, #classes) float tensor. Predited logits for each class. target: (B, #anchors, #classes) float tensor. One-hot classification targets. weights: (B, #anchors) float tensor. Anchor-wise weights. Returns: loss: (B, #anchors) float tensor. Weighted cross entropy loss without reduction """ input = input.permute(0, 2, 1) target = target.argmax(dim=-1) loss = F.cross_entropy(input, target, reduction='none') * weights return loss def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language 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__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_argmax_nll_loss2d_forward_1(in_ptr0, in_ptr1, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp56 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp58 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp61 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp64 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tmp47 = tl.full([1], -100, tl.int64) tmp48 = tmp46 != tmp47 tmp49 = tl.where(tmp48, tmp46, tmp10) tmp50 = tl.full([XBLOCK], 4, tl.int32) tmp51 = tmp49 + tmp50 tmp52 = tmp49 < 0 tmp53 = tl.where(tmp52, tmp51, tmp49) tl.device_assert((0 <= tmp53) & (tmp53 < 4) | ~xmask, 'index out of bounds: 0 <= tmp53 < 4') tmp55 = tl.load(in_ptr1 + (tmp53 + 4 * x0), xmask, eviction_policy= 'evict_last') 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 = tmp55 - tmp67 tmp69 = -tmp68 tmp70 = 0.0 tmp71 = tl.where(tmp48, tmp69, tmp70) tl.store(out_ptr1 + x0, tmp71, xmask) @triton.jit def triton_poi_fused_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(64)](arg0_1, buf1, 64, XBLOCK= 64, num_warps=1, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32) triton_poi_fused_argmax_nll_loss2d_forward_1[grid(16)](arg1_1, buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg1_1 buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_mul_2[grid(64)](buf2, arg2_1, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg2_1 del buf2 return buf3, class WeightedCrossEntropyLossNew(nn.Module): """ Transform input to fit the fomation of PyTorch offical cross entropy loss with anchor-wise weighting. """ def __init__(self): super(WeightedCrossEntropyLossNew, self).__init__() def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
Jiaolong/trajectory-prediction
WeightedCrossEntropyLoss
false
17,479
[ "Apache-2.0" ]
6
3fd4e6253b44dfdc86e7c08e93c002baf66f2e46
https://github.com/Jiaolong/trajectory-prediction/tree/3fd4e6253b44dfdc86e7c08e93c002baf66f2e46
SRB
import torch import torch.nn as nn import torch.utils.model_zoo class SRB(nn.Module): def __init__(self): super(SRB, self).__init__() self.conv1 = nn.Conv2d(3, 64, 9, padding=4) self.conv2 = nn.Conv2d(64, 32, 5, padding=2) self.conv3 = nn.Conv2d(32, 3, 5, padding=2) self.act = nn.ReLU(True) def forward(self, x): o1 = self.act(self.conv1(x)) o2 = self.act(self.conv2(o1)) o3 = self.conv3(o2) return o3 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 import torch.utils.model_zoo 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_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 // 4096 % 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_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 // 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, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (64, 3, 9, 9), (243, 81, 9, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (32, 64, 5, 5), (1600, 25, 5, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (3, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_7, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(4, 4), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1048576)](buf1, primals_2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(524288)](buf3, primals_5, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 3, 64, 64), (12288, 4096, 64, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(49152)](buf5, primals_7, 49152, XBLOCK=512, num_warps=4, num_stages=1) del primals_7 return buf5, primals_1, primals_3, primals_4, primals_6, buf1, buf3 class SRBNew(nn.Module): def __init__(self): super(SRBNew, self).__init__() self.conv1 = nn.Conv2d(3, 64, 9, padding=4) self.conv2 = nn.Conv2d(64, 32, 5, padding=2) self.conv3 = nn.Conv2d(32, 3, 5, padding=2) self.act = nn.ReLU(True) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
JiahangGu/RFN
SRB
false
17,480
[ "MIT" ]
4
8f7b33e22bb0a9f4057476720e05cc694a46ec00
https://github.com/JiahangGu/RFN/tree/8f7b33e22bb0a9f4057476720e05cc694a46ec00
SigmoidFocalClassificationLoss
import torch import torch.nn as nn class SigmoidFocalClassificationLoss(nn.Module): """ Sigmoid focal cross entropy loss. """ def __init__(self, gamma: 'float'=2.0, alpha: 'float'=0.25): """ Args: gamma: Weighting parameter to balance loss for hard and easy examples. alpha: Weighting parameter to balance loss for positive and negative examples. """ super(SigmoidFocalClassificationLoss, self).__init__() self.alpha = alpha self.gamma = gamma @staticmethod def sigmoid_cross_entropy_with_logits(input: 'torch.Tensor', target: 'torch.Tensor'): """ PyTorch Implementation for tf.nn.sigmoid_cross_entropy_with_logits: max(x, 0) - x * z + log(1 + exp(-abs(x))) in https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets Returns: loss: (B, #anchors, #classes) float tensor. Sigmoid cross entropy loss without reduction """ loss = torch.clamp(input, min=0) - input * target + torch.log1p(torch .exp(-torch.abs(input))) return loss def forward(self, input: 'torch.Tensor', target: 'torch.Tensor', weights: 'torch.Tensor'): """ Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets weights: (B, #anchors) float tensor. Anchor-wise weights. Returns: weighted_loss: (B, #anchors, #classes) float tensor after weighting. """ pred_sigmoid = torch.sigmoid(input) alpha_weight = target * self.alpha + (1 - target) * (1 - self.alpha) pt = target * (1.0 - pred_sigmoid) + (1.0 - target) * pred_sigmoid focal_weight = alpha_weight * torch.pow(pt, self.gamma) bce_loss = self.sigmoid_cross_entropy_with_logits(input, target) loss = focal_weight * bce_loss if weights.shape.__len__() == 2 or weights.shape.__len__( ) == 1 and target.shape.__len__() == 2: weights = weights.unsqueeze(-1) assert weights.shape.__len__() == loss.shape.__len__() return loss * weights def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_add_clamp_exp_log1p_mul_neg_pow_rsub_sigmoid_sub_0( in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp8 = tl.load(in_ptr1 + x0, xmask) tmp26 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp5 = 0.75 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp9 = tl.sigmoid(tmp8) tmp10 = tmp3 - tmp9 tmp11 = tmp0 * tmp10 tmp12 = tmp4 * tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp13 * tmp13 tmp15 = tmp7 * tmp14 tmp16 = 0.0 tmp17 = triton_helpers.maximum(tmp8, tmp16) tmp18 = tmp8 * tmp0 tmp19 = tmp17 - tmp18 tmp20 = tl_math.abs(tmp8) tmp21 = -tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = libdevice.log1p(tmp22) tmp24 = tmp19 + tmp23 tmp25 = tmp15 * tmp24 tmp27 = tmp25 * tmp26 tl.store(out_ptr0 + x0, tmp27, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_abs_add_clamp_exp_log1p_mul_neg_pow_rsub_sigmoid_sub_0[ grid(256)](arg1_1, arg0_1, arg2_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf0, class SigmoidFocalClassificationLossNew(nn.Module): """ Sigmoid focal cross entropy loss. """ def __init__(self, gamma: 'float'=2.0, alpha: 'float'=0.25): """ Args: gamma: Weighting parameter to balance loss for hard and easy examples. alpha: Weighting parameter to balance loss for positive and negative examples. """ super(SigmoidFocalClassificationLossNew, self).__init__() self.alpha = alpha self.gamma = gamma @staticmethod def sigmoid_cross_entropy_with_logits(input: 'torch.Tensor', target: 'torch.Tensor'): """ PyTorch Implementation for tf.nn.sigmoid_cross_entropy_with_logits: max(x, 0) - x * z + log(1 + exp(-abs(x))) in https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets Returns: loss: (B, #anchors, #classes) float tensor. Sigmoid cross entropy loss without reduction """ loss = torch.clamp(input, min=0) - input * target + torch.log1p(torch .exp(-torch.abs(input))) return loss def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
Jiaolong/trajectory-prediction
SigmoidFocalClassificationLoss
false
17,481
[ "Apache-2.0" ]
6
3fd4e6253b44dfdc86e7c08e93c002baf66f2e46
https://github.com/Jiaolong/trajectory-prediction/tree/3fd4e6253b44dfdc86e7c08e93c002baf66f2e46
SelectAdaptivePool2d
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F from torch.nn import functional as F def adaptive_avgmax_pool2d(x, output_size=1): x_avg = F.adaptive_avg_pool2d(x, output_size) x_max = F.adaptive_max_pool2d(x, output_size) return 0.5 * (x_avg + x_max) def adaptive_catavgmax_pool2d(x, output_size=1): x_avg = F.adaptive_avg_pool2d(x, output_size) x_max = F.adaptive_max_pool2d(x, output_size) return torch.cat((x_avg, x_max), 1) def adaptive_pool_feat_mult(pool_type='avg'): if pool_type == 'catavgmax': return 2 else: return 1 class AdaptiveAvgMaxPool2d(nn.Module): def __init__(self, output_size=1): super(AdaptiveAvgMaxPool2d, self).__init__() self.output_size = output_size def forward(self, x): return adaptive_avgmax_pool2d(x, self.output_size) class AdaptiveCatAvgMaxPool2d(nn.Module): def __init__(self, output_size=1): super(AdaptiveCatAvgMaxPool2d, self).__init__() self.output_size = output_size def forward(self, x): return adaptive_catavgmax_pool2d(x, self.output_size) class SelectAdaptivePool2d(nn.Module): """Selectable global pooling layer with dynamic input kernel size """ def __init__(self, output_size=1, pool_type='avg'): super(SelectAdaptivePool2d, self).__init__() self.output_size = output_size self.pool_type = pool_type if pool_type == 'avgmax': self.pool = AdaptiveAvgMaxPool2d(output_size) elif pool_type == 'catavgmax': self.pool = AdaptiveCatAvgMaxPool2d(output_size) elif pool_type == 'max': self.pool = nn.AdaptiveMaxPool2d(output_size) else: if pool_type != 'avg': assert False, 'Invalid pool type: %s' % pool_type self.pool = nn.AdaptiveAvgPool2d(output_size) def forward(self, x): return self.pool(x) def feat_mult(self): return adaptive_pool_feat_mult(self.pool_type) def __repr__(self): return self.__class__.__name__ + ' (' + 'output_size=' + str(self. output_size) + ', pool_type=' + self.pool_type + ')' def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, arg0_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del arg0_1 return buf1, def adaptive_avgmax_pool2d(x, output_size=1): x_avg = F.adaptive_avg_pool2d(x, output_size) x_max = F.adaptive_max_pool2d(x, output_size) return 0.5 * (x_avg + x_max) def adaptive_catavgmax_pool2d(x, output_size=1): x_avg = F.adaptive_avg_pool2d(x, output_size) x_max = F.adaptive_max_pool2d(x, output_size) return torch.cat((x_avg, x_max), 1) def adaptive_pool_feat_mult(pool_type='avg'): if pool_type == 'catavgmax': return 2 else: return 1 class AdaptiveAvgMaxPool2d(nn.Module): def __init__(self, output_size=1): super(AdaptiveAvgMaxPool2d, self).__init__() self.output_size = output_size def forward(self, x): return adaptive_avgmax_pool2d(x, self.output_size) class AdaptiveCatAvgMaxPool2d(nn.Module): def __init__(self, output_size=1): super(AdaptiveCatAvgMaxPool2d, self).__init__() self.output_size = output_size def forward(self, x): return adaptive_catavgmax_pool2d(x, self.output_size) class SelectAdaptivePool2dNew(nn.Module): """Selectable global pooling layer with dynamic input kernel size """ def __init__(self, output_size=1, pool_type='avg'): super(SelectAdaptivePool2dNew, self).__init__() self.output_size = output_size self.pool_type = pool_type if pool_type == 'avgmax': self.pool = AdaptiveAvgMaxPool2d(output_size) elif pool_type == 'catavgmax': self.pool = AdaptiveCatAvgMaxPool2d(output_size) elif pool_type == 'max': self.pool = nn.AdaptiveMaxPool2d(output_size) else: if pool_type != 'avg': assert False, 'Invalid pool type: %s' % pool_type self.pool = nn.AdaptiveAvgPool2d(output_size) def feat_mult(self): return adaptive_pool_feat_mult(self.pool_type) def __repr__(self): return self.__class__.__name__ + ' (' + 'output_size=' + str(self. output_size) + ', pool_type=' + self.pool_type + ')' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
BigFishMaster/tnt
SelectAdaptivePool2d
false
17,482
[ "BSD-3-Clause" ]
3
8b80bb3b194eb87ac18924428ef0924c2fb263c5
https://github.com/BigFishMaster/tnt/tree/8b80bb3b194eb87ac18924428ef0924c2fb263c5
SpatialAttention
import torch from torch import nn class SpatialAttention(nn.Module): def __init__(self, kernel_size=7): super(SpatialAttention, self).__init__() assert kernel_size in (3, 7), 'kernel size must be 3 or 7' padding = 3 if kernel_size == 7 else 1 self.conv1 = nn.Conv3d(2, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): avg_out = torch.mean(x, dim=1, keepdim=True) max_out, _ = torch.max(x, dim=1, keepdim=True) x = torch.cat([avg_out, max_out], dim=1) x = self.conv1(x) return self.sigmoid(x) def get_inputs(): return [torch.rand([4, 2, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 262144 % 2 x0 = xindex % 262144 x2 = xindex // 524288 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 524288 * x2), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (262144 + x0 + 524288 * x2), tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = 2.0 tmp9 = tmp7 / tmp8 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp15 = tl.load(in_ptr0 + (x0 + 524288 * x2), tmp12, eviction_policy= 'evict_last', other=0.0) tmp16 = tl.load(in_ptr0 + (262144 + x0 + 524288 * x2), tmp12, eviction_policy='evict_last', other=0.0) tmp17 = triton_helpers.maximum(tmp15, tmp16) tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp12, tmp17, tmp18) tmp20 = tl.where(tmp4, tmp11, tmp19) tl.store(out_ptr0 + x3, tmp20, None) @triton.jit def triton_poi_fused_sigmoid_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.sigmoid(tmp0) tl.store(in_out_ptr0 + x0, tmp1, None) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 2, 64, 64, 64), (524288, 262144, 4096, 64, 1)) assert_size_stride(primals_2, (1, 2, 7, 7, 7), (686, 343, 49, 7, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 2, 64, 64, 64), (524288, 262144, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(2097152)](primals_1, buf0, 2097152, XBLOCK=512, num_warps=8, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1, 1), padding=(3, 3, 3), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 1, 64, 64, 64), (262144, 262144, 4096, 64, 1)) buf2 = buf1 del buf1 triton_poi_fused_sigmoid_1[grid(1048576)](buf2, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) return buf2, primals_2, buf0, buf2 class SpatialAttentionNew(nn.Module): def __init__(self, kernel_size=7): super(SpatialAttentionNew, self).__init__() assert kernel_size in (3, 7), 'kernel size must be 3 or 7' padding = 3 if kernel_size == 7 else 1 self.conv1 = nn.Conv3d(2, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_2 = self.conv1.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
JiehuaYang/DLCA
SpatialAttention
false
17,483
[ "MIT" ]
5
9f06fe171f6b66e88767a8a9e2246a56373dfe12
https://github.com/JiehuaYang/DLCA/tree/9f06fe171f6b66e88767a8a9e2246a56373dfe12
UpsamplingBlock
import torch import torch.nn as nn class UpsamplingBlock(nn.Module): def __init__(self, input_nc, output_nc, kernel, stride, pad): """ Single block of upsampling operation Input: - int input_nc : Input number of channels - int output_nc : Output number of channels - int kernel : Kernel size - int stride : Stride length - int pad : Padd_moduleing """ super(UpsamplingBlock, self).__init__() conv = nn.Conv2d biup = nn.Upsample block = nn.Sequential() block.add_module('conv_1', conv(input_nc, output_nc, kernel, stride, pad)) block.add_module('upsample_2', biup(scale_factor=2, mode='bilinear')) self.biup_block = block def forward(self, x): return self.biup_block(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_nc': 4, 'output_nc': 4, 'kernel': 4, 'stride': 1, 'pad': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18 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_1(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18 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], 8, 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_2(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18 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_mul_sub_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 5184 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 18 % 18 x0 = xindex % 18 x6 = xindex // 324 x2 = xindex // 324 % 4 xindex // 1296 xindex % 1296 x7 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp22 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last') tmp34 = tl.load(in_ptr7 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 9, 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 + 9 * tmp4 + 81 * x6), xmask, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp13 = tmp12 + tmp1 tmp14 = tmp12 < 0 tmp15 = tl.where(tmp14, tmp13, tmp12) tmp16 = tl.load(in_ptr2 + (tmp15 + 9 * tmp4 + 81 * x6), xmask, eviction_policy='evict_last') tmp17 = tmp16 + tmp10 tmp18 = tmp17 - tmp11 tmp20 = tmp18 * tmp19 tmp21 = tmp11 + tmp20 tmp23 = tmp22 + tmp1 tmp24 = tmp22 < 0 tmp25 = tl.where(tmp24, tmp23, tmp22) tmp26 = tl.load(in_ptr2 + (tmp8 + 9 * tmp25 + 81 * x6), xmask, eviction_policy='evict_last') tmp27 = tmp26 + tmp10 tmp28 = tl.load(in_ptr2 + (tmp15 + 9 * tmp25 + 81 * x6), xmask, eviction_policy='evict_last') tmp29 = tmp28 + tmp10 tmp30 = tmp29 - tmp27 tmp31 = tmp30 * tmp19 tmp32 = tmp27 + tmp31 tmp33 = tmp32 - tmp21 tmp35 = tmp33 * tmp34 tmp36 = tmp21 + tmp35 tl.store(out_ptr2 + x7, tmp36, 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=(4, 4), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 9, 9), (324, 81, 9, 1)) buf1 = empty_strided_cuda((18, 1), (1, 1), torch.int64) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(18)](buf1, 18, XBLOCK=32, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((18, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_1[grid(18)](buf2, 18, XBLOCK=32, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((18,), (1,), torch.int64) triton_poi_fused__to_copy_0[grid(18)](buf3, 18, XBLOCK=32, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((18,), (1,), torch.int64) triton_poi_fused_add_clamp_1[grid(18)](buf4, 18, XBLOCK=32, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((18,), (1,), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(18)](buf5, 18, XBLOCK=32, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((18, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_2[grid(18)](buf7, 18, XBLOCK=32, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 4, 18, 18), (1296, 324, 18, 1), torch .float32) triton_poi_fused__unsafe_index_add_convolution_mul_sub_3[grid(5184)]( buf1, buf3, buf0, primals_2, buf4, buf5, buf2, buf7, buf9, 5184, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 return buf9, primals_1, primals_3, buf1, buf2, buf3, buf4, buf5, buf7 class UpsamplingBlockNew(nn.Module): def __init__(self, input_nc, output_nc, kernel, stride, pad): """ Single block of upsampling operation Input: - int input_nc : Input number of channels - int output_nc : Output number of channels - int kernel : Kernel size - int stride : Stride length - int pad : Padd_moduleing """ super(UpsamplingBlockNew, self).__init__() conv = nn.Conv2d biup = nn.Upsample block = nn.Sequential() block.add_module('conv_1', conv(input_nc, output_nc, kernel, stride, pad)) block.add_module('upsample_2', biup(scale_factor=2, mode='bilinear')) self.biup_block = block def forward(self, input_0): primals_1 = self.biup_block.conv_1.weight primals_2 = self.biup_block.conv_1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Jay2020-01/TextureGAN--Flask
UpsamplingBlock
false
17,484
[ "MIT" ]
5
cddea505b0d66b58d58fb24435f8bae42fd5a852
https://github.com/Jay2020-01/TextureGAN--Flask/tree/cddea505b0d66b58d58fb24435f8bae42fd5a852
MLP
import torch import torch.nn as nn import torch.utils.data from torch.nn import init class MLP(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim, act=nn.ReLU(), normalize_input=True): super(MLP, self).__init__() self.linear_1 = nn.Linear(input_dim, hidden_dim) self.linear_2 = nn.Linear(hidden_dim, output_dim) self.act = act self.normalize_input = normalize_input for m in self.modules(): if isinstance(m, nn.Linear): m.weight.data = init.xavier_uniform_(m.weight.data, gain=nn .init.calculate_gain('relu')) if m.bias is not None: m.bias.data = init.constant_(m.bias.data, 0.0) def forward(self, x): if self.normalize_input: x = (x - torch.mean(x, dim=0)) / torch.std(x, dim=0) x = self.act(self.linear_1(x)) return self.linear_2(x) def get_inputs(): return [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 from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.data from torch.nn import 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_div_mean_std_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex 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 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tmp11 = tmp1 - tmp9 tmp12 = tmp11 * tmp11 tmp13 = tmp2 - tmp9 tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp16 = tmp4 - tmp9 tmp17 = tmp16 * tmp16 tmp18 = tmp15 + tmp17 tmp19 = tmp6 - tmp9 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = 3.0 tmp23 = tmp21 / tmp22 tmp24 = libdevice.sqrt(tmp23) tmp25 = tmp10 / tmp24 tl.store(out_ptr0 + x2, tmp25, 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) 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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_mean_std_sub_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf2, primals_3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor( buf2, (64, 4), (4, 1), 0), primals_4, buf4 class MLPNew(nn.Module): def __init__(self, input_dim, hidden_dim, output_dim, act=nn.ReLU(), normalize_input=True): super(MLPNew, self).__init__() self.linear_1 = nn.Linear(input_dim, hidden_dim) self.linear_2 = nn.Linear(hidden_dim, output_dim) self.act = act self.normalize_input = normalize_input for m in self.modules(): if isinstance(m, nn.Linear): m.weight.data = init.xavier_uniform_(m.weight.data, gain=nn .init.calculate_gain('relu')) if m.bias is not None: m.bias.data = init.constant_(m.bias.data, 0.0) def forward(self, input_0): primals_2 = self.linear_1.weight primals_3 = self.linear_1.bias primals_4 = self.linear_2.weight primals_5 = self.linear_2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JiaxuanYou/graph-pooling
MLP
false
17,485
[ "MIT" ]
5
e6237f03a72ac55d8a10192ca36fa596973461f5
https://github.com/JiaxuanYou/graph-pooling/tree/e6237f03a72ac55d8a10192ca36fa596973461f5
FM
import torch from torch import nn class FM(nn.Module): """Factorization Machine models pairwise (order-2) feature interactions without linear term and bias. Input shape - 3D tensor with shape: ``(batch_size,field_size,embedding_size)``. Output shape - 2D tensor with shape: ``(batch_size, 1)``. References - [Factorization Machines](https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf) """ def __init__(self): super(FM, self).__init__() def forward(self, inputs): fm_input = inputs square_of_sum = torch.pow(torch.sum(fm_input, dim=1, keepdim=True), 2) sum_of_square = torch.sum(fm_input * fm_input, dim=1, keepdim=True) cross_term = square_of_sum - sum_of_square cross_term = 0.5 * torch.sum(cross_term, dim=2, keepdim=False) return cross_term def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_pow_sub_sum_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp16 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), xmask) tmp17 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), xmask) tmp19 = tl.load(in_ptr0 + (36 + x0 + 64 * x1), xmask) tmp21 = tl.load(in_ptr0 + (52 + x0 + 64 * x1), xmask) tmp33 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), xmask) tmp34 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), xmask) tmp36 = tl.load(in_ptr0 + (40 + x0 + 64 * x1), xmask) tmp38 = tl.load(in_ptr0 + (56 + x0 + 64 * x1), xmask) tmp50 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), xmask) tmp51 = tl.load(in_ptr0 + (28 + x0 + 64 * x1), xmask) tmp53 = tl.load(in_ptr0 + (44 + x0 + 64 * x1), xmask) tmp55 = tl.load(in_ptr0 + (60 + x0 + 64 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp0 * tmp0 tmp9 = tmp1 * tmp1 tmp10 = tmp8 + tmp9 tmp11 = tmp3 * tmp3 tmp12 = tmp10 + tmp11 tmp13 = tmp5 * tmp5 tmp14 = tmp12 + tmp13 tmp15 = tmp7 - tmp14 tmp18 = tmp16 + tmp17 tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp23 = tmp22 * tmp22 tmp24 = tmp16 * tmp16 tmp25 = tmp17 * tmp17 tmp26 = tmp24 + tmp25 tmp27 = tmp19 * tmp19 tmp28 = tmp26 + tmp27 tmp29 = tmp21 * tmp21 tmp30 = tmp28 + tmp29 tmp31 = tmp23 - tmp30 tmp32 = tmp15 + tmp31 tmp35 = tmp33 + tmp34 tmp37 = tmp35 + tmp36 tmp39 = tmp37 + tmp38 tmp40 = tmp39 * tmp39 tmp41 = tmp33 * tmp33 tmp42 = tmp34 * tmp34 tmp43 = tmp41 + tmp42 tmp44 = tmp36 * tmp36 tmp45 = tmp43 + tmp44 tmp46 = tmp38 * tmp38 tmp47 = tmp45 + tmp46 tmp48 = tmp40 - tmp47 tmp49 = tmp32 + tmp48 tmp52 = tmp50 + tmp51 tmp54 = tmp52 + tmp53 tmp56 = tmp54 + tmp55 tmp57 = tmp56 * tmp56 tmp58 = tmp50 * tmp50 tmp59 = tmp51 * tmp51 tmp60 = tmp58 + tmp59 tmp61 = tmp53 * tmp53 tmp62 = tmp60 + tmp61 tmp63 = tmp55 * tmp55 tmp64 = tmp62 + tmp63 tmp65 = tmp57 - tmp64 tmp66 = tmp49 + tmp65 tmp67 = 0.5 tmp68 = tmp66 * tmp67 tl.store(in_out_ptr0 + x2, tmp68, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1, 4), (4, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_mul_pow_sub_sum_0[grid(16)](buf1, arg0_1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf1, class FMNew(nn.Module): """Factorization Machine models pairwise (order-2) feature interactions without linear term and bias. Input shape - 3D tensor with shape: ``(batch_size,field_size,embedding_size)``. Output shape - 2D tensor with shape: ``(batch_size, 1)``. References - [Factorization Machines](https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf) """ def __init__(self): super(FMNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Jie-Yuan/Deeps
FM
false
17,486
[ "MIT" ]
4
b4acbb8e16b8ff5d181e70c3b549df0d818d0d76
https://github.com/Jie-Yuan/Deeps/tree/b4acbb8e16b8ff5d181e70c3b549df0d818d0d76
GaussianPolicy
import torch import torch as tor from torch import nn from torch.distributions import Normal def gauss_weights_init(mu, std): def init(m): classname = m.__class__.__name__ if classname.find('Linear') != -1: m.weight.data.normal_(mu, std) return init class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticContinuousNeuralNet(NeuralNet): def __init__(self): super(StochasticContinuousNeuralNet, self).__init__() def sigma(self): pass def mu(self): pass class GaussianPolicy(StochasticContinuousNeuralNet): def __init__(self, architecture, weight_init=gauss_weights_init(0, 0.02 ), activation_functions=None): super(GaussianPolicy, self).__init__() if len(architecture) < 2: raise Exception( 'Architecture needs at least two numbers to create network') self.activation_functions = activation_functions self.layer_list = [] for i in range(len(architecture) - 1): self.layer_list.append(nn.Linear(architecture[i], architecture[ i + 1])) setattr(self, 'fc' + str(i), self.layer_list[-1]) self.apply(weight_init) def forward(self, x): if self.activation_functions: for i, func in enumerate(self.activation_functions): x = func(self.layer_list[i](x)) else: for i, layer in enumerate(self.layer_list[:-1]): x = self.relu(layer(x)) x = self.layer_list[-1](x) self.means = self.tanh(x[None, :int(x.shape[1] / 2)]) self.sigmas = self.softmax(x[None, int(x.shape[1] / 2):]) self.dist = Normal(self.means, self.sigmas) self.sampled = self.dist.rsample() x = self.sampled self.out = x return x def sigma(self): return self.sigmas def mu(self): return self.means def log_prob(self, values): return self.dist.log_prob(values) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'architecture': [4, 4]}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch as tor from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_add_mul_tanh_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex x1 = xindex % 64 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr0 + (128 + x0), xmask) tmp3 = tl.load(in_ptr0 + (128 + x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (192 + x1), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp2 - tmp5 tmp7 = tl_math.exp(tmp6) tmp8 = tmp3 - tmp5 tmp9 = tl_math.exp(tmp8) tmp10 = tmp4 - tmp5 tmp11 = tl_math.exp(tmp10) tmp12 = tmp9 + tmp11 tmp13 = tmp7 / tmp12 tmp15 = tmp14 * tmp13 tmp16 = tmp1 + tmp15 tl.store(out_ptr0 + x0, tmp1, xmask) tl.store(out_ptr1 + x0, tmp13, xmask) tl.store(out_ptr2 + x0, tmp16, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf3 = empty_strided_cuda((1, 2, 4, 4, 4), (128, 64, 16, 4, 1), torch.float32) buf4 = torch.ops.aten.normal_functional.default(buf3) buf5 = buf4 del buf4 buf1 = buf3 del buf3 buf2 = empty_strided_cuda((1, 2, 4, 4, 4), (128, 64, 16, 4, 1), torch.float32) buf6 = empty_strided_cuda((1, 2, 4, 4, 4), (128, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_add_mul_tanh_0[grid(128)](buf0, buf5, buf1, buf2, buf6, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf0 return buf6, buf2, buf1, buf2, buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1, buf2, buf5 def gauss_weights_init(mu, std): def init(m): classname = m.__class__.__name__ if classname.find('Linear') != -1: m.weight.data.normal_(mu, std) return init class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticContinuousNeuralNet(NeuralNet): def __init__(self): super(StochasticContinuousNeuralNet, self).__init__() def sigma(self): pass def mu(self): pass class GaussianPolicyNew(StochasticContinuousNeuralNet): def __init__(self, architecture, weight_init=gauss_weights_init(0, 0.02 ), activation_functions=None): super(GaussianPolicyNew, self).__init__() if len(architecture) < 2: raise Exception( 'Architecture needs at least two numbers to create network') self.activation_functions = activation_functions self.layer_list = [] for i in range(len(architecture) - 1): self.layer_list.append(nn.Linear(architecture[i], architecture[ i + 1])) setattr(self, 'fc' + str(i), self.layer_list[-1]) self.apply(weight_init) def sigma(self): return self.sigmas def mu(self): return self.means def log_prob(self, values): return self.dist.log_prob(values) def forward(self, input_0): primals_1 = self.fc0.weight primals_2 = self.fc0.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JimmyMVP/plain_rl
GaussianPolicy
false
17,487
[ "MIT" ]
10
4780f05fffb62533a339197b49de487cdc9d9954
https://github.com/JimmyMVP/plain_rl/tree/4780f05fffb62533a339197b49de487cdc9d9954
MultiheadAttention
import math import torch import torch.nn as nn class MultiheadAttention(nn.Module): def __init__(self, num_heads=4): super().__init__() self.num_heads = num_heads def forward(self, key, query, value): b, d, n = key.size() _, _, m = query.size() _, do, _ = value.size() key = key.reshape(b * self.num_heads, d // self.num_heads, n) query = query.reshape(b * self.num_heads, d // self.num_heads, m) value = value.reshape(b * self.num_heads, do // self.num_heads, m) affinity = torch.bmm(key.transpose(1, 2), query) weight = torch.softmax(affinity / math.sqrt(d), dim=1) output = torch.bmm(value, weight) output = output.reshape(b, -1, m) weight = weight.reshape(b, self.num_heads, n, m) return output, weight def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_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 % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x3, tmp17, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * 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) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (16, 4, 1), (4, 1, 4), 0), reinterpret_tensor(arg1_1, (16, 1, 4), (4, 4, 1), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused__softmax_1[grid(256)](buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 buf3 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg2_1, (16, 1, 4), (4, 4, 1), 0), buf2, out=buf3) del arg2_1 return reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) class MultiheadAttentionNew(nn.Module): def __init__(self, num_heads=4): super().__init__() self.num_heads = num_heads def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0], output[1]
Jiayuan-Gu/policy-refactorization
MultiheadAttention
false
17,488
[ "MIT" ]
6
c626c598d735d4c08c2c0553da34196b3fba0b6d
https://github.com/Jiayuan-Gu/policy-refactorization/tree/c626c598d735d4c08c2c0553da34196b3fba0b6d
ActorCriticPPO
import torch import torch as tor from torch import nn from torch.distributions import Normal def gauss_weights_init(mu, std): def init(m): classname = m.__class__.__name__ if classname.find('Linear') != -1: m.weight.data.normal_(mu, std) return init class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticContinuousNeuralNet(NeuralNet): def __init__(self): super(StochasticContinuousNeuralNet, self).__init__() def sigma(self): pass def mu(self): pass class ActorCriticPPO(StochasticContinuousNeuralNet): def __init__(self, architecture, weight_init=gauss_weights_init(0, 0.02 ), activation_functions=None): super(ActorCriticPPO, self).__init__() if len(architecture) < 2: raise Exception( 'Architecture needs at least two numbers to create network') self.activation_functions = activation_functions self.layer_list = [] self.layer_list_val = [] self.siglog = tor.zeros(1, requires_grad=True) self.siglog = nn.Parameter(self.siglog) for i in range(len(architecture) - 1): self.layer_list.append(nn.Linear(architecture[i], architecture[ i + 1])) setattr(self, 'fc' + str(i), self.layer_list[-1]) for i in range(len(architecture) - 2): self.layer_list_val.append(nn.Linear(architecture[i], architecture[i + 1])) setattr(self, 'fc_val' + str(i), self.layer_list_val[-1]) self.layer_list_val.append(nn.Linear(architecture[-2], 1)) setattr(self, 'fc_val' + str(len(architecture) - 1), self. layer_list_val[-1]) self.apply(weight_init) def policy_forward(self, x): if self.activation_functions: for i, func in enumerate(self.activation_functions): x = func(self.layer_list[i](x)) else: for i, layer in enumerate(self.layer_list[:-1]): x = self.tanh(layer(x)) x = self.layer_list[-1](x) self._means = self.tanh(x) self._dist = Normal(self._means, tor.exp(self.siglog)) self.sampled = self._dist.rsample() x = self.sampled return x def mu(self): return self.means def value_forward(self, x): if self.activation_functions: for i, func in enumerate(self.activation_functions): x = func(self.layer_list_val[i](x)) else: for i, layer in enumerate(self.layer_list_val[:-1]): x = self.tanh(layer(x)) x = self.layer_list_val[-1](x) return x def forward(self, x): action = self.policy_forward(x) value = self.value_forward(x) return tor.cat([action, value], dim=1) def __call__(self, state): action, value = self.policy_forward(state), self.value_forward(state) return action, value def sigma(self): return self.sigmas def mu(self): return self._means def logprob(self, values): return self._dist.log_prob(values) def entropy(self): return self._dist.entropy() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'architecture': [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.triton_helpers import libdevice, math as tl_math import torch as tor from torch import nn from torch.distributions import Normal assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_exp_0(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) @triton.jit def triton_poi_fused_add_mul_tanh_1(in_out_ptr0, 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_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + x2, xmask) tmp5 = tl.load(in_ptr2 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tl.store(in_out_ptr0 + x2, tmp3, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1,), (1,)) assert_size_stride(primals_5, (1, 4), (4, 1)) assert_size_stride(primals_6, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf2 = empty_strided_cuda((1,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_exp_0[grid(1)](primals_4, buf2, 1, XBLOCK=1, num_warps=1, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = torch.ops.aten.normal_functional.default(buf3) buf5 = buf4 del buf4 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf6 = buf3 del buf3 triton_poi_fused_add_mul_tanh_1[grid(256)](buf1, primals_2, buf5, buf2, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf8 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf8) del primals_5 del primals_6 return buf6, reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0 ), buf1, reinterpret_tensor(buf2, (4, 4, 4, 4), (0, 0, 0, 0), 0 ), buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf2, buf5 def gauss_weights_init(mu, std): def init(m): classname = m.__class__.__name__ if classname.find('Linear') != -1: m.weight.data.normal_(mu, std) return init class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticContinuousNeuralNet(NeuralNet): def __init__(self): super(StochasticContinuousNeuralNet, self).__init__() def sigma(self): pass def mu(self): pass class ActorCriticPPONew(StochasticContinuousNeuralNet): def __init__(self, architecture, weight_init=gauss_weights_init(0, 0.02 ), activation_functions=None): super(ActorCriticPPONew, self).__init__() if len(architecture) < 2: raise Exception( 'Architecture needs at least two numbers to create network') self.activation_functions = activation_functions self.layer_list = [] self.layer_list_val = [] self.siglog = tor.zeros(1, requires_grad=True) self.siglog = nn.Parameter(self.siglog) for i in range(len(architecture) - 1): self.layer_list.append(nn.Linear(architecture[i], architecture[ i + 1])) setattr(self, 'fc' + str(i), self.layer_list[-1]) for i in range(len(architecture) - 2): self.layer_list_val.append(nn.Linear(architecture[i], architecture[i + 1])) setattr(self, 'fc_val' + str(i), self.layer_list_val[-1]) self.layer_list_val.append(nn.Linear(architecture[-2], 1)) setattr(self, 'fc_val' + str(len(architecture) - 1), self. layer_list_val[-1]) self.apply(weight_init) def policy_forward(self, x): if self.activation_functions: for i, func in enumerate(self.activation_functions): x = func(self.layer_list[i](x)) else: for i, layer in enumerate(self.layer_list[:-1]): x = self.tanh(layer(x)) x = self.layer_list[-1](x) self._means = self.tanh(x) self._dist = Normal(self._means, tor.exp(self.siglog)) self.sampled = self._dist.rsample() x = self.sampled return x def mu(self): return self.means def value_forward(self, x): if self.activation_functions: for i, func in enumerate(self.activation_functions): x = func(self.layer_list_val[i](x)) else: for i, layer in enumerate(self.layer_list_val[:-1]): x = self.tanh(layer(x)) x = self.layer_list_val[-1](x) return x def __call__(self, state): action, value = self.policy_forward(state), self.value_forward(state) return action, value def sigma(self): return self.sigmas def mu(self): return self._means def logprob(self, values): return self._dist.log_prob(values) def entropy(self): return self._dist.entropy() def forward(self, input_0): primals_4 = self.siglog primals_1 = self.fc0.weight primals_2 = self.fc0.bias primals_5 = self.fc_val1.weight primals_6 = self.fc_val1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
JimmyMVP/plain_rl
ActorCriticPPO
false
17,489
[ "MIT" ]
10
4780f05fffb62533a339197b49de487cdc9d9954
https://github.com/JimmyMVP/plain_rl/tree/4780f05fffb62533a339197b49de487cdc9d9954
ECA
import torch import torch.nn as nn class ECA(nn.Module): """Constructs a ECA module. Args: channel: Number of channels of the input feature map k_size: Adaptive selection of kernel size """ def __init__(self, channel, k_size=3): super(ECA, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.conv = nn.Conv1d(1, 1, kernel_size=k_size, padding=(k_size - 1 ) // 2, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): _b, _c, _h, _w = x.size() y = self.avg_pool(x) y = self.conv(y.squeeze(-1).transpose(-1, -2)).transpose(-1, -2 ).unsqueeze(-1) y = self.sigmoid(y) return x * y.expand_as(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_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 x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 1, 3), (3, 3, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (4, 1, 4 ), (4, 0, 1), 0), primals_2, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 4), (4, 4, 1)) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_1[grid(256)](primals_1, buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf3, primals_1, primals_2, reinterpret_tensor(buf1, (4, 1, 4), (4, 1, 1), 0), buf2 class ECANew(nn.Module): """Constructs a ECA module. Args: channel: Number of channels of the input feature map k_size: Adaptive selection of kernel size """ def __init__(self, channel, k_size=3): super(ECANew, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.conv = nn.Conv1d(1, 1, kernel_size=k_size, padding=(k_size - 1 ) // 2, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_2 = self.conv.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
Jiannan-Liu/nCoVSegNet
ECA
false
17,490
[ "MIT" ]
5
7543e68edff011a7f7b694c97cf0f185d441fd6b
https://github.com/Jiannan-Liu/nCoVSegNet/tree/7543e68edff011a7f7b694c97cf0f185d441fd6b
GraphConvolution
from torch.nn import Module import torch import torch.nn.functional as F from torch.nn.parameter import Parameter from torch.nn.modules.module import Module import torch.nn.modules.loss class GraphConvolution(Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, dropout=0.0, act=F.relu): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.dropout = dropout self.act = act self.weight = Parameter(torch.FloatTensor(in_features, out_features)) self.reset_parameters() def reset_parameters(self): torch.nn.init.xavier_uniform_(self.weight) def forward(self, input, adj): input = F.dropout(input, self.dropout, self.training) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) output = self.act(output) return output def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch.nn import Module import torch.nn.functional as F from torch.nn.parameter import Parameter from torch.nn.modules.module import Module import torch.nn.modules.loss 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 = 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) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(in_out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, buf0, out=buf1) del buf0 buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf2, buf3, reinterpret_tensor(primals_3, (4, 4), (1, 4), 0 ), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0) class GraphConvolutionNew(Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, dropout=0.0, act=F.relu): super(GraphConvolutionNew, self).__init__() self.in_features = in_features self.out_features = out_features self.dropout = dropout self.act = act self.weight = Parameter(torch.FloatTensor(in_features, out_features)) self.reset_parameters() def reset_parameters(self): torch.nn.init.xavier_uniform_(self.weight) def forward(self, input_0, input_1): primals_1 = self.weight primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
JinmiaoChenLab/SEDR
GraphConvolution
false
17,491
[ "MIT" ]
5
18616dfe2ecb56e22225ffefe949d353e819a7d8
https://github.com/JinmiaoChenLab/SEDR/tree/18616dfe2ecb56e22225ffefe949d353e819a7d8
InnerProductDecoder
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.modules.loss class InnerProductDecoder(nn.Module): """Decoder for using inner product for prediction.""" def __init__(self, dropout, act=torch.sigmoid): super(InnerProductDecoder, self).__init__() self.dropout = dropout self.act = act def forward(self, z): z = F.dropout(z, self.dropout, training=self.training) adj = self.act(torch.mm(z, z.t())) return adj def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.modules.loss 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 = 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) del arg0_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(16)](buf1, 16, XBLOCK=16, num_warps =1, num_stages=1) return buf1, class InnerProductDecoderNew(nn.Module): """Decoder for using inner product for prediction.""" def __init__(self, dropout, act=torch.sigmoid): super(InnerProductDecoderNew, self).__init__() self.dropout = dropout self.act = act def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
JinmiaoChenLab/SEDR
InnerProductDecoder
false
17,492
[ "MIT" ]
5
18616dfe2ecb56e22225ffefe949d353e819a7d8
https://github.com/JinmiaoChenLab/SEDR/tree/18616dfe2ecb56e22225ffefe949d353e819a7d8
CE
import torch import torch.nn as nn class CE(nn.Module): def __init__(self): super(CE, self).__init__() def forward(self, mat1, mat2): return -torch.mean(mat2 * torch.log(mat1 + 1e-10) + (1 - mat2) * torch.log(1 - mat1 + 1e-10)) 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_log_mean_mul_neg_rsub_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 = 1e-10 tmp3 = tmp1 + tmp2 tmp4 = tl_math.log(tmp3) tmp5 = tmp0 * tmp4 tmp6 = 1.0 tmp7 = tmp6 - tmp0 tmp8 = tmp6 - tmp1 tmp9 = tmp8 + tmp2 tmp10 = tl_math.log(tmp9) tmp11 = tmp7 * tmp10 tmp12 = tmp5 + tmp11 tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tmp16 = 256.0 tmp17 = tmp15 / tmp16 tmp18 = -tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_log_mean_mul_neg_rsub_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 CENew(nn.Module): def __init__(self): super(CENew, 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]
Jiangtong-Li/ZHSIR
CE
false
17,493
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
MSE
import torch import torch.nn as nn class MSE(nn.Module): def __init__(self): super(MSE, self).__init__() def forward(self, x_true, x_pred): return torch.sqrt(torch.mean(torch.pow(x_pred - x_true, 2), dim=-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.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mean_pow_sqrt_sub_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 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') tmp4 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp16 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = 4.0 tmp20 = tmp18 / tmp19 tmp21 = libdevice.sqrt(tmp20) tl.store(out_ptr0 + x0, tmp21, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_pow_sqrt_sub_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf0, class MSENew(nn.Module): def __init__(self): super(MSENew, 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]
Jiangtong-Li/ZHSIR
MSE
false
17,494
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
PolicyAHG
import torch import numpy as np import torch as tor from torch import nn class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticNeuralNet(NeuralNet): def __init__(self): super(StochasticNeuralNet, self).__init__() def sample_action(self, action_distribution=None): if not action_distribution: action_distribution = self.out action_distribution = action_distribution.cpu().data.numpy() action = np.random.choice(action_distribution.squeeze(), p= action_distribution.squeeze()) action = np.argmax(action_distribution == action) return action class PolicyAHG(StochasticNeuralNet): def __init__(self, input_size, output_size): super(PolicyAHG, self).__init__() self.f1 = nn.Linear(input_size, 32) self.f2 = nn.Linear(32, output_size) def forward(self, x): out = self.f1(x) out = self.tanh(out) out = self.f2(out) out = self.softmax(out) self.out = out return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import numpy as np import torch as tor from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, None) @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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (32, 4), (4, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 32), (32, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 32), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 32), (512, 128, 32, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(2048)](buf1, primals_2, 2048, 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, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 4), (1, 32), 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__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused__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 ), buf1, buf4, primals_4 class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticNeuralNet(NeuralNet): def __init__(self): super(StochasticNeuralNet, self).__init__() def sample_action(self, action_distribution=None): if not action_distribution: action_distribution = self.out action_distribution = action_distribution.cpu().data.numpy() action = np.random.choice(action_distribution.squeeze(), p= action_distribution.squeeze()) action = np.argmax(action_distribution == action) return action class PolicyAHGNew(StochasticNeuralNet): def __init__(self, input_size, output_size): super(PolicyAHGNew, self).__init__() self.f1 = nn.Linear(input_size, 32) self.f2 = nn.Linear(32, output_size) def forward(self, input_0): primals_1 = self.f1.weight primals_2 = self.f1.bias primals_4 = self.f2.weight primals_5 = self.f2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JimmyMVP/plain_rl
PolicyAHG
false
17,495
[ "MIT" ]
10
4780f05fffb62533a339197b49de487cdc9d9954
https://github.com/JimmyMVP/plain_rl/tree/4780f05fffb62533a339197b49de487cdc9d9954
PolicySPG
import torch import numpy as np import torch as tor from torch import nn class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticNeuralNet(NeuralNet): def __init__(self): super(StochasticNeuralNet, self).__init__() def sample_action(self, action_distribution=None): if not action_distribution: action_distribution = self.out action_distribution = action_distribution.cpu().data.numpy() action = np.random.choice(action_distribution.squeeze(), p= action_distribution.squeeze()) action = np.argmax(action_distribution == action) return action class PolicySPG(StochasticNeuralNet): def __init__(self, input_size, output_size): super(PolicySPG, self).__init__() self.f1 = nn.Linear(input_size, 64) self.f2 = nn.Linear(64, output_size) def forward(self, x): out = self.f1(x) out = self.relu(out) out = self.f2(out) out = self.softmax(out) self.out = out return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import numpy as np import torch as tor 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): 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) @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) 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 buf5 = 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, buf5, 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 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused__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, 64), (64, 1), 0 ), buf4, primals_4, buf5 class SaveableModel(object): def save(self, path): tor.save(self, path) @classmethod def load(cls, path): return tor.load(path) @classmethod def load_best(cls, path): assert os.path.isdir(path) best_models = glob.glob(os.path.join(path, '*best*')) assert not len(best_models > 1) return tor.load(os.path.join(path, best_models[0])) class NeuralNet(nn.Module, SaveableModel): def __init__(self): super(NeuralNet, self).__init__() self.relu = nn.ReLU() self.tanh = nn.Tanh() self.softmax = nn.Softmax() def action(self, x): pass class StochasticNeuralNet(NeuralNet): def __init__(self): super(StochasticNeuralNet, self).__init__() def sample_action(self, action_distribution=None): if not action_distribution: action_distribution = self.out action_distribution = action_distribution.cpu().data.numpy() action = np.random.choice(action_distribution.squeeze(), p= action_distribution.squeeze()) action = np.argmax(action_distribution == action) return action class PolicySPGNew(StochasticNeuralNet): def __init__(self, input_size, output_size): super(PolicySPGNew, self).__init__() self.f1 = nn.Linear(input_size, 64) self.f2 = nn.Linear(64, output_size) def forward(self, input_0): primals_1 = self.f1.weight primals_2 = self.f1.bias primals_4 = self.f2.weight primals_5 = self.f2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JimmyMVP/plain_rl
PolicySPG
false
17,496
[ "MIT" ]
10
4780f05fffb62533a339197b49de487cdc9d9954
https://github.com/JimmyMVP/plain_rl/tree/4780f05fffb62533a339197b49de487cdc9d9954
_CMT_loss
import torch import torch.nn as nn class _CMT_loss(nn.Module): def __init__(self): super(_CMT_loss, self).__init__() self.d = nn.PairwiseDistance() def forward(self, feat, sematics): """ :param feat: features of images or images. bs * d. d is the length of word vector. :param sematics: sematics of sketches. bs * d. d is the length of word vector. :return: loss """ return torch.mean(self.d(feat.float(), sematics.float()) ** 2) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.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_mean_norm_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp18 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = 1e-06 tmp4 = tmp2 + tmp3 tmp5 = tmp4 * tmp4 tmp8 = tmp6 - tmp7 tmp9 = tmp8 + tmp3 tmp10 = tmp9 * tmp9 tmp11 = tmp5 + tmp10 tmp14 = tmp12 - tmp13 tmp15 = tmp14 + tmp3 tmp16 = tmp15 * tmp15 tmp17 = tmp11 + tmp16 tmp20 = tmp18 - tmp19 tmp21 = tmp20 + tmp3 tmp22 = tmp21 * tmp21 tmp23 = tmp17 + tmp22 tmp24 = libdevice.sqrt(tmp23) tmp25 = tmp24 * tmp24 tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK]) tmp28 = tl.sum(tmp26, 1)[:, None] tmp29 = 64.0 tmp30 = tmp28 / tmp29 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp30, 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_mean_norm_pow_sub_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 _CMT_lossNew(nn.Module): def __init__(self): super(_CMT_lossNew, self).__init__() self.d = nn.PairwiseDistance() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Jiangtong-Li/ZHSIR
_CMT_loss
false
17,497
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
_D3Shape_loss
import torch import torch.nn as nn class _D3Shape_loss(nn.Module): def __init__(self, cp=0.2, cn=10): super(_D3Shape_loss, self).__init__() self.alpha = 1 / cp self.beta = cn self.gamma = -2.77 / cn def _d(self, feat1, feat2): return torch.sum(torch.abs(feat1 - feat2), 1) def _l(self, d, is_same): return is_same * self.alpha * d * d + (1 - is_same ) * self.beta * torch.exp(self.gamma * d) def forward(self, sketch1_feat, imsk1_feat, sketch2_feat, imsk2_feat, is_same): d_sk2sk = self._d(sketch1_feat, sketch2_feat) d_is2is = self._d(imsk1_feat, imsk2_feat) d_sk2is = self._d(sketch1_feat, imsk1_feat) is_same = is_same.view(is_same.size(0) * is_same.size(1)) loss = self._l(d_sk2sk, is_same) + self._l(d_is2is, is_same) + self._l( d_sk2is, is_same) return torch.mean(loss) def get_inputs(): return [torch.rand([64, 4]), torch.rand([64, 4]), torch.rand([64, 4]), torch.rand([64, 4]), torch.rand([16, 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_exp_mean_mul_rsub_sub_sum_0(in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp15 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last') tmp20 = tl.load(in_ptr3 + 4 * r0, None, eviction_policy='evict_last') tmp23 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp24 = tl.load(in_ptr3 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp29 = tl.load(in_ptr3 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp33 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp34 = tl.load(in_ptr3 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp49 = tl.load(in_ptr4 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp6 = tmp4 - tmp5 tmp7 = tl_math.abs(tmp6) tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tl_math.abs(tmp11) tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tl_math.abs(tmp16) tmp18 = tmp13 + tmp17 tmp21 = tmp19 - tmp20 tmp22 = tl_math.abs(tmp21) tmp25 = tmp23 - tmp24 tmp26 = tl_math.abs(tmp25) tmp27 = tmp22 + tmp26 tmp30 = tmp28 - tmp29 tmp31 = tl_math.abs(tmp30) tmp32 = tmp27 + tmp31 tmp35 = tmp33 - tmp34 tmp36 = tl_math.abs(tmp35) tmp37 = tmp32 + tmp36 tmp38 = tmp0 - tmp19 tmp39 = tl_math.abs(tmp38) tmp40 = tmp4 - tmp23 tmp41 = tl_math.abs(tmp40) tmp42 = tmp39 + tmp41 tmp43 = tmp9 - tmp28 tmp44 = tl_math.abs(tmp43) tmp45 = tmp42 + tmp44 tmp46 = tmp14 - tmp33 tmp47 = tl_math.abs(tmp46) tmp48 = tmp45 + tmp47 tmp50 = 5.0 tmp51 = tmp49 * tmp50 tmp52 = tmp51 * tmp18 tmp53 = tmp52 * tmp18 tmp54 = 1.0 tmp55 = tmp54 - tmp49 tmp56 = 10.0 tmp57 = tmp55 * tmp56 tmp58 = -0.277 tmp59 = tmp18 * tmp58 tmp60 = tl_math.exp(tmp59) tmp61 = tmp57 * tmp60 tmp62 = tmp53 + tmp61 tmp63 = tmp51 * tmp37 tmp64 = tmp63 * tmp37 tmp65 = tmp37 * tmp58 tmp66 = tl_math.exp(tmp65) tmp67 = tmp57 * tmp66 tmp68 = tmp64 + tmp67 tmp69 = tmp62 + tmp68 tmp70 = tmp51 * tmp48 tmp71 = tmp70 * tmp48 tmp72 = tmp48 * tmp58 tmp73 = tl_math.exp(tmp72) tmp74 = tmp57 * tmp73 tmp75 = tmp71 + tmp74 tmp76 = tmp69 + tmp75 tmp77 = tl.broadcast_to(tmp76, [XBLOCK, RBLOCK]) tmp79 = tl.sum(tmp77, 1)[:, None] tmp80 = 64.0 tmp81 = tmp79 / tmp80 tl.debug_barrier() tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp81, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1, arg4_1 = args args.clear() assert_size_stride(arg0_1, (64, 4), (4, 1)) assert_size_stride(arg1_1, (64, 4), (4, 1)) assert_size_stride(arg2_1, (64, 4), (4, 1)) assert_size_stride(arg3_1, (64, 4), (4, 1)) assert_size_stride(arg4_1, (16, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 get_raw_stream(0) triton_per_fused_abs_add_exp_mean_mul_rsub_sub_sum_0[grid(1)](buf5, arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 del arg4_1 return buf5, class _D3Shape_lossNew(nn.Module): def __init__(self, cp=0.2, cn=10): super(_D3Shape_lossNew, self).__init__() self.alpha = 1 / cp self.beta = cn self.gamma = -2.77 / cn def _d(self, feat1, feat2): return torch.sum(torch.abs(feat1 - feat2), 1) def _l(self, d, is_same): return is_same * self.alpha * d * d + (1 - is_same ) * self.beta * torch.exp(self.gamma * d) def forward(self, input_0, input_1, input_2, input_3, input_4): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 arg4_1 = input_4 output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1]) return output[0]
Jiangtong-Li/ZHSIR
_D3Shape_loss
false
17,498
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
GraphConvolution
import math import torch import torch.nn as nn from torch.nn.parameter import Parameter class GraphConvolution(nn.Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, bias=True): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.FloatTensor(in_features, out_features)) if bias: self.bias = Parameter(torch.FloatTensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def forward(self, x, adj): support = x @ self.weight output = adj @ support if self.bias is not None: output += self.bias return output def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = 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)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), primals_1, out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_3, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0), out=buf1) del buf0 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf2, primals_4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 return buf2, reinterpret_tensor(primals_3, (16, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(primals_2, (4, 64), (1, 4), 0) class GraphConvolutionNew(nn.Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, bias=True): super(GraphConvolutionNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.FloatTensor(in_features, out_features)) if bias: self.bias = Parameter(torch.FloatTensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' def forward(self, input_0, input_1): primals_1 = self.weight primals_4 = self.bias primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
Jiangtong-Li/ZHSIR
GraphConvolution
false
17,499
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
CNN_attention
import torch import torch.nn as nn class CNN_attention(nn.Module): def __init__(self, channel_size): super(CNN_attention, self).__init__() self.attention = nn.Conv2d(channel_size, channel_size, kernel_size=1) self.softmax = nn.Softmax(dim=-1) self._initialize_weights() def forward(self, conv_feature): conv_shape = conv_feature.shape assert len(conv_shape) == 4 att_weight = self.attention(conv_feature) att_weight = att_weight.reshape((conv_shape[0], conv_shape[1], conv_shape[2] * conv_shape[3])) att_weight = self.softmax(att_weight) att_weight = att_weight.reshape((conv_shape[0], conv_shape[1], conv_shape[2], conv_shape[3])) assert att_weight.shape == conv_feature.shape weighted_conv_feature = att_weight * conv_feature weighted_conv_feature = weighted_conv_feature.mean([2, 3]) return weighted_conv_feature def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') if m.bias is not None: nn.init.constant_(m.bias, 0) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn 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__softmax_convolution_mean_mul_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + (r2 + 16 * x3), xmask, other=0.0) tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tmp7 = tmp2 - tmp6 tmp8 = tl_math.exp(tmp7) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.where(xmask, tmp9, 0) tmp12 = tl.sum(tmp11, 1)[:, None] tmp13 = tmp8 / tmp12 tmp15 = tmp13 * tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = tl.where(xmask, tmp16, 0) tmp19 = tl.sum(tmp18, 1)[:, None] tmp20 = 16.0 tmp21 = tmp19 / tmp20 tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp21, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr1 + x3, tmp12, 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, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf5 = buf4 del buf4 get_raw_stream(0) triton_per_fused__softmax_convolution_mean_mul_0[grid(16)](buf1, buf5, primals_3, primals_1, buf2, buf3, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_3 return buf5, primals_1, primals_2, buf1, buf2, buf3 class CNN_attentionNew(nn.Module): def __init__(self, channel_size): super(CNN_attentionNew, self).__init__() self.attention = nn.Conv2d(channel_size, channel_size, kernel_size=1) self.softmax = nn.Softmax(dim=-1) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu') if m.bias is not None: nn.init.constant_(m.bias, 0) def forward(self, input_0): primals_2 = self.attention.weight primals_3 = self.attention.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Jiangtong-Li/ZHSIR
CNN_attention
false
17,500
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
InnerProductDecoder
import torch import torch.fx import torch.utils.data class InnerProductDecoder(torch.nn.Module): """The inner product decoder from the `"Variational Graph Auto-Encoders" <https://arxiv.org/abs/1611.07308>`_ paper .. math:: \\sigma(\\mathbf{Z}\\mathbf{Z}^{\\top}) where :math:`\\mathbf{Z} \\in \\mathbb{R}^{N \\times d}` denotes the latent space produced by the encoder.""" def forward(self, z, edge_index, sigmoid=True): """Decodes the latent variables :obj:`z` into edge probabilities for the given node-pairs :obj:`edge_index`. Args: z (Tensor): The latent space :math:`\\mathbf{Z}`. sigmoid (bool, optional): If set to :obj:`False`, does not apply the logistic sigmoid function to the output. (default: :obj:`True`) """ value = (z[edge_index[0]] * z[edge_index[1]]).sum(dim=1) return torch.sigmoid(value) if sigmoid else value def forward_all(self, z, sigmoid=True): """Decodes the latent variables :obj:`z` into a probabilistic dense adjacency matrix. Args: z (Tensor): The latent space :math:`\\mathbf{Z}`. sigmoid (bool, optional): If set to :obj:`False`, does not apply the logistic sigmoid function to the output. (default: :obj:`True`) """ adj = torch.matmul(z, z.t()) return torch.sigmoid(adj) if sigmoid else adj def get_inputs(): return [torch.ones([4, 4], dtype=torch.int64), torch.ones([4, 4], dtype =torch.int64)] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.fx 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_index_mul_sigmoid_sum_0(in_ptr0, in_ptr1, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp7 = tl.load(in_ptr0 + (4 + x0), xmask) tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask, 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + 4 * tmp4, xmask, eviction_policy='evict_last') tmp8 = tmp7 + tmp1 tmp9 = tmp7 < 0 tmp10 = tl.where(tmp9, tmp8, tmp7) tl.device_assert((0 <= tmp10) & (tmp10 < 4) | ~xmask, 'index out of bounds: 0 <= tmp10 < 4') tmp12 = tl.load(in_ptr1 + 4 * tmp10, xmask, eviction_policy='evict_last') tmp13 = tmp6 * tmp12 tmp14 = tl.load(in_ptr1 + (1 + 4 * tmp4), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (1 + 4 * tmp10), xmask, eviction_policy= 'evict_last') tmp16 = tmp14 * tmp15 tmp17 = tmp13 + tmp16 tmp18 = tl.load(in_ptr1 + (2 + 4 * tmp4), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr1 + (2 + 4 * tmp10), xmask, eviction_policy= 'evict_last') tmp20 = tmp18 * tmp19 tmp21 = tmp17 + tmp20 tmp22 = tl.load(in_ptr1 + (3 + 4 * tmp4), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr1 + (3 + 4 * tmp10), xmask, eviction_policy= 'evict_last') tmp24 = tmp22 * tmp23 tmp25 = tmp21 + tmp24 tmp26 = tmp25.to(tl.float32) tmp27 = tl.sigmoid(tmp26) tl.store(out_ptr1 + x0, tmp27, 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) buf1 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_index_mul_sigmoid_sum_0[grid(4)](arg0_1, arg1_1, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf1, class InnerProductDecoderNew(torch.nn.Module): """The inner product decoder from the `"Variational Graph Auto-Encoders" <https://arxiv.org/abs/1611.07308>`_ paper .. math:: \\sigma(\\mathbf{Z}\\mathbf{Z}^{\\top}) where :math:`\\mathbf{Z} \\in \\mathbb{R}^{N \\times d}` denotes the latent space produced by the encoder.""" def forward_all(self, z, sigmoid=True): """Decodes the latent variables :obj:`z` into a probabilistic dense adjacency matrix. Args: z (Tensor): The latent space :math:`\\mathbf{Z}`. sigmoid (bool, optional): If set to :obj:`False`, does not apply the logistic sigmoid function to the output. (default: :obj:`True`) """ adj = torch.matmul(z, z.t()) return torch.sigmoid(adj) if sigmoid else adj def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
JinheonBaek/pytorch_geometric
InnerProductDecoder
false
17,501
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
L2Normalization
import torch import torch.nn as nn class L2Normalization(nn.Module): def __init__(self): super(L2Normalization, self).__init__() def forward(self, x): div = torch.sqrt(torch.sum(x * x, 1)) x = (x.T / (div + 1e-10)).T return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_sqrt_sum_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 64 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 % 4 x2 = xindex // 4 % 4 x3 = xindex // 16 y0 = yindex x4 = xindex % 16 x5 = xindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x3 + 16 * x2 + 64 * x1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (x4 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x4 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x4 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x4 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-10 tmp14 = tmp12 + tmp13 tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + (x5 + 64 * y0), tmp15, xmask & ymask) @triton.jit def triton_poi_fused_add_div_mul_permute_sqrt_sum_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 64 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 % 4 x2 = xindex // 4 % 4 x3 = xindex // 16 y0 = yindex x4 = xindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x3 + 16 * x2 + 64 * x1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x4 + 64 * y0), tmp0, xmask & ymask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mul_sqrt_sum_0[grid(4, 64)](arg0_1, buf0, 4, 64, XBLOCK=32, YBLOCK=4, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mul_permute_sqrt_sum_1[grid(4, 64)](buf0, buf1, 4, 64, XBLOCK=32, YBLOCK=4, num_warps=4, num_stages=1) del buf0 return buf1, class L2NormalizationNew(nn.Module): def __init__(self): super(L2NormalizationNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Jiangtong-Li/ZHSIR
L2Normalization
false
17,502
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
_DSH_loss
import torch import torch.nn as nn class _DSH_loss(nn.Module): def __init__(self, gamma=1): super(_DSH_loss, self).__init__() self.gamma = gamma self.d = nn.PairwiseDistance() def forward(self, sk_feat, im_feat, bs, bi): """ :param sk_feat: features of sketches. bs * m. :param im_feat: features of images. bs * m. :param bs: hash codes of sketches. bs * m. :param bi: hash codes of images. bs * m. :return: loss """ return torch.mean(self.d(sk_feat, bs) ** 2 + self.d(im_feat, bi) ** 2 ) * self.gamma def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_per_fused_add_mean_mul_norm_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp18 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp26 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last') tmp27 = tl.load(in_ptr3 + 4 * r0, None, eviction_policy='evict_last') tmp31 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp32 = tl.load(in_ptr3 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp37 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp38 = tl.load(in_ptr3 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp43 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp44 = tl.load(in_ptr3 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = 1e-06 tmp4 = tmp2 + tmp3 tmp5 = tmp4 * tmp4 tmp8 = tmp6 - tmp7 tmp9 = tmp8 + tmp3 tmp10 = tmp9 * tmp9 tmp11 = tmp5 + tmp10 tmp14 = tmp12 - tmp13 tmp15 = tmp14 + tmp3 tmp16 = tmp15 * tmp15 tmp17 = tmp11 + tmp16 tmp20 = tmp18 - tmp19 tmp21 = tmp20 + tmp3 tmp22 = tmp21 * tmp21 tmp23 = tmp17 + tmp22 tmp24 = libdevice.sqrt(tmp23) tmp25 = tmp24 * tmp24 tmp28 = tmp26 - tmp27 tmp29 = tmp28 + tmp3 tmp30 = tmp29 * tmp29 tmp33 = tmp31 - tmp32 tmp34 = tmp33 + tmp3 tmp35 = tmp34 * tmp34 tmp36 = tmp30 + tmp35 tmp39 = tmp37 - tmp38 tmp40 = tmp39 + tmp3 tmp41 = tmp40 * tmp40 tmp42 = tmp36 + tmp41 tmp45 = tmp43 - tmp44 tmp46 = tmp45 + tmp3 tmp47 = tmp46 * tmp46 tmp48 = tmp42 + tmp47 tmp49 = libdevice.sqrt(tmp48) tmp50 = tmp49 * tmp49 tmp51 = tmp25 + tmp50 tmp52 = tl.broadcast_to(tmp51, [XBLOCK, RBLOCK]) tmp54 = tl.sum(tmp52, 1)[:, None] tmp55 = 64.0 tmp56 = tmp54 / tmp55 tmp57 = 1.0 tmp58 = tmp56 * tmp57 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp58, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_mean_mul_norm_pow_sub_0[grid(1)](buf2, arg1_1, arg0_1, arg3_1, arg2_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 return buf2, class _DSH_lossNew(nn.Module): def __init__(self, gamma=1): super(_DSH_lossNew, self).__init__() self.gamma = gamma self.d = nn.PairwiseDistance() def forward(self, input_0, input_1, input_2, input_3): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 output = call([arg0_1, arg1_1, arg2_1, arg3_1]) return output[0]
Jiangtong-Li/ZHSIR
_DSH_loss
false
17,503
[ "Apache-2.0" ]
8
fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
https://github.com/Jiangtong-Li/ZHSIR/tree/fd2c0a7e79f22cbf565ccd5e13342f1b317ac9b7
Net
import torch import torch.nn as tnn class Net(tnn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = tnn.Conv2d(3, 6, 5) self.pool = tnn.MaxPool2d(2, 2) self.conv2 = tnn.Conv2d(6, 16, 5) self.fc1 = tnn.Linear(16 * 5 * 5, 120) self.fc2 = tnn.Linear(120, 84) self.fc3 = tnn.Linear(84, 10) def forward(self, x): x = self.pool(self.conv1(x)) x = self.pool(self.conv2(x)) x = x.view(-1, 16 * 5 * 5) x = self.fc1(x) x = self.fc2(x) x = self.fc3(x) return x def get_inputs(): return [torch.rand([4, 3, 32, 32])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as tnn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 18816 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 6 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4704 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 14 x3 = xindex // 14 x2 = xindex // 1176 x4 = xindex % 1176 tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x3), xmask, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x4 + 1184 * x2), tmp6, xmask) tl.store(out_ptr1 + (x4 + 1280 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 6400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 100 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 20 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 20 * x1), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (10 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (11 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x2, tmp15, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) 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, (6, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_2, (6,), (1,)) assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1)) assert_size_stride(primals_4, (16, 6, 5, 5), (150, 25, 5, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (120, 400), (400, 1)) assert_size_stride(primals_7, (120,), (1,)) assert_size_stride(primals_8, (84, 120), (120, 1)) assert_size_stride(primals_9, (84,), (1,)) assert_size_stride(primals_10, (10, 84), (84, 1)) assert_size_stride(primals_11, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 6, 28, 28), (4704, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(18816)](buf1, primals_2, 18816, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 6, 14, 14), (1184, 196, 14, 1), torch .float32) buf3 = empty_strided_cuda((4, 6, 14, 14), (1280, 196, 14, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_1[grid(4704)](buf1, buf2, buf3, 4704, XBLOCK=128, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 16, 10, 10), (1600, 100, 10, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(6400)](buf5, primals_5, 6400, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.int8) buf7 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.float32 ) triton_poi_fused_max_pool2d_with_indices_3[grid(1600)](buf5, buf6, buf7, 1600, XBLOCK=128, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 120), (120, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf7, (4, 400), (400, 1), 0), reinterpret_tensor(primals_6, (400, 120), (1, 400 ), 0), alpha=1, beta=1, out=buf8) del primals_7 buf9 = empty_strided_cuda((4, 84), (84, 1), torch.float32) extern_kernels.addmm(primals_9, buf8, reinterpret_tensor(primals_8, (120, 84), (1, 120), 0), alpha=1, beta=1, out=buf9) del primals_9 buf10 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_11, buf9, reinterpret_tensor( primals_10, (84, 10), (1, 84), 0), alpha=1, beta=1, out=buf10) del primals_11 return (buf10, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 400), (400, 1), 0), buf8, buf9, primals_10, primals_8, primals_6) class NetNew(tnn.Module): def __init__(self): super(NetNew, self).__init__() self.conv1 = tnn.Conv2d(3, 6, 5) self.pool = tnn.MaxPool2d(2, 2) self.conv2 = tnn.Conv2d(6, 16, 5) self.fc1 = tnn.Linear(16 * 5 * 5, 120) self.fc2 = tnn.Linear(120, 84) self.fc3 = tnn.Linear(84, 10) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_10 = self.fc3.weight primals_11 = 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]) return output[0]
Jittor/Jittor
Net
false
17,504
[ "Apache-2.0" ]
4
bc945bae94bded917214b0afe12be6bf5b919dbe
https://github.com/Jittor/Jittor/tree/bc945bae94bded917214b0afe12be6bf5b919dbe
IdentityMessage
import torch import torch.fx import torch.utils.data class IdentityMessage(torch.nn.Module): def __init__(self, raw_msg_dim: 'int', memory_dim: 'int', time_dim: 'int'): super(IdentityMessage, self).__init__() self.out_channels = raw_msg_dim + 2 * memory_dim + time_dim def forward(self, z_src, z_dst, raw_msg, t_enc): return torch.cat([z_src, z_dst, raw_msg, t_enc], dim=-1) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'raw_msg_dim': 4, 'memory_dim': 4, 'time_dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.fx import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr2 + (4 * x1 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp19 = tl.load(in_ptr3 + (4 * x1 + (-12 + x0)), tmp16 & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tl.where(tmp14, tmp15, tmp19) tmp21 = tl.where(tmp9, tmp10, tmp20) tmp22 = tl.where(tmp4, tmp5, tmp21) tl.store(out_ptr0 + x2, tmp22, xmask) def call(args): arg0_1, arg1_1, arg2_1, arg3_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch. float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(1024)](arg0_1, arg1_1, arg2_1, arg3_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 return buf0, class IdentityMessageNew(torch.nn.Module): def __init__(self, raw_msg_dim: 'int', memory_dim: 'int', time_dim: 'int'): super(IdentityMessageNew, self).__init__() self.out_channels = raw_msg_dim + 2 * memory_dim + time_dim def forward(self, input_0, input_1, input_2, input_3): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 output = call([arg0_1, arg1_1, arg2_1, arg3_1]) return output[0]
JinheonBaek/pytorch_geometric
IdentityMessage
false
17,505
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
HardSwish
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F from torch.nn import functional as F def hard_swish(x, inplace: 'bool'=False): inner = F.relu6(x + 3.0).div_(6.0) return x.mul_(inner) if inplace else x.mul(inner) class HardSwish(nn.Module): def __init__(self, inplace: 'bool'=False): super(HardSwish, self).__init__() self.inplace = inplace def forward(self, x): return hard_swish(x, self.inplace) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F 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_add_div_hardtanh_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 3.0 tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 6.0 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = 0.16666666666666666 tmp8 = tmp6 * tmp7 tmp9 = tmp0 * tmp8 tl.store(out_ptr0 + x0, tmp9, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_hardtanh_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, def hard_swish(x, inplace: 'bool'=False): inner = F.relu6(x + 3.0).div_(6.0) return x.mul_(inner) if inplace else x.mul(inner) class HardSwishNew(nn.Module): def __init__(self, inplace: 'bool'=False): super(HardSwishNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
BigFishMaster/tnt
HardSwish
false
17,506
[ "BSD-3-Clause" ]
3
8b80bb3b194eb87ac18924428ef0924c2fb263c5
https://github.com/BigFishMaster/tnt/tree/8b80bb3b194eb87ac18924428ef0924c2fb263c5
MessageNorm
import torch from torch import Tensor import torch.nn.functional as F from torch.nn import Parameter import torch.fx import torch.utils.data from inspect import Parameter from torch.nn.parameter import Parameter class MessageNorm(torch.nn.Module): """Applies message normalization over the aggregated messages as described in the `"DeeperGCNs: All You Need to Train Deeper GCNs" <https://arxiv.org/abs/2006.07739>`_ paper .. math:: \\mathbf{x}_i^{\\prime} = \\mathrm{MLP} \\left( \\mathbf{x}_{i} + s \\cdot {\\| \\mathbf{x}_i \\|}_2 \\cdot \\frac{\\mathbf{m}_{i}}{{\\|\\mathbf{m}_i\\|}_2} \\right) Args: learn_scale (bool, optional): If set to :obj:`True`, will learn the scaling factor :math:`s` of message normalization. (default: :obj:`False`) """ def __init__(self, learn_scale: 'bool'=False): super(MessageNorm, self).__init__() self.scale = Parameter(torch.Tensor([1.0]), requires_grad=learn_scale) def reset_parameters(self): self.scale.data.fill_(1.0) def forward(self, x: 'Tensor', msg: 'Tensor', p: 'int'=2): """""" msg = F.normalize(msg, p=p, dim=-1) x_norm = x.norm(p=p, dim=-1, keepdim=True) return msg * x_norm * self.scale def __repr__(self): return '{}(learn_scale={})'.format(self.__class__.__name__, self. scale.requires_grad) 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 from torch.nn import Parameter import torch.fx import torch.utils.data from inspect import Parameter 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_div_linalg_vector_norm_mul_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp21 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp24 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp29 = tl.load(in_ptr2 + 0) tmp30 = tl.broadcast_to(tmp29, [XBLOCK]) tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tmp17 = tmp16 * tmp16 tmp19 = tmp18 * tmp18 tmp20 = tmp17 + tmp19 tmp22 = tmp21 * tmp21 tmp23 = tmp20 + tmp22 tmp25 = tmp24 * tmp24 tmp26 = tmp23 + tmp25 tmp27 = libdevice.sqrt(tmp26) tmp28 = tmp15 * tmp27 tmp31 = tmp28 * tmp30 tl.store(in_out_ptr0 + x2, tmp31, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_div_linalg_vector_norm_mul_0[grid(256)](buf1, arg0_1, arg1_1, arg2_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf1, class MessageNormNew(torch.nn.Module): """Applies message normalization over the aggregated messages as described in the `"DeeperGCNs: All You Need to Train Deeper GCNs" <https://arxiv.org/abs/2006.07739>`_ paper .. math:: \\mathbf{x}_i^{\\prime} = \\mathrm{MLP} \\left( \\mathbf{x}_{i} + s \\cdot {\\| \\mathbf{x}_i \\|}_2 \\cdot \\frac{\\mathbf{m}_{i}}{{\\|\\mathbf{m}_i\\|}_2} \\right) Args: learn_scale (bool, optional): If set to :obj:`True`, will learn the scaling factor :math:`s` of message normalization. (default: :obj:`False`) """ def __init__(self, learn_scale: 'bool'=False): super(MessageNormNew, self).__init__() self.scale = Parameter(torch.Tensor([1.0]), requires_grad=learn_scale) def reset_parameters(self): self.scale.data.fill_(1.0) def __repr__(self): return '{}(learn_scale={})'.format(self.__class__.__name__, self. scale.requires_grad) def forward(self, input_0, input_1): arg2_1 = self.scale arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
JinheonBaek/pytorch_geometric
MessageNorm
false
17,507
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
Attention
import math import torch import torch.nn.functional as F import torch.fx import torch.utils.data def restricted_softmax(src, dim: 'int'=-1, margin: 'float'=0.0): src_max = torch.clamp(src.max(dim=dim, keepdim=True)[0], min=0.0) out = (src - src_max).exp() out = out / (out.sum(dim=dim, keepdim=True) + (margin - src_max).exp()) return out class Attention(torch.nn.Module): def __init__(self, dropout=0): super(Attention, self).__init__() self.dropout = dropout def forward(self, query, key, value): return self.compute_attention(query, key, value) def compute_attention(self, query, key, value): assert query.dim() == key.dim() == value.dim() >= 2 assert query.size(-1) == key.size(-1) assert key.size(-2) == value.size(-2) score = torch.matmul(query, key.transpose(-2, -1)) score = score / math.sqrt(key.size(-1)) score = restricted_softmax(score, dim=-1) score = F.dropout(score, p=self.dropout, training=self.training) return torch.matmul(score, value) def __repr__(self): return '{}(dropout={})'.format(self.__class__.__name__, self.dropout) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import math import torch.nn.functional as F import torch.fx 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_clamp_div_exp_max_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = 0.0 tmp15 = triton_helpers.maximum(tmp13, tmp14) tmp16 = tmp2 - tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x2, tmp17, xmask) @triton.jit def triton_poi_fused_add_clamp_div_exp_max_rsub_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 + 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') tmp7 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp11 = tmp10 * tmp8 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp14 = tmp13 * tmp8 tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp17 = tmp16 * tmp8 tmp18 = triton_helpers.maximum(tmp15, tmp17) tmp19 = 0.0 tmp20 = triton_helpers.maximum(tmp18, tmp19) tmp21 = tmp19 - tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = tmp6 + tmp22 tl.store(out_ptr0 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_add_clamp_div_exp_max_rsub_sum_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, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (16, 4, 4), (16, 4, 1 ), 0), reinterpret_tensor(arg1_1, (16, 4, 4), (16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_div_exp_max_sub_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_clamp_div_exp_max_rsub_sum_1[grid(64)](buf1, buf0, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf1 del buf1 triton_poi_fused_add_clamp_div_exp_max_rsub_sum_2[grid(256)](buf3, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 buf4 = buf0 del buf0 extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1), 0), out=buf4 ) del arg2_1 del buf3 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0), def restricted_softmax(src, dim: 'int'=-1, margin: 'float'=0.0): src_max = torch.clamp(src.max(dim=dim, keepdim=True)[0], min=0.0) out = (src - src_max).exp() out = out / (out.sum(dim=dim, keepdim=True) + (margin - src_max).exp()) return out class AttentionNew(torch.nn.Module): def __init__(self, dropout=0): super(AttentionNew, self).__init__() self.dropout = dropout def compute_attention(self, query, key, value): assert query.dim() == key.dim() == value.dim() >= 2 assert query.size(-1) == key.size(-1) assert key.size(-2) == value.size(-2) score = torch.matmul(query, key.transpose(-2, -1)) score = score / math.sqrt(key.size(-1)) score = restricted_softmax(score, dim=-1) score = F.dropout(score, p=self.dropout, training=self.training) return torch.matmul(score, value) def __repr__(self): return '{}(dropout={})'.format(self.__class__.__name__, self.dropout) def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
JinheonBaek/pytorch_geometric
Attention
false
17,508
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
MaxPool2dDynamicSamePadding
import math import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F from torch.nn import functional as F class MaxPool2dDynamicSamePadding(nn.MaxPool2d): """2D MaxPooling like TensorFlow's 'SAME' mode, with a dynamic image size. The padding is operated in forward function by calculating dynamically. """ def __init__(self, kernel_size, stride, padding=0, dilation=1, return_indices=False, ceil_mode=False): super().__init__(kernel_size, stride, padding, dilation, return_indices, ceil_mode) self.stride = [self.stride] * 2 if isinstance(self.stride, int ) else self.stride self.kernel_size = [self.kernel_size] * 2 if isinstance(self. kernel_size, int) else self.kernel_size self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int ) else self.dilation def forward(self, x): ih, iw = x.size()[-2:] kh, kw = self.kernel_size sh, sw = self.stride oh, ow = math.ceil(ih / sh), math.ceil(iw / sw) pad_h = max((oh - 1) * self.stride[0] + (kh - 1) * self.dilation[0] + 1 - ih, 0) pad_w = max((ow - 1) * self.stride[1] + (kw - 1) * self.dilation[1] + 1 - iw, 0) if pad_h > 0 or pad_w > 0: x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2]) return F.max_pool2d(x, self.kernel_size, self.stride, self.padding, self.dilation, self.ceil_mode, self.return_indices) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4, 'stride': 1}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_pool2d_with_indices_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 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x4), tmp10 & xmask, other=0.0) tmp12 = x0 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp8 & tmp13 tmp16 = tmp15 & tmp14 tmp17 = tl.load(in_ptr0 + (-4 + x4), tmp16 & xmask, other=0.0) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp8 & tmp20 tmp23 = tmp22 & tmp21 tmp24 = tl.load(in_ptr0 + (-3 + x4), tmp23 & xmask, other=0.0) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 + x0 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp8 & tmp27 tmp30 = tmp29 & tmp28 tmp31 = tl.load(in_ptr0 + (-2 + x4), tmp30 & xmask, other=0.0) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = x1 tmp34 = tmp33 >= tmp1 tmp35 = tmp33 < tmp3 tmp36 = tmp34 & tmp35 tmp37 = tmp36 & tmp6 tmp38 = tmp37 & tmp7 tmp39 = tl.load(in_ptr0 + (-1 + x4), tmp38 & xmask, other=0.0) tmp40 = triton_helpers.maximum(tmp39, tmp32) tmp41 = tmp36 & tmp13 tmp42 = tmp41 & tmp14 tmp43 = tl.load(in_ptr0 + x4, tmp42 & xmask, other=0.0) tmp44 = triton_helpers.maximum(tmp43, tmp40) tmp45 = tmp36 & tmp20 tmp46 = tmp45 & tmp21 tmp47 = tl.load(in_ptr0 + (1 + x4), tmp46 & xmask, other=0.0) tmp48 = triton_helpers.maximum(tmp47, tmp44) tmp49 = tmp36 & tmp27 tmp50 = tmp49 & tmp28 tmp51 = tl.load(in_ptr0 + (2 + x4), tmp50 & xmask, other=0.0) tmp52 = triton_helpers.maximum(tmp51, tmp48) tmp53 = 1 + x1 tmp54 = tmp53 >= tmp1 tmp55 = tmp53 < tmp3 tmp56 = tmp54 & tmp55 tmp57 = tmp56 & tmp6 tmp58 = tmp57 & tmp7 tmp59 = tl.load(in_ptr0 + (3 + x4), tmp58 & xmask, other=0.0) tmp60 = triton_helpers.maximum(tmp59, tmp52) tmp61 = tmp56 & tmp13 tmp62 = tmp61 & tmp14 tmp63 = tl.load(in_ptr0 + (4 + x4), tmp62 & xmask, other=0.0) tmp64 = triton_helpers.maximum(tmp63, tmp60) tmp65 = tmp56 & tmp20 tmp66 = tmp65 & tmp21 tmp67 = tl.load(in_ptr0 + (5 + x4), tmp66 & xmask, other=0.0) tmp68 = triton_helpers.maximum(tmp67, tmp64) tmp69 = tmp56 & tmp27 tmp70 = tmp69 & tmp28 tmp71 = tl.load(in_ptr0 + (6 + x4), tmp70 & xmask, other=0.0) tmp72 = triton_helpers.maximum(tmp71, tmp68) tmp73 = 2 + x1 tmp74 = tmp73 >= tmp1 tmp75 = tmp73 < tmp3 tmp76 = tmp74 & tmp75 tmp77 = tmp76 & tmp6 tmp78 = tmp77 & tmp7 tmp79 = tl.load(in_ptr0 + (7 + x4), tmp78 & xmask, other=0.0) tmp80 = triton_helpers.maximum(tmp79, tmp72) tmp81 = tmp76 & tmp13 tmp82 = tmp81 & tmp14 tmp83 = tl.load(in_ptr0 + (8 + x4), tmp82 & xmask, other=0.0) tmp84 = triton_helpers.maximum(tmp83, tmp80) tmp85 = tmp76 & tmp20 tmp86 = tmp85 & tmp21 tmp87 = tl.load(in_ptr0 + (9 + x4), tmp86 & xmask, other=0.0) tmp88 = triton_helpers.maximum(tmp87, tmp84) tmp89 = tmp76 & tmp27 tmp90 = tmp89 & tmp28 tmp91 = tl.load(in_ptr0 + (10 + x4), tmp90 & xmask, other=0.0) tmp92 = triton_helpers.maximum(tmp91, tmp88) tl.store(out_ptr0 + x4, tmp92, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_pool2d_with_indices_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class MaxPool2dDynamicSamePaddingNew(nn.MaxPool2d): """2D MaxPooling like TensorFlow's 'SAME' mode, with a dynamic image size. The padding is operated in forward function by calculating dynamically. """ def __init__(self, kernel_size, stride, padding=0, dilation=1, return_indices=False, ceil_mode=False): super().__init__(kernel_size, stride, padding, dilation, return_indices, ceil_mode) self.stride = [self.stride] * 2 if isinstance(self.stride, int ) else self.stride self.kernel_size = [self.kernel_size] * 2 if isinstance(self. kernel_size, int) else self.kernel_size self.dilation = [self.dilation] * 2 if isinstance(self.dilation, int ) else self.dilation def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
BigFishMaster/tnt
MaxPool2dDynamicSamePadding
false
17,509
[ "BSD-3-Clause" ]
3
8b80bb3b194eb87ac18924428ef0924c2fb263c5
https://github.com/BigFishMaster/tnt/tree/8b80bb3b194eb87ac18924428ef0924c2fb263c5
StdConv2d
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F from torch.nn import functional as F class StdConv2d(nn.Conv2d): def forward(self, x): w = self.weight s = w.std(dim=[1, 2, 3], keepdim=True) m = w.mean(dim=[1, 2, 3], keepdim=True) v = s * s w = (w - m) / torch.sqrt(v + 1e-10) return F.conv2d(x, w, self.bias, self.stride, self.padding, self. dilation, self.groups) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice 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_per_fused_add_div_mean_mul_sqrt_std_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = 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] tmp18 = tl.sum(tmp3, 1)[:, None] tmp19 = 63.0 tmp20 = tmp16 / tmp19 tmp21 = libdevice.sqrt(tmp20) tmp22 = 64.0 tmp23 = tmp18 / tmp22 tmp24 = tmp0 - tmp23 tmp25 = tmp21 * tmp21 tmp26 = 1e-10 tmp27 = tmp25 + tmp26 tmp28 = libdevice.sqrt(tmp27) tmp29 = tmp24 / tmp28 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp23, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp29, 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,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf4 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf3 = reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf1 buf5 = reinterpret_tensor(buf4, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf4 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_sqrt_std_sub_0[grid(4)](buf3, buf5, primals_1, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf7 = extern_kernels.convolution(primals_3, buf6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 1, 1), (4, 1, 1, 1)) buf8 = buf7 del buf7 triton_poi_fused_convolution_1[grid(16)](buf8, primals_2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf8, primals_1, primals_3, buf3, buf5, buf6 class StdConv2dNew(nn.Conv2d): 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]
BigFishMaster/tnt
StdConv2d
false
17,510
[ "BSD-3-Clause" ]
3
8b80bb3b194eb87ac18924428ef0924c2fb263c5
https://github.com/BigFishMaster/tnt/tree/8b80bb3b194eb87ac18924428ef0924c2fb263c5
ShiftedSoftplus
import torch import torch.nn.functional as F import torch.fx import torch.utils.data class ShiftedSoftplus(torch.nn.Module): def __init__(self): super(ShiftedSoftplus, self).__init__() self.shift = torch.log(torch.tensor(2.0)).item() def forward(self, x): return F.softplus(x) - self.shift def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.fx 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_softplus_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 20.0 tmp2 = tmp0 > tmp1 tmp3 = tl_math.exp(tmp0) tmp4 = libdevice.log1p(tmp3) tmp5 = tl.where(tmp2, tmp0, tmp4) tmp6 = 0.6931471824645996 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_softplus_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class ShiftedSoftplusNew(torch.nn.Module): def __init__(self): super(ShiftedSoftplusNew, self).__init__() self.shift = torch.log(torch.tensor(2.0)).item() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
JinheonBaek/pytorch_geometric
ShiftedSoftplus
false
17,511
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
Hidden2Normal
import torch class Hidden2Normal(torch.nn.Module): def __init__(self, hidden_dim): super(Hidden2Normal, self).__init__() self.linear = torch.nn.Linear(hidden_dim, 5) def forward(self, hidden_state): normal = self.linear(hidden_state) normal[:, 2] = 0.01 + 0.2 * torch.sigmoid(normal[:, 2]) normal[:, 3] = 0.01 + 0.2 * torch.sigmoid(normal[:, 3]) normal[:, 4] = 0.7 * torch.sigmoid(normal[:, 4]) return normal def get_inputs(): return [torch.rand([4, 5, 4, 4])] def get_init_inputs(): return [[], {'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 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_copy_mul_sigmoid_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 20 % 5 x0 = xindex % 20 x2 = xindex // 100 x3 = xindex tmp3 = tl.load(in_ptr0 + (40 + x0 + 100 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + x3, xmask) tmp0 = x1 tmp1 = tl.full([1], 2, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = 0.2 tmp6 = tmp4 * tmp5 tmp7 = 0.01 tmp8 = tmp6 + tmp7 tmp10 = tl.where(tmp2, tmp8, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_select_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 % 4 x2 = xindex // 20 x3 = xindex tmp0 = tl.load(in_ptr0 + (60 + x0 + 5 * x1 + 100 * x2 + 100 * ((12 + x1 ) // 20)), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_add_copy_mul_sigmoid_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 20 % 5 x3 = xindex // 100 x4 = xindex % 20 x6 = xindex tmp3 = tl.load(in_ptr0 + (x4 + 20 * x3), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr1 + x6, xmask) tmp0 = x2 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = 0.2 tmp6 = tmp4 * tmp5 tmp7 = 0.01 tmp8 = tmp6 + tmp7 tmp10 = tl.where(tmp2, tmp8, tmp9) tl.store(out_ptr0 + x6, tmp10, xmask) @triton.jit def triton_poi_fused_select_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 % 4 x2 = xindex // 20 x3 = xindex tmp0 = tl.load(in_ptr0 + (80 + x0 + 5 * x1 + 100 * x2 + 100 * ((16 + x1 ) // 20)), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_copy_mul_sigmoid_4(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 20 % 5 x3 = xindex // 100 x5 = xindex % 20 x6 = xindex tmp3 = tl.load(in_ptr0 + (x5 + 20 * x3), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr1 + x6, xmask) tmp0 = x2 tmp1 = tl.full([1], 4, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = 0.7 tmp6 = tmp4 * tmp5 tmp8 = tl.where(tmp2, tmp6, tmp7) tl.store(in_out_ptr0 + x6, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (5, 4), (4, 1)) assert_size_stride(primals_2, (5,), (1,)) assert_size_stride(primals_3, (4, 5, 4, 4), (80, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((80, 5), (5, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (80, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 5), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 5, 4, 5), (100, 20, 5, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_copy_mul_sigmoid_0[grid(400)](buf0, buf1, 400, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32) triton_poi_fused_select_1[grid(80)](buf1, buf2, 80, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 5, 4, 5), (100, 20, 5, 1), torch.float32) triton_poi_fused_add_copy_mul_sigmoid_2[grid(400)](buf2, buf1, buf3, 400, XBLOCK=256, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((4, 4, 5), (20, 5, 1), torch.float32) triton_poi_fused_select_3[grid(80)](buf3, buf4, 80, XBLOCK=128, num_warps=4, num_stages=1) buf5 = buf1 del buf1 buf6 = buf5 del buf5 triton_poi_fused_copy_mul_sigmoid_4[grid(400)](buf6, buf4, buf3, 400, XBLOCK=256, num_warps=4, num_stages=1) del buf3 return buf6, reinterpret_tensor(primals_3, (80, 4), (4, 1), 0 ), reinterpret_tensor(buf0, (4, 4, 5), (100, 5, 1), 40), buf2, buf4 class Hidden2NormalNew(torch.nn.Module): def __init__(self, hidden_dim): super(Hidden2NormalNew, self).__init__() self.linear = torch.nn.Linear(hidden_dim, 5) def forward(self, input_0): primals_1 = self.linear.weight primals_2 = self.linear.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JosephGesnouin/Asymmetrical-Bi-RNNs-to-encode-pedestrian-trajectories
Hidden2Normal
false
17,512
[ "MIT" ]
9
488924e938fc1674b5a0d2cb9f05178cad8de561
https://github.com/JosephGesnouin/Asymmetrical-Bi-RNNs-to-encode-pedestrian-trajectories/tree/488924e938fc1674b5a0d2cb9f05178cad8de561
Envelope
import torch import torch.fx import torch.utils.data class Envelope(torch.nn.Module): def __init__(self, exponent): super(Envelope, self).__init__() self.p = exponent + 1 self.a = -(self.p + 1) * (self.p + 2) / 2 self.b = self.p * (self.p + 2) self.c = -self.p * (self.p + 1) / 2 def forward(self, x): p, a, b, c = self.p, self.a, self.b, self.c x_pow_p0 = x.pow(p - 1) x_pow_p1 = x_pow_p0 * x x_pow_p2 = x_pow_p1 * x return 1.0 / x + a * x_pow_p0 + b * x_pow_p1 + c * x_pow_p2 def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'exponent': 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.fx import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_pow_reciprocal_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], 1, tl.int32) tmp2 = tmp1 / tmp0 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tmp5 = tmp0 * tmp0 tmp6 = tmp5 * tmp5 tmp7 = -21.0 tmp8 = tmp6 * tmp7 tmp9 = tmp4 + tmp8 tmp10 = tmp6 * tmp0 tmp11 = 35.0 tmp12 = tmp10 * tmp11 tmp13 = tmp9 + tmp12 tmp14 = tmp10 * tmp0 tmp15 = -15.0 tmp16 = tmp14 * tmp15 tmp17 = tmp13 + tmp16 tl.store(out_ptr0 + x0, tmp17, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_pow_reciprocal_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class EnvelopeNew(torch.nn.Module): def __init__(self, exponent): super(EnvelopeNew, self).__init__() self.p = exponent + 1 self.a = -(self.p + 1) * (self.p + 2) / 2 self.b = self.p * (self.p + 2) self.c = -self.p * (self.p + 1) / 2 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
JinheonBaek/pytorch_geometric
Envelope
false
17,513
[ "MIT" ]
4
dfd32d08a3d8191d6290e53458d4eda515d04fd6
https://github.com/JinheonBaek/pytorch_geometric/tree/dfd32d08a3d8191d6290e53458d4eda515d04fd6
LinearSQ
import math import torch from torch import Tensor import torch.nn as nn from torch.nn.parameter import Parameter from torch.nn import functional as F class LinearSQ(nn.Module): __constants__ = ['in_features', 'out_features'] in_features: 'int' out_features: 'int' weight: 'Tensor' def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True) ->None: super(LinearSQ, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self) ->None: nn.init.kaiming_uniform_(self.weight, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def forward(self, input: 'Tensor') ->Tensor: return F.linear(input, self.weight ** 2, self.bias) def extra_repr(self) ->str: return 'in_features={}, out_features={}, bias={}'.format(self. in_features, self.out_features, self.bias is not None) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math from torch import Tensor 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_pow_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 * tmp0 tl.store(out_ptr0 + x0, tmp1, 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_pow_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1) del buf0 del primals_2 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0) class LinearSQNew(nn.Module): __constants__ = ['in_features', 'out_features'] in_features: 'int' out_features: 'int' weight: 'Tensor' def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True) ->None: super(LinearSQNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self) ->None: nn.init.kaiming_uniform_(self.weight, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def extra_repr(self) ->str: return 'in_features={}, out_features={}, bias={}'.format(self. in_features, self.out_features, self.bias is not None) 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]
June01/WFSAL-icmr21
LinearSQ
false
17,514
[ "MIT" ]
9
86fd6e9e34483ea17e088e4c1ee8f66edf3aecce
https://github.com/June01/WFSAL-icmr21/tree/86fd6e9e34483ea17e088e4c1ee8f66edf3aecce
MyAdd
import torch from torch import nn import torch.nn.parallel import torch.optim import torch.utils.data class MyAdd(nn.Module): def __init__(self, size): super(MyAdd, self).__init__() self.weight = nn.Parameter(torch.rand(size)) def forward(self, x): out = x + self.weight return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.nn.parallel import torch.optim import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, class MyAddNew(nn.Module): def __init__(self, size): super(MyAddNew, self).__init__() self.weight = nn.Parameter(torch.rand(size)) def forward(self, input_0): primals_1 = self.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
JurijsNazarovs/bayesian_nn
MyAdd
false
17,515
[ "MIT" ]
6
936bf55e0a1e620504d5159c100a74493bd16399
https://github.com/JurijsNazarovs/bayesian_nn/tree/936bf55e0a1e620504d5159c100a74493bd16399
MetricCELoss
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F from torch.nn import functional as F class MetricCELoss(nn.Module): """ Cross-entropy loss for metric learning with a specified feature size. In addition, there exists a ReLU layer to pre-process the input feature. Args: feature_size (int): usually 128, 256, 512 ... num_classes (int): num of classes when training """ def __init__(self, feature_size, num_classes): super(MetricCELoss, self).__init__() self.in_features = feature_size self.out_features = num_classes self.weight = nn.Parameter(torch.FloatTensor(self.out_features, self.in_features)) nn.init.xavier_uniform_(self.weight) self.ce = nn.CrossEntropyLoss() def output(self, feature): """ Output the logit. Args: feature (:obj:`torch.FloatTensor`): image features from previous layers. Returns: :obj:`torch.FloatTensor`: logit """ output = F.linear(F.relu(feature), self.weight) return output def forward(self, feature, label): """ Calculate MetricCE loss. Args: feature (:obj:`torch.FloatTensor`): image features from previous layers. label (:obj:`torch.LongTensor`): image labels. Returns: (:obj:`torch.FloatTensor`, :obj:`torch.FloatTensor`): * loss: MetricCE loss over the batch. * logit: logit output after ReLU. """ output = self.output(feature) loss = self.ce(output, label) return loss, output def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'feature_size': 4, 'num_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torchvision.transforms.functional as F 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @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__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_per_fused__log_softmax_div_mul_neg_sum_2(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 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 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_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](buf1, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused__log_softmax_div_mul_neg_sum_2[grid(1)](buf4, buf2, primals_3, 1, 256, num_warps=2, num_stages=1) del buf2 return buf4, reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_3, reinterpret_tensor(buf0, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) class MetricCELossNew(nn.Module): """ Cross-entropy loss for metric learning with a specified feature size. In addition, there exists a ReLU layer to pre-process the input feature. Args: feature_size (int): usually 128, 256, 512 ... num_classes (int): num of classes when training """ def __init__(self, feature_size, num_classes): super(MetricCELossNew, self).__init__() self.in_features = feature_size self.out_features = num_classes self.weight = nn.Parameter(torch.FloatTensor(self.out_features, self.in_features)) nn.init.xavier_uniform_(self.weight) self.ce = nn.CrossEntropyLoss() def output(self, feature): """ Output the logit. Args: feature (:obj:`torch.FloatTensor`): image features from previous layers. Returns: :obj:`torch.FloatTensor`: logit """ output = F.linear(F.relu(feature), self.weight) return output def forward(self, input_0, input_1): primals_2 = self.weight primals_1 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
BigFishMaster/tnt
MetricCELoss
false
17,516
[ "BSD-3-Clause" ]
3
8b80bb3b194eb87ac18924428ef0924c2fb263c5
https://github.com/BigFishMaster/tnt/tree/8b80bb3b194eb87ac18924428ef0924c2fb263c5
CosineLinear
from torch.nn import Module import math import torch from torch.nn.parameter import Parameter from torch.nn import functional as F import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed from torch.nn.modules.module import Module class CosineLinear(Module): def __init__(self, in_features, out_features, sigma=True): super(CosineLinear, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if sigma: self.sigma = Parameter(torch.Tensor(1)) else: self.register_parameter('sigma', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.sigma is not None: self.sigma.data.fill_(1) def forward(self, input): out = F.linear(F.normalize(input, p=2, dim=1), F.normalize(self. weight, p=2, dim=1)) if self.sigma is not None: out = self.sigma * out return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch.nn import Module import math from torch.nn.parameter import Parameter import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed from torch.nn.modules.module import Module assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x3, tmp15, xmask) @triton.jit def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_1[grid(16)](primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2) del buf1 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_2[grid(256)](primals_3, buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf3, primals_2, primals_3, reinterpret_tensor(buf0, (64, 4), (4, 1), 0), buf2 class CosineLinearNew(Module): def __init__(self, in_features, out_features, sigma=True): super(CosineLinearNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if sigma: self.sigma = Parameter(torch.Tensor(1)) else: self.register_parameter('sigma', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.sigma is not None: self.sigma.data.fill_(1) def forward(self, input_0): primals_2 = self.weight primals_3 = self.sigma primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JosephKJ/class-incremental-learning
CosineLinear
false
17,517
[ "MIT" ]
8
689271b84f2e553930ca6687d036ac99bd84b311
https://github.com/JosephKJ/class-incremental-learning/tree/689271b84f2e553930ca6687d036ac99bd84b311
Conv2dMtl
from torch.nn import Module import math import torch from torch.nn.parameter import Parameter from torch.nn import functional as F import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed from torch.nn.modules.module import Module from torch.nn.modules.utils import _pair class _ConvNdMtl(Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias): super(_ConvNdMtl, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups if transposed: self.weight = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(in_channels, out_channels // groups, 1, 1)) else: self.weight = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(out_channels, in_channels // groups, 1, 1)) self.weight.requires_grad = False if bias: self.bias = Parameter(torch.Tensor(out_channels)) self.bias.requires_grad = False self.mtl_bias = Parameter(torch.zeros(out_channels)) else: self.register_parameter('bias', None) self.register_parameter('mtl_bias', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels for k in self.kernel_size: n *= k stdv = 1.0 / math.sqrt(n) self.weight.data.uniform_(-stdv, stdv) self.mtl_weight.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) self.mtl_bias.data.uniform_(0, 0) def extra_repr(self): s = ( '{in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is None: s += ', bias=False' return s.format(**self.__dict__) class Conv2dMtl(_ConvNdMtl): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(Conv2dMtl, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias) def forward(self, input): new_mtl_weight = self.mtl_weight.expand(self.weight.shape) new_weight = self.weight.mul(new_mtl_weight) if self.bias is not None: new_bias = self.bias + self.mtl_bias else: new_bias = None return F.conv2d(input, new_weight, new_bias, self.stride, self. padding, self.dilation, self.groups) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch.nn import Module import math from torch.nn.parameter import Parameter import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed from torch.nn.modules.module import Module from torch.nn.modules.utils import _pair assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_add_convolution_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_add_convolution_1[grid(4)](primals_3, primals_4, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 del primals_4 buf2 = extern_kernels.convolution(primals_5, buf0, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_2[grid(16)](buf3, buf1, 16, XBLOCK =16, num_warps=1, num_stages=1) del buf1 return buf3, primals_2, primals_5, buf0 class _ConvNdMtl(Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias): super(_ConvNdMtl, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups if transposed: self.weight = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(in_channels, out_channels // groups, 1, 1)) else: self.weight = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.mtl_weight = Parameter(torch.ones(out_channels, in_channels // groups, 1, 1)) self.weight.requires_grad = False if bias: self.bias = Parameter(torch.Tensor(out_channels)) self.bias.requires_grad = False self.mtl_bias = Parameter(torch.zeros(out_channels)) else: self.register_parameter('bias', None) self.register_parameter('mtl_bias', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels for k in self.kernel_size: n *= k stdv = 1.0 / math.sqrt(n) self.weight.data.uniform_(-stdv, stdv) self.mtl_weight.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) self.mtl_bias.data.uniform_(0, 0) def extra_repr(self): s = ( '{in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is None: s += ', bias=False' return s.format(**self.__dict__) class Conv2dMtlNew(_ConvNdMtl): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(Conv2dMtlNew, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias) def forward(self, input_0): primals_2 = self.weight primals_1 = self.mtl_weight primals_3 = self.bias primals_4 = self.mtl_bias primals_5 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
JosephKJ/class-incremental-learning
Conv2dMtl
false
17,518
[ "MIT" ]
8
689271b84f2e553930ca6687d036ac99bd84b311
https://github.com/JosephKJ/class-incremental-learning/tree/689271b84f2e553930ca6687d036ac99bd84b311
MyMul
import torch from torch import nn import torch.nn.parallel import torch.optim import torch.utils.data class MyMul(nn.Module): def __init__(self, size): super(MyMul, self).__init__() self.weight = nn.Parameter(torch.rand(1)) def forward(self, x): out = x * torch.abs(self.weight) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn import torch.nn.parallel import torch.optim import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl_math.abs(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, 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_abs_mul_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf0, primals_1, primals_2 class MyMulNew(nn.Module): def __init__(self, size): super(MyMulNew, self).__init__() self.weight = nn.Parameter(torch.rand(1)) def forward(self, input_0): primals_1 = self.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
JurijsNazarovs/bayesian_nn
MyMul
false
17,519
[ "MIT" ]
6
936bf55e0a1e620504d5159c100a74493bd16399
https://github.com/JurijsNazarovs/bayesian_nn/tree/936bf55e0a1e620504d5159c100a74493bd16399