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
Foo
import torch import torch.nn.parallel import torch.utils.data import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed def add_lowp(a: 'torch.Tensor', b: 'torch.Tensor'): a, b = a.float(), b.float() c = a + b return c.half() def sigmoid_lowp(x: 'torch.Tensor'): x = x.float() x = x.sigmoid() return x.half() class Foo(torch.nn.Module): def forward(self, x, y): x = sigmoid_lowp(x) y = sigmoid_lowp(y) return add_lowp(x, y) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn.parallel import torch.utils.data import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy_add_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = tl.sigmoid(tmp2) tmp4 = tmp1 + tmp3 tmp5 = tmp4.to(tl.float32) tl.store(out_ptr0 + x0, tmp5, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float16) get_raw_stream(0) triton_poi_fused__to_copy_add_sigmoid_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, def add_lowp(a: 'torch.Tensor', b: 'torch.Tensor'): a, b = a.float(), b.float() c = a + b return c.half() def sigmoid_lowp(x: 'torch.Tensor'): x = x.float() x = x.sigmoid() return x.half() class FooNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lenaguignard/examples
Foo
false
15,895
[ "BSD-3-Clause" ]
19,783
973e77b725a6028289a90170f0b237ea2e71d4f2
https://github.com/lenaguignard/examples/tree/973e77b725a6028289a90170f0b237ea2e71d4f2
DCLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class DCLoss(torch.nn.Module): """DC loss function module. See [Wright & Välimäki, 2019](https://arxiv.org/abs/1911.08922). Args: reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, reduction='mean'): super(DCLoss, self).__init__() self.reduction = reduction def forward(self, input, target): losses = ((target - input).mean(-1) ** 2).abs() / target.abs().mean(-1 ) ** 2 losses = apply_reduction(losses, self.reduction) return losses def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math 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_div_mean_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') tmp3 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp5 = tmp3 - tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 - tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 - tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp16 * tmp16 tmp18 = tl_math.abs(tmp17) tmp19 = tl_math.abs(tmp0) tmp20 = tl_math.abs(tmp3) tmp21 = tmp19 + tmp20 tmp22 = tl_math.abs(tmp7) tmp23 = tmp21 + tmp22 tmp24 = tl_math.abs(tmp11) tmp25 = tmp23 + tmp24 tmp26 = tmp25 / tmp15 tmp27 = tmp26 * tmp26 tmp28 = tmp18 / tmp27 tmp29 = tl.broadcast_to(tmp28, [XBLOCK, RBLOCK]) tmp31 = tl.sum(tmp29, 1)[:, None] tmp32 = 64.0 tmp33 = tmp31 / tmp32 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp33, 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_div_mean_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, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class DCLossNew(torch.nn.Module): """DC loss function module. See [Wright & Välimäki, 2019](https://arxiv.org/abs/1911.08922). Args: reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, reduction='mean'): super(DCLossNew, self).__init__() 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]
leoauri/auraloss
DCLoss
false
15,896
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
ChannelAttention
import torch import torch.nn as nn class ChannelAttention(nn.Module): def __init__(self, in_planes, ratio=4): super(ChannelAttention, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc1 = nn.Conv2d(in_planes, in_planes // ratio, 1, bias=False) self.relu1 = nn.ReLU() self.fc2 = nn.Conv2d(in_planes // ratio, in_planes, 1, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x)))) max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x)))) out = avg_out + max_out return self.sigmoid(out) * x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, 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.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_adaptive_max_pool2d_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp8 = triton_helpers.maximum(tmp7, tmp6) tmp10 = triton_helpers.maximum(tmp9, tmp8) tmp12 = triton_helpers.maximum(tmp11, tmp10) tmp14 = triton_helpers.maximum(tmp13, tmp12) tmp16 = triton_helpers.maximum(tmp15, tmp14) tmp18 = triton_helpers.maximum(tmp17, tmp16) tmp20 = triton_helpers.maximum(tmp19, tmp18) tmp22 = triton_helpers.maximum(tmp21, tmp20) tmp24 = triton_helpers.maximum(tmp23, tmp22) tmp26 = triton_helpers.maximum(tmp25, tmp24) tmp28 = triton_helpers.maximum(tmp27, tmp26) tmp30 = triton_helpers.maximum(tmp29, tmp28) tl.store(out_ptr0 + x0, tmp30, xmask) @triton.jit def triton_poi_fused_add_mul_sigmoid_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_add_sigmoid_sigmoid_backward_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp4 = 1.0 tmp5 = tmp4 - tmp3 tmp6 = tmp3 * tmp5 tl.store(in_out_ptr0 + x0, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4, 1, 1, 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) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 1, 1), (1, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(4)](buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_adaptive_max_pool2d_2[grid(16)](primals_1, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 1, 1, 1), (1, 1, 1, 1)) buf7 = buf6 del buf6 triton_poi_fused_relu_1[grid(4)](buf7, 4, XBLOCK=4, num_warps=1, num_stages=1) buf8 = extern_kernels.convolution(buf7, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1)) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_3[grid(256)](buf4, buf8, primals_1, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) buf10 = buf4 del buf4 triton_poi_fused_add_sigmoid_sigmoid_backward_4[grid(16)](buf10, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf8 return buf9, primals_1, primals_2, primals_3, buf1, buf3, buf5, buf7, buf10 class ChannelAttentionNew(nn.Module): def __init__(self, in_planes, ratio=4): super(ChannelAttentionNew, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc1 = nn.Conv2d(in_planes, in_planes // ratio, 1, bias=False) self.relu1 = nn.ReLU() self.fc2 = nn.Conv2d(in_planes // ratio, in_planes, 1, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc2.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lee-zq/VesselSeg-pytorch
ChannelAttention
false
15,897
[ "Apache-2.0" ]
83
b4f6571fc1fb1fbdaad60ff9282a54a1f1c455fa
https://github.com/lee-zq/VesselSeg-pytorch/tree/b4f6571fc1fb1fbdaad60ff9282a54a1f1c455fa
ScaledDotProductAttention
import torch import numpy as np import torch.nn as nn class ScaledDotProductAttention(nn.Module): def __init__(self, d_k): super(ScaledDotProductAttention, self).__init__() self.d_k = d_k def forward(self, Q, K, V, attn_mask=None): scores = torch.matmul(Q, K.transpose(-1, -2)) / np.sqrt(self.d_k) scores = torch.exp(scores) if attn_mask is not None: scores = scores * attn_mask attn = scores / (torch.sum(scores, dim=-1, keepdim=True) + 1e-08) context = torch.matmul(attn, V) return context, attn def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_k': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_exp_sqrt_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp4 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 2.0 tmp2 = tmp0 / tmp1 tmp3 = tl_math.exp(tmp2) tmp5 = tmp4 / tmp1 tmp6 = tl_math.exp(tmp5) tmp8 = tmp7 / tmp1 tmp9 = tl_math.exp(tmp8) tmp10 = tmp6 + tmp9 tmp12 = tmp11 / tmp1 tmp13 = tl_math.exp(tmp12) tmp14 = tmp10 + tmp13 tmp16 = tmp15 / tmp1 tmp17 = tl_math.exp(tmp16) tmp18 = tmp14 + tmp17 tmp19 = 1e-08 tmp20 = tmp18 + tmp19 tmp21 = tmp3 / tmp20 tl.store(out_ptr0 + x2, tmp21, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg1_1, (16, 4, 4), (16, 4, 1 ), 0), reinterpret_tensor(arg0_1, (16, 4, 4), (16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_exp_sqrt_sum_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = buf0 del buf0 extern_kernels.bmm(reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1), 0), out=buf2 ) del arg2_1 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0), buf1 class ScaledDotProductAttentionNew(nn.Module): def __init__(self, d_k): super(ScaledDotProductAttentionNew, self).__init__() self.d_k = d_k 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]
limhj159/NewsRecommendation
ScaledDotProductAttention
false
15,898
[ "MIT" ]
125
5d19566b63b6cf35b5be0c2b175c5050e51f57b8
https://github.com/limhj159/NewsRecommendation/tree/5d19566b63b6cf35b5be0c2b175c5050e51f57b8
MyElementwiseModule
import torch import torch.nn.parallel import torch.utils.data import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed class MyElementwiseModule(torch.nn.Module): def forward(self, x, y): return x * y + y def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn.parallel import torch.utils.data import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_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 + x0, xmask) tmp2 = tmp0 * tmp1 tmp3 = tmp2 + tmp1 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class MyElementwiseModuleNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lenaguignard/examples
MyElementwiseModule
false
15,899
[ "BSD-3-Clause" ]
19,783
973e77b725a6028289a90170f0b237ea2e71d4f2
https://github.com/lenaguignard/examples/tree/973e77b725a6028289a90170f0b237ea2e71d4f2
BasicBlock
import torch def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1, padding=0): """3x3 convolution with padding""" return torch.nn.Conv2d(in_planes, out_planes, kernel_size=3, stride= stride, padding=padding, groups=groups, bias=False, dilation=dilation) class BasicBlock(torch.nn.Module): expansion = 1 def __init__(self, inplanes, planes, stride=1, downsample=None, groups= 1, base_width=64, dilation=1, activation_fct='relu', norm_layer=None): super(BasicBlock, self).__init__() if groups != 1 or base_width != 64: raise ValueError( 'BasicBlock only supports groups=1 and base_width=64') if dilation > 1: raise NotImplementedError( 'Dilation > 1 not supported in BasicBlock') self.conv1 = conv3x3(in_planes=inplanes, out_planes=planes, stride= stride, padding=(1, 0)) self.activation = torch.nn.ReLU(inplace=True ) if activation_fct == 'relu' else torch.nn.Tanh() self.conv2 = conv3x3(in_planes=planes, out_planes=planes, padding=( 1, 0)) self.downsample = downsample self.stride = stride def forward(self, x): identity = x out = torch.nn.functional.pad(input=x, pad=(1, 1, 0, 0), mode= 'circular') out = self.conv1(out) out = self.activation(out) out = torch.nn.functional.pad(input=out, pad=(1, 1, 0, 0), mode= 'circular') out = self.conv2(out) if self.downsample is not None: identity = self.downsample(x) out += identity out = self.activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'inplanes': 4, 'planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_copy_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 x2 = xindex tmp0 = x0 tmp1 = tl.full([1], 5, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = -4 + x0 tmp4 = tl.full([1], 1, tl.int64) tmp5 = tmp3 < tmp4 tmp6 = tmp5 & tmp2 tmp7 = tmp0 >= tmp4 tmp8 = tmp0 < tmp1 tmp9 = tmp7 & tmp8 tmp10 = tmp9 & tmp6 tmp11 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp10 & xmask, other=0.0) tmp12 = float('nan') tmp13 = tl.where(tmp9, tmp11, tmp12) tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp6, tmp13, tmp14) tmp16 = tmp3 >= tmp4 tmp17 = tmp3 < tmp1 tmp18 = tmp16 & tmp17 tmp19 = tmp18 & tmp2 tmp20 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1), tmp19 & xmask, other=0.0) tmp21 = tl.where(tmp18, tmp20, tmp12) tmp22 = tl.where(tmp5, tmp15, tmp21) tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype) tmp24 = tl.where(tmp2, tmp22, tmp23) tmp25 = tmp0 < tmp4 tmp26 = 4 + x0 tmp27 = tmp26 >= tmp4 tmp28 = tmp26 < tmp1 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp25 tmp31 = tl.load(in_ptr0 + (3 + x0 + 4 * x1), tmp30 & xmask, other=0.0) tmp32 = tl.where(tmp29, tmp31, tmp12) tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype) tmp34 = tl.where(tmp25, tmp32, tmp33) tmp35 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp9 & xmask, other=0.0) tmp36 = tl.where(tmp9, tmp35, tmp12) tmp37 = tl.where(tmp25, tmp34, tmp36) tmp38 = tl.where(tmp2, tmp24, tmp37) tl.store(out_ptr0 + x2, tmp38, xmask) @triton.jit def triton_poi_fused_copy_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 x2 = xindex tmp0 = x0 tmp1 = tl.full([1], 5, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = -4 + x0 tmp4 = tl.full([1], 1, tl.int64) tmp5 = tmp3 < tmp4 tmp6 = tmp5 & tmp2 tmp7 = tmp0 >= tmp4 tmp8 = tmp0 < tmp1 tmp9 = tmp7 & tmp8 tmp10 = tmp9 & tmp6 tmp11 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp10 & xmask, other=0.0) tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp10, tmp13, tmp14) tmp16 = float('nan') tmp17 = tl.where(tmp9, tmp15, tmp16) tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp6, tmp17, tmp18) tmp20 = tmp3 >= tmp4 tmp21 = tmp3 < tmp1 tmp22 = tmp20 & tmp21 tmp23 = tmp22 & tmp2 tmp24 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1), tmp23 & xmask, other=0.0) tmp25 = triton_helpers.maximum(tmp12, tmp24) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp23, tmp25, tmp26) tmp28 = tl.where(tmp22, tmp27, tmp16) tmp29 = tl.where(tmp5, tmp19, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp2, tmp29, tmp30) tmp32 = tmp0 < tmp4 tmp33 = 4 + x0 tmp34 = tmp33 >= tmp4 tmp35 = tmp33 < tmp1 tmp36 = tmp34 & tmp35 tmp37 = tmp36 & tmp32 tmp38 = tl.load(in_ptr0 + (3 + x0 + 4 * x1), tmp37 & xmask, other=0.0) tmp39 = triton_helpers.maximum(tmp12, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp37, tmp39, tmp40) tmp42 = tl.where(tmp36, tmp41, tmp16) tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype) tmp44 = tl.where(tmp32, tmp42, tmp43) tmp45 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp9 & xmask, other=0.0) tmp46 = triton_helpers.maximum(tmp12, tmp45) tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype) tmp48 = tl.where(tmp9, tmp46, tmp47) tmp49 = tl.where(tmp9, tmp48, tmp16) tmp50 = tl.where(tmp32, tmp44, tmp49) tmp51 = tl.where(tmp2, tmp31, tmp50) tl.store(out_ptr0 + x2, tmp51, xmask) @triton.jit def triton_poi_fused_add_relu_threshold_backward_2(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 x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) 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 + x0, tmp4, xmask) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_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 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4, 4, 3, 3), (36, 9, 3, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_copy_0[grid(384)](primals_1, buf1, 384, XBLOCK=128, num_warps=4, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(1, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32) triton_poi_fused_copy_1[grid(384)](buf2, buf4, 384, XBLOCK=128, num_warps=4, num_stages=1) buf5 = extern_kernels.convolution(buf4, primals_3, stride=(1, 1), padding=(1, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1)) buf6 = buf5 del buf5 buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_relu_threshold_backward_2[grid(256)](buf6, primals_1, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_3[grid(256)](buf2, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 return buf6, primals_2, primals_3, buf1, buf4, buf7, buf8 def conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1, padding=0): """3x3 convolution with padding""" return torch.nn.Conv2d(in_planes, out_planes, kernel_size=3, stride= stride, padding=padding, groups=groups, bias=False, dilation=dilation) class BasicBlockNew(torch.nn.Module): expansion = 1 def __init__(self, inplanes, planes, stride=1, downsample=None, groups= 1, base_width=64, dilation=1, activation_fct='relu', norm_layer=None): super(BasicBlockNew, self).__init__() if groups != 1 or base_width != 64: raise ValueError( 'BasicBlock only supports groups=1 and base_width=64') if dilation > 1: raise NotImplementedError( 'Dilation > 1 not supported in BasicBlock') self.conv1 = conv3x3(in_planes=inplanes, out_planes=planes, stride= stride, padding=(1, 0)) self.activation = torch.nn.ReLU(inplace=True ) if activation_fct == 'relu' else torch.nn.Tanh() self.conv2 = conv3x3(in_planes=planes, out_planes=planes, padding=( 1, 0)) self.downsample = downsample self.stride = stride def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv2.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
leggedrobotics/DeLORA
BasicBlock
false
15,900
[ "BSD-3-Clause" ]
154
909948d63a9517e6dd54bedcf099f6b39ded2cb4
https://github.com/leggedrobotics/DeLORA/tree/909948d63a9517e6dd54bedcf099f6b39ded2cb4
Residual
import torch import torch.nn as nn class Residual(nn.Module): def __init__(self, channels, filter=3, stride=1, padding=1, activation= nn.ReLU): super(Residual, self).__init__() self.conv = nn.Conv2d(channels, channels, filter, stride, padding) self.activation = activation() def forward(self, x): return x + self.activation(self.conv(x)) 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 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_convolution_relu_threshold_backward_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x3, xmask) tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = tmp0 + tmp5 tmp7 = 0.0 tmp8 = tmp5 <= tmp7 tl.store(out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr1 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_convolution_relu_threshold_backward_0[grid(256)]( primals_3, buf0, primals_2, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 return buf1, primals_1, primals_3, buf2 class ResidualNew(nn.Module): def __init__(self, channels, filter=3, stride=1, padding=1, activation= nn.ReLU): super(ResidualNew, self).__init__() self.conv = nn.Conv2d(channels, channels, filter, stride, padding) self.activation = activation() def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
limberc/HyperGAN
Residual
false
15,901
[ "MIT" ]
889
b074e74abf0ed9b81bd52084706e3707a47e0fe2
https://github.com/limberc/HyperGAN/tree/b074e74abf0ed9b81bd52084706e3707a47e0fe2
SDSDRLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SDSDRLoss(torch.nn.Module): """Scale-dependent signal-to-distortion ratio loss module. Note that this returns the negative of the SD-SDR loss. See [Le Roux et al., 2018](https://arxiv.org/abs/1811.02508) Args: zero_mean (bool, optional) Remove any DC offset in the inputs. Default: ``True`` eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SDSDRLoss, self).__init__() self.zero_mean = zero_mean self.eps = eps self.reduction = reduction def forward(self, input, target): if self.zero_mean: input_mean = torch.mean(input, dim=-1, keepdim=True) target_mean = torch.mean(target, dim=-1, keepdim=True) input = input - input_mean target = target - target_mean alpha = (input * target).sum(-1) / ((target ** 2).sum(-1) + self.eps) scaled_target = target * alpha.unsqueeze(-1) res = input - target losses = 10 * torch.log10((scaled_target ** 2).sum(-1) / ((res ** 2 ).sum(-1) + self.eps) + self.eps) losses = apply_reduction(losses, self.reduction) return -losses 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mean_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1(in_out_ptr1, 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') tmp3 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = tmp1 * tmp1 tmp16 = tmp4 * tmp4 tmp17 = tmp15 + tmp16 tmp18 = tmp8 * tmp8 tmp19 = tmp17 + tmp18 tmp20 = tmp12 * tmp12 tmp21 = tmp19 + tmp20 tmp22 = 1e-08 tmp23 = tmp21 + tmp22 tmp24 = tmp14 / tmp23 tmp25 = tmp1 * tmp24 tmp26 = tmp25 * tmp25 tmp27 = tmp4 * tmp24 tmp28 = tmp27 * tmp27 tmp29 = tmp26 + tmp28 tmp30 = tmp8 * tmp24 tmp31 = tmp30 * tmp30 tmp32 = tmp29 + tmp31 tmp33 = tmp12 * tmp24 tmp34 = tmp33 * tmp33 tmp35 = tmp32 + tmp34 tmp36 = tmp0 - tmp1 tmp37 = tmp36 * tmp36 tmp38 = tmp3 - tmp4 tmp39 = tmp38 * tmp38 tmp40 = tmp37 + tmp39 tmp41 = tmp7 - tmp8 tmp42 = tmp41 * tmp41 tmp43 = tmp40 + tmp42 tmp44 = tmp11 - tmp12 tmp45 = tmp44 * tmp44 tmp46 = tmp43 + tmp45 tmp47 = tmp46 + tmp22 tmp48 = tmp35 / tmp47 tmp49 = tmp48 + tmp22 tmp50 = libdevice.log10(tmp49) tmp51 = 10.0 tmp52 = tmp50 * tmp51 tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK]) tmp55 = tl.sum(tmp53, 1)[:, None] tmp56 = 64.0 tmp57 = tmp55 / tmp56 tmp58 = -tmp57 tl.debug_barrier() tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp58, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, 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_mean_sub_0[grid(256)](arg1_1, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1[grid(1)](buf5 , buf0, buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 return buf5, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SDSDRLossNew(torch.nn.Module): """Scale-dependent signal-to-distortion ratio loss module. Note that this returns the negative of the SD-SDR loss. See [Le Roux et al., 2018](https://arxiv.org/abs/1811.02508) Args: zero_mean (bool, optional) Remove any DC offset in the inputs. Default: ``True`` eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SDSDRLossNew, self).__init__() self.zero_mean = zero_mean self.eps = eps 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]
leoauri/auraloss
SDSDRLoss
false
15,902
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
Codebook
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class Codebook(nn.Module): """ Codebook mapping: takes in an encoded image and maps each vector onto its closest codebook vector. Metric: mean squared error = (z_e - z_q)**2 = (z_e**2) - (2*z_e*z_q) + (z_q**2) """ def __init__(self, args): super().__init__() self.num_codebook_vectors = args.num_codebook_vectors self.latent_dim = args.latent_dim self.beta = args.beta self.embedding = nn.Embedding(self.num_codebook_vectors, self. latent_dim) self.embedding.weight.data.uniform_(-1.0 / self. num_codebook_vectors, 1.0 / self.num_codebook_vectors) def forward(self, z): z = z.permute(0, 2, 3, 1).contiguous() z_flattened = z.view(-1, self.latent_dim) d = torch.sum(z_flattened ** 2, dim=1, keepdim=True) + torch.sum( self.embedding.weight ** 2, dim=1) - 2 * torch.matmul(z_flattened, self.embedding.weight.t()) min_encoding_indices = torch.argmin(d, dim=1) z_q = self.embedding(min_encoding_indices).view(z.shape) loss = torch.mean((z_q.detach() - z) ** 2) + self.beta * torch.mean( (z_q - z.detach()) ** 2) z_q = z + (z_q - z).detach() z_q = z_q.permute(0, 3, 1, 2) return z_q, min_encoding_indices, loss def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'args': _mock_config(num_codebook_vectors=4, latent_dim=4, beta=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_view_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (16 * x1 + 64 * (y0 // 16) + y0 % 16), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_mul_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = 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') tmp11 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp23 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp12 = tmp11 * tmp11 tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp17 = tmp16 * tmp16 tmp18 = tmp15 + tmp17 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp10 + tmp21 tmp24 = 2.0 tmp25 = tmp23 * tmp24 tmp26 = tmp22 - tmp25 tl.store(in_out_ptr0 + x2, tmp26, xmask) @triton.jit def triton_poi_fused_argmin_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 < tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 < tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 < tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tl.store(out_ptr0 + x0, tmp46, xmask) @triton.jit def triton_per_fused_add_clone_mean_mul_pow_sub_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex % 16 r2 = rindex // 64 r1 = rindex // 16 % 4 r3 = rindex tmp0 = tl.load(in_ptr0 + (r0 + 16 * r2), None, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr2 + r3, None) tmp1 = tl.full([RBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4), 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + (r1 + 4 * tmp4), None, eviction_policy= 'evict_last') tmp8 = tmp6 - 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 tmp15 = 4.0 tmp16 = tmp14 * tmp15 tmp17 = tmp14 + tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp17, None) @triton.jit def triton_poi_fused_add_clone_sub_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y1 = yindex // 4 y0 = yindex % 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask) tmp1 = tl.load(in_ptr1 + (x2 + 16 * y1), xmask & ymask, eviction_policy ='evict_last') tmp2 = tl.full([XBLOCK, YBLOCK], 4, tl.int32) tmp3 = tmp1 + tmp2 tmp4 = tmp1 < 0 tmp5 = tl.where(tmp4, tmp3, tmp1) tl.device_assert((0 <= tmp5) & (tmp5 < 4) | ~(xmask & ymask), 'index out of bounds: 0 <= tmp5 < 4') tmp7 = tl.load(in_ptr2 + (y0 + 4 * tmp5), xmask & ymask) tmp8 = tmp7 - tmp0 tmp9 = tmp0 + tmp8 tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp9, xmask & ymask) @triton.jit def triton_poi_fused_clone_mul_pow_sub_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel y3 = yindex x2 = xindex y0 = yindex % 16 y1 = yindex // 16 tmp0 = tl.load(in_ptr0 + y3, ymask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr2 + (y0 + 16 * x2 + 64 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK, YBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~ymask, 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + (x2 + 4 * tmp4), xmask & ymask) tmp8 = tmp6 - tmp7 tmp9 = 2.0 tmp10 = tmp8 * tmp9 tl.store(out_ptr0 + (x2 + 4 * y3), tmp10, xmask & ymask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_view_0[grid(64, 4)](primals_1, buf0, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_2, (4, 4), (1, 4 ), 0), out=buf1) buf2 = buf1 del buf1 triton_poi_fused_add_mul_pow_sub_sum_1[grid(256)](buf2, buf0, primals_2, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused_argmin_2[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((), (), torch.float32) buf7 = buf4 del buf4 triton_per_fused_add_clone_mean_mul_pow_sub_3[grid(1)](buf7, buf3, primals_2, primals_1, 1, 256, num_warps=2, num_stages=1) buf5 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_add_clone_sub_4[grid(16, 16)](primals_1, buf3, primals_2, buf5, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_clone_mul_pow_sub_5[grid(64, 4)](buf3, primals_2, primals_1, buf6, 64, 4, XBLOCK=4, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 del primals_2 return reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 1, 16, 4), 0 ), buf3, buf7, buf3, buf6 class CodebookNew(nn.Module): """ Codebook mapping: takes in an encoded image and maps each vector onto its closest codebook vector. Metric: mean squared error = (z_e - z_q)**2 = (z_e**2) - (2*z_e*z_q) + (z_q**2) """ def __init__(self, args): super().__init__() self.num_codebook_vectors = args.num_codebook_vectors self.latent_dim = args.latent_dim self.beta = args.beta self.embedding = nn.Embedding(self.num_codebook_vectors, self. latent_dim) self.embedding.weight.data.uniform_(-1.0 / self. num_codebook_vectors, 1.0 / self.num_codebook_vectors) def forward(self, input_0): primals_2 = self.embedding.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0], output[1], output[2]
JiangtaoFeng/MaskGIT-pytorch
Codebook
false
15,903
[ "MIT" ]
163
198b32e29a306fae2830a71621befad008500f76
https://github.com/JiangtaoFeng/MaskGIT-pytorch/tree/198b32e29a306fae2830a71621befad008500f76
LogCoshLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class LogCoshLoss(torch.nn.Module): """Log-cosh loss function module. See [Chen et al., 2019](https://openreview.net/forum?id=rkglvsC9Ym). Args: a (float, optional): Smoothness hyperparameter. Smaller is smoother. Default: 1.0 eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, a=1.0, eps=1e-08, reduction='mean'): super(LogCoshLoss, self).__init__() self.a = a self.eps = eps self.reduction = reduction def forward(self, input, target): losses = (1 / self.a * torch.log(torch.cosh(self.a * (input - target)) + self.eps)).mean(-1) losses = apply_reduction(losses, self.reduction) return losses 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, 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_per_fused_add_cosh_log_mean_mul_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') tmp10 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp28 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp29 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tmp5 = libdevice.cosh(tmp4) tmp6 = 1e-08 tmp7 = tmp5 + tmp6 tmp8 = tl_math.log(tmp7) tmp9 = tmp8 * tmp3 tmp12 = tmp10 - tmp11 tmp13 = tmp12 * tmp3 tmp14 = libdevice.cosh(tmp13) tmp15 = tmp14 + tmp6 tmp16 = tl_math.log(tmp15) tmp17 = tmp16 * tmp3 tmp18 = tmp9 + tmp17 tmp21 = tmp19 - tmp20 tmp22 = tmp21 * tmp3 tmp23 = libdevice.cosh(tmp22) tmp24 = tmp23 + tmp6 tmp25 = tl_math.log(tmp24) tmp26 = tmp25 * tmp3 tmp27 = tmp18 + tmp26 tmp30 = tmp28 - tmp29 tmp31 = tmp30 * tmp3 tmp32 = libdevice.cosh(tmp31) tmp33 = tmp32 + tmp6 tmp34 = tl_math.log(tmp33) tmp35 = tmp34 * tmp3 tmp36 = tmp27 + tmp35 tmp37 = 4.0 tmp38 = tmp36 / tmp37 tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = tl.sum(tmp39, 1)[:, None] tmp42 = 64.0 tmp43 = tmp41 / tmp42 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_cosh_log_mean_mul_sub_0[grid(1)](buf2, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class LogCoshLossNew(torch.nn.Module): """Log-cosh loss function module. See [Chen et al., 2019](https://openreview.net/forum?id=rkglvsC9Ym). Args: a (float, optional): Smoothness hyperparameter. Smaller is smoother. Default: 1.0 eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, a=1.0, eps=1e-08, reduction='mean'): super(LogCoshLossNew, self).__init__() self.a = a self.eps = eps 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]
leoauri/auraloss
LogCoshLoss
false
15,904
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
ESRLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class ESRLoss(torch.nn.Module): """Error-to-signal ratio loss function module. See [Wright & Välimäki, 2019](https://arxiv.org/abs/1911.08922). Args: reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, reduction='mean'): super(ESRLoss, self).__init__() self.reduction = reduction def forward(self, input, target): losses = ((target - input).abs() ** 2).sum(-1) / (target.abs() ** 2 ).sum(-1) losses = apply_reduction(losses, reduction=self.reduction) return losses def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math 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_div_mean_pow_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp18 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tmp3 * tmp3 tmp7 = tmp5 - tmp6 tmp8 = tl_math.abs(tmp7) tmp9 = tmp8 * tmp8 tmp10 = tmp4 + tmp9 tmp13 = tmp11 - tmp12 tmp14 = tl_math.abs(tmp13) tmp15 = tmp14 * tmp14 tmp16 = tmp10 + tmp15 tmp19 = tmp17 - tmp18 tmp20 = tl_math.abs(tmp19) tmp21 = tmp20 * tmp20 tmp22 = tmp16 + tmp21 tmp23 = tl_math.abs(tmp0) tmp24 = tmp23 * tmp23 tmp25 = tl_math.abs(tmp5) tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tl_math.abs(tmp11) tmp29 = tmp28 * tmp28 tmp30 = tmp27 + tmp29 tmp31 = tl_math.abs(tmp17) tmp32 = tmp31 * tmp31 tmp33 = tmp30 + tmp32 tmp34 = tmp22 / tmp33 tmp35 = tl.broadcast_to(tmp34, [XBLOCK, RBLOCK]) tmp37 = tl.sum(tmp35, 1)[:, None] tmp38 = 64.0 tmp39 = tmp37 / tmp38 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp39, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_abs_div_mean_pow_sub_sum_0[grid(1)](buf2, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class ESRLossNew(torch.nn.Module): """Error-to-signal ratio loss function module. See [Wright & Välimäki, 2019](https://arxiv.org/abs/1911.08922). Args: reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, reduction='mean'): super(ESRLossNew, self).__init__() 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]
leoauri/auraloss
ESRLoss
false
15,905
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
MulticlassDiceLoss
import torch import torch.nn as nn class DiceLoss(nn.Module): def __init__(self): super(DiceLoss, self).__init__() def forward(self, input, target): N = target.size(0) smooth = 1 input_flat = input.view(N, -1) target_flat = target.view(N, -1) intersection = input_flat * target_flat loss = 2 * (intersection.sum(1) + smooth) / (input_flat.sum(1) + target_flat.sum(1) + smooth) loss = 1 - loss.sum() / N return loss class MulticlassDiceLoss(nn.Module): """ requires one hot encoded target. Applies DiceLoss on each class iteratively. requires input.shape[0:1] and target.shape[0:1] to be (N, C) where N is batch size and C is number of classes """ def __init__(self): super(MulticlassDiceLoss, self).__init__() def forward(self, input, target, weights=None): C = target.shape[1] if weights is None: weights = torch.ones(C) dice = DiceLoss() totalLoss = 0 for i in range(C): diceLoss = dice(input[:, i], target[:, i]) if weights is not None: diceLoss *= weights[i] totalLoss += diceLoss return totalLoss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_mul_sum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = 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_mul_sum_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = 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_mul_sum_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = 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_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, 0) tmp6 = tl.sum(tmp5, 1)[:, None] tmp7 = 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_mul_rsub_sum_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp5 = tl.load(in_ptr1 + r0, None) tmp6 = tl.load(in_ptr2 + r0, None) tmp13 = tl.load(in_ptr3 + r0, None) tmp16 = tl.load(in_ptr4 + r0, None) tmp17 = tl.load(in_ptr5 + r0, None) tmp24 = tl.load(in_ptr6 + r0, None) tmp27 = tl.load(in_ptr7 + r0, None) tmp28 = tl.load(in_ptr8 + r0, None) tmp35 = tl.load(in_ptr9 + r0, None) tmp38 = tl.load(in_ptr10 + r0, None) tmp39 = tl.load(in_ptr11 + r0, None) tmp1 = 1.0 tmp2 = tmp0 + tmp1 tmp3 = 2.0 tmp4 = tmp2 * tmp3 tmp7 = tmp5 + tmp6 tmp8 = tmp7 + tmp1 tmp9 = tmp4 / tmp8 tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp12 = tl.sum(tmp10, 1)[:, None] tmp14 = tmp13 + tmp1 tmp15 = tmp14 * tmp3 tmp18 = tmp16 + tmp17 tmp19 = tmp18 + tmp1 tmp20 = tmp15 / tmp19 tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK]) tmp23 = tl.sum(tmp21, 1)[:, None] tmp25 = tmp24 + tmp1 tmp26 = tmp25 * tmp3 tmp29 = tmp27 + tmp28 tmp30 = tmp29 + tmp1 tmp31 = tmp26 / tmp30 tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK]) tmp34 = tl.sum(tmp32, 1)[:, None] tmp36 = tmp35 + tmp1 tmp37 = tmp36 * tmp3 tmp40 = tmp38 + tmp39 tmp41 = tmp40 + tmp1 tmp42 = tmp37 / tmp41 tmp43 = tl.broadcast_to(tmp42, [XBLOCK, RBLOCK]) tmp45 = tl.sum(tmp43, 1)[:, None] tmp46 = 0.25 tmp47 = tmp12 * tmp46 tmp48 = tmp1 - tmp47 tmp49 = tmp48 * tmp1 tmp50 = 0.0 tmp51 = tmp49 + tmp50 tmp52 = tmp23 * tmp46 tmp53 = tmp1 - tmp52 tmp54 = tmp53 * tmp1 tmp55 = tmp51 + tmp54 tmp56 = tmp34 * tmp46 tmp57 = tmp1 - tmp56 tmp58 = tmp57 * tmp1 tmp59 = tmp55 + tmp58 tmp60 = tmp45 * tmp46 tmp61 = tmp1 - tmp60 tmp62 = tmp61 * tmp1 tmp63 = tmp59 + tmp62 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp63, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) buf1 = empty_strided_cuda((4,), (1,), torch.float32) buf2 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_mul_sum_0[grid(4)](arg1_1, arg0_1, buf0, buf1, buf2, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) buf8 = empty_strided_cuda((4,), (1,), torch.float32) buf9 = empty_strided_cuda((4,), (1,), torch.float32) buf10 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_mul_sum_1[grid(4)](arg1_1, arg0_1, buf8, buf9, buf10, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) buf12 = empty_strided_cuda((4,), (1,), torch.float32) buf13 = empty_strided_cuda((4,), (1,), torch.float32) buf14 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_mul_sum_2[grid(4)](arg1_1, arg0_1, buf12, buf13, buf14, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4,), (1,), torch.float32) buf5 = empty_strided_cuda((4,), (1,), torch.float32) buf6 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_mul_sum_3[grid(4)](arg1_1, arg0_1, buf4, buf5, buf6, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf11 = empty_strided_cuda((), (), torch.float32) buf16 = buf11 del buf11 triton_per_fused_add_div_mul_rsub_sum_4[grid(1)](buf16, buf0, buf1, buf2, buf4, buf5, buf6, buf8, buf9, buf10, buf12, buf13, buf14, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 del buf10 del buf12 del buf13 del buf14 del buf2 del buf4 del buf5 del buf6 del buf8 del buf9 return buf16, class DiceLoss(nn.Module): def __init__(self): super(DiceLoss, self).__init__() def forward(self, input, target): N = target.size(0) smooth = 1 input_flat = input.view(N, -1) target_flat = target.view(N, -1) intersection = input_flat * target_flat loss = 2 * (intersection.sum(1) + smooth) / (input_flat.sum(1) + target_flat.sum(1) + smooth) loss = 1 - loss.sum() / N return loss class MulticlassDiceLossNew(nn.Module): """ requires one hot encoded target. Applies DiceLoss on each class iteratively. requires input.shape[0:1] and target.shape[0:1] to be (N, C) where N is batch size and C is number of classes """ def __init__(self): super(MulticlassDiceLossNew, 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]
lee-zq/VesselSeg-pytorch
MulticlassDiceLoss
false
15,906
[ "Apache-2.0" ]
83
b4f6571fc1fb1fbdaad60ff9282a54a1f1c455fa
https://github.com/lee-zq/VesselSeg-pytorch/tree/b4f6571fc1fb1fbdaad60ff9282a54a1f1c455fa
Variational
import torch import torch.nn as nn class Variational(nn.Module): def __init__(self, channels, filter=1, stride=1, padding=0, activation= nn.LeakyReLU): super(Variational, self).__init__() self.mu_logit = nn.Conv2d(channels, channels, filter, stride, padding, padding_mode='reflect') self.sigma_logit = nn.Conv2d(channels, channels, filter, stride, padding, padding_mode='reflect') def forward(self, x): sigma = self.sigma_logit(x) mu = self.mu_logit(x) z = mu + torch.exp(0.5 * sigma) * torch.randn_like(sigma) self.sigma = sigma.view(x.shape[0], -1) self.mu = mu.view(x.shape[0], -1) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4}]
import torch from torch import device from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_reflection_pad2d_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 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + x0) + -4 * tl_math .abs(-3 + x1) + 16 * x2), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_add_convolution_exp_mul_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr3 + x3, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.5 tmp7 = tmp2 * tmp6 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 * tmp9 tmp11 = tmp5 + tmp10 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp11, xmask) tl.store(out_ptr1 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(256)](primals_3, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = extern_kernels.convolution(buf0, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = torch.ops.aten.randn.default([4, 4, 4, 4], dtype=torch. float32, device=device(type='cuda', index=0), pin_memory=False) buf5 = buf4 del buf4 buf2 = buf1 del buf1 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_exp_mul_1[grid(256)](buf2, primals_2, buf3, primals_5, buf5, buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf3 del primals_2 del primals_5 return buf6, reinterpret_tensor(buf7, (4, 64), (64, 1), 0 ), reinterpret_tensor(buf2, (4, 64), (64, 1), 0 ), primals_1, primals_4, buf0, buf2, buf5 class VariationalNew(nn.Module): def __init__(self, channels, filter=1, stride=1, padding=0, activation= nn.LeakyReLU): super(VariationalNew, self).__init__() self.mu_logit = nn.Conv2d(channels, channels, filter, stride, padding, padding_mode='reflect') self.sigma_logit = nn.Conv2d(channels, channels, filter, stride, padding, padding_mode='reflect') def forward(self, input_0): primals_1 = self.mu_logit.weight primals_2 = self.mu_logit.bias primals_4 = self.sigma_logit.weight primals_5 = self.sigma_logit.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
limberc/HyperGAN
Variational
false
15,907
[ "MIT" ]
889
b074e74abf0ed9b81bd52084706e3707a47e0fe2
https://github.com/limberc/HyperGAN/tree/b074e74abf0ed9b81bd52084706e3707a47e0fe2
SNRLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SNRLoss(torch.nn.Module): """Signal-to-noise ratio loss module. Note that this does NOT implement the SDR from [Vincent et al., 2006](https://ieeexplore.ieee.org/document/1643671), which includes the application of a 512-tap FIR filter. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SNRLoss, self).__init__() self.zero_mean = zero_mean self.eps = eps self.reduction = reduction def forward(self, input, target): if self.zero_mean: input_mean = torch.mean(input, dim=-1, keepdim=True) target_mean = torch.mean(target, dim=-1, keepdim=True) input = input - input_mean target = target - target_mean res = input - target losses = 10 * torch.log10((target ** 2).sum(-1) / ((res ** 2).sum(- 1) + self.eps) + self.eps) losses = apply_reduction(losses, self.reduction) return -losses 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mean_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp17 = tmp15 + tmp16 tmp18 = 4.0 tmp19 = tmp17 / tmp18 tmp20 = tmp11 - tmp19 tmp21 = tmp20 - tmp0 tmp22 = tmp21 * tmp21 tmp23 = tmp12 - tmp19 tmp24 = tmp23 - tmp2 tmp25 = tmp24 * tmp24 tmp26 = tmp22 + tmp25 tmp27 = tmp14 - tmp19 tmp28 = tmp27 - tmp5 tmp29 = tmp28 * tmp28 tmp30 = tmp26 + tmp29 tmp31 = tmp16 - tmp19 tmp32 = tmp31 - tmp8 tmp33 = tmp32 * tmp32 tmp34 = tmp30 + tmp33 tmp35 = 1e-08 tmp36 = tmp34 + tmp35 tmp37 = tmp10 / tmp36 tmp38 = tmp37 + tmp35 tmp39 = libdevice.log10(tmp38) tmp40 = 10.0 tmp41 = tmp39 * tmp40 tmp42 = tl.broadcast_to(tmp41, [XBLOCK, RBLOCK]) tmp44 = tl.sum(tmp42, 1)[:, None] tmp45 = 64.0 tmp46 = tmp44 / tmp45 tmp47 = -tmp46 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp47, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_sub_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1[grid(1)](buf3 , buf0, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del buf0 return buf3, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SNRLossNew(torch.nn.Module): """Signal-to-noise ratio loss module. Note that this does NOT implement the SDR from [Vincent et al., 2006](https://ieeexplore.ieee.org/document/1643671), which includes the application of a 512-tap FIR filter. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SNRLossNew, self).__init__() self.zero_mean = zero_mean self.eps = eps 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]
leoauri/auraloss
SNRLoss
false
15,908
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
SISDRLoss
import torch def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SISDRLoss(torch.nn.Module): """Scale-invariant signal-to-distortion ratio loss module. Note that this returns the negative of the SI-SDR loss. See [Le Roux et al., 2018](https://arxiv.org/abs/1811.02508) Args: zero_mean (bool, optional) Remove any DC offset in the inputs. Default: ``True`` eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SISDRLoss, self).__init__() self.zero_mean = zero_mean self.eps = eps self.reduction = reduction def forward(self, input, target): if self.zero_mean: input_mean = torch.mean(input, dim=-1, keepdim=True) target_mean = torch.mean(target, dim=-1, keepdim=True) input = input - input_mean target = target - target_mean alpha = (input * target).sum(-1) / ((target ** 2).sum(-1) + self.eps) target = target * alpha.unsqueeze(-1) res = input - target losses = 10 * torch.log10((target ** 2).sum(-1) / ((res ** 2).sum(- 1) + self.eps) + self.eps) losses = apply_reduction(losses, self.reduction) return -losses 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mean_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = tmp1 * tmp1 tmp16 = tmp4 * tmp4 tmp17 = tmp15 + tmp16 tmp18 = tmp8 * tmp8 tmp19 = tmp17 + tmp18 tmp20 = tmp12 * tmp12 tmp21 = tmp19 + tmp20 tmp22 = 1e-08 tmp23 = tmp21 + tmp22 tmp24 = tmp14 / tmp23 tmp25 = tmp1 * tmp24 tmp26 = tmp0 - tmp25 tmp27 = tmp26 * tmp26 tmp28 = tmp4 * tmp24 tmp29 = tmp3 - tmp28 tmp30 = tmp29 * tmp29 tmp31 = tmp27 + tmp30 tmp32 = tmp8 * tmp24 tmp33 = tmp7 - tmp32 tmp34 = tmp33 * tmp33 tmp35 = tmp31 + tmp34 tmp36 = tmp12 * tmp24 tmp37 = tmp11 - tmp36 tmp38 = tmp37 * tmp37 tmp39 = tmp35 + tmp38 tmp40 = tmp25 * tmp25 tmp41 = tmp28 * tmp28 tmp42 = tmp40 + tmp41 tmp43 = tmp32 * tmp32 tmp44 = tmp42 + tmp43 tmp45 = tmp36 * tmp36 tmp46 = tmp44 + tmp45 tmp47 = tmp39 + tmp22 tmp48 = tmp46 / tmp47 tmp49 = tmp48 + tmp22 tmp50 = libdevice.log10(tmp49) tmp51 = 10.0 tmp52 = tmp50 * tmp51 tmp53 = tl.broadcast_to(tmp52, [XBLOCK, RBLOCK]) tmp55 = tl.sum(tmp53, 1)[:, None] tmp56 = 64.0 tmp57 = tmp55 / tmp56 tmp58 = -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 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, 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_mean_sub_0[grid(256)](arg1_1, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 triton_per_fused_add_div_log10_mean_mul_neg_pow_sub_sum_1[grid(1)](buf5 , buf0, buf1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 return buf5, def apply_reduction(losses, reduction='none'): """Apply reduction to collection of losses.""" if reduction == 'mean': losses = losses.mean() elif reduction == 'sum': losses = losses.sum() return losses class SISDRLossNew(torch.nn.Module): """Scale-invariant signal-to-distortion ratio loss module. Note that this returns the negative of the SI-SDR loss. See [Le Roux et al., 2018](https://arxiv.org/abs/1811.02508) Args: zero_mean (bool, optional) Remove any DC offset in the inputs. Default: ``True`` eps (float, optional): Small epsilon value for stablity. Default: 1e-8 reduction (string, optional): Specifies the reduction to apply to the output: '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. Default: 'mean' Shape: - input : :math:`(batch, nchs, ...)`. - target: :math:`(batch, nchs, ...)`. """ def __init__(self, zero_mean=True, eps=1e-08, reduction='mean'): super(SISDRLossNew, self).__init__() self.zero_mean = zero_mean self.eps = eps 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]
leoauri/auraloss
SISDRLoss
false
15,909
[ "Apache-2.0" ]
272
0e3362674ae1b53aa61c6a631fb4e6970c5683c1
https://github.com/leoauri/auraloss/tree/0e3362674ae1b53aa61c6a631fb4e6970c5683c1
ComplexConv
import torch import torch.nn as nn class ComplexConv(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): super(ComplexConv, self).__init__() self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') self.padding = padding self.conv_re = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias) self.conv_im = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias) 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 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, 4, 1), 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, 4, 1), 16), 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, 4, 1), 16), 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, 4, 1), 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, 2, 1), (2, 1, 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 reinterpret_tensor(buf4, (4, 2, 1, 1), (2, 1, 1, 1), 0 ), primals_2, primals_4, reinterpret_tensor(primals_1, (1, 4, 4, 4), (256, 64, 4, 1), 0), reinterpret_tensor(primals_1, (1, 4, 4, 4), ( 256, 64, 4, 1), 16) class ComplexConvNew(nn.Module): def __init__(self, in_channel, out_channel, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): super(ComplexConvNew, self).__init__() self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') self.padding = padding self.conv_re = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias) self.conv_im = nn.Conv2d(in_channel, out_channel, kernel_size, stride=stride, padding=padding, dilation=dilation, groups= groups, bias=bias) 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]
litcoderr/ComplexCNN
ComplexConv
false
15,910
[ "MIT" ]
154
97db7c94b1ad91fc689faf36693977cc476818e9
https://github.com/litcoderr/ComplexCNN/tree/97db7c94b1ad91fc689faf36693977cc476818e9
CO2Regularizer
import torch class MemoryBankModule(torch.nn.Module): """Memory bank implementation This is a parent class to all loss functions implemented by the lightly Python package. This way, any loss can be used with a memory bank if desired. Attributes: size: Number of keys the memory bank can store. If set to 0, memory bank is not used. Examples: >>> class MyLossFunction(MemoryBankModule): >>> >>> def __init__(self, memory_bank_size: int = 2 ** 16): >>> super(MyLossFunction, self).__init__(memory_bank_size) >>> >>> def forward(self, output: torch.Tensor, >>> labels: torch.Tensor = None): >>> >>> output, negatives = super( >>> MyLossFunction, self).forward(output) >>> >>> if negatives is not None: >>> # evaluate loss with negative samples >>> else: >>> # evaluate loss without negative samples """ def __init__(self, size: 'int'=2 ** 16): super(MemoryBankModule, self).__init__() if size < 0: msg = f'Illegal memory bank size {size}, must be non-negative.' raise ValueError(msg) self.size = size self.bank = None self.bank_ptr = None @torch.no_grad() def _init_memory_bank(self, dim: 'int'): """Initialize the memory bank if it's empty Args: dim: The dimension of the which are stored in the bank. """ self.bank = torch.randn(dim, self.size) self.bank = torch.nn.functional.normalize(self.bank, dim=0) self.bank_ptr = torch.LongTensor([0]) @torch.no_grad() def _dequeue_and_enqueue(self, batch: 'torch.Tensor'): """Dequeue the oldest batch and add the latest one Args: batch: The latest batch of keys to add to the memory bank. """ batch_size = batch.shape[0] ptr = int(self.bank_ptr) if ptr + batch_size >= self.size: self.bank[:, ptr:] = batch[:self.size - ptr].T.detach() self.bank_ptr[0] = 0 else: self.bank[:, ptr:ptr + batch_size] = batch.T.detach() self.bank_ptr[0] = ptr + batch_size def forward(self, output: 'torch.Tensor', labels: 'torch.Tensor'=None, update: 'bool'=False): """Query memory bank for additional negative samples Args: output: The output of the model. labels: Should always be None, will be ignored. Returns: The output if the memory bank is of size 0, otherwise the output and the entries from the memory bank. """ if self.size == 0: return output, None _, dim = output.shape if self.bank is None: self._init_memory_bank(dim) bank = self.bank.clone().detach() if update: self._dequeue_and_enqueue(output) return output, bank class CO2Regularizer(MemoryBankModule): """Implementation of the CO2 regularizer [0] for self-supervised learning. [0] CO2, 2021, https://arxiv.org/abs/2010.02217 Attributes: alpha: Weight of the regularization term. t_consistency: Temperature used during softmax calculations. memory_bank_size: Number of negative samples to store in the memory bank. Use 0 to use the second batch for negative samples. Examples: >>> # initialize loss function for MoCo >>> loss_fn = NTXentLoss(memory_bank_size=4096) >>> >>> # initialize CO2 regularizer >>> co2 = CO2Regularizer(alpha=1.0, memory_bank_size=4096) >>> >>> # generate two random trasnforms of images >>> t0 = transforms(images) >>> t1 = transforms(images) >>> >>> # feed through the MoCo model >>> out0, out1 = model(t0, t1) >>> >>> # calculate loss and apply regularizer >>> loss = loss_fn(out0, out1) + co2(out0, out1) """ def __init__(self, alpha: 'float'=1, t_consistency: 'float'=0.05, memory_bank_size: 'int'=0): super(CO2Regularizer, self).__init__(size=memory_bank_size) self.log_target = True try: self.kl_div = torch.nn.KLDivLoss(reduction='batchmean', log_target=True) except TypeError: self.log_target = False self.kl_div = torch.nn.KLDivLoss(reduction='batchmean') self.t_consistency = t_consistency self.alpha = alpha def _get_pseudo_labels(self, out0: 'torch.Tensor', out1: 'torch.Tensor', negatives: 'torch.Tensor'=None): """Computes the soft pseudo labels across negative samples. Args: out0: Output projections of the first set of transformed images (query). Shape: bsz x n_ftrs out1: Output projections of the second set of transformed images (positive sample). Shape: bsz x n_ftrs negatives: Negative samples to compare against. If this is None, the second batch of images will be used as negative samples. Shape: memory_bank_size x n_ftrs Returns: Log probability that a positive samples will classify each negative sample as the positive sample. Shape: bsz x (bsz - 1) or bsz x memory_bank_size """ batch_size, _ = out0.shape if negatives is None: l_pos = torch.einsum('nc,nc->n', [out0, out1]).unsqueeze(-1) l_neg = torch.einsum('nc,ck->nk', [out0, out1.t()]) l_neg = l_neg.masked_select(~torch.eye(batch_size, dtype=bool, device=l_neg.device)).view(batch_size, batch_size - 1) else: negatives = negatives l_pos = torch.einsum('nc,nc->n', [out0, out1]).unsqueeze(-1) l_neg = torch.einsum('nc,ck->nk', [out0, negatives.clone(). detach()]) logits = torch.cat([l_pos, l_neg], dim=1) logits = logits / self.t_consistency return torch.nn.functional.log_softmax(logits, dim=-1) def forward(self, out0: 'torch.Tensor', out1: 'torch.Tensor'): """Computes the CO2 regularization term for two model outputs. Args: out0: Output projections of the first set of transformed images. out1: Output projections of the second set of transformed images. Returns: The regularization term multiplied by the weight factor alpha. """ out0 = torch.nn.functional.normalize(out0, dim=1) out1 = torch.nn.functional.normalize(out1, dim=1) out1, negatives = super(CO2Regularizer, self).forward(out1, update=True ) p = self._get_pseudo_labels(out0, out1, negatives) q = self._get_pseudo_labels(out1, out0, negatives) if self.log_target: div = self.kl_div(p, q) + self.kl_div(q, p) else: div = self.kl_div(p, torch.exp(q)) + self.kl_div(q, torch.exp(p)) return self.alpha * 0.5 * div def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_0(in_ptr0, 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) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_0[grid(16)](arg1_1, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg1_1 return buf0, buf1 class MemoryBankModule(torch.nn.Module): """Memory bank implementation This is a parent class to all loss functions implemented by the lightly Python package. This way, any loss can be used with a memory bank if desired. Attributes: size: Number of keys the memory bank can store. If set to 0, memory bank is not used. Examples: >>> class MyLossFunction(MemoryBankModule): >>> >>> def __init__(self, memory_bank_size: int = 2 ** 16): >>> super(MyLossFunction, self).__init__(memory_bank_size) >>> >>> def forward(self, output: torch.Tensor, >>> labels: torch.Tensor = None): >>> >>> output, negatives = super( >>> MyLossFunction, self).forward(output) >>> >>> if negatives is not None: >>> # evaluate loss with negative samples >>> else: >>> # evaluate loss without negative samples """ def __init__(self, size: 'int'=2 ** 16): super(MemoryBankModule, self).__init__() if size < 0: msg = f'Illegal memory bank size {size}, must be non-negative.' raise ValueError(msg) self.size = size self.bank = None self.bank_ptr = None @torch.no_grad() def _init_memory_bank(self, dim: 'int'): """Initialize the memory bank if it's empty Args: dim: The dimension of the which are stored in the bank. """ self.bank = torch.randn(dim, self.size) self.bank = torch.nn.functional.normalize(self.bank, dim=0) self.bank_ptr = torch.LongTensor([0]) @torch.no_grad() def _dequeue_and_enqueue(self, batch: 'torch.Tensor'): """Dequeue the oldest batch and add the latest one Args: batch: The latest batch of keys to add to the memory bank. """ batch_size = batch.shape[0] ptr = int(self.bank_ptr) if ptr + batch_size >= self.size: self.bank[:, ptr:] = batch[:self.size - ptr].T.detach() self.bank_ptr[0] = 0 else: self.bank[:, ptr:ptr + batch_size] = batch.T.detach() self.bank_ptr[0] = ptr + batch_size def forward(self, output: 'torch.Tensor', labels: 'torch.Tensor'=None, update: 'bool'=False): """Query memory bank for additional negative samples Args: output: The output of the model. labels: Should always be None, will be ignored. Returns: The output if the memory bank is of size 0, otherwise the output and the entries from the memory bank. """ if self.size == 0: return output, None _, dim = output.shape if self.bank is None: self._init_memory_bank(dim) bank = self.bank.clone().detach() if update: self._dequeue_and_enqueue(output) return output, bank class CO2RegularizerNew(MemoryBankModule): """Implementation of the CO2 regularizer [0] for self-supervised learning. [0] CO2, 2021, https://arxiv.org/abs/2010.02217 Attributes: alpha: Weight of the regularization term. t_consistency: Temperature used during softmax calculations. memory_bank_size: Number of negative samples to store in the memory bank. Use 0 to use the second batch for negative samples. Examples: >>> # initialize loss function for MoCo >>> loss_fn = NTXentLoss(memory_bank_size=4096) >>> >>> # initialize CO2 regularizer >>> co2 = CO2Regularizer(alpha=1.0, memory_bank_size=4096) >>> >>> # generate two random trasnforms of images >>> t0 = transforms(images) >>> t1 = transforms(images) >>> >>> # feed through the MoCo model >>> out0, out1 = model(t0, t1) >>> >>> # calculate loss and apply regularizer >>> loss = loss_fn(out0, out1) + co2(out0, out1) """ def __init__(self, alpha: 'float'=1, t_consistency: 'float'=0.05, memory_bank_size: 'int'=0): super(CO2RegularizerNew, self).__init__(size=memory_bank_size) self.log_target = True try: self.kl_div = torch.nn.KLDivLoss(reduction='batchmean', log_target=True) except TypeError: self.log_target = False self.kl_div = torch.nn.KLDivLoss(reduction='batchmean') self.t_consistency = t_consistency self.alpha = alpha def _get_pseudo_labels(self, out0: 'torch.Tensor', out1: 'torch.Tensor', negatives: 'torch.Tensor'=None): """Computes the soft pseudo labels across negative samples. Args: out0: Output projections of the first set of transformed images (query). Shape: bsz x n_ftrs out1: Output projections of the second set of transformed images (positive sample). Shape: bsz x n_ftrs negatives: Negative samples to compare against. If this is None, the second batch of images will be used as negative samples. Shape: memory_bank_size x n_ftrs Returns: Log probability that a positive samples will classify each negative sample as the positive sample. Shape: bsz x (bsz - 1) or bsz x memory_bank_size """ batch_size, _ = out0.shape if negatives is None: l_pos = torch.einsum('nc,nc->n', [out0, out1]).unsqueeze(-1) l_neg = torch.einsum('nc,ck->nk', [out0, out1.t()]) l_neg = l_neg.masked_select(~torch.eye(batch_size, dtype=bool, device=l_neg.device)).view(batch_size, batch_size - 1) else: negatives = negatives l_pos = torch.einsum('nc,nc->n', [out0, out1]).unsqueeze(-1) l_neg = torch.einsum('nc,ck->nk', [out0, negatives.clone(). detach()]) logits = torch.cat([l_pos, l_neg], dim=1) logits = logits / self.t_consistency return torch.nn.functional.log_softmax(logits, dim=-1) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lightly-ai/lightly
CO2Regularizer
false
15,911
[ "MIT" ]
1,515
0b98bda640d13d842fd13f9354271d0cef116ba5
https://github.com/lightly-ai/lightly/tree/0b98bda640d13d842fd13f9354271d0cef116ba5
DepthNormalizer
import torch import torch.nn as nn class DepthNormalizer(nn.Module): def __init__(self, input_size: 'int'=512, z_size: 'int'=200): """ Class about DepthNormalizer which use to generate depth-information Parameters: input_size: the size of image, initially, 512 x 512 z_size: z normalization factor """ super(DepthNormalizer, self).__init__() self.input_size = input_size self.z_size = z_size self.name = 'DepthNormalizer' self.input_para = dict(input_size=input_size, z_size=z_size) def forward(self, z, calibs=None, index_feat=None) ->torch.Tensor: """ Normalize z_feature Parameters: z_feat: [B, 1, N] depth value for z in the image coordinate system calibs: cameara matrix :return: normalized features z_feat [B,1,N] """ z_feat = z * (self.input_size // 2) / self.z_size return z_feat @property def name(self): __repr = '{}(Parameters: '.format(self.__name) for key in self.input_para.keys(): __repr += '{}:{}, '.format(key, self.input_para[key]) __repr = __repr[:-2] return __repr + ')' @name.setter def name(self, v): self.__name = v def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_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 = 256.0 tmp2 = tmp0 * tmp1 tmp3 = 0.005 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class DepthNormalizerNew(nn.Module): def __init__(self, input_size: 'int'=512, z_size: 'int'=200): """ Class about DepthNormalizer which use to generate depth-information Parameters: input_size: the size of image, initially, 512 x 512 z_size: z normalization factor """ super(DepthNormalizerNew, self).__init__() self.input_size = input_size self.z_size = z_size self.name = 'DepthNormalizer' self.input_para = dict(input_size=input_size, z_size=z_size) @property def name(self): __repr = '{}(Parameters: '.format(self.__name) for key in self.input_para.keys(): __repr += '{}:{}, '.format(key, self.input_para[key]) __repr = __repr[:-2] return __repr + ')' @name.setter def name(self, v): self.__name = v def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
lingtengqiu/Open-PIFuhd
DepthNormalizer
false
15,912
[ "MIT" ]
191
3a66b647bcf5591e818af62735e64a93c4aaef85
https://github.com/lingtengqiu/Open-PIFuhd/tree/3a66b647bcf5591e818af62735e64a93c4aaef85
MultiHeadSelfAttention
import torch import numpy as np import torch.nn as nn class ScaledDotProductAttention(nn.Module): def __init__(self, d_k): super(ScaledDotProductAttention, self).__init__() self.d_k = d_k def forward(self, Q, K, V, attn_mask=None): scores = torch.matmul(Q, K.transpose(-1, -2)) / np.sqrt(self.d_k) scores = torch.exp(scores) if attn_mask is not None: scores = scores * attn_mask attn = scores / (torch.sum(scores, dim=-1, keepdim=True) + 1e-08) context = torch.matmul(attn, V) return context, attn class MultiHeadSelfAttention(nn.Module): def __init__(self, d_model, num_attention_heads): super(MultiHeadSelfAttention, self).__init__() self.d_model = d_model self.num_attention_heads = num_attention_heads assert d_model % num_attention_heads == 0 self.d_k = d_model // num_attention_heads self.d_v = d_model // num_attention_heads self.W_Q = nn.Linear(d_model, d_model) self.W_K = nn.Linear(d_model, d_model) self.W_V = nn.Linear(d_model, d_model) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Linear): nn.init.xavier_uniform_(m.weight, gain=1) def forward(self, Q, K=None, V=None, length=None): if K is None: K = Q if V is None: V = Q batch_size = Q.size(0) q_s = self.W_Q(Q).view(batch_size, -1, self.num_attention_heads, self.d_k).transpose(1, 2) k_s = self.W_K(K).view(batch_size, -1, self.num_attention_heads, self.d_k).transpose(1, 2) v_s = self.W_V(V).view(batch_size, -1, self.num_attention_heads, self.d_v).transpose(1, 2) if length is not None: maxlen = Q.size(1) attn_mask = torch.arange(maxlen).expand(batch_size, maxlen ) < length.view(-1, 1) attn_mask = attn_mask.unsqueeze(1).expand(batch_size, maxlen, maxlen) attn_mask = attn_mask.unsqueeze(1).repeat(1, self. num_attention_heads, 1, 1) else: attn_mask = None context, _attn = ScaledDotProductAttention(self.d_k)(q_s, k_s, v_s, attn_mask) context = context.transpose(1, 2).contiguous().view(batch_size, -1, self.num_attention_heads * self.d_v) return context def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'num_attention_heads': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import numpy as np import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask) tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask) @triton.jit def triton_per_fused_add_div_exp_sum_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl_math.exp(tmp0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = 1e-08 tmp7 = tmp5 + tmp6 tmp8 = tmp1 / tmp7 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp7, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp8, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 16 y1 = yindex // 16 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 16, 1), (64, 16, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 16)](buf0, primals_3, buf3, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 16), (64, 16, 16, 1), 0) del buf0 triton_poi_fused_clone_0[grid(16, 16)](buf1, primals_5, buf4, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 16, 16), (256, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 16, 1), (16, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 16), (16, 0, 1), 0), out=buf5) buf6 = reinterpret_tensor(buf1, (4, 4, 16, 1), (64, 16, 1, 256), 0) del buf1 buf7 = reinterpret_tensor(buf6, (4, 4, 16, 1), (64, 16, 1, 1), 0) del buf6 buf8 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch .float32) triton_per_fused_add_div_exp_sum_1[grid(256)](buf7, buf5, buf8, 256, 16, XBLOCK=8, num_warps=2, num_stages=1) buf9 = empty_strided_cuda((4, 4, 16, 1), (64, 16, 1, 1), torch.float32) triton_poi_fused_clone_0[grid(16, 16)](buf2, primals_7, buf9, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_7 buf10 = reinterpret_tensor(buf2, (16, 16, 1), (16, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf8, (16, 16, 16), (256, 16, 1), 0), reinterpret_tensor(buf9, (16, 16, 1), (16, 1, 0), 0), out=buf10) buf11 = empty_strided_cuda((4, 16, 4, 1), (64, 4, 1, 1), torch.float32) triton_poi_fused_clone_2[grid(64, 4)](buf10, buf11, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) del buf10 return reinterpret_tensor(buf11, (4, 16, 4), (64, 4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf5, buf7, buf8, reinterpret_tensor(buf9, (16, 1, 16), (16, 1, 1), 0), reinterpret_tensor(buf3, (16, 1, 16), (16, 1, 1), 0 ), reinterpret_tensor(buf4, (16, 16, 1), (16, 1, 16), 0) class ScaledDotProductAttention(nn.Module): def __init__(self, d_k): super(ScaledDotProductAttention, self).__init__() self.d_k = d_k def forward(self, Q, K, V, attn_mask=None): scores = torch.matmul(Q, K.transpose(-1, -2)) / np.sqrt(self.d_k) scores = torch.exp(scores) if attn_mask is not None: scores = scores * attn_mask attn = scores / (torch.sum(scores, dim=-1, keepdim=True) + 1e-08) context = torch.matmul(attn, V) return context, attn class MultiHeadSelfAttentionNew(nn.Module): def __init__(self, d_model, num_attention_heads): super(MultiHeadSelfAttentionNew, self).__init__() self.d_model = d_model self.num_attention_heads = num_attention_heads assert d_model % num_attention_heads == 0 self.d_k = d_model // num_attention_heads self.d_v = d_model // num_attention_heads self.W_Q = nn.Linear(d_model, d_model) self.W_K = nn.Linear(d_model, d_model) self.W_V = nn.Linear(d_model, d_model) self._initialize_weights() def _initialize_weights(self): for m in self.modules(): if isinstance(m, nn.Linear): nn.init.xavier_uniform_(m.weight, gain=1) def forward(self, input_0): primals_2 = self.W_Q.weight primals_3 = self.W_Q.bias primals_4 = self.W_K.weight primals_5 = self.W_K.bias primals_6 = self.W_V.weight primals_7 = self.W_V.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
limhj159/NewsRecommendation
MultiHeadSelfAttention
false
15,913
[ "MIT" ]
125
5d19566b63b6cf35b5be0c2b175c5050e51f57b8
https://github.com/limhj159/NewsRecommendation/tree/5d19566b63b6cf35b5be0c2b175c5050e51f57b8
RayAngEncoder
import torch import numpy as np import torch.nn as nn def calculate_angle(a, b=None): if b is None: b = torch.Tensor([0.0, 0.0, 1.0]).view(1, 1, -1) dot_product = (a * b).sum(-1) norm_a = torch.norm(a, p=2, dim=-1) norm_b = torch.norm(b, p=2, dim=-1) cos = dot_product / (norm_a * norm_b) cos = torch.clamp(cos, -1.0 + 1e-06, 1.0 - 1e-06) angle = torch.acos(cos) assert not torch.isnan(angle).any() return angle - 0.5 * np.pi class BaseEncoder(nn.Module): def __init__(self, N_joints=24, N_dims=None): super().__init__() self.N_joints = N_joints self.N_dims = N_dims if N_dims is not None else 1 @property def dims(self): return self.N_joints * self.N_dims @property def encoder_name(self): raise NotImplementedError def forward(self, *args, **kwargs): raise NotImplementedError class RayAngEncoder(BaseEncoder): def __init__(self, N_joints=24, N_dims=1): super().__init__(N_joints, N_dims) @property def encoder_name(self): return 'RayAng' def forward(self, rays_t, pts_t, *args, **kwargs): """ Args: rays_t (N_rays, 1, N_joints, 3): rays direction in local space (joints at (0, 0, 0)) pts_t (N_rays, N_pts, N_joints, 3): 3d queries in local space (joints at (0, 0, 0)) Returns: d (N_rays, N_pts, N_joints*3): normalized ray direction in local space """ return calculate_angle(pts_t, rays_t) 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 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 @triton.jit def triton_per_fused_acos_any_clamp_div_isnan_linalg_vector_norm_mul_sum_0( in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = tmp0 * tmp0 tmp16 = tmp3 * tmp3 tmp17 = tmp15 + tmp16 tmp18 = tmp7 * tmp7 tmp19 = tmp17 + tmp18 tmp20 = tmp11 * tmp11 tmp21 = tmp19 + tmp20 tmp22 = libdevice.sqrt(tmp21) tmp23 = tmp1 * tmp1 tmp24 = tmp4 * tmp4 tmp25 = tmp23 + tmp24 tmp26 = tmp8 * tmp8 tmp27 = tmp25 + tmp26 tmp28 = tmp12 * tmp12 tmp29 = tmp27 + tmp28 tmp30 = libdevice.sqrt(tmp29) tmp31 = tmp22 * tmp30 tmp32 = tmp14 / tmp31 tmp33 = -0.999999 tmp34 = triton_helpers.maximum(tmp32, tmp33) tmp35 = 0.999999 tmp36 = triton_helpers.minimum(tmp34, tmp35) tmp37 = libdevice.acos(tmp36) tmp38 = libdevice.isnan(tmp37).to(tl.int1) tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = triton_helpers.any(tmp39, 1)[:, None] tl.store(in_out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp37, None) tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp41, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 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) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((), (), torch.bool) get_raw_stream(0) triton_per_fused_acos_any_clamp_div_isnan_linalg_vector_norm_mul_sum_0[ grid(1)](buf1, arg1_1, arg0_1, buf2, 1, 64, XBLOCK=1, num_warps =2, num_stages=1) del arg0_1 del arg1_1 return buf1, buf2 def calculate_angle(a, b=None): if b is None: b = torch.Tensor([0.0, 0.0, 1.0]).view(1, 1, -1) dot_product = (a * b).sum(-1) norm_a = torch.norm(a, p=2, dim=-1) norm_b = torch.norm(b, p=2, dim=-1) cos = dot_product / (norm_a * norm_b) cos = torch.clamp(cos, -1.0 + 1e-06, 1.0 - 1e-06) angle = torch.acos(cos) assert not torch.isnan(angle).any() return angle - 0.5 * np.pi class BaseEncoder(nn.Module): def __init__(self, N_joints=24, N_dims=None): super().__init__() self.N_joints = N_joints self.N_dims = N_dims if N_dims is not None else 1 @property def dims(self): return self.N_joints * self.N_dims @property def encoder_name(self): raise NotImplementedError def forward(self, *args, **kwargs): raise NotImplementedError class RayAngEncoderNew(BaseEncoder): def __init__(self, N_joints=24, N_dims=1): super().__init__(N_joints, N_dims) @property def encoder_name(self): return 'RayAng' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
liruilong940607/A-NeRF
RayAngEncoder
false
15,914
[ "MIT" ]
110
19cb6c4fd389266214ac0d7215a44011cb1bebf5
https://github.com/liruilong940607/A-NeRF/tree/19cb6c4fd389266214ac0d7215a44011cb1bebf5
CustomizedNet
import torch import torch.nn as nn import torch.utils.data.distributed class CustomizedNet(nn.Module): def __init__(self, dropout, input_size, input_feature_num, hidden_dim, output_size): """ Simply use linear layers for multi-variate single-step forecasting. """ super().__init__() self.fc1 = nn.Linear(input_size * input_feature_num, hidden_dim) self.dropout = nn.Dropout(dropout) self.relu1 = nn.ReLU() self.fc2 = nn.Linear(hidden_dim, output_size) def forward(self, x): x = x.view(-1, x.shape[1] * x.shape[2]) x = self.fc1(x) x = self.dropout(x) x = self.relu1(x) x = self.fc2(x) x = torch.unsqueeze(x, 1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dropout': 0.5, 'input_size': 4, 'input_feature_num': 4, 'hidden_dim': 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 import torch.nn as nn import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 16), (16, 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((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 16), (16, 1), 0), reinterpret_tensor(primals_2, (16, 4), (1, 16), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(64)](buf1, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, buf1, reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (16, 1, 4), (4, 4, 1), 0 ), reinterpret_tensor(primals_1, (16, 16), (16, 1), 0), buf1, primals_4 class CustomizedNetNew(nn.Module): def __init__(self, dropout, input_size, input_feature_num, hidden_dim, output_size): """ Simply use linear layers for multi-variate single-step forecasting. """ super().__init__() self.fc1 = nn.Linear(input_size * input_feature_num, hidden_dim) self.dropout = nn.Dropout(dropout) self.relu1 = nn.ReLU() self.fc2 = nn.Linear(hidden_dim, output_size) 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]
limn2o4/analytics-zoo
CustomizedNet
false
15,915
[ "Apache-2.0" ]
2,970
78d6ce10976a7e1320ff5ebdf431db93a439ec56
https://github.com/limn2o4/analytics-zoo/tree/78d6ce10976a7e1320ff5ebdf431db93a439ec56
ParseL1loss
import torch from torch import nn import torch.nn.functional as F class ParseL1loss(nn.Module): def __init__(self): super(ParseL1loss, self).__init__() def forward(self, output, target, mask): mask = (mask == 1).float() loss = F.l1_loss(output * mask, target * mask, size_average=False) loss = loss / (mask.sum() + 0.0001) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import 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__to_copy_abs_add_div_eq_mul_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp6 = tl.load(in_ptr2 + r0, None) tmp2 = 1.0 tmp3 = tmp1 == tmp2 tmp4 = tmp3.to(tl.float32) tmp5 = tmp0 * tmp4 tmp7 = tmp6 * tmp4 tmp8 = tmp5 - tmp7 tmp9 = tl_math.abs(tmp8) tmp10 = tl.broadcast_to(tmp9, [RBLOCK]) tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0)) tmp13 = tl.broadcast_to(tmp4, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tmp16 = 0.0001 tmp17 = tmp15 + tmp16 tmp18 = tmp12 / tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused__to_copy_abs_add_div_eq_mul_sub_sum_0[grid(1)](buf2, arg1_1, arg0_1, arg2_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class ParseL1lossNew(nn.Module): def __init__(self): super(ParseL1lossNew, 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]
litsunshine/NonCuboidRoom
ParseL1loss
false
15,916
[ "MIT" ]
54
c782222b951c622d80cae5f3217424dc2cbe6ef5
https://github.com/litsunshine/NonCuboidRoom/tree/c782222b951c622d80cae5f3217424dc2cbe6ef5
UserEncoder
from _paritybench_helpers import _mock_config import torch import torch.nn as nn import torch.nn.functional as F class AdditiveAttention(torch.nn.Module): """ A general additive attention module. Originally for NAML. """ def __init__(self, query_vector_dim, candidate_vector_dim, writer=None, tag=None, names=None): super(AdditiveAttention, self).__init__() self.linear = nn.Linear(candidate_vector_dim, query_vector_dim) self.attention_query_vector = nn.Parameter(torch.empty( query_vector_dim).uniform_(-0.1, 0.1)) self.writer = writer self.tag = tag self.names = names self.local_step = 1 def forward(self, candidate_vector): """ Args: candidate_vector: batch_size, candidate_size, candidate_vector_dim Returns: (shape) batch_size, candidate_vector_dim """ temp = torch.tanh(self.linear(candidate_vector)) candidate_weights = F.softmax(torch.matmul(temp, self. attention_query_vector), dim=1) if self.writer is not None: assert candidate_weights.size(1) == len(self.names) if self.local_step % 10 == 0: self.writer.add_scalars(self.tag, {x: y for x, y in zip( self.names, candidate_weights.mean(dim=0))}, self. local_step) self.local_step += 1 target = torch.bmm(candidate_weights.unsqueeze(dim=1), candidate_vector ).squeeze(dim=1) return target class UserEncoder(torch.nn.Module): def __init__(self, config): super(UserEncoder, self).__init__() self.additive_attention = AdditiveAttention(config.query_vector_dim, config.num_filters) def forward(self, clicked_news_vector): """ Args: clicked_news_vector: batch_size, num_clicked_news_a_user, num_filters Returns: (shape) batch_size, num_filters """ user_vector = self.additive_attention(clicked_news_vector) return user_vector def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(query_vector_dim=4, num_filters=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mv_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp11 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr1 + 2) tmp14 = tl.broadcast_to(tmp13, [XBLOCK]) tmp17 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + 3) tmp20 = tl.broadcast_to(tmp19, [XBLOCK]) tmp1 = libdevice.tanh(tmp0) tmp4 = tmp1 * tmp3 tmp6 = libdevice.tanh(tmp5) tmp9 = tmp6 * tmp8 tmp10 = tmp4 + tmp9 tmp12 = libdevice.tanh(tmp11) tmp15 = tmp12 * tmp14 tmp16 = tmp10 + tmp15 tmp18 = libdevice.tanh(tmp17) tmp21 = tmp18 * tmp20 tmp22 = tmp16 + tmp21 tl.store(out_ptr0 + x0, tmp22, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((16,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_mv_0[grid(16)](buf0, primals_4, buf1, 16, XBLOCK= 16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_1[grid(16)](buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (4, 4), (4, 1), 0) del buf1 triton_poi_fused__softmax_2[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 1, 4), (4, 4, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf3, (4, 1, 4), (4, 0, 1), 0 ), primals_3, out=buf4) del buf3 return reinterpret_tensor(buf4, (4, 4), (4, 1), 0 ), primals_3, primals_4, buf0 class AdditiveAttention(torch.nn.Module): """ A general additive attention module. Originally for NAML. """ def __init__(self, query_vector_dim, candidate_vector_dim, writer=None, tag=None, names=None): super(AdditiveAttention, self).__init__() self.linear = nn.Linear(candidate_vector_dim, query_vector_dim) self.attention_query_vector = nn.Parameter(torch.empty( query_vector_dim).uniform_(-0.1, 0.1)) self.writer = writer self.tag = tag self.names = names self.local_step = 1 def forward(self, candidate_vector): """ Args: candidate_vector: batch_size, candidate_size, candidate_vector_dim Returns: (shape) batch_size, candidate_vector_dim """ temp = torch.tanh(self.linear(candidate_vector)) candidate_weights = F.softmax(torch.matmul(temp, self. attention_query_vector), dim=1) if self.writer is not None: assert candidate_weights.size(1) == len(self.names) if self.local_step % 10 == 0: self.writer.add_scalars(self.tag, {x: y for x, y in zip( self.names, candidate_weights.mean(dim=0))}, self. local_step) self.local_step += 1 target = torch.bmm(candidate_weights.unsqueeze(dim=1), candidate_vector ).squeeze(dim=1) return target class UserEncoderNew(torch.nn.Module): def __init__(self, config): super(UserEncoderNew, self).__init__() self.additive_attention = AdditiveAttention(config.query_vector_dim, config.num_filters) def forward(self, input_0): primals_2 = self.additive_attention.attention_query_vector primals_1 = self.additive_attention.linear.weight primals_4 = self.additive_attention.linear.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
limhj159/NewsRecommendation
UserEncoder
false
15,917
[ "MIT" ]
125
5d19566b63b6cf35b5be0c2b175c5050e51f57b8
https://github.com/limhj159/NewsRecommendation/tree/5d19566b63b6cf35b5be0c2b175c5050e51f57b8
NTXentLoss
import torch class MemoryBankModule(torch.nn.Module): """Memory bank implementation This is a parent class to all loss functions implemented by the lightly Python package. This way, any loss can be used with a memory bank if desired. Attributes: size: Number of keys the memory bank can store. If set to 0, memory bank is not used. Examples: >>> class MyLossFunction(MemoryBankModule): >>> >>> def __init__(self, memory_bank_size: int = 2 ** 16): >>> super(MyLossFunction, self).__init__(memory_bank_size) >>> >>> def forward(self, output: torch.Tensor, >>> labels: torch.Tensor = None): >>> >>> output, negatives = super( >>> MyLossFunction, self).forward(output) >>> >>> if negatives is not None: >>> # evaluate loss with negative samples >>> else: >>> # evaluate loss without negative samples """ def __init__(self, size: 'int'=2 ** 16): super(MemoryBankModule, self).__init__() if size < 0: msg = f'Illegal memory bank size {size}, must be non-negative.' raise ValueError(msg) self.size = size self.bank = None self.bank_ptr = None @torch.no_grad() def _init_memory_bank(self, dim: 'int'): """Initialize the memory bank if it's empty Args: dim: The dimension of the which are stored in the bank. """ self.bank = torch.randn(dim, self.size) self.bank = torch.nn.functional.normalize(self.bank, dim=0) self.bank_ptr = torch.LongTensor([0]) @torch.no_grad() def _dequeue_and_enqueue(self, batch: 'torch.Tensor'): """Dequeue the oldest batch and add the latest one Args: batch: The latest batch of keys to add to the memory bank. """ batch_size = batch.shape[0] ptr = int(self.bank_ptr) if ptr + batch_size >= self.size: self.bank[:, ptr:] = batch[:self.size - ptr].T.detach() self.bank_ptr[0] = 0 else: self.bank[:, ptr:ptr + batch_size] = batch.T.detach() self.bank_ptr[0] = ptr + batch_size def forward(self, output: 'torch.Tensor', labels: 'torch.Tensor'=None, update: 'bool'=False): """Query memory bank for additional negative samples Args: output: The output of the model. labels: Should always be None, will be ignored. Returns: The output if the memory bank is of size 0, otherwise the output and the entries from the memory bank. """ if self.size == 0: return output, None _, dim = output.shape if self.bank is None: self._init_memory_bank(dim) bank = self.bank.clone().detach() if update: self._dequeue_and_enqueue(output) return output, bank class NTXentLoss(MemoryBankModule): """Implementation of the Contrastive Cross Entropy Loss. This implementation follows the SimCLR[0] paper. If you enable the memory bank by setting the `memory_bank_size` value > 0 the loss behaves like the one described in the MoCo[1] paper. [0] SimCLR, 2020, https://arxiv.org/abs/2002.05709 [1] MoCo, 2020, https://arxiv.org/abs/1911.05722 Attributes: temperature: Scale logits by the inverse of the temperature. memory_bank_size: Number of negative samples to store in the memory bank. Use 0 for SimCLR. For MoCo we typically use numbers like 4096 or 65536. Raises: ValueError if abs(temperature) < 1e-8 to prevent divide by zero. Examples: >>> # initialize loss function without memory bank >>> loss_fn = NTXentLoss(memory_bank_size=0) >>> >>> # generate two random transforms of images >>> t0 = transforms(images) >>> t1 = transforms(images) >>> >>> # feed through SimCLR or MoCo model >>> batch = torch.cat((t0, t1), dim=0) >>> output = model(batch) >>> >>> # calculate loss >>> loss = loss_fn(output) """ def __init__(self, temperature: 'float'=0.5, memory_bank_size: 'int'=0): super(NTXentLoss, self).__init__(size=memory_bank_size) self.temperature = temperature self.cross_entropy = torch.nn.CrossEntropyLoss(reduction='mean') self.eps = 1e-08 if abs(self.temperature) < self.eps: raise ValueError('Illegal temperature: abs({}) < 1e-8'.format( self.temperature)) def forward(self, out0: 'torch.Tensor', out1: 'torch.Tensor'): """Forward pass through Contrastive Cross-Entropy Loss. If used with a memory bank, the samples from the memory bank are used as negative examples. Otherwise, within-batch samples are used as negative samples. Args: out0: Output projections of the first set of transformed images. Shape: (batch_size, embedding_size) out1: Output projections of the second set of transformed images. Shape: (batch_size, embedding_size) Returns: Contrastive Cross Entropy Loss value. """ device = out0.device batch_size, _ = out0.shape out0 = torch.nn.functional.normalize(out0, dim=1) out1 = torch.nn.functional.normalize(out1, dim=1) out1, negatives = super(NTXentLoss, self).forward(out1, update=out0 .requires_grad) if negatives is not None: negatives = negatives sim_pos = torch.einsum('nc,nc->n', out0, out1).unsqueeze(-1) sim_neg = torch.einsum('nc,ck->nk', out0, negatives) logits = torch.cat([sim_pos, sim_neg], dim=1) / self.temperature labels = torch.zeros(logits.shape[0], device=device, dtype= torch.long) else: output = torch.cat((out0, out1), axis=0) logits = torch.einsum('nc,mc->nm', output, output ) / self.temperature logits = logits[~torch.eye(2 * batch_size, dtype=torch.bool, device=out0.device)].view(2 * batch_size, -1) labels = torch.arange(batch_size, device=device, dtype=torch.long) labels = torch.cat([labels + batch_size - 1, labels]) loss = self.cross_entropy(logits, labels) return loss def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp4 & xmask, other=0.0) tmp6 = tl.load(in_ptr0 + 4 * x1, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp6 * tmp6 tmp8 = tl.load(in_ptr0 + (1 + 4 * x1), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = tl.load(in_ptr0 + (2 + 4 * x1), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tl.load(in_ptr0 + (3 + 4 * x1), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = libdevice.sqrt(tmp16) tmp18 = 1e-12 tmp19 = triton_helpers.maximum(tmp17, tmp18) tmp20 = tmp5 / tmp19 tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp4, tmp20, tmp21) tmp23 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp26 = tl.load(in_ptr1 + (x0 + 4 * (-4 + x1)), tmp23 & xmask, other=0.0) tmp27 = tl.load(in_ptr1 + 4 * (-4 + x1), tmp23 & xmask, eviction_policy ='evict_last', other=0.0) tmp28 = tmp27 * tmp27 tmp29 = tl.load(in_ptr1 + (1 + 4 * (-4 + x1)), tmp23 & xmask, eviction_policy='evict_last', other=0.0) tmp30 = tmp29 * tmp29 tmp31 = tmp28 + tmp30 tmp32 = tl.load(in_ptr1 + (2 + 4 * (-4 + x1)), tmp23 & xmask, eviction_policy='evict_last', other=0.0) tmp33 = tmp32 * tmp32 tmp34 = tmp31 + tmp33 tmp35 = tl.load(in_ptr1 + (3 + 4 * (-4 + x1)), tmp23 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tmp35 * tmp35 tmp37 = tmp34 + tmp36 tmp38 = libdevice.sqrt(tmp37) tmp39 = triton_helpers.maximum(tmp38, tmp18) tmp40 = tmp26 / tmp39 tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype) tmp42 = tl.where(tmp23, tmp40, tmp41) tmp43 = tl.where(tmp4, tmp22, tmp42) tl.store(out_ptr0 + x2, tmp43, xmask) @triton.jit def triton_poi_fused_div_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = 2.0 tmp2 = tmp0 * tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_bitwise_not_eye_2(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 x0 = xindex % 8 x2 = xindex tmp0 = x1 tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = tmp2 == 0 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](arg0_1, arg1_1, buf0, 32, XBLOCK= 32, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((1, 8, 8), (64, 8, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (1, 8, 4), (32, 4, 1), 0), reinterpret_tensor(buf0, (1, 4, 8), (0, 1, 4), 0), out=buf1) del buf0 buf2 = reinterpret_tensor(buf1, (8, 8), (8, 1), 0) del buf1 triton_poi_fused_div_1[grid(64)](buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((8, 8), (8, 1), torch.bool) triton_poi_fused_bitwise_not_eye_2[grid(64)](buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf2, buf3 class MemoryBankModule(torch.nn.Module): """Memory bank implementation This is a parent class to all loss functions implemented by the lightly Python package. This way, any loss can be used with a memory bank if desired. Attributes: size: Number of keys the memory bank can store. If set to 0, memory bank is not used. Examples: >>> class MyLossFunction(MemoryBankModule): >>> >>> def __init__(self, memory_bank_size: int = 2 ** 16): >>> super(MyLossFunction, self).__init__(memory_bank_size) >>> >>> def forward(self, output: torch.Tensor, >>> labels: torch.Tensor = None): >>> >>> output, negatives = super( >>> MyLossFunction, self).forward(output) >>> >>> if negatives is not None: >>> # evaluate loss with negative samples >>> else: >>> # evaluate loss without negative samples """ def __init__(self, size: 'int'=2 ** 16): super(MemoryBankModule, self).__init__() if size < 0: msg = f'Illegal memory bank size {size}, must be non-negative.' raise ValueError(msg) self.size = size self.bank = None self.bank_ptr = None @torch.no_grad() def _init_memory_bank(self, dim: 'int'): """Initialize the memory bank if it's empty Args: dim: The dimension of the which are stored in the bank. """ self.bank = torch.randn(dim, self.size) self.bank = torch.nn.functional.normalize(self.bank, dim=0) self.bank_ptr = torch.LongTensor([0]) @torch.no_grad() def _dequeue_and_enqueue(self, batch: 'torch.Tensor'): """Dequeue the oldest batch and add the latest one Args: batch: The latest batch of keys to add to the memory bank. """ batch_size = batch.shape[0] ptr = int(self.bank_ptr) if ptr + batch_size >= self.size: self.bank[:, ptr:] = batch[:self.size - ptr].T.detach() self.bank_ptr[0] = 0 else: self.bank[:, ptr:ptr + batch_size] = batch.T.detach() self.bank_ptr[0] = ptr + batch_size def forward(self, output: 'torch.Tensor', labels: 'torch.Tensor'=None, update: 'bool'=False): """Query memory bank for additional negative samples Args: output: The output of the model. labels: Should always be None, will be ignored. Returns: The output if the memory bank is of size 0, otherwise the output and the entries from the memory bank. """ if self.size == 0: return output, None _, dim = output.shape if self.bank is None: self._init_memory_bank(dim) bank = self.bank.clone().detach() if update: self._dequeue_and_enqueue(output) return output, bank class NTXentLossNew(MemoryBankModule): """Implementation of the Contrastive Cross Entropy Loss. This implementation follows the SimCLR[0] paper. If you enable the memory bank by setting the `memory_bank_size` value > 0 the loss behaves like the one described in the MoCo[1] paper. [0] SimCLR, 2020, https://arxiv.org/abs/2002.05709 [1] MoCo, 2020, https://arxiv.org/abs/1911.05722 Attributes: temperature: Scale logits by the inverse of the temperature. memory_bank_size: Number of negative samples to store in the memory bank. Use 0 for SimCLR. For MoCo we typically use numbers like 4096 or 65536. Raises: ValueError if abs(temperature) < 1e-8 to prevent divide by zero. Examples: >>> # initialize loss function without memory bank >>> loss_fn = NTXentLoss(memory_bank_size=0) >>> >>> # generate two random transforms of images >>> t0 = transforms(images) >>> t1 = transforms(images) >>> >>> # feed through SimCLR or MoCo model >>> batch = torch.cat((t0, t1), dim=0) >>> output = model(batch) >>> >>> # calculate loss >>> loss = loss_fn(output) """ def __init__(self, temperature: 'float'=0.5, memory_bank_size: 'int'=0): super(NTXentLossNew, self).__init__(size=memory_bank_size) self.temperature = temperature self.cross_entropy = torch.nn.CrossEntropyLoss(reduction='mean') self.eps = 1e-08 if abs(self.temperature) < self.eps: raise ValueError('Illegal temperature: abs({}) < 1e-8'.format( self.temperature)) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lightly-ai/lightly
NTXentLoss
false
15,918
[ "MIT" ]
1,515
0b98bda640d13d842fd13f9354271d0cef116ba5
https://github.com/lightly-ai/lightly/tree/0b98bda640d13d842fd13f9354271d0cef116ba5
DCGanGenerator
import torch import torch.nn as nn from torch.nn import functional as F class DCGanGenerator(nn.Module): def __init__(self, latent_dim): super().__init__() self.fc1 = nn.Linear(latent_dim, 2 * 2 * 512) self.conv1 = nn.ConvTranspose2d(512, 256, kernel_size=5, stride=1, padding=1, output_padding=0) self.conv2 = nn.ConvTranspose2d(256, 128, kernel_size=4, stride=2, padding=1) self.conv3 = nn.ConvTranspose2d(128, 64, kernel_size=4, stride=2, padding=1, output_padding=0) self.conv4 = nn.ConvTranspose2d(64, 3, kernel_size=5, stride=2, padding=3) def forward(self, input): x = self.fc1(input) x = x.view(x.size(0), 512, 2, 2) x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = F.relu(self.conv4(x)) return torch.tanh(x) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'latent_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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 256 * x2 + 6400 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 128 * x2 + 2048 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 64 * x2 + 1024 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 192 xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 75 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_view_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 4 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 2048 * y1), tmp0, xmask) @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_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_tanh_8(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 12 xnumel = 841 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 % 3 y1 = yindex // 3 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 3 * x2 + 2523 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = libdevice.tanh(tmp4) tl.store(out_ptr0 + (x2 + 841 * y3), tmp5, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_9(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 10092 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 3 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, primals_11) = args args.clear() assert_size_stride(primals_1, (2048, 4), (4, 1)) assert_size_stride(primals_2, (2048,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (512, 256, 5, 5), (6400, 25, 5, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (256, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (64, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_11, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((512, 256, 5, 5), (6400, 1, 1280, 256), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(131072, 25)](primals_4, buf0, 131072, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_4 buf1 = empty_strided_cuda((256, 128, 4, 4), (2048, 1, 512, 128), torch.float32) triton_poi_fused_1[grid(32768, 16)](primals_6, buf1, 32768, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf2 = empty_strided_cuda((128, 64, 4, 4), (1024, 1, 256, 64), torch.float32) triton_poi_fused_2[grid(8192, 16)](primals_8, buf2, 8192, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf3 = empty_strided_cuda((64, 3, 5, 5), (75, 1, 15, 3), torch.float32) triton_poi_fused_3[grid(192, 25)](primals_10, buf3, 192, 25, XBLOCK =32, YBLOCK=32, num_warps=4, num_stages=1) del primals_10 buf4 = empty_strided_cuda((4, 2048), (2048, 1), torch.float32) extern_kernels.addmm(primals_2, primals_3, reinterpret_tensor( primals_1, (4, 2048), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_1 del primals_2 buf5 = empty_strided_cuda((4, 512, 2, 2), (2048, 1, 1024, 512), torch.float32) triton_poi_fused_view_4[grid(2048, 4)](buf4, buf5, 2048, 4, XBLOCK= 4, YBLOCK=256, num_warps=4, num_stages=1) del buf4 buf6 = extern_kernels.convolution(buf5, buf0, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_5[grid(16384)](buf7, primals_5, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf8 = extern_kernels.convolution(buf7, buf1, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_6[grid(32768)](buf9, primals_7, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf10 = extern_kernels.convolution(buf9, buf2, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf11 = buf10 del buf10 triton_poi_fused_convolution_relu_7[grid(65536)](buf11, primals_9, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_9 buf12 = extern_kernels.convolution(buf11, buf3, stride=(2, 2), padding=(3, 3), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 3, 29, 29), (2523, 1, 87, 3)) buf13 = empty_strided_cuda((4, 3, 29, 29), (2523, 841, 29, 1), torch.float32) triton_poi_fused_convolution_relu_tanh_8[grid(12, 841)](buf12, primals_11, buf13, 12, 841, XBLOCK=256, YBLOCK=1, num_warps=4, num_stages=1) buf14 = empty_strided_cuda((4, 3, 29, 29), (2523, 1, 87, 3), torch.bool ) triton_poi_fused_convolution_relu_threshold_backward_9[grid(10092)]( buf12, primals_11, buf14, 10092, XBLOCK=256, num_warps=4, num_stages=1) del buf12 del primals_11 return (buf13, primals_3, buf0, buf1, buf2, buf3, buf5, buf7, buf9, buf11, buf13, buf14) class DCGanGeneratorNew(nn.Module): def __init__(self, latent_dim): super().__init__() self.fc1 = nn.Linear(latent_dim, 2 * 2 * 512) self.conv1 = nn.ConvTranspose2d(512, 256, kernel_size=5, stride=1, padding=1, output_padding=0) self.conv2 = nn.ConvTranspose2d(256, 128, kernel_size=4, stride=2, padding=1) self.conv3 = nn.ConvTranspose2d(128, 64, kernel_size=4, stride=2, padding=1, output_padding=0) self.conv4 = nn.ConvTranspose2d(64, 3, kernel_size=5, stride=2, padding=3) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.conv1.weight primals_5 = self.conv1.bias primals_6 = self.conv2.weight primals_7 = self.conv2.bias primals_8 = self.conv3.weight primals_9 = self.conv3.bias primals_10 = self.conv4.weight primals_11 = self.conv4.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
krylea/mine-pytorch
DCGanGenerator
false
15,919
[ "MIT" ]
108
a638ca3e46ff21a3b9dfebe25480eaed0e3304bc
https://github.com/krylea/mine-pytorch/tree/a638ca3e46ff21a3b9dfebe25480eaed0e3304bc
BalancedNet
import torch import torch.nn as nn from torch import logsumexp as logsumexp import torch.nn.functional as F class BalancedNet(nn.Module): """A torch.model used as a component of the HEMM module to determine the outcome as a function of confounders. The balanced net consists of two different neural networks for the outcome and counteractual. """ def __init__(self, D_in, H, D_out): """Instantiate two nn.Linear modules and assign them as member variables. Args: D_in: input dimension H: dimension of hidden layer D_out: output dimension """ super(BalancedNet, self).__init__() self.f1 = nn.Linear(D_in, H) self.f2 = nn.Linear(H, D_out) self.cf1 = nn.Linear(D_in, H) self.cf2 = nn.Linear(H, D_out) def forward(self, x): """Accept a Variable of input data and return a Variable of output data. We can use Modules defined in the constructor as well as arbitrary operators on Variables. """ h_relu = F.elu(self.f1(x)) f = self.f2(h_relu) h_relu = F.elu(self.cf1(x)) cf = self.cf2(h_relu) out = torch.cat((f, cf), dim=1) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'D_in': 4, 'H': 4, 'D_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch import logsumexp as logsumexp assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 8 x0 = xindex % 16 x2 = xindex // 128 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) def call(args): (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.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf3) del primals_6 del primals_7 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_elu_0[grid(256)](buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf4, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf5) del primals_9 buf6 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) triton_poi_fused_cat_1[grid(512)](buf2, buf5, buf6, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf2 del buf5 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0 ), buf3, reinterpret_tensor(buf4, (64, 4), (4, 1), 0 ), primals_8, primals_4 class BalancedNetNew(nn.Module): """A torch.model used as a component of the HEMM module to determine the outcome as a function of confounders. The balanced net consists of two different neural networks for the outcome and counteractual. """ def __init__(self, D_in, H, D_out): """Instantiate two nn.Linear modules and assign them as member variables. Args: D_in: input dimension H: dimension of hidden layer D_out: output dimension """ super(BalancedNetNew, self).__init__() self.f1 = nn.Linear(D_in, H) self.f2 = nn.Linear(H, D_out) self.cf1 = nn.Linear(D_in, H) self.cf2 = nn.Linear(H, D_out) 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.cf1.weight primals_7 = self.cf1.bias primals_8 = self.cf2.weight primals_9 = self.cf2.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]
liranszlak/causallib
BalancedNet
false
15,920
[ "Apache-2.0" ]
350
2636149f6b1e307672aff638a53f8eaf2be56bc9
https://github.com/liranszlak/causallib/tree/2636149f6b1e307672aff638a53f8eaf2be56bc9
AttentionLayer
import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import * class AttentionLayer(nn.Module): def __init__(self, hidden_dim_en, hidden_dim_de, projected_size): super(AttentionLayer, self).__init__() self.linear1 = nn.Linear(hidden_dim_en, projected_size) self.linear2 = nn.Linear(hidden_dim_de, projected_size) self.linear3 = nn.Linear(projected_size, 1, False) def forward(self, out_e, h): """ out_e: batch_size * num_frames * en_hidden_dim h : batch_size * de_hidden_dim """ assert out_e.size(0) == h.size(0) batch_size, num_frames, _ = out_e.size() hidden_dim = h.size(1) h_att = h.unsqueeze(1).expand(batch_size, num_frames, hidden_dim) x = F.tanh(F.dropout(self.linear1(out_e)) + F.dropout(self.linear2( h_att))) x = F.dropout(self.linear3(x)) a = F.softmax(x.squeeze(2)) return a def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'hidden_dim_en': 4, 'hidden_dim_de': 4, 'projected_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 from torch.autograd import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_add_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (1, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_3 del primals_4 buf1 = torch.ops.aten.native_dropout.default(reinterpret_tensor( buf0, (4, 4, 4), (16, 4, 1), 0), 0.5, True) buf2 = buf1[0] buf3 = buf1[1] del buf1 buf4 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_2, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf5 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf5) del primals_5 buf6 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0) del buf5 triton_poi_fused_add_1[grid(64)](buf6, primals_6, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_6 buf7 = torch.ops.aten.native_dropout.default(buf6, 0.5, True) del buf6 buf8 = buf7[0] buf9 = buf7[1] del buf7 buf10 = buf2 del buf2 triton_poi_fused_add_tanh_2[grid(64)](buf10, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf8 buf11 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf10, (16, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 1), (1, 4), 0), out=buf11) buf12 = torch.ops.aten.native_dropout.default(reinterpret_tensor( buf11, (4, 4, 1), (4, 1, 1), 0), 0.5, True) buf13 = buf12[0] buf14 = buf12[1] del buf12 buf15 = reinterpret_tensor(buf11, (4, 4), (4, 1), 0) del buf11 triton_poi_fused__softmax_3[grid(16)](buf13, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = reinterpret_tensor(buf13, (4, 4), (4, 1), 0) del buf13 triton_poi_fused__softmax_4[grid(16)](buf15, buf16, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf15 return buf16, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0 ), buf3, reinterpret_tensor(buf4, (16, 4), (4, 1), 0 ), buf9, buf10, buf14, buf16, primals_7 class AttentionLayerNew(nn.Module): def __init__(self, hidden_dim_en, hidden_dim_de, projected_size): super(AttentionLayerNew, self).__init__() self.linear1 = nn.Linear(hidden_dim_en, projected_size) self.linear2 = nn.Linear(hidden_dim_de, projected_size) self.linear3 = nn.Linear(projected_size, 1, False) def forward(self, input_0, input_1): primals_2 = self.linear1.weight primals_4 = self.linear1.bias primals_3 = self.linear2.weight primals_6 = self.linear2.bias primals_7 = self.linear3.weight primals_1 = input_0 primals_5 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
littlekobe/AREL-for-Visual-Storytelling
AttentionLayer
false
15,921
[ "MIT" ]
82
7df46be67a2de22a763bad25c70066b702a6afba
https://github.com/littlekobe/AREL-for-Visual-Storytelling/tree/7df46be67a2de22a763bad25c70066b702a6afba
VecNormEncoder
import torch import torch.nn as nn import torch.nn.functional as F class BaseEncoder(nn.Module): def __init__(self, N_joints=24, N_dims=None): super().__init__() self.N_joints = N_joints self.N_dims = N_dims if N_dims is not None else 1 @property def dims(self): return self.N_joints * self.N_dims @property def encoder_name(self): raise NotImplementedError def forward(self, *args, **kwargs): raise NotImplementedError class VecNormEncoder(BaseEncoder): def __init__(self, N_joints=24, N_dims=3): super().__init__(N_joints, N_dims) @property def encoder_name(self): return 'VecNorm' def forward(self, vecs, refs=None, *args, **kwargs): """ Args: vecs (N_rays, *, ...): vector to normalize. refs (N_rays, N_pts, ...): reference tensor for shape expansion. Returns: (N_rays, N_pts, *): normalized vector with expanded shape (if needed). """ n = F.normalize(vecs, dim=-1, p=2).flatten(start_dim=2) if refs is not None: n = n.expand(*refs.shape[:2], -1) return n def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn 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_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') 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) 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_div_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4, 16), (64, 16, 1), 0), class BaseEncoder(nn.Module): def __init__(self, N_joints=24, N_dims=None): super().__init__() self.N_joints = N_joints self.N_dims = N_dims if N_dims is not None else 1 @property def dims(self): return self.N_joints * self.N_dims @property def encoder_name(self): raise NotImplementedError def forward(self, *args, **kwargs): raise NotImplementedError class VecNormEncoderNew(BaseEncoder): def __init__(self, N_joints=24, N_dims=3): super().__init__(N_joints, N_dims) @property def encoder_name(self): return 'VecNorm' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
liruilong940607/A-NeRF
VecNormEncoder
false
15,922
[ "MIT" ]
110
19cb6c4fd389266214ac0d7215a44011cb1bebf5
https://github.com/liruilong940607/A-NeRF/tree/19cb6c4fd389266214ac0d7215a44011cb1bebf5
BertLinear
import math import torch import torch.nn as nn def gelu(x): """Implementation of the gelu activation function. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see https://arxiv.org/abs/1606.08415 refer to: https://github.com/huggingface/pytorch-transformers/blob/master/pytorch_transformers/modeling_bert.py """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class BertLayerNorm(nn.Module): """This class is LayerNorm model for Bert """ def __init__(self, hidden_size, eps=1e-12): """This function sets `BertLayerNorm` parameters Arguments: hidden_size {int} -- input size Keyword Arguments: eps {float} -- epsilon (default: {1e-12}) """ super().__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): """This function propagates forwardly Arguments: x {tensor} -- input tesor Returns: tensor -- LayerNorm outputs """ u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.weight * x + self.bias class BertLinear(nn.Module): """This class is Linear model for Bert """ def __init__(self, input_size, output_size, activation=gelu, dropout=0.0): """This function sets `BertLinear` model parameters Arguments: input_size {int} -- input size output_size {int} -- output size Keyword Arguments: activation {function} -- activation function (default: {gelu}) dropout {float} -- dropout rate (default: {0.0}) """ super().__init__() self.input_size = input_size self.output_size = output_size self.linear = nn.Linear(input_size, output_size) self.linear.weight.data.normal_(mean=0.0, std=0.02) self.linear.bias.data.zero_() self.activation = activation self.layer_norm = BertLayerNorm(self.output_size) if dropout > 0: self.dropout = nn.Dropout(p=dropout) else: self.dropout = lambda x: x def get_input_dims(self): return self.input_size def get_output_dims(self): return self.output_size def forward(self, x): """This function propagates forwardly Arguments: x {tensor} -- input tensor Returns: tenor -- Linear outputs """ output = self.activation(self.linear(x)) return self.dropout(self.layer_norm(output)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_erf_mean_mul_pow_sub_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp23 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865475 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tmp10 = tmp9 * tmp1 tmp11 = tmp9 * tmp3 tmp12 = libdevice.erf(tmp11) tmp13 = tmp12 + tmp6 tmp14 = tmp10 * tmp13 tmp15 = tmp8 + tmp14 tmp17 = tmp16 * tmp1 tmp18 = tmp16 * tmp3 tmp19 = libdevice.erf(tmp18) tmp20 = tmp19 + tmp6 tmp21 = tmp17 * tmp20 tmp22 = tmp15 + tmp21 tmp24 = tmp23 * tmp1 tmp25 = tmp23 * tmp3 tmp26 = libdevice.erf(tmp25) tmp27 = tmp26 + tmp6 tmp28 = tmp24 * tmp27 tmp29 = tmp22 + tmp28 tmp30 = 4.0 tmp31 = tmp29 / tmp30 tmp32 = tmp8 - tmp31 tmp33 = tmp32 * tmp32 tmp34 = tmp14 - tmp31 tmp35 = tmp34 * tmp34 tmp36 = tmp33 + tmp35 tmp37 = tmp21 - tmp31 tmp38 = tmp37 * tmp37 tmp39 = tmp36 + tmp38 tmp40 = tmp28 - tmp31 tmp41 = tmp40 * tmp40 tmp42 = tmp39 + tmp41 tmp43 = tmp42 / tmp30 tl.store(out_ptr0 + x0, tmp31, xmask) tl.store(out_ptr1 + x0, tmp43, xmask) @triton.jit def triton_poi_fused_add_div_erf_mul_sqrt_sub_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp10 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = 0.7071067811865475 tmp5 = tmp1 * tmp4 tmp6 = libdevice.erf(tmp5) tmp7 = 1.0 tmp8 = tmp6 + tmp7 tmp9 = tmp3 * tmp8 tmp11 = tmp9 - tmp10 tmp13 = 1e-12 tmp14 = tmp12 + tmp13 tmp15 = libdevice.sqrt(tmp14) tmp16 = tmp11 / tmp15 tmp17 = tmp0 * tmp16 tmp19 = tmp17 + tmp18 tl.store(out_ptr0 + x2, tmp19, 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,), (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.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_erf_mean_mul_pow_sub_0[grid(64)](buf0, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_erf_mul_sqrt_sub_1[grid(256)](primals_4, buf0, buf1, buf2, primals_5, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del buf2 del primals_5 return buf3, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0 def gelu(x): """Implementation of the gelu activation function. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results): 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see https://arxiv.org/abs/1606.08415 refer to: https://github.com/huggingface/pytorch-transformers/blob/master/pytorch_transformers/modeling_bert.py """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class BertLayerNorm(nn.Module): """This class is LayerNorm model for Bert """ def __init__(self, hidden_size, eps=1e-12): """This function sets `BertLayerNorm` parameters Arguments: hidden_size {int} -- input size Keyword Arguments: eps {float} -- epsilon (default: {1e-12}) """ super().__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps def forward(self, x): """This function propagates forwardly Arguments: x {tensor} -- input tesor Returns: tensor -- LayerNorm outputs """ u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.weight * x + self.bias class BertLinearNew(nn.Module): """This class is Linear model for Bert """ def __init__(self, input_size, output_size, activation=gelu, dropout=0.0): """This function sets `BertLinear` model parameters Arguments: input_size {int} -- input size output_size {int} -- output size Keyword Arguments: activation {function} -- activation function (default: {gelu}) dropout {float} -- dropout rate (default: {0.0}) """ super().__init__() self.input_size = input_size self.output_size = output_size self.linear = nn.Linear(input_size, output_size) self.linear.weight.data.normal_(mean=0.0, std=0.02) self.linear.bias.data.zero_() self.activation = activation self.layer_norm = BertLayerNorm(self.output_size) if dropout > 0: self.dropout = nn.Dropout(p=dropout) else: self.dropout = lambda x: x def get_input_dims(self): return self.input_size def get_output_dims(self): return self.output_size def forward(self, input_0): primals_1 = self.linear.weight primals_2 = self.linear.bias primals_4 = self.layer_norm.weight primals_5 = self.layer_norm.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
liu4lin/UniRE
BertLinear
false
15,923
[ "MIT" ]
87
fb31801161758e50762f9a70820b71aefb5c5515
https://github.com/liu4lin/UniRE/tree/fb31801161758e50762f9a70820b71aefb5c5515
TwoMLPHead
import torch from torch import nn import torch.nn.functional as F import torch.utils.data class TwoMLPHead(nn.Module): """ Standard heads for FPN-based models Arguments: in_channels (int): number of input channels representation_size (int): size of the intermediate representation """ def __init__(self, in_channels, representation_size): super(TwoMLPHead, self).__init__() self.fc6 = nn.Linear(in_channels, representation_size) self.fc7 = nn.Linear(representation_size, representation_size) def forward(self, x): x = x.flatten(start_dim=1) x = F.relu(self.fc6(x)) x = F.relu(self.fc7(x)) return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'representation_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(16)](buf1, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf2) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(16)](buf3, primals_5, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return buf3, primals_1, buf1, buf4, primals_4 class TwoMLPHeadNew(nn.Module): """ Standard heads for FPN-based models Arguments: in_channels (int): number of input channels representation_size (int): size of the intermediate representation """ def __init__(self, in_channels, representation_size): super(TwoMLPHeadNew, self).__init__() self.fc6 = nn.Linear(in_channels, representation_size) self.fc7 = nn.Linear(representation_size, representation_size) def forward(self, input_0): primals_1 = self.fc6.weight primals_3 = self.fc6.bias primals_2 = self.fc7.weight primals_5 = self.fc7.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
littlerain2310/japances_character
TwoMLPHead
false
15,924
[ "MIT", "BSD-3-Clause" ]
81
bdca6b30f3058af30462dcd5729eacb69f6fa83b
https://github.com/littlerain2310/japances_character/tree/bdca6b30f3058af30462dcd5729eacb69f6fa83b
SoftDetectionModule
import torch import torch.nn.functional as F import torch.nn as nn class SoftDetectionModule(nn.Module): def __init__(self, soft_local_max_size=3): super(SoftDetectionModule, self).__init__() self.soft_local_max_size = soft_local_max_size self.pad = self.soft_local_max_size // 2 def forward(self, batch): b = batch.size(0) batch = F.relu(batch) max_per_sample = torch.max(batch.view(b, -1), dim=1)[0] exp = torch.exp(batch / max_per_sample.view(b, 1, 1, 1)) sum_exp = self.soft_local_max_size ** 2 * F.avg_pool2d(F.pad(exp, [ self.pad] * 4, mode='constant', value=1.0), self. soft_local_max_size, stride=1) local_max_score = exp / sum_exp depth_wise_max = torch.max(batch, dim=1)[0] depth_wise_max_score = batch / depth_wise_max.unsqueeze(1) all_scores = local_max_score * depth_wise_max_score score = torch.max(all_scores, dim=1)[0] score = score / torch.sum(score.view(b, -1), dim=1).view(b, 1, 1) return score def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_max_0(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.full([1, 1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_div_exp_relu_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 6 % 6 x0 = xindex % 6 x4 = xindex // 36 x3 = xindex // 144 x6 = 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 * x4), tmp10 & xmask, other=0.0) tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp14 = tl.load(in_ptr1 + x3, tmp10 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tmp13 / tmp14 tmp16 = tl_math.exp(tmp15) tmp17 = tl.full(tmp16.shape, 1.0, tmp16.dtype) tmp18 = tl.where(tmp10, tmp16, tmp17) tl.store(out_ptr0 + x6, tmp18, xmask) @triton.jit def triton_poi_fused_avg_pool2d_constant_pad_nd_div_exp_relu_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 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 6 * x1 + 36 * x2), xmask) tmp1 = tl.load(in_ptr0 + (1 + x0 + 6 * x1 + 36 * x2), xmask) tmp3 = tl.load(in_ptr0 + (2 + x0 + 6 * x1 + 36 * x2), xmask) tmp5 = tl.load(in_ptr0 + (6 + x0 + 6 * x1 + 36 * x2), xmask) tmp7 = tl.load(in_ptr0 + (7 + x0 + 6 * x1 + 36 * x2), xmask) tmp9 = tl.load(in_ptr0 + (8 + x0 + 6 * x1 + 36 * x2), xmask) tmp11 = tl.load(in_ptr0 + (12 + x0 + 6 * x1 + 36 * x2), xmask) tmp13 = tl.load(in_ptr0 + (13 + x0 + 6 * x1 + 36 * x2), xmask) tmp15 = tl.load(in_ptr0 + (14 + x0 + 6 * x1 + 36 * x2), xmask) tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp8 = tmp7 + tmp6 tmp10 = tmp9 + tmp8 tmp12 = tmp11 + tmp10 tmp14 = tmp13 + tmp12 tmp16 = tmp15 + tmp14 tmp17 = 0.1111111111111111 tmp18 = tmp16 * tmp17 tl.store(out_ptr0 + x3, tmp18, xmask) @triton.jit def triton_per_fused_div_exp_max_mul_relu_sum_3(in_ptr0, in_ptr1, in_ptr2, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + (r1 + 64 * x0), xmask, other=0.0) tmp10 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp13 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp16 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp23 = tl.load(in_ptr2 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp31 = tl.load(in_ptr2 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp39 = tl.load(in_ptr2 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.full([1, 1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tmp2 / tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = 9.0 tmp8 = tmp6 * tmp7 tmp9 = tmp5 / tmp8 tmp11 = triton_helpers.maximum(tmp1, tmp10) tmp12 = triton_helpers.maximum(tmp2, tmp11) tmp14 = triton_helpers.maximum(tmp1, tmp13) tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp17 = triton_helpers.maximum(tmp1, tmp16) tmp18 = triton_helpers.maximum(tmp15, tmp17) tmp19 = tmp2 / tmp18 tmp20 = tmp9 * tmp19 tmp21 = tmp11 / tmp3 tmp22 = tl_math.exp(tmp21) tmp24 = tmp23 * tmp7 tmp25 = tmp22 / tmp24 tmp26 = tmp11 / tmp18 tmp27 = tmp25 * tmp26 tmp28 = triton_helpers.maximum(tmp20, tmp27) tmp29 = tmp14 / tmp3 tmp30 = tl_math.exp(tmp29) tmp32 = tmp31 * tmp7 tmp33 = tmp30 / tmp32 tmp34 = tmp14 / tmp18 tmp35 = tmp33 * tmp34 tmp36 = triton_helpers.maximum(tmp28, tmp35) tmp37 = tmp17 / tmp3 tmp38 = tl_math.exp(tmp37) tmp40 = tmp39 * tmp7 tmp41 = tmp38 / tmp40 tmp42 = tmp17 / tmp18 tmp43 = tmp41 * tmp42 tmp44 = triton_helpers.maximum(tmp36, tmp43) tmp45 = tl.broadcast_to(tmp44, [XBLOCK, RBLOCK]) tmp47 = tl.where(xmask, tmp45, 0) tmp48 = tl.sum(tmp47, 1)[:, None] tmp49 = tmp44 / tmp48 tl.store(out_ptr2 + (r1 + 16 * x0), tmp49, 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,), torch.float32) get_raw_stream(0) triton_per_fused_max_0[grid(4)](arg0_1, buf0, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf2 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused_constant_pad_nd_div_exp_relu_1[grid(576)](arg0_1, buf0, buf2, 576, XBLOCK=256, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_avg_pool2d_constant_pad_nd_div_exp_relu_2[grid(256)]( buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_per_fused_div_exp_max_mul_relu_sum_3[grid(4)](arg0_1, buf0, buf3, buf6, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del buf0 del buf3 return buf6, class SoftDetectionModuleNew(nn.Module): def __init__(self, soft_local_max_size=3): super(SoftDetectionModuleNew, self).__init__() self.soft_local_max_size = soft_local_max_size self.pad = self.soft_local_max_size // 2 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
liuyuzhenn/d2-net
SoftDetectionModule
false
15,925
[ "BSD-3-Clause-Clear" ]
603
bc3394934c87cba232144756b1fece4c8ed3aba1
https://github.com/liuyuzhenn/d2-net/tree/bc3394934c87cba232144756b1fece4c8ed3aba1
MLPFunc
import torch from torch import nn from torch.nn import functional as F from torch.autograd import Variable def seq_dropout(x, p=0, training=False): """ x: batch * len * input_size """ if training is False or p == 0: return x dropout_mask = Variable(1.0 / (1 - p) * torch.bernoulli((1 - p) * (x. data.new(x.size(0), x.size(2)).zero_() + 1)), requires_grad=False) return dropout_mask.unsqueeze(1).expand_as(x) * x def dropout(x, p=0, training=False): """ x: (batch * len * input_size) or (any other shape) """ if len(x.size()) == 3: return seq_dropout(x, p=p, training=training) else: return F.dropout(x, p=p, training=training) class MLPFunc(nn.Module): """ A multi-layer perceptron function for x: o = v'tanh(Wx+b). """ def __init__(self, input_size, hidden_size, num_class): super(MLPFunc, self).__init__() self.linear = nn.Linear(input_size, hidden_size) self.linear_final = nn.Linear(hidden_size, num_class, bias=False) def forward(self, x): """ x = batch * input_size """ x = dropout(x, p=0.2, training=self.training) h = F.tanh(self.linear(x)) h = dropout(h, p=0.2, training=self.training) o = self.linear_final(h) return o def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4, 'num_class': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn from torch.nn import functional as F from torch.autograd import Variable assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(256)](buf1, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2) return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), buf1, primals_4 def seq_dropout(x, p=0, training=False): """ x: batch * len * input_size """ if training is False or p == 0: return x dropout_mask = Variable(1.0 / (1 - p) * torch.bernoulli((1 - p) * (x. data.new(x.size(0), x.size(2)).zero_() + 1)), requires_grad=False) return dropout_mask.unsqueeze(1).expand_as(x) * x def dropout(x, p=0, training=False): """ x: (batch * len * input_size) or (any other shape) """ if len(x.size()) == 3: return seq_dropout(x, p=p, training=training) else: return F.dropout(x, p=p, training=training) class MLPFuncNew(nn.Module): """ A multi-layer perceptron function for x: o = v'tanh(Wx+b). """ def __init__(self, input_size, hidden_size, num_class): super(MLPFuncNew, self).__init__() self.linear = nn.Linear(input_size, hidden_size) self.linear_final = nn.Linear(hidden_size, num_class, bias=False) def forward(self, input_0): primals_2 = self.linear.weight primals_3 = self.linear.bias primals_4 = self.linear_final.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
lixinsu/RCZoo
MLPFunc
false
15,926
[ "MIT" ]
166
37fcb7962fbd4c751c561d4a0c84173881ea8339
https://github.com/lixinsu/RCZoo/tree/37fcb7962fbd4c751c561d4a0c84173881ea8339
SmoothL1Loss
import torch import torch.nn as nn class SmoothL1Loss(nn.Module): def __init__(self, beta=1.0, reduction='mean'): super().__init__() self.beta = beta self.reduction = reduction def forward(self, pred, target, weight=None): assert pred.size() == target.size() and target.numel() > 0 diff = torch.abs(pred - target) loss = torch.where(diff < self.beta, 0.5 * diff * diff / self.beta, diff - 0.5 * self.beta) if weight is not None: loss = loss * weight return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_div_lt_mul_sub_where_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 1.0 tmp5 = tmp3 < tmp4 tmp6 = 0.5 tmp7 = tmp3 * tmp6 tmp8 = tmp7 * tmp3 tmp9 = tmp8 * tmp4 tmp10 = tmp3 - tmp6 tmp11 = tl.where(tmp5, tmp9, tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_abs_div_lt_mul_sub_where_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SmoothL1LossNew(nn.Module): def __init__(self, beta=1.0, reduction='mean'): super().__init__() self.beta = beta 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]
liuhuaijjin/epnet_det3d_rcnn_reg_dir_cls_iou3d_loss
SmoothL1Loss
false
15,927
[ "MIT" ]
175
92376a99d919d983742df97bcf29eaea29afaf00
https://github.com/liuhuaijjin/epnet_det3d_rcnn_reg_dir_cls_iou3d_loss/tree/92376a99d919d983742df97bcf29eaea29afaf00
CrossRegion
import torch import torch.nn as nn import torch.fft class CrossRegion(nn.Module): def __init__(self, step=1, dim=1): super().__init__() self.step = step self.dim = dim def forward(self, x): return torch.roll(x, self.step, self.dim) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.fft 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_roll_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * ((3 + x1) % 4) + 64 * x2), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_roll_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class CrossRegionNew(nn.Module): def __init__(self, step=1, dim=1): super().__init__() self.step = step self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
liuruiyang98/Jittor-MLP
CrossRegion
false
15,928
[ "MIT" ]
49
b86656b65cf5f18ba9eb760d1f7565ed95e7e96e
https://github.com/liuruiyang98/Jittor-MLP/tree/b86656b65cf5f18ba9eb760d1f7565ed95e7e96e
CharbonnierLoss
import torch import torch.nn as nn from torch.nn import init as init class CharbonnierLoss(nn.Module): def __init__(self, loss_weight=1.0, eps=1e-06): """ the original eps is 1e-12 """ super(CharbonnierLoss, self).__init__() self.eps = eps def forward(self, pred, target, **kwargs): """ Args: pred (Tensor): of shape (N, C, H, W). Predicted tensor. target (Tensor): of shape (N, C, H, W). Ground truth tensor. """ return torch.sum(torch.sqrt((pred - target) ** 2 + self.eps) ) / target.shape[0] 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 torch.nn as nn from torch.nn import init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_div_pow_sqrt_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = 1e-06 tmp5 = tmp3 + tmp4 tmp6 = libdevice.sqrt(tmp5) tmp7 = tl.broadcast_to(tmp6, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = 0.25 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_add_div_pow_sqrt_sub_sum_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 CharbonnierLossNew(nn.Module): def __init__(self, loss_weight=1.0, eps=1e-06): """ the original eps is 1e-12 """ super(CharbonnierLossNew, self).__init__() self.eps = eps def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
ljzycmd/SimDeblur
CharbonnierLoss
false
15,929
[ "MIT" ]
190
dd2f60c41176b75c4eaf80d740f547c206aa8227
https://github.com/ljzycmd/SimDeblur/tree/dd2f60c41176b75c4eaf80d740f547c206aa8227
GaussianNoise
import torch from torch import nn import torch.cuda import torch.backends import torch.multiprocessing class GaussianNoise(nn.Module): """Add random gaussian noise to images.""" def __init__(self, std=0.05): super(GaussianNoise, self).__init__() self.std = std def forward(self, x): return x + torch.randn(x.size()).type_as(x) * self.std def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch import device import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.cuda import torch.backends import torch.multiprocessing assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_0(in_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 = 0.05 tmp3 = tmp1 * tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) buf0 = torch.ops.aten.randn.default([4, 4, 4, 4], device=device(type= 'cpu'), pin_memory=False) buf1 = buf0 del buf0 with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf2.copy_(buf1) del buf1 buf3 = buf2 del buf2 get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](buf3, arg0_1, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf3, class GaussianNoiseNew(nn.Module): """Add random gaussian noise to images.""" def __init__(self, std=0.05): super(GaussianNoiseNew, self).__init__() self.std = std def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
llv22/baal_tf2.4_mac
GaussianNoise
false
15,930
[ "Apache-2.0" ]
575
6eed225f8b57e61d8d16b1868ea655384c566700
https://github.com/llv22/baal_tf2.4_mac/tree/6eed225f8b57e61d8d16b1868ea655384c566700
Hidden2Discrete
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torch.nn.init class Hidden2Discrete(nn.Module): def __init__(self, input_size, y_size, k_size, is_lstm=False, has_bias=True ): super(Hidden2Discrete, self).__init__() self.y_size = y_size self.k_size = k_size latent_size = self.k_size * self.y_size if is_lstm: self.p_h = nn.Linear(input_size, latent_size, bias=has_bias) self.p_c = nn.Linear(input_size, latent_size, bias=has_bias) else: self.p_h = nn.Linear(input_size, latent_size, bias=has_bias) self.is_lstm = is_lstm def forward(self, inputs): """ :param inputs: batch_size x input_size :return: """ if self.is_lstm: h, c = inputs if h.dim() == 3: h = h.squeeze(0) c = c.squeeze(0) logits = self.p_h(h) + self.p_c(c) else: logits = self.p_h(inputs) logits = logits.view(-1, self.k_size) log_qy = F.log_softmax(logits, dim=1) return logits, log_qy def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'y_size': 4, 'k_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils.data import torch.nn.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__log_softmax_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (16, 4), (4, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((256, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(1024)](buf0, buf1, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((256, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(1024)](buf1, buf2, 1024, XBLOCK=256, num_warps=4, num_stages=1) del buf1 return reinterpret_tensor(buf0, (256, 4), (4, 1), 0 ), buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf2 class Hidden2DiscreteNew(nn.Module): def __init__(self, input_size, y_size, k_size, is_lstm=False, has_bias=True ): super(Hidden2DiscreteNew, self).__init__() self.y_size = y_size self.k_size = k_size latent_size = self.k_size * self.y_size if is_lstm: self.p_h = nn.Linear(input_size, latent_size, bias=has_bias) self.p_c = nn.Linear(input_size, latent_size, bias=has_bias) else: self.p_h = nn.Linear(input_size, latent_size, bias=has_bias) self.is_lstm = is_lstm def forward(self, input_0): primals_1 = self.p_h.weight primals_2 = self.p_h.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
ljw23/ConvLab-2
Hidden2Discrete
false
15,931
[ "Apache-2.0" ]
339
13d48ea0e441701bd66100689b6c25b561f15525
https://github.com/ljw23/ConvLab-2/tree/13d48ea0e441701bd66100689b6c25b561f15525
ProductOfExperts
import torch import torch.nn as nn class ProductOfExperts(nn.Module): """Return parameters for product of independent experts. See https://arxiv.org/pdf/1410.7827.pdf for equations. @param mu: M x D for M experts @param logvar: M x D for M experts """ def forward(self, mu, logvar, eps=1e-08): var = torch.exp(logvar) + eps T = 1.0 / var pd_mu = torch.sum(mu * T, dim=0) / torch.sum(T, dim=0) pd_var = 1.0 / torch.sum(T, dim=0) pd_logvar = torch.log(pd_var) return pd_mu, pd_logvar def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_exp_log_mul_reciprocal_sum_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp10 = tl.load(in_ptr0 + (64 + x0), xmask) tmp11 = tl.load(in_ptr1 + (64 + x0), xmask) tmp18 = tl.load(in_ptr0 + (128 + x0), xmask) tmp19 = tl.load(in_ptr1 + (128 + x0), xmask) tmp26 = tl.load(in_ptr0 + (192 + x0), xmask) tmp27 = tl.load(in_ptr1 + (192 + x0), xmask) tmp2 = tl_math.exp(tmp1) tmp3 = 1e-08 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 1, tl.int32) tmp6 = tmp5 / tmp4 tmp7 = 1.0 tmp8 = tmp6 * tmp7 tmp9 = tmp0 * tmp8 tmp12 = tl_math.exp(tmp11) tmp13 = tmp12 + tmp3 tmp14 = tmp5 / tmp13 tmp15 = tmp14 * tmp7 tmp16 = tmp10 * tmp15 tmp17 = tmp9 + tmp16 tmp20 = tl_math.exp(tmp19) tmp21 = tmp20 + tmp3 tmp22 = tmp5 / tmp21 tmp23 = tmp22 * tmp7 tmp24 = tmp18 * tmp23 tmp25 = tmp17 + tmp24 tmp28 = tl_math.exp(tmp27) tmp29 = tmp28 + tmp3 tmp30 = tmp5 / tmp29 tmp31 = tmp30 * tmp7 tmp32 = tmp26 * tmp31 tmp33 = tmp25 + tmp32 tmp34 = tmp8 + tmp15 tmp35 = tmp34 + tmp23 tmp36 = tmp35 + tmp31 tmp37 = tmp33 / tmp36 tmp38 = tmp5 / tmp36 tmp39 = tmp38 * tmp7 tmp40 = tl_math.log(tmp39) tl.store(in_out_ptr0 + x0, tmp37, xmask) tl.store(out_ptr0 + x0, tmp40, 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) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_exp_log_mul_reciprocal_sum_0[grid(64)](buf1, arg1_1, arg0_1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf1, buf2 class ProductOfExpertsNew(nn.Module): """Return parameters for product of independent experts. See https://arxiv.org/pdf/1410.7827.pdf for equations. @param mu: M x D for M experts @param logvar: M x D for M experts """ def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0], output[1]
liuyangdh/multimodal-vae-public
ProductOfExperts
false
15,932
[ "MIT" ]
98
ba5941d010b0164094f5818b93baad9df546494e
https://github.com/liuyangdh/multimodal-vae-public/tree/ba5941d010b0164094f5818b93baad9df546494e
ResBlock1D
import torch import torch.nn as nn import torch.nn.functional as F class ResBlock1D(nn.Module): def __init__(self, inplanes, planes, seq_len, stride=1, downsample=None): super(ResBlock1D, self).__init__() self.conv1 = nn.Conv1d(inplanes, planes, kernel_size=3, stride= stride, padding=1, bias=False) self.ln1 = nn.LayerNorm([planes, seq_len]) self.conv2 = nn.Conv1d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.ln2 = nn.LayerNorm([planes, seq_len]) def forward(self, x): residual = x x = F.relu(self.ln1(x)) x = self.conv1(x) x = F.relu(self.ln2(x)) x = self.conv2(x) x = x + residual return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'inplanes': 4, 'planes': 4, 'seq_len': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_native_layer_norm_relu_threshold_backward_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): 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) tmp21 = tl.load(in_ptr1 + r0, None) tmp23 = tl.load(in_ptr2 + r0, None) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp5 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.full([XBLOCK, 1], 16, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13 = tl.sum(tmp11, 1)[:, None] tmp14 = 16.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 * tmp18 tmp22 = tmp20 * tmp21 tmp24 = tmp22 + tmp23 tmp25 = tl.full([1, 1], 0, tl.int32) tmp26 = triton_helpers.maximum(tmp25, tmp24) tmp27 = 0.0 tmp28 = tmp26 <= tmp27 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp18, None) tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp26, None) tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp28, None) tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 3), (12, 3, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4, 3), (12, 3, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 1), (1, 1), torch.float32) buf1 = empty_strided_cuda((1, 1), (1, 1), torch.float32) buf3 = buf1 del buf1 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_per_fused_native_layer_norm_relu_threshold_backward_0[grid(1)]( buf3, primals_1, primals_2, primals_3, buf0, buf4, buf14, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 buf5 = extern_kernels.convolution(reinterpret_tensor(buf4, (1, 4, 4 ), (16, 4, 1), 0), primals_4, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf5, (1, 4, 4), (16, 4, 1)) buf6 = empty_strided_cuda((1, 1), (1, 1), torch.float32) buf7 = empty_strided_cuda((1, 1), (1, 1), torch.float32) buf9 = buf7 del buf7 buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_per_fused_native_layer_norm_relu_threshold_backward_0[grid(1)]( buf9, buf5, primals_5, primals_6, buf6, buf10, buf13, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_6 buf11 = extern_kernels.convolution(reinterpret_tensor(buf10, (1, 4, 4), (16, 4, 1), 0), primals_7, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf11, (1, 4, 4), (16, 4, 1)) buf12 = reinterpret_tensor(buf11, (4, 4), (4, 1), 0) del buf11 triton_poi_fused_add_1[grid(16)](buf12, primals_1, 16, XBLOCK=16, num_warps=1, num_stages=1) return (buf12, primals_1, primals_4, primals_5, primals_7, buf0, buf3, reinterpret_tensor(buf4, (1, 4, 4), (16, 4, 1), 0), buf5, buf6, buf9, reinterpret_tensor(buf10, (1, 4, 4), (16, 4, 1), 0), buf13, buf14 ) class ResBlock1DNew(nn.Module): def __init__(self, inplanes, planes, seq_len, stride=1, downsample=None): super(ResBlock1DNew, self).__init__() self.conv1 = nn.Conv1d(inplanes, planes, kernel_size=3, stride= stride, padding=1, bias=False) self.ln1 = nn.LayerNorm([planes, seq_len]) self.conv2 = nn.Conv1d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.ln2 = nn.LayerNorm([planes, seq_len]) def forward(self, input_0): primals_4 = self.conv1.weight primals_1 = self.ln1.weight primals_2 = self.ln1.bias primals_7 = self.conv2.weight primals_3 = self.ln2.weight primals_5 = self.ln2.bias primals_6 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
liuruoze/mini-AlphaStar
ResBlock1D
false
15,933
[ "Apache-2.0" ]
108
cf9de2507d526a5fb8ef67676aab2ffb92738640
https://github.com/liuruoze/mini-AlphaStar/tree/cf9de2507d526a5fb8ef67676aab2ffb92738640
GlobalPerceptron
import torch import torch.nn as nn import torch.nn.functional as F import torch.fft class GlobalPerceptron(nn.Module): def __init__(self, input_channels, internal_neurons): super(GlobalPerceptron, self).__init__() self.fc1 = nn.Conv2d(in_channels=input_channels, out_channels= internal_neurons, kernel_size=1, stride=1, bias=True) self.fc2 = nn.Conv2d(in_channels=internal_neurons, out_channels= input_channels, kernel_size=1, stride=1, bias=True) self.input_channels = input_channels def forward(self, inputs): x = F.adaptive_avg_pool2d(inputs, output_size=(1, 1)) x = self.fc1(x) x = F.relu(x, inplace=True) x = self.fc2(x) x = F.sigmoid(x) x = x.view(-1, self.input_channels, 1, 1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'internal_neurons': 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.fft assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_sigmoid_sigmoid_backward_view_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp4 = 1.0 tmp5 = tmp4 - tmp3 tmp6 = tmp3 * tmp5 tl.store(out_ptr0 + x2, tmp3, xmask) tl.store(out_ptr1 + 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, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) 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, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) buf6 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_convolution_sigmoid_sigmoid_backward_view_2[grid(16)]( buf4, primals_5, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf4 del primals_5 return buf5, primals_2, primals_4, buf1, buf3, buf6 class GlobalPerceptronNew(nn.Module): def __init__(self, input_channels, internal_neurons): super(GlobalPerceptronNew, self).__init__() self.fc1 = nn.Conv2d(in_channels=input_channels, out_channels= internal_neurons, kernel_size=1, stride=1, bias=True) self.fc2 = nn.Conv2d(in_channels=internal_neurons, out_channels= input_channels, kernel_size=1, stride=1, bias=True) self.input_channels = input_channels 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]
liuruiyang98/Jittor-MLP
GlobalPerceptron
false
15,934
[ "MIT" ]
49
b86656b65cf5f18ba9eb760d1f7565ed95e7e96e
https://github.com/liuruiyang98/Jittor-MLP/tree/b86656b65cf5f18ba9eb760d1f7565ed95e7e96e
RobertaSequenceClassificationHead
import torch import torch.nn as nn import torch.utils.data import torch.onnx.operators import torch.optim import torch.optim.lr_scheduler class RobertaSequenceClassificationHead(nn.Module): """Head for sequence-level classification tasks. Ignores the <s> vector.""" def __init__(self, input_dim, inner_dim, kernel_size, num_classes, pooler_dropout): super().__init__() self.conv_layer = nn.Conv1d(in_channels=input_dim, out_channels= inner_dim, kernel_size=kernel_size) self.dropout = nn.Dropout(p=pooler_dropout) self.out_proj = nn.Linear(inner_dim, num_classes) def forward(self, features, **kwargs): x = torch.transpose(features, 1, 2) x = self.conv_layer(x) x = torch.max(x, dim=2).values x = self.dropout(x) x = self.out_proj(x) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'inner_dim': 4, 'kernel_size': 4, 'num_classes': 4, 'pooler_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.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_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_max_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(16, 4)](primals_1, buf0, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 1), (4, 1, 1)) del buf0 buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_convolution_max_1[grid(16)](buf2, primals_3, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, buf3, reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del buf3 del primals_5 return buf4, primals_2, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), buf2, primals_4 class RobertaSequenceClassificationHeadNew(nn.Module): """Head for sequence-level classification tasks. Ignores the <s> vector.""" def __init__(self, input_dim, inner_dim, kernel_size, num_classes, pooler_dropout): super().__init__() self.conv_layer = nn.Conv1d(in_channels=input_dim, out_channels= inner_dim, kernel_size=kernel_size) self.dropout = nn.Dropout(p=pooler_dropout) self.out_proj = nn.Linear(inner_dim, num_classes) def forward(self, input_0): primals_1 = self.conv_layer.weight primals_3 = self.conv_layer.bias primals_4 = self.out_proj.weight primals_5 = self.out_proj.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
llMuShu/NEW_repstp
RobertaSequenceClassificationHead
false
15,935
[ "MIT" ]
138
314ba30e4ab2af2b23a435db49a8eb4b89e48680
https://github.com/llMuShu/NEW_repstp/tree/314ba30e4ab2af2b23a435db49a8eb4b89e48680
CosLoss
import torch import torch.nn as nn import torch.nn.functional as F class CosLoss(nn.Module): def __init__(self): super().__init__() def forward(self, state_S, state_T, mask=None): """ This is the loss used in DistilBERT :param state_S: Tensor of shape (batch_size, length, hidden_size) :param state_T: Tensor of shape (batch_size, length, hidden_size) :param mask: Tensor of shape (batch_size, length) """ if mask is None: state_S = state_S.view(-1, state_S.size(-1)) state_T = state_T.view(-1, state_T.size(-1)) else: mask = mask.to(state_S).unsqueeze(-1).expand_as(state_S) state_S = torch.masked_select(state_S, mask).view(-1, mask.size(-1) ) state_T = torch.masked_select(state_T, mask).view(-1, mask.size(-1) ) target = state_S.new(state_S.size(0)).fill_(1) loss = F.cosine_embedding_loss(state_S, state_T, target, reduction= 'mean') return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_clamp_min_div_eq_fill_mean_mul_sqrt_sub_sum_where_zeros_like_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') tmp3 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp15 = tmp0 * tmp0 tmp16 = tmp3 * tmp3 tmp17 = tmp15 + tmp16 tmp18 = tmp7 * tmp7 tmp19 = tmp17 + tmp18 tmp20 = tmp11 * tmp11 tmp21 = tmp19 + tmp20 tmp22 = 9.999999960041972e-13 tmp23 = tmp21 + tmp22 tmp24 = tmp1 * tmp1 tmp25 = tmp4 * tmp4 tmp26 = tmp24 + tmp25 tmp27 = tmp8 * tmp8 tmp28 = tmp26 + tmp27 tmp29 = tmp12 * tmp12 tmp30 = tmp28 + tmp29 tmp31 = tmp30 + tmp22 tmp32 = tmp23 * tmp31 tmp33 = libdevice.sqrt(tmp32) tmp34 = tmp14 / tmp33 tmp35 = 1.0 tmp36 = tmp35 - tmp34 tmp37 = tl.full([1, 1], True, tl.int1) tmp38 = 0.0 tmp39 = tl.where(tmp37, tmp36, tmp38) tmp40 = tmp34 - tmp38 tmp41 = triton_helpers.maximum(tmp40, tmp38) tmp42 = tl.full([1, 1], False, tl.int1) tmp43 = tl.where(tmp42, tmp41, tmp38) tmp44 = tmp39 + tmp43 tmp45 = tl.broadcast_to(tmp44, [XBLOCK, RBLOCK]) tmp47 = tl.sum(tmp45, 1)[:, None] tmp48 = 64.0 tmp49 = tmp47 / tmp48 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp49, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_add_clamp_min_div_eq_fill_mean_mul_sqrt_sub_sum_where_zeros_like_0[ grid(1)](buf2, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class CosLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
CosLoss
false
15,936
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
SelfAttn
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data import torch.nn.init import torch as th class SelfAttn(nn.Module): def __init__(self, hidden_size): super(SelfAttn, self).__init__() self.query = nn.Linear(hidden_size, 1) def forward(self, keys, values, attn_mask=None): """ :param attn_inputs: batch_size x time_len x hidden_size :param attn_mask: batch_size x time_len :return: summary state """ alpha = F.softmax(self.query(keys), dim=1) if attn_mask is not None: alpha = alpha * attn_mask.unsqueeze(2) alpha = alpha / th.sum(alpha, dim=1, keepdim=True) summary = th.sum(values * alpha, dim=1) return summary def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils.data import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_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) @triton.jit def triton_poi_fused__softmax_mul_sum_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 x3 = xindex % 16 x1 = xindex // 4 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 64 * x2), xmask) tmp1 = tl.load(in_ptr1 + (x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x3 + 64 * x2), xmask) tmp4 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr0 + (32 + x3 + 64 * x2), xmask) tmp8 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (48 + x3 + 64 * x2), xmask) tmp12 = tl.load(in_ptr1 + (12 + x1 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tl.store(out_ptr0 + x4, tmp14, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_1 del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_1[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0) del buf2 triton_poi_fused__softmax_mul_sum_2[grid(64)](primals_4, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 return buf4, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1 class SelfAttnNew(nn.Module): def __init__(self, hidden_size): super(SelfAttnNew, self).__init__() self.query = nn.Linear(hidden_size, 1) def forward(self, input_0, input_1): primals_1 = self.query.weight primals_2 = self.query.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
ljw23/ConvLab-2
SelfAttn
false
15,937
[ "Apache-2.0" ]
339
13d48ea0e441701bd66100689b6c25b561f15525
https://github.com/ljw23/ConvLab-2/tree/13d48ea0e441701bd66100689b6c25b561f15525
SeparableConv
import torch from torch import nn class SeparableConv(nn.Module): def __init__(self, nb_dim, nb_out, kernel_size): super().__init__() self.conv1 = nn.Conv1d(nb_dim, nb_dim, kernel_size, groups=nb_dim, padding=kernel_size // 2, bias=True) self.conv2 = nn.Conv1d(nb_dim, nb_out, 1, groups=1, padding=0, bias =True) def forward(self, x): """ :param x: shape(bsz, seqlen, 500) """ out = self.conv1(x.transpose(1, 2)) out = self.conv2(out) return out.transpose(1, 2) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'nb_dim': 4, 'nb_out': 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 import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 5 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 1, 4), (4, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(16, 4)](primals_1, buf0, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,), padding=(2,), dilation=(1,), transposed=False, output_padding=( 0,), groups=4, bias=None) assert_size_stride(buf1, (4, 4, 5), (20, 5, 1)) del buf0 buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(80)](buf2, primals_3, 80, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 5), (20, 5, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_1[grid(80)](buf4, primals_5, 80, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return reinterpret_tensor(buf4, (4, 5, 4), (20, 1, 5), 0 ), primals_2, primals_4, reinterpret_tensor(primals_1, (4, 4, 4), ( 16, 1, 4), 0), buf2 class SeparableConvNew(nn.Module): def __init__(self, nb_dim, nb_out, kernel_size): super().__init__() self.conv1 = nn.Conv1d(nb_dim, nb_dim, kernel_size, groups=nb_dim, padding=kernel_size // 2, bias=True) self.conv2 = nn.Conv1d(nb_dim, nb_out, 1, groups=1, padding=0, bias =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_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
lixinsu/RCZoo
SeparableConv
false
15,938
[ "MIT" ]
166
37fcb7962fbd4c751c561d4a0c84173881ea8339
https://github.com/lixinsu/RCZoo/tree/37fcb7962fbd4c751c561d4a0c84173881ea8339
Attention
import math import torch from torch import nn class Attention(nn.Module): def __init__(self, input_size, max_seq_len): super(Attention, self).__init__() self.atten_w = nn.Parameter(torch.randn(max_seq_len, input_size, 1)) self.atten_bias = nn.Parameter(torch.randn(max_seq_len, 1, 1)) self.glorot(self.atten_w) self.zeros(self.atten_bias) def forward(self, lstm_input): input_tensor = lstm_input.transpose(1, 0) input_tensor = torch.bmm(input_tensor, self.atten_w) + self.atten_bias input_tensor = input_tensor.transpose(1, 0) atten_weight = input_tensor.tanh() weighted_sum = torch.bmm(atten_weight.transpose(1, 2), lstm_input ).squeeze() return weighted_sum def glorot(self, tensor): if tensor is not None: stdv = math.sqrt(6.0 / (tensor.size(-2) + tensor.size(-1))) tensor.data.uniform_(-stdv, stdv) def zeros(self, tensor): if tensor is not None: tensor.data.fill_(0) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'max_seq_len': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(out_ptr0 + (x1 + 4 * y0), tmp3, xmask & ymask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 1), (4, 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), (4, 1, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_1, (4, 4, 4), (4, 16, 1), 0), primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_tanh_0[grid(4, 4)](buf0, primals_3, buf1, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (4, 1, 4), (4, 0, 1), 0 ), primals_1, out=buf2) del buf1 return reinterpret_tensor(buf2, (4, 4), (4, 1), 0 ), primals_1, primals_3, buf0 class AttentionNew(nn.Module): def __init__(self, input_size, max_seq_len): super(AttentionNew, self).__init__() self.atten_w = nn.Parameter(torch.randn(max_seq_len, input_size, 1)) self.atten_bias = nn.Parameter(torch.randn(max_seq_len, 1, 1)) self.glorot(self.atten_w) self.zeros(self.atten_bias) def glorot(self, tensor): if tensor is not None: stdv = math.sqrt(6.0 / (tensor.size(-2) + tensor.size(-1))) tensor.data.uniform_(-stdv, stdv) def zeros(self, tensor): if tensor is not None: tensor.data.fill_(0) def forward(self, input_0): primals_2 = self.atten_w primals_3 = self.atten_bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
logpai/deep-loglizer-
Attention
false
15,939
[ "Apache-2.0" ]
55
1069a1e0e9b000e1bc9b353fb01d3d451d9a6d5d
https://github.com/logpai/deep-loglizer-/tree/1069a1e0e9b000e1bc9b353fb01d3d451d9a6d5d
FusionLayer
import torch from torch import nn from torch.nn import functional as F class FusionLayer(nn.Module): """ make a fusion two vectors """ def __init__(self, hdim): super(FusionLayer, self).__init__() self.linear_fusion = nn.Linear(hdim * 4, hdim) self.linear_gate = nn.Linear(hdim * 4, 1) def forward(self, x1, x2): """ Args: x1: bxnxd x2: bxnxd Returns: ret: bxnxd """ m = F.tanh(self.linear_fusion(torch.cat([x1, x2, x1 * x2, x1 - x2], dim=2))) g = F.sigmoid(self.linear_gate(torch.cat([x1, x2, x1 * x2, x1 - x2], dim=2))) ret = g * m + (1 - g) * x2 return ret def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'hdim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_ptr0 + (4 * x1 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.load(in_ptr1 + (4 * x1 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tmp15 * tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp14, tmp17, tmp18) tmp20 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp23 = tl.load(in_ptr0 + (4 * x1 + (-12 + x0)), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tl.load(in_ptr1 + (4 * x1 + (-12 + x0)), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = tmp23 - tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp20, tmp25, tmp26) tmp28 = tl.where(tmp14, tmp19, tmp27) tmp29 = tl.where(tmp9, tmp10, tmp28) tmp30 = tl.where(tmp4, tmp5, tmp29) tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_sigmoid_tanh_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + x2, xmask) tmp7 = tl.load(in_ptr2 + x2, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = libdevice.tanh(tmp2) tmp4 = tmp1 * tmp3 tmp5 = 1.0 tmp6 = tmp5 - tmp1 tmp8 = tmp6 * tmp7 tmp9 = tmp4 + tmp8 tl.store(out_ptr0 + x2, tmp9, 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, 16), (16, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (1, 16), (16, 1)) assert_size_stride(primals_6, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(256)](primals_1, primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(buf0, (16, 16), (16, 1), 0), reinterpret_tensor(primals_3, (16, 4), (1, 16), 0), alpha=1, beta=1, out=buf1) del primals_3 del primals_4 buf3 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(buf0, (16, 16), (16, 1), 0), reinterpret_tensor(primals_5, (16, 1), (1, 16), 0), alpha=1, beta=1, out=buf3) del primals_5 del primals_6 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_rsub_sigmoid_tanh_1[grid(64)](buf3, buf1, primals_2, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf4, primals_2, reinterpret_tensor(buf0, (16, 16), (16, 1), 0 ), buf1, buf3 class FusionLayerNew(nn.Module): """ make a fusion two vectors """ def __init__(self, hdim): super(FusionLayerNew, self).__init__() self.linear_fusion = nn.Linear(hdim * 4, hdim) self.linear_gate = nn.Linear(hdim * 4, 1) def forward(self, input_0, input_1): primals_3 = self.linear_fusion.weight primals_4 = self.linear_fusion.bias primals_5 = self.linear_gate.weight primals_6 = self.linear_gate.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]
lixinsu/RCZoo
FusionLayer
false
15,940
[ "MIT" ]
166
37fcb7962fbd4c751c561d4a0c84173881ea8339
https://github.com/lixinsu/RCZoo/tree/37fcb7962fbd4c751c561d4a0c84173881ea8339
VAE
import torch import torch.nn as nn import torch.nn.parallel import torch.utils.data import torch.nn.functional as F import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed class VAE(nn.Module): def __init__(self): super(VAE, self).__init__() self.fc1 = nn.Linear(784, 400) self.fc21 = nn.Linear(400, 20) self.fc22 = nn.Linear(400, 20) self.fc3 = nn.Linear(20, 400) self.fc4 = nn.Linear(400, 784) def encode(self, x): h1 = F.relu(self.fc1(x)) return self.fc21(h1), self.fc22(h1) def reparameterize(self, mu, logvar): std = torch.exp(0.5 * logvar) eps = torch.randn_like(std) return mu + eps * std def decode(self, z): h3 = F.relu(self.fc3(z)) return torch.sigmoid(self.fc4(h3)) def forward(self, x): mu, logvar = self.encode(x.view(-1, 784)) z = self.reparameterize(mu, logvar) return self.decode(z), mu, logvar def get_inputs(): return [torch.rand([4, 784])] def get_init_inputs(): return [[], {}]
import torch from torch import device from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.nn.parallel import torch.utils.data import torch.nn.functional as F import torch.onnx import torch.fx import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 400 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_exp_mul_1(in_ptr0, in_ptr1, in_ptr2, 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 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask) tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tl_math.exp(tmp4) tmp6 = tmp1 * tmp5 tmp7 = tmp0 + tmp6 tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 3136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 784 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 784), (784, 1)) assert_size_stride(primals_2, (400, 784), (784, 1)) assert_size_stride(primals_3, (400,), (1,)) assert_size_stride(primals_4, (20, 400), (400, 1)) assert_size_stride(primals_5, (20,), (1,)) assert_size_stride(primals_6, (20, 400), (400, 1)) assert_size_stride(primals_7, (20,), (1,)) assert_size_stride(primals_8, (400, 20), (20, 1)) assert_size_stride(primals_9, (400,), (1,)) assert_size_stride(primals_10, (784, 400), (400, 1)) assert_size_stride(primals_11, (784,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 400), (400, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (784, 400), (1, 784), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(1600)](buf1, primals_3, 1600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 20), (20, 1), torch.float32) extern_kernels.addmm(primals_5, buf1, reinterpret_tensor(primals_4, (400, 20), (1, 400), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 20), (20, 1), torch.float32) extern_kernels.addmm(primals_7, buf1, reinterpret_tensor(primals_6, (400, 20), (1, 400), 0), alpha=1, beta=1, out=buf3) del primals_7 buf4 = torch.ops.aten.randn.default([4, 20], dtype=torch.float32, device=device(type='cuda', index=0), pin_memory=False) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((4, 20), (20, 1), torch.float32) triton_poi_fused_add_exp_mul_1[grid(80)](buf2, buf5, buf3, buf6, 80, XBLOCK=128, num_warps=4, num_stages=1) buf7 = empty_strided_cuda((4, 400), (400, 1), torch.float32) extern_kernels.mm(buf6, reinterpret_tensor(primals_8, (20, 400), (1, 20), 0), out=buf7) buf8 = buf7 del buf7 triton_poi_fused_relu_0[grid(1600)](buf8, primals_9, 1600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_9 buf9 = empty_strided_cuda((4, 784), (784, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_10, (400, 784), (1, 400), 0), out=buf9) buf10 = buf9 del buf9 triton_poi_fused_sigmoid_2[grid(3136)](buf10, primals_11, 3136, XBLOCK=128, num_warps=4, num_stages=1) del primals_11 return (buf10, buf2, buf3, primals_1, buf1, buf3, buf5, buf6, buf8, buf10, primals_10, primals_8, primals_6, primals_4) class VAENew(nn.Module): def __init__(self): super(VAENew, self).__init__() self.fc1 = nn.Linear(784, 400) self.fc21 = nn.Linear(400, 20) self.fc22 = nn.Linear(400, 20) self.fc3 = nn.Linear(20, 400) self.fc4 = nn.Linear(400, 784) def encode(self, x): h1 = F.relu(self.fc1(x)) return self.fc21(h1), self.fc22(h1) def reparameterize(self, mu, logvar): std = torch.exp(0.5 * logvar) eps = torch.randn_like(std) return mu + eps * std def decode(self, z): h3 = F.relu(self.fc3(z)) return torch.sigmoid(self.fc4(h3)) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc21.weight primals_5 = self.fc21.bias primals_6 = self.fc22.weight primals_7 = self.fc22.bias primals_8 = self.fc3.weight primals_9 = self.fc3.bias primals_10 = self.fc4.weight primals_11 = self.fc4.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0], output[1], output[2]
lenaguignard/examples
VAE
false
15,941
[ "BSD-3-Clause" ]
19,783
973e77b725a6028289a90170f0b237ea2e71d4f2
https://github.com/lenaguignard/examples/tree/973e77b725a6028289a90170f0b237ea2e71d4f2
LocalResponseNorm
from torch.nn import Module import torch import torch.optim from torch.nn.modules.module import Module from torch.nn.functional import * class LocalResponseNorm(Module): def __init__(self, size, alpha=0.0001, beta=0.75, k=1): """Applies local response normalization over an input signal composed of several input planes, where channels occupy the second dimension. Applies normalization across channels. .. math:: `b_{c} = a_{c}\\left(k + \\frac{\\alpha}{n} \\sum_{c'=\\max(0, c-n/2)}^{\\min(N-1,c+n/2)}a_{c'}^2\\right)^{-\\beta}` Args: size: amount of neighbouring channels used for normalization alpha: multiplicative factor. Default: 0.0001 beta: exponent. Default: 0.75 k: additive factor. Default: 1 Shape: - Input: :math:`(N, C, ...)` - Output: :math:`(N, C, ...)` (same shape as input) Examples:: >>> lrn = nn.LocalResponseNorm(2) >>> signal_2d = autograd.Variable(torch.randn(32, 5, 24, 24)) >>> signal_4d = autograd.Variable(torch.randn(16, 5, 7, 7, 7, 7)) >>> output_2d = lrn(signal_2d) >>> output_4d = lrn(signal_4d) """ super(LocalResponseNorm, self).__init__() self.size = size self.alpha = alpha self.beta = beta self.k = k def forward(self, input): return local_response_norm(input, self.size, self.alpha, self.beta, self.k) def __repr__(self): return self.__class__.__name__ + '(' + str(self.size ) + ', alpha=' + str(self.alpha) + ', beta=' + str(self.beta ) + ', k=' + str(self.k) + ')' 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 libdevice from torch.nn import Module import torch.optim from torch.nn.modules.module import Module from torch.nn.functional 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_add_avg_pool3d_constant_pad_nd_div_mul_pow_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 4 x3 = xindex tmp39 = tl.load(in_ptr0 + x3, xmask) tmp0 = -2 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-32 + x3), tmp5 & xmask, other=0.0) tmp7 = tmp6 * tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp5, tmp7, tmp8) tmp10 = -1 + x1 tmp11 = tmp10 >= tmp1 tmp12 = tmp10 < tmp3 tmp13 = tmp11 & tmp12 tmp14 = tl.load(in_ptr0 + (-16 + x3), tmp13 & xmask, other=0.0) tmp15 = tmp14 * tmp14 tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp13, tmp15, tmp16) tmp18 = tmp17 + tmp9 tmp19 = x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tl.load(in_ptr0 + x3, tmp22 & xmask, other=0.0) tmp24 = tmp23 * tmp23 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp22, tmp24, tmp25) tmp27 = tmp26 + tmp18 tmp28 = 1 + x1 tmp29 = tmp28 >= tmp1 tmp30 = tmp28 < tmp3 tmp31 = tmp29 & tmp30 tmp32 = tl.load(in_ptr0 + (16 + x3), tmp31 & xmask, other=0.0) tmp33 = tmp32 * tmp32 tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp31, tmp33, tmp34) tmp36 = tmp35 + tmp27 tmp37 = 0.25 tmp38 = tmp36 * tmp37 tmp40 = 0.0001 tmp41 = tmp38 * tmp40 tmp42 = 1.0 tmp43 = tmp41 + tmp42 tmp44 = 0.75 tmp45 = libdevice.pow(tmp43, tmp44) tmp46 = tmp39 / tmp45 tl.store(in_out_ptr0 + x3, tmp46, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 4, 4, 4), (64, 64, 16, 4, 1), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_add_avg_pool3d_constant_pad_nd_div_mul_pow_0[grid(256) ](buf1, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf1, class LocalResponseNormNew(Module): def __init__(self, size, alpha=0.0001, beta=0.75, k=1): """Applies local response normalization over an input signal composed of several input planes, where channels occupy the second dimension. Applies normalization across channels. .. math:: `b_{c} = a_{c}\\left(k + \\frac{\\alpha}{n} \\sum_{c'=\\max(0, c-n/2)}^{\\min(N-1,c+n/2)}a_{c'}^2\\right)^{-\\beta}` Args: size: amount of neighbouring channels used for normalization alpha: multiplicative factor. Default: 0.0001 beta: exponent. Default: 0.75 k: additive factor. Default: 1 Shape: - Input: :math:`(N, C, ...)` - Output: :math:`(N, C, ...)` (same shape as input) Examples:: >>> lrn = nn.LocalResponseNorm(2) >>> signal_2d = autograd.Variable(torch.randn(32, 5, 24, 24)) >>> signal_4d = autograd.Variable(torch.randn(16, 5, 7, 7, 7, 7)) >>> output_2d = lrn(signal_2d) >>> output_4d = lrn(signal_4d) """ super(LocalResponseNormNew, self).__init__() self.size = size self.alpha = alpha self.beta = beta self.k = k def __repr__(self): return self.__class__.__name__ + '(' + str(self.size ) + ', alpha=' + str(self.alpha) + ', beta=' + str(self.beta ) + ', k=' + str(self.k) + ')' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
leoshine/Spherical_Regression
LocalResponseNorm
false
15,942
[ "BSD-2-Clause-FreeBSD" ]
133
d19bc2f6f52982d4d58f5ddabe4231381d7facd7
https://github.com/leoshine/Spherical_Regression/tree/d19bc2f6f52982d4d58f5ddabe4231381d7facd7
PyConv2
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv2(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5], stride=1, pyconv_groups=[1, 4]): super(PyConv2, self).__init__() self.conv2_1 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) def forward(self, x): return torch.cat((self.conv2_1(x), self.conv2_2(x)), dim=1) def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {'inplans': 64, 'planes': 32}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_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) x1 = xindex // 4096 % 32 x0 = xindex % 4096 x2 = xindex // 131072 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 16, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 65536 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 32, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 4096 * (-16 + x1) + 65536 * x2), tmp6, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (16, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_2, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_3, (16, 16, 5, 5), (400, 25, 5, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf1 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None) assert_size_stride(buf1, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf2 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(524288)](buf0, buf1, buf2, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del buf1 return buf2, primals_1, primals_2, primals_3 def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv2New(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5], stride=1, pyconv_groups=[1, 4]): super(PyConv2New, self).__init__() self.conv2_1 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) def forward(self, input_0): primals_1 = self.conv2_1.weight primals_3 = self.conv2_2.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lkf59553/pyconv
PyConv2
false
15,943
[ "MIT" ]
295
d8b39cf43014b8fd277dcefc9eb7f8880511e977
https://github.com/lkf59553/pyconv/tree/d8b39cf43014b8fd277dcefc9eb7f8880511e977
PyConv3
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv3(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5, 7], stride=1, pyconv_groups=[1, 4, 8]): super(PyConv3, self).__init__() self.conv2_1 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) self.conv2_3 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[2], padding=pyconv_kernels[2] // 2, stride= stride, groups=pyconv_groups[2]) def forward(self, x): return torch.cat((self.conv2_1(x), self.conv2_2(x), self.conv2_3(x) ), dim=1) def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {'inplans': 64, 'planes': 32}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 4096 % 32 x0 = xindex % 4096 x2 = xindex // 131072 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 32768 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 16, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (x0 + 4096 * (-8 + x1) + 32768 * x2), tmp9, other=0.0) tmp11 = tmp0 >= tmp7 tl.full([1], 32, tl.int64) tmp14 = tl.load(in_ptr2 + (x0 + 4096 * (-16 + x1) + 65536 * x2), tmp11, other=0.0) tmp15 = tl.where(tmp9, tmp10, tmp14) tmp16 = tl.where(tmp4, tmp5, tmp15) tl.store(out_ptr0 + x3, tmp16, None) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (8, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_2, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_3, (8, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_4, (16, 8, 7, 7), (392, 49, 7, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 64, 64), (32768, 4096, 64, 1)) buf1 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None) assert_size_stride(buf1, (4, 8, 64, 64), (32768, 4096, 64, 1)) buf2 = extern_kernels.convolution(primals_2, primals_4, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=8, bias=None) assert_size_stride(buf2, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf3 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(524288)](buf0, buf1, buf2, buf3, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 return buf3, primals_1, primals_2, primals_3, primals_4 def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv3New(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5, 7], stride=1, pyconv_groups=[1, 4, 8]): super(PyConv3New, self).__init__() self.conv2_1 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) self.conv2_3 = conv(inplans, planes // 2, kernel_size= pyconv_kernels[2], padding=pyconv_kernels[2] // 2, stride= stride, groups=pyconv_groups[2]) def forward(self, input_0): primals_1 = self.conv2_1.weight primals_3 = self.conv2_2.weight primals_4 = self.conv2_3.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
lkf59553/pyconv
PyConv3
false
15,944
[ "MIT" ]
295
d8b39cf43014b8fd277dcefc9eb7f8880511e977
https://github.com/lkf59553/pyconv/tree/d8b39cf43014b8fd277dcefc9eb7f8880511e977
DenseSynthesizer
import torch import torch.nn as nn class DenseSynthesizer(nn.Module): def __init__(self, head_dim, n_heads, n_tokens, big=True): super().__init__() h = max(head_dim, n_tokens) if big else min(head_dim, n_tokens) w1 = torch.empty(n_heads, head_dim, h) b1 = torch.empty(n_heads, h) w2 = torch.empty(n_heads, h, n_tokens) b2 = torch.empty(n_heads, n_tokens) nn.init.kaiming_uniform_(w1) nn.init.kaiming_uniform_(w2) nn.init.zeros_(b1) nn.init.zeros_(b2) self.register_parameter('w1', nn.Parameter(w1)) self.register_parameter('b1', nn.Parameter(b1)) self.register_parameter('w2', nn.Parameter(w2)) self.register_parameter('b2', nn.Parameter(b2)) self.activation = nn.ReLU() def forward(self, x): """ :param x: tensor of shape (batch_size, n_tokens, n_heads, head_dim) :return: tensor of shape (batch_size * n_heads, n_tokens, n_tokens) """ bs, l, nh, _dh = x.size() x = torch.einsum('ijkl,klm->ijkm', x, self.w1) + self.b1 x = self.activation(x) x = torch.einsum('ijkl,klm->ijkm', x, self.w2) + self.b2 x = x[:, :, :, :l] x = x.transpose(0, 3).contiguous().view(l, l, bs * nh).transpose(0, 2) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'head_dim': 4, 'n_heads': 4, 'n_tokens': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_relu_threshold_backward_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex % 16 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + x3, 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 + x4, tmp4, xmask) tl.store(out_ptr1 + (x0 + 4 * x2 + 64 * x1), tmp6, xmask) @triton.jit def triton_poi_fused_clone_1(in_ptr0, in_ptr1, 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 x3 = xindex // 16 x4 = xindex % 16 y0 = yindex x2 = xindex // 4 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x3 + 16 * x4), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (y0 + 4 * x2), xmask & ymask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x5 + 64 * y0), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_transpose_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 x1 = xindex // 4 % 16 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_1, (4, 16, 4), (4, 16, 1), 0), primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf5 = empty_strided_cuda((4, 4, 4, 4), (16, 4, 64, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_relu_threshold_backward_0[grid(256)](buf0, primals_3, buf1, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = buf0 del buf0 extern_kernels.bmm(reinterpret_tensor(buf1, (4, 16, 4), (4, 16, 1), 0), primals_4, out=buf2) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_1[grid(4, 64)](buf2, primals_5, buf3, 4, 64, XBLOCK=32, YBLOCK=4, num_warps=4, num_stages=1) del primals_5 buf4 = reinterpret_tensor(buf2, (4, 4, 16), (64, 1, 4), 0) del buf2 triton_poi_fused_transpose_2[grid(256)](buf1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 return reinterpret_tensor(buf3, (16, 4, 4), (1, 16, 64), 0 ), buf4, reinterpret_tensor(primals_4, (4, 4, 4), (16, 1, 4), 0 ), buf5, reinterpret_tensor(primals_1, (4, 4, 16), (4, 1, 16), 0) class DenseSynthesizerNew(nn.Module): def __init__(self, head_dim, n_heads, n_tokens, big=True): super().__init__() h = max(head_dim, n_tokens) if big else min(head_dim, n_tokens) w1 = torch.empty(n_heads, head_dim, h) b1 = torch.empty(n_heads, h) w2 = torch.empty(n_heads, h, n_tokens) b2 = torch.empty(n_heads, n_tokens) nn.init.kaiming_uniform_(w1) nn.init.kaiming_uniform_(w2) nn.init.zeros_(b1) nn.init.zeros_(b2) self.register_parameter('w1', nn.Parameter(w1)) self.register_parameter('b1', nn.Parameter(b1)) self.register_parameter('w2', nn.Parameter(w2)) self.register_parameter('b2', nn.Parameter(b2)) self.activation = nn.ReLU() def forward(self, input_0): primals_2 = self.w1 primals_3 = self.b1 primals_4 = self.w2 primals_5 = self.b2 primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
llucid-97/dfa-scales-to-modern-deep-learning
DenseSynthesizer
false
15,945
[ "MIT" ]
63
66efb4b4ef8a378bf01ea0e5e6794d6bb4380c97
https://github.com/llucid-97/dfa-scales-to-modern-deep-learning/tree/66efb4b4ef8a378bf01ea0e5e6794d6bb4380c97
PyConv4
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv4(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5, 7, 9], stride =1, pyconv_groups=[1, 4, 8, 16]): super(PyConv4, self).__init__() self.conv2_1 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) self.conv2_3 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[2], padding=pyconv_kernels[2] // 2, stride= stride, groups=pyconv_groups[2]) self.conv2_4 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[3], padding=pyconv_kernels[3] // 2, stride= stride, groups=pyconv_groups[3]) def forward(self, x): return torch.cat((self.conv2_1(x), self.conv2_2(x), self.conv2_3(x), self.conv2_4(x)), dim=1) def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {'inplans': 64, 'planes': 64}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 4096 % 64 x0 = xindex % 4096 x2 = xindex // 262144 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 16, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 65536 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 32, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (x0 + 4096 * (-16 + x1) + 65536 * x2), tmp9, other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 48, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr2 + (x0 + 4096 * (-32 + x1) + 65536 * x2), tmp14, other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 64, tl.int64) tmp19 = tl.load(in_ptr3 + (x0 + 4096 * (-48 + x1) + 65536 * x2), tmp16, other=0.0) tmp20 = tl.where(tmp14, tmp15, tmp19) tmp21 = tl.where(tmp9, tmp10, tmp20) tmp22 = tl.where(tmp4, tmp5, tmp21) tl.store(out_ptr0 + x3, tmp22, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (16, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_2, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_3, (16, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_4, (16, 8, 7, 7), (392, 49, 7, 1)) assert_size_stride(primals_5, (16, 4, 9, 9), (324, 81, 9, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf1 = extern_kernels.convolution(primals_2, primals_3, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None) assert_size_stride(buf1, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf2 = extern_kernels.convolution(primals_2, primals_4, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=8, bias=None) assert_size_stride(buf2, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf3 = extern_kernels.convolution(primals_2, primals_5, stride=(1, 1), padding=(4, 4), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=16, bias=None) assert_size_stride(buf3, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf4 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(1048576)](buf0, buf1, buf2, buf3, buf4, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 del buf3 return buf4, primals_1, primals_2, primals_3, primals_4, primals_5 def conv(in_planes, out_planes, kernel_size=3, stride=1, padding=1, dilation=1, groups=1): """standard convolution with padding""" return nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride =stride, padding=padding, dilation=dilation, groups=groups, bias=False) class PyConv4New(nn.Module): def __init__(self, inplans, planes, pyconv_kernels=[3, 5, 7, 9], stride =1, pyconv_groups=[1, 4, 8, 16]): super(PyConv4New, self).__init__() self.conv2_1 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[0], padding=pyconv_kernels[0] // 2, stride= stride, groups=pyconv_groups[0]) self.conv2_2 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[1], padding=pyconv_kernels[1] // 2, stride= stride, groups=pyconv_groups[1]) self.conv2_3 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[2], padding=pyconv_kernels[2] // 2, stride= stride, groups=pyconv_groups[2]) self.conv2_4 = conv(inplans, planes // 4, kernel_size= pyconv_kernels[3], padding=pyconv_kernels[3] // 2, stride= stride, groups=pyconv_groups[3]) def forward(self, input_0): primals_1 = self.conv2_1.weight primals_3 = self.conv2_2.weight primals_4 = self.conv2_3.weight primals_5 = self.conv2_4.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
lkf59553/pyconv
PyConv4
false
15,946
[ "MIT" ]
295
d8b39cf43014b8fd277dcefc9eb7f8880511e977
https://github.com/lkf59553/pyconv/tree/d8b39cf43014b8fd277dcefc9eb7f8880511e977
AttMseLoss
import torch import torch.nn as nn import torch.nn.functional as F class AttMseLoss(nn.Module): def __init__(self): super().__init__() def forward(self, attention_S, attention_T, mask=None): """ Calculate the mse loss between attention_S and attention_T. :param logits_S: Tensor of shape (batch_size, num_heads, length, length) :param logits_T: Tensor of shape (batch_size, num_heads, length, length) :param mask: Tensor of shape (batch_size, length) """ if mask is None: attention_S_select = torch.where(attention_S <= -0.001, torch. zeros_like(attention_S), attention_S) attention_T_select = torch.where(attention_T <= -0.001, torch. zeros_like(attention_T), attention_T) loss = F.mse_loss(attention_S_select, attention_T_select) else: mask = mask.unsqueeze(1).expand(-1, attention_S.size(1), -1) valid_count = torch.pow(mask.sum(dim=2), 2).sum() loss = (F.mse_loss(attention_S, attention_T, reduction='none') * mask.unsqueeze(-1) * mask.unsqueeze(2)).sum() / valid_count 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 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_le_mse_loss_where_zeros_like_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) tmp5 = tl.load(in_ptr1 + r0, None) tmp1 = -0.001 tmp2 = tmp0 <= tmp1 tmp3 = 0.0 tmp4 = tl.where(tmp2, tmp3, tmp0) tmp6 = tmp5 <= tmp1 tmp7 = tl.where(tmp6, tmp3, tmp5) 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 = 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_le_mse_loss_where_zeros_like_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 AttMseLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
AttMseLoss
false
15,947
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
DecoderLayer
import torch import torch.nn as nn import torch.nn.functional as F class ScaledDotProductAttention(nn.Module): """ Scaled Dot-Product Attention """ def __init__(self, temperature, attn_dropout=0.1): super().__init__() self.temperature = temperature self.dropout = nn.Dropout(attn_dropout) def forward(self, q, k, v, mask=None): attn = torch.matmul(q / self.temperature, k.transpose(2, 3)) if mask is not None: attn = attn.masked_fill(mask == 0, -1000000000.0) attn = self.dropout(F.softmax(attn, dim=-1)) output = torch.matmul(attn, v) return output, attn class MultiHeadAttention(nn.Module): """ Multi-Head Attention module """ def __init__(self, n_head, d_model, d_k, d_v, dropout=0.1): super().__init__() self.n_head = n_head self.d_k = d_k self.d_v = d_v self.w_qs = nn.Linear(d_model, n_head * d_k, bias=False) self.w_ks = nn.Linear(d_model, n_head * d_k, bias=False) self.w_vs = nn.Linear(d_model, n_head * d_v, bias=False) self.fc = nn.Linear(n_head * d_v, d_model, bias=False) self.attention = ScaledDotProductAttention(temperature=d_k ** 0.5) self.dropout = nn.Dropout(dropout) self.layer_norm = nn.LayerNorm(d_model, eps=1e-06) def forward(self, q, k, v, mask=None): d_k, d_v, n_head = self.d_k, self.d_v, self.n_head sz_b, len_q, len_k, len_v = q.size(0), q.size(1), k.size(1), v.size(1) residual = q q = self.layer_norm(q) q = self.w_qs(q).view(sz_b, len_q, n_head, d_k) k = self.w_ks(k).view(sz_b, len_k, n_head, d_k) v = self.w_vs(v).view(sz_b, len_v, n_head, d_v) q, k, v = q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2) if mask is not None: mask = mask.unsqueeze(1) q, attn = self.attention(q, k, v, mask=mask) q = q.transpose(1, 2).contiguous().view(sz_b, len_q, -1) q = self.dropout(self.fc(q)) q = q + residual return q, attn class PositionwiseFeedForward(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1 = nn.Linear(d_in, d_hid) self.w_2 = nn.Linear(d_hid, d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) def forward(self, x): residual = x x = self.layer_norm(x) x = self.w_2(F.relu(self.w_1(x))) x = self.dropout(x) x = x + residual return x class DecoderLayer(nn.Module): """ Compose with three layers """ def __init__(self, d_model, d_inner, n_head, d_k, d_v, dropout=0.1): super(DecoderLayer, self).__init__() self.slf_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout) self.enc_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout) self.pos_ffn = PositionwiseFeedForward(d_model, d_inner, dropout= dropout) def forward(self, dec_input, enc_output, slf_attn_mask=None, dec_enc_attn_mask=None): dec_output, dec_slf_attn = self.slf_attn(dec_input, dec_input, dec_input, mask=slf_attn_mask) dec_output, dec_enc_attn = self.enc_attn(dec_output, enc_output, enc_output, mask=dec_enc_attn_mask) dec_output = self.pos_ffn(dec_output) return dec_output, dec_slf_attn, dec_enc_attn def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'd_inner': 4, 'n_head': 4, 'd_k': 4, 'd_v': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-06 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_clone_div_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x4, tmp2, xmask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 16 y1 = yindex // 16 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused__softmax_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 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_clone_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tl.store(out_ptr0 + x4, tmp0, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_7(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tmp27 / tmp15 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_8(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-06 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_add_9(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_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_10(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_add_11(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, 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) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16, 4), (4, 1)) assert_size_stride(primals_6, (16, 4), (4, 1)) assert_size_stride(primals_7, (4, 16), (16, 1)) assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (16, 4), (4, 1)) assert_size_stride(primals_12, (16, 4), (4, 1)) assert_size_stride(primals_13, (16, 4), (4, 1)) assert_size_stride(primals_14, (4, 16), (16, 1)) assert_size_stride(primals_15, (4,), (1,)) assert_size_stride(primals_16, (4,), (1,)) assert_size_stride(primals_17, (4, 4), (4, 1)) assert_size_stride(primals_18, (4,), (1,)) assert_size_stride(primals_19, (4, 4), (4, 1)) assert_size_stride(primals_20, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(16)](primals_1, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](primals_1, buf0, buf1, primals_2, primals_3, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 del primals_3 buf3 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 16), (1, 4), 0), out=buf4) del primals_5 buf5 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 16), (1, 4), 0), out=buf5) del primals_6 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_div_2[grid(256)](buf3, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf7 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused_clone_3[grid(64, 4)](buf4, buf7, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) buf8 = reinterpret_tensor(buf4, (16, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1), 0), out=buf8) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_4[grid(256)](buf8, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) buf10 = reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf8 triton_poi_fused__softmax_5[grid(256)](buf9, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) buf11 = buf9 del buf9 triton_poi_fused_clone_6[grid(256)](buf5, buf11, 256, XBLOCK=128, num_warps=4, num_stages=1) buf12 = reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0) del buf5 extern_kernels.bmm(reinterpret_tensor(buf10, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf11, (16, 4, 4), (16, 4, 1), 0), out=buf12 ) buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_6[grid(256)](buf12, buf13, 256, XBLOCK=128, num_warps=4, num_stages=1) buf14 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf13, (16, 16), (16, 1), 0), reinterpret_tensor(primals_7, (16, 4), (1, 16), 0), out=buf14) buf15 = buf1 del buf1 buf16 = buf0 del buf0 triton_poi_fused_add_native_layer_norm_7[grid(16)](buf14, primals_1, buf15, buf16, 16, XBLOCK=16, num_warps=1, num_stages=1) buf17 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_8[grid(64)](buf14, primals_1, buf15, buf16, primals_9, primals_10, buf17, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_10 buf18 = reinterpret_tensor(buf12, (16, 16), (16, 1), 0) del buf12 extern_kernels.mm(reinterpret_tensor(buf17, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 16), (1, 4), 0), out=buf18) buf19 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_8, (16, 4), (4, 1), 0), reinterpret_tensor(primals_12, (4, 16), (1, 4), 0), out=buf19) del primals_12 buf20 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_8, (16, 4), (4, 1), 0), reinterpret_tensor(primals_13, (4, 16), (1, 4), 0), out=buf20) del primals_13 buf21 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_div_2[grid(256)](buf18, buf21, 256, XBLOCK= 256, num_warps=4, num_stages=1) buf22 = reinterpret_tensor(buf18, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf18 triton_poi_fused_clone_3[grid(64, 4)](buf19, buf22, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) buf23 = reinterpret_tensor(buf19, (16, 4, 4), (16, 4, 1), 0) del buf19 extern_kernels.bmm(reinterpret_tensor(buf21, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf22, (16, 4, 4), (16, 4, 1), 0), out=buf23 ) buf24 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_4[grid(256)](buf23, buf24, 256, XBLOCK= 256, num_warps=4, num_stages=1) buf25 = reinterpret_tensor(buf23, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf23 triton_poi_fused__softmax_5[grid(256)](buf24, buf25, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf26 = buf24 del buf24 triton_poi_fused_clone_6[grid(256)](buf20, buf26, 256, XBLOCK=128, num_warps=4, num_stages=1) buf27 = reinterpret_tensor(buf20, (16, 4, 4), (16, 4, 1), 0) del buf20 extern_kernels.bmm(reinterpret_tensor(buf25, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf26, (16, 4, 4), (16, 4, 1), 0), out=buf27 ) buf28 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_6[grid(256)](buf27, buf28, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf27 buf29 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf28, (16, 16), (16, 1), 0), reinterpret_tensor(primals_14, (16, 4), (1, 16), 0), out=buf29) buf30 = reinterpret_tensor(buf29, (4, 4, 4), (16, 4, 1), 0) del buf29 triton_poi_fused_add_9[grid(64)](buf30, buf14, primals_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf31 = buf16 del buf16 buf32 = buf15 del buf15 triton_poi_fused_native_layer_norm_0[grid(16)](buf30, buf31, buf32, 16, XBLOCK=16, num_warps=1, num_stages=1) buf33 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](buf30, buf31, buf32, primals_15, primals_16, buf33, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf31 del buf32 del primals_16 buf34 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf33, (16, 4), (4, 1), 0), reinterpret_tensor(primals_17, (4, 4), (1, 4), 0), out=buf34) buf35 = reinterpret_tensor(buf34, (4, 4, 4), (16, 4, 1), 0) del buf34 buf38 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_10[grid(64)](buf35, primals_18, buf38, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_18 buf36 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf35, (16, 4), (4, 1), 0), reinterpret_tensor(primals_19, (4, 4), (1, 4), 0), out=buf36) buf37 = reinterpret_tensor(buf36, (4, 4, 4), (16, 4, 1), 0) del buf36 triton_poi_fused_add_11[grid(64)](buf37, primals_20, buf30, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_20 return (buf37, buf10, buf25, primals_1, primals_9, primals_15, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), buf10, reinterpret_tensor(buf13, (16, 16), (16, 1), 0), buf14, reinterpret_tensor(buf17, (16, 4), (4, 1), 0), reinterpret_tensor( primals_8, (16, 4), (4, 1), 0), buf25, reinterpret_tensor(buf28, ( 16, 16), (16, 1), 0), buf30, reinterpret_tensor(buf33, (16, 4), (4, 1), 0), reinterpret_tensor(buf35, (16, 4), (4, 1), 0), primals_19, buf38, primals_17, primals_14, reinterpret_tensor(buf26, (16, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf21, (16, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf22, (16, 4, 4), (16, 1, 4), 0), primals_11, primals_7, reinterpret_tensor(buf11, (16, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf6, (16, 4, 4), (16, 1, 4), 0), reinterpret_tensor(buf7, (16, 4, 4), (16, 1, 4), 0), primals_4) class ScaledDotProductAttention(nn.Module): """ Scaled Dot-Product Attention """ def __init__(self, temperature, attn_dropout=0.1): super().__init__() self.temperature = temperature self.dropout = nn.Dropout(attn_dropout) def forward(self, q, k, v, mask=None): attn = torch.matmul(q / self.temperature, k.transpose(2, 3)) if mask is not None: attn = attn.masked_fill(mask == 0, -1000000000.0) attn = self.dropout(F.softmax(attn, dim=-1)) output = torch.matmul(attn, v) return output, attn class MultiHeadAttention(nn.Module): """ Multi-Head Attention module """ def __init__(self, n_head, d_model, d_k, d_v, dropout=0.1): super().__init__() self.n_head = n_head self.d_k = d_k self.d_v = d_v self.w_qs = nn.Linear(d_model, n_head * d_k, bias=False) self.w_ks = nn.Linear(d_model, n_head * d_k, bias=False) self.w_vs = nn.Linear(d_model, n_head * d_v, bias=False) self.fc = nn.Linear(n_head * d_v, d_model, bias=False) self.attention = ScaledDotProductAttention(temperature=d_k ** 0.5) self.dropout = nn.Dropout(dropout) self.layer_norm = nn.LayerNorm(d_model, eps=1e-06) def forward(self, q, k, v, mask=None): d_k, d_v, n_head = self.d_k, self.d_v, self.n_head sz_b, len_q, len_k, len_v = q.size(0), q.size(1), k.size(1), v.size(1) residual = q q = self.layer_norm(q) q = self.w_qs(q).view(sz_b, len_q, n_head, d_k) k = self.w_ks(k).view(sz_b, len_k, n_head, d_k) v = self.w_vs(v).view(sz_b, len_v, n_head, d_v) q, k, v = q.transpose(1, 2), k.transpose(1, 2), v.transpose(1, 2) if mask is not None: mask = mask.unsqueeze(1) q, attn = self.attention(q, k, v, mask=mask) q = q.transpose(1, 2).contiguous().view(sz_b, len_q, -1) q = self.dropout(self.fc(q)) q = q + residual return q, attn class PositionwiseFeedForward(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1 = nn.Linear(d_in, d_hid) self.w_2 = nn.Linear(d_hid, d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) def forward(self, x): residual = x x = self.layer_norm(x) x = self.w_2(F.relu(self.w_1(x))) x = self.dropout(x) x = x + residual return x class DecoderLayerNew(nn.Module): """ Compose with three layers """ def __init__(self, d_model, d_inner, n_head, d_k, d_v, dropout=0.1): super(DecoderLayerNew, self).__init__() self.slf_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout) self.enc_attn = MultiHeadAttention(n_head, d_model, d_k, d_v, dropout=dropout) self.pos_ffn = PositionwiseFeedForward(d_model, d_inner, dropout= dropout) def forward(self, input_0, input_1): primals_4 = self.slf_attn.w_qs.weight primals_5 = self.slf_attn.w_ks.weight primals_6 = self.slf_attn.w_vs.weight primals_7 = self.slf_attn.fc.weight primals_2 = self.slf_attn.layer_norm.weight primals_3 = self.slf_attn.layer_norm.bias primals_11 = self.enc_attn.w_qs.weight primals_12 = self.enc_attn.w_ks.weight primals_13 = self.enc_attn.w_vs.weight primals_14 = self.enc_attn.fc.weight primals_9 = self.enc_attn.layer_norm.weight primals_10 = self.enc_attn.layer_norm.bias primals_17 = self.pos_ffn.w_1.weight primals_15 = self.pos_ffn.w_1.bias primals_19 = self.pos_ffn.w_2.weight primals_16 = self.pos_ffn.w_2.bias primals_18 = self.pos_ffn.layer_norm.weight primals_20 = self.pos_ffn.layer_norm.bias primals_1 = input_0 primals_8 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20]) return output[0], output[1], output[2]
liuruoze/mini-AlphaStar
DecoderLayer
false
15,948
[ "Apache-2.0" ]
108
cf9de2507d526a5fb8ef67676aab2ffb92738640
https://github.com/liuruoze/mini-AlphaStar/tree/cf9de2507d526a5fb8ef67676aab2ffb92738640
AvgPoolWithMask
import torch import torch.nn as nn class AvgPoolWithMask(nn.Module): """ 给定形如[batch_size, max_len, hidden_size]的输入,在最后一维进行avg pooling. 输出为[batch_size, hidden_size], pooling 的时候只会考虑mask为1的位置 """ def __init__(self): super(AvgPoolWithMask, self).__init__() self.inf = 10000000000000.0 def forward(self, tensor, mask, dim=1): """ :param torch.FloatTensor tensor: [batch_size, seq_len, channels] 初始tensor :param torch.LongTensor mask: [batch_size, seq_len] 0/1的mask矩阵 :param int dim: 需要进行max pooling的维度 :return: """ masks = mask.view(mask.size(0), mask.size(1), -1).float() return torch.sum(tensor * masks.float(), dim=dim) / torch.sum(masks .float(), dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 16]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_mul_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 64 x3 = xindex % 64 x0 = xindex % 16 x1 = xindex // 16 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 256 * x2), xmask) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (64 + x3 + 256 * x2), xmask) tmp4 = tl.load(in_ptr1 + (64 + x3), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (128 + x3 + 256 * x2), xmask) tmp8 = tl.load(in_ptr1 + (128 + x3), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (192 + x3 + 256 * x2), xmask) tmp12 = tl.load(in_ptr1 + (192 + x3), xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 * tmp12 tmp14 = tmp10 + tmp13 tmp17 = tmp15 + tmp16 tmp19 = tmp17 + tmp18 tmp21 = tmp19 + tmp20 tmp22 = tmp14 / tmp21 tl.store(out_ptr0 + x4, tmp22, 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, 16), (256, 64, 16, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_mul_sum_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class AvgPoolWithMaskNew(nn.Module): """ 给定形如[batch_size, max_len, hidden_size]的输入,在最后一维进行avg pooling. 输出为[batch_size, hidden_size], pooling 的时候只会考虑mask为1的位置 """ def __init__(self): super(AvgPoolWithMaskNew, self).__init__() self.inf = 10000000000000.0 def forward(self, input_0, input_1): arg1_1 = input_0 arg0_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
AvgPoolWithMask
false
15,949
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
Gate
import torch import torch.nn as nn import torch.nn.functional as F class Gate(nn.Module): """Gate Unit g = sigmoid(Wx) x = g * x """ def __init__(self, input_size, dropout_rate=0.0): super(Gate, self).__init__() self.linear = nn.Linear(input_size, input_size, bias=False) self.dropout_rate = dropout_rate def forward(self, x): """ Args: x: batch * len * dim x_mask: batch * len (1 for padding, 0 for true) Output: res: batch * len * dim """ if self.dropout_rate: x = F.dropout(x, p=self.dropout_rate, training=self.training) x_proj = self.linear(x) gate = torch.sigmoid(x) return x_proj * gate 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sigmoid_0(in_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_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](buf1, primals_2, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf1, primals_2 class GateNew(nn.Module): """Gate Unit g = sigmoid(Wx) x = g * x """ def __init__(self, input_size, dropout_rate=0.0): super(GateNew, self).__init__() self.linear = nn.Linear(input_size, input_size, bias=False) self.dropout_rate = dropout_rate def forward(self, input_0): primals_1 = self.linear.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
lonePatient/TorchBlocks
Gate
false
15,950
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
KL
import torch import torch.nn as nn import torch.nn.functional as F class KL(nn.Module): def __init__(self, reduction='batchmean'): super(KL, self).__init__() self.reduction = reduction def forward(self, input, target): input = input.float() target = target.float() loss = F.kl_div(F.log_softmax(input, dim=-1), F.softmax(target, dim =-1), reduction='batchmean') return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_red_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl. constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp34 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp17 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp18 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp20 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp23 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp26 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = libdevice.isnan(tmp8).to(tl.int1) tmp10 = 0.0 tmp11 = tmp8 == tmp10 tmp12 = tl_math.log(tmp8) tmp13 = tmp8 * tmp12 tmp14 = tl.where(tmp11, tmp10, tmp13) tmp15 = float('nan') tmp16 = tl.where(tmp9, tmp15, tmp14) tmp19 = tl_math.exp(tmp18) tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tl_math.log(tmp28) tmp30 = tmp17 - tmp29 tmp31 = tmp8 * tmp30 tmp32 = tmp16 - tmp31 tmp33 = tl.broadcast_to(tmp32, [XBLOCK, RBLOCK]) tmp35 = _tmp34 + tmp33 _tmp34 = tl.where(rmask, tmp35, _tmp34) tmp34 = tl.sum(_tmp34, 1)[:, None] tmp36 = 0.25 tmp37 = tmp34 * tmp36 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp37, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](arg0_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_red_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2[grid(1) ](buf4, buf0, buf2, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 return buf4, class KLNew(nn.Module): def __init__(self, reduction='batchmean'): super(KLNew, self).__init__() 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]
lonePatient/TorchBlocks
KL
false
15,951
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
StochasticGate
import torch import torchvision.transforms.functional as F import torch.nn as nn import torch.nn.functional as F class StochasticGate(nn.Module): """Stochastically merges features from two levels with varying size of the receptive field """ def __init__(self): super(StochasticGate, self).__init__() self._mask_drop = None def forward(self, x1, x2, alpha_rate=0.3): """Stochastic Gate (SG) SG stochastically mixes deep and shallow features at training time and deterministically combines them at test time with a hyperparam. alpha """ if self.training: if self._mask_drop is None: _bs, c, _h, _w = x1.size() assert c == x2.size(1), 'Number of features is different' self._mask_drop = torch.ones_like(x1) mask_drop = (1 - alpha_rate) * F.dropout(self._mask_drop, alpha_rate) x1 = (x1 - alpha_rate * x2) / max(1e-08, 1 - alpha_rate) x = mask_drop * x1 + (1 - mask_drop) * x2 else: x = (1 - alpha_rate) * x1 + alpha_rate * x2 return x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_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) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp1 = 0.7 tmp2 = tmp0 * tmp1 tmp4 = 0.3 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class StochasticGateNew(nn.Module): """Stochastically merges features from two levels with varying size of the receptive field """ def __init__(self): super(StochasticGateNew, self).__init__() self._mask_drop = None def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
loserbbb/1-stage-wseg
StochasticGate
false
15,952
[ "Apache-2.0" ]
364
f1579be241986c1e19420bfbf6711b6c2208d99a
https://github.com/loserbbb/1-stage-wseg/tree/f1579be241986c1e19420bfbf6711b6c2208d99a
NormKLLoss
import torch import torch.utils.data import torch.nn.init import torch as th from torch.nn.modules.loss import _Loss class NormKLLoss(_Loss): def __init__(self, unit_average=False): super(NormKLLoss, self).__init__() self.unit_average = unit_average def forward(self, recog_mu, recog_logvar, prior_mu, prior_logvar): loss = 1.0 + (recog_logvar - prior_logvar) loss -= th.div(th.pow(prior_mu - recog_mu, 2), th.exp(prior_logvar)) loss -= th.div(th.exp(recog_logvar), th.exp(prior_logvar)) if self.unit_average: kl_loss = -0.5 * th.mean(loss, dim=1) else: kl_loss = -0.5 * th.sum(loss, dim=1) avg_kl_loss = th.mean(kl_loss) return avg_kl_loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.utils.data import torch.nn.init 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_add_div_exp_mean_mul_pow_sub_sum_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 % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp5 = tl.load(in_ptr2 + (r0 + 64 * r1), None) tmp6 = tl.load(in_ptr3 + (r0 + 64 * r1), None) tmp15 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp16 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp19 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None) tmp20 = tl.load(in_ptr3 + (16 + r0 + 64 * r1), None) tmp30 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp31 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp34 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None) tmp35 = tl.load(in_ptr3 + (32 + r0 + 64 * r1), None) tmp45 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp46 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp49 = tl.load(in_ptr2 + (48 + r0 + 64 * r1), None) tmp50 = tl.load(in_ptr3 + (48 + r0 + 64 * r1), None) tmp2 = tmp0 - tmp1 tmp3 = 1.0 tmp4 = tmp2 + tmp3 tmp7 = tmp5 - tmp6 tmp8 = tmp7 * tmp7 tmp9 = tl_math.exp(tmp1) tmp10 = tmp8 / tmp9 tmp11 = tmp4 - tmp10 tmp12 = tl_math.exp(tmp0) tmp13 = tmp12 / tmp9 tmp14 = tmp11 - tmp13 tmp17 = tmp15 - tmp16 tmp18 = tmp17 + tmp3 tmp21 = tmp19 - tmp20 tmp22 = tmp21 * tmp21 tmp23 = tl_math.exp(tmp16) tmp24 = tmp22 / tmp23 tmp25 = tmp18 - tmp24 tmp26 = tl_math.exp(tmp15) tmp27 = tmp26 / tmp23 tmp28 = tmp25 - tmp27 tmp29 = tmp14 + tmp28 tmp32 = tmp30 - tmp31 tmp33 = tmp32 + tmp3 tmp36 = tmp34 - tmp35 tmp37 = tmp36 * tmp36 tmp38 = tl_math.exp(tmp31) tmp39 = tmp37 / tmp38 tmp40 = tmp33 - tmp39 tmp41 = tl_math.exp(tmp30) tmp42 = tmp41 / tmp38 tmp43 = tmp40 - tmp42 tmp44 = tmp29 + tmp43 tmp47 = tmp45 - tmp46 tmp48 = tmp47 + tmp3 tmp51 = tmp49 - tmp50 tmp52 = tmp51 * tmp51 tmp53 = tl_math.exp(tmp46) tmp54 = tmp52 / tmp53 tmp55 = tmp48 - tmp54 tmp56 = tl_math.exp(tmp45) tmp57 = tmp56 / tmp53 tmp58 = tmp55 - tmp57 tmp59 = tmp44 + tmp58 tmp60 = -0.5 tmp61 = tmp59 * tmp60 tmp62 = tl.broadcast_to(tmp61, [XBLOCK, RBLOCK]) tmp64 = tl.sum(tmp62, 1)[:, None] tmp65 = 64.0 tmp66 = tmp64 / tmp65 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp66, 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_div_exp_mean_mul_pow_sub_sum_0[grid(1)](buf2, arg0_1, arg1_1, arg2_1, arg3_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 NormKLLossNew(_Loss): def __init__(self, unit_average=False): super(NormKLLossNew, self).__init__() self.unit_average = unit_average 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]
ljw23/ConvLab-2
NormKLLoss
false
15,953
[ "Apache-2.0" ]
339
13d48ea0e441701bd66100689b6c25b561f15525
https://github.com/ljw23/ConvLab-2/tree/13d48ea0e441701bd66100689b6c25b561f15525
AttCeLoss
import torch import torch.nn as nn import torch.nn.functional as F class AttCeLoss(nn.Module): def __init__(self): super().__init__() def forward(self, attention_S, attention_T, mask=None): """ Calculate the cross entropy between attention_S and attention_T. :param logits_S: Tensor of shape (batch_size, num_heads, length, length) :param logits_T: Tensor of shape (batch_size, num_heads, length, length) :param mask: Tensor of shape (batch_size, length) """ probs_T = F.softmax(attention_T, dim=-1) if mask is None: probs_T_select = torch.where(attention_T <= -0.001, torch. zeros_like(attention_T), probs_T) loss = -(probs_T_select * F.log_softmax(attention_S, dim=-1)).sum( dim=-1).mean() else: mask = mask.unsqueeze(1).expand(-1, attention_S.size(1), -1) loss = -((probs_T * F.log_softmax(attention_S, dim=-1) * mask. unsqueeze(2)).sum(dim=-1) * mask).sum() / mask.sum() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax__softmax_le_mul_where_zeros_like_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x2, xmask) tmp4 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr2 + x2, xmask) tmp15 = tl.load(in_ptr2 + 4 * x1, xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr2 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr2 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp23 = tl.load(in_ptr2 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = -0.001 tmp2 = tmp0 <= tmp1 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp10 = tmp8 + tmp9 tmp11 = tmp3 / tmp10 tmp12 = 0.0 tmp13 = tl.where(tmp2, tmp12, tmp11) tmp16 = tl_math.exp(tmp15) tmp18 = tl_math.exp(tmp17) tmp19 = tmp16 + tmp18 tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = tl_math.log(tmp25) tmp27 = tmp14 - tmp26 tmp28 = tmp13 * tmp27 tl.store(out_ptr0 + x2, tmp28, xmask) @triton.jit def triton_per_fused_mean_neg_sum_3(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 64.0 tmp11 = tmp9 / tmp10 tmp12 = -tmp11 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp12, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(256)](arg1_1, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__softmax_le_mul_where_zeros_like_2[grid (256)](arg0_1, buf0, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del buf0 del buf1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused_mean_neg_sum_3[grid(1)](buf4, buf2, 1, 64, XBLOCK= 1, num_warps=2, num_stages=1) del buf2 return buf4, class AttCeLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
AttCeLoss
false
15,954
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
MaskedConv1d
import torch import torch.nn as nn class MaskedConv1d(nn.Conv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): if causal: padding = (kernel_size - 1) * dilation else: padding = (kernel_size - 1) * dilation // 2 super(MaskedConv1d, self).__init__(in_channels, out_channels, kernel_size, stride=1, padding=padding, dilation=dilation, groups=groups, bias=bias) def forward(self, inputs): output = super(MaskedConv1d, self).forward(inputs) return output[:, :, :inputs.size(2)] def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride 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 = 112 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 7 % 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), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,), padding=(3,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 7), (28, 7, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(112)](buf1, primals_2, 112, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return reinterpret_tensor(buf1, (4, 4, 4), (28, 7, 1), 0 ), primals_1, primals_3 class MaskedConv1dNew(nn.Conv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): if causal: padding = (kernel_size - 1) * dilation else: padding = (kernel_size - 1) * dilation // 2 super(MaskedConv1dNew, self).__init__(in_channels, out_channels, kernel_size, stride=1, padding=padding, dilation=dilation, groups=groups, bias=bias) 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]
lonePatient/TorchBlocks
MaskedConv1d
false
15,955
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
CosAttention
import torch import torch.nn as nn class CosAttention(nn.Module): def __init__(self): super(CosAttention, self).__init__() def forward(self, q, k, v): """ q: (batchsize, hidden_dim) k: (batchsize, seqlen, hidden_dim) v: (batchsize, seqlen, hidden_dim) """ seq_len = k.size()[1] q_output = q.unsqueeze(1).repeat(1, seq_len, 1) cos_sim = torch.cosine_similarity(q_output, k, -1) cos_sim = cos_sim.unsqueeze(-1) outputs = v * cos_sim return outputs def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clamp_min_div_linalg_vector_norm_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 % 4 x2 = xindex // 16 % 4 x5 = xindex x6 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x2), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x2), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x2), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr1 + x5, xmask) tmp17 = tl.load(in_ptr1 + 4 * x6, xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr1 + (1 + 4 * x6), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + (2 + 4 * x6), xmask, eviction_policy='evict_last' ) tmp25 = tl.load(in_ptr1 + (3 + 4 * x6), 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-08 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tmp18 = tmp17 * tmp17 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = libdevice.sqrt(tmp27) tmp29 = triton_helpers.maximum(tmp28, tmp13) tmp30 = tmp16 / tmp29 tmp31 = tmp15 * tmp30 tl.store(out_ptr0 + x5, tmp31, 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 // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 * tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 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_clamp_min_div_linalg_vector_norm_mul_0[grid(256)]( arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_1[grid(256)](arg2_1, buf0, buf1, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg2_1 del buf0 return buf1, class CosAttentionNew(nn.Module): def __init__(self): super(CosAttentionNew, self).__init__() def forward(self, input_0, input_1, input_2): arg1_1 = input_0 arg0_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
lonePatient/TorchBlocks
CosAttention
false
15,956
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
MultiSampleDropout
import torch import torch.nn as nn class MultiSampleDropout(nn.Module): """ # multisample dropout (wut): https://arxiv.org/abs/1905.09788 """ def __init__(self, hidden_size, num_labels, K=5, p=0.5): super().__init__() self.K = K self.dropout = nn.Dropout(p) self.classifier = nn.Linear(hidden_size, num_labels) def forward(self, input): logits = torch.stack([self.classifier(self.dropout(input)) for _ in range(self.K)], dim=0) logits = torch.mean(logits, dim=0) return logits def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'num_labels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_stack_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1280 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 64 x0 = xindex % 64 x2 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x1), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr0 + (x0 + 64 * (-4 + x1)), tmp9 & xmask, other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + (x0 + 64 * (-8 + x1)), tmp14 & xmask, other=0.0) tmp16 = tmp0 >= tmp12 tmp17 = tl.full([1], 16, tl.int64) tmp18 = tmp0 < tmp17 tmp19 = tmp16 & tmp18 tmp20 = tl.load(in_ptr0 + (x0 + 64 * (-12 + x1)), tmp19 & xmask, other=0.0) tmp21 = tmp0 >= tmp17 tl.full([1], 20, tl.int64) tmp24 = tl.load(in_ptr0 + (x0 + 64 * (-16 + x1)), tmp21 & xmask, other=0.0) tmp25 = tl.where(tmp19, tmp20, tmp24) tmp26 = tl.where(tmp14, tmp15, tmp25) tmp27 = tl.where(tmp9, tmp10, tmp26) tmp28 = tl.where(tmp4, tmp5, tmp27) tl.store(out_ptr0 + x2, tmp28, xmask) @triton.jit def triton_poi_fused_mean_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 = tl.load(in_ptr0 + (256 + x0), xmask) tmp3 = tl.load(in_ptr0 + (512 + x0), xmask) tmp5 = tl.load(in_ptr0 + (768 + x0), xmask) tmp7 = tl.load(in_ptr0 + (1024 + x0), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp9 = 5.0 tmp10 = tmp8 / tmp9 tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((20, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(1280)](buf0, buf1, 1280, XBLOCK=128, num_warps=4, num_stages=1) buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_mean_1[grid(256)](buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 return buf2, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0) class MultiSampleDropoutNew(nn.Module): """ # multisample dropout (wut): https://arxiv.org/abs/1905.09788 """ def __init__(self, hidden_size, num_labels, K=5, p=0.5): super().__init__() self.K = K self.dropout = nn.Dropout(p) self.classifier = nn.Linear(hidden_size, num_labels) def forward(self, input_0): primals_2 = self.classifier.weight primals_3 = self.classifier.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lonePatient/TorchBlocks
MultiSampleDropout
false
15,957
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
MaxPoolWithMask
import torch import torch.nn as nn class MaxPoolWithMask(nn.Module): """ 带mask矩阵的max pooling。在做max-pooling的时候不会考虑mask值为0的位置。 """ def __init__(self): super(MaxPoolWithMask, self).__init__() self.inf = 10000000000000.0 def forward(self, tensor, mask, dim=1): """ :param torch.FloatTensor tensor: [batch_size, seq_len, channels] 初始tensor :param torch.LongTensor mask: [batch_size, seq_len] 0/1的mask矩阵 :param int dim: 需要进行max pooling的维度 :return: """ masks = mask.view(mask.size(0), mask.size(1), -1) masks = masks.expand(-1, -1, tensor.size(2)).float() return torch.max(tensor + masks.le(0.5).float() * -self.inf, dim=dim)[0 ] def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp9 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp16 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp23 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp2 = 0.5 tmp3 = tmp1 <= tmp2 tmp4 = tmp3.to(tl.float32) tmp5 = -10000000000000.0 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + tmp6 tmp10 = tmp9 <= tmp2 tmp11 = tmp10.to(tl.float32) tmp12 = tmp11 * tmp5 tmp13 = tmp8 + tmp12 tmp14 = triton_helpers.maximum(tmp7, tmp13) tmp17 = tmp16 <= tmp2 tmp18 = tmp17.to(tl.float32) tmp19 = tmp18 * tmp5 tmp20 = tmp15 + tmp19 tmp21 = triton_helpers.maximum(tmp14, tmp20) tmp24 = tmp23 <= tmp2 tmp25 = tmp24.to(tl.float32) tmp26 = tmp25 * tmp5 tmp27 = tmp22 + tmp26 tmp28 = triton_helpers.maximum(tmp21, tmp27) tl.store(out_ptr0 + x2, tmp28, 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), (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_max_0[grid(16)](arg1_1, arg0_1, buf0, 16, XBLOCK= 16, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf0, class MaxPoolWithMaskNew(nn.Module): """ 带mask矩阵的max pooling。在做max-pooling的时候不会考虑mask值为0的位置。 """ def __init__(self): super(MaxPoolWithMaskNew, self).__init__() self.inf = 10000000000000.0 def forward(self, input_0, input_1): arg1_1 = input_0 arg0_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
MaxPoolWithMask
false
15,958
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
KdMseLoss
import torch import torch.nn as nn import torch.nn.functional as F class KdMseLoss(nn.Module): def __init__(self): super().__init__() def forward(self, logits_S, logits_T, temperature=1): """ Calculate the mse loss between logits_S and logits_T :param logits_S: Tensor of shape (batch_size, length, num_labels) or (batch_size, num_labels) :param logits_T: Tensor of shape (batch_size, length, num_labels) or (batch_size, num_labels) :param temperature: A float or a tensor of shape (batch_size, length) or (batch_size,) """ if isinstance(temperature, torch.Tensor) and temperature.dim() > 0: temperature = temperature.unsqueeze(-1) beta_logits_T = logits_T / temperature beta_logits_S = logits_S / temperature loss = F.mse_loss(beta_logits_S, beta_logits_T) 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 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_div_mse_loss_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp5 = tmp2 - tmp4 tmp6 = tmp5 * 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_div_mse_loss_0[grid(1)](buf1, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class KdMseLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
KdMseLoss
false
15,959
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
SKL
import torch import torch.nn as nn import torch.nn.functional as F class SKL(nn.Module): def __init__(self, epsilon=1e-08): super(SKL, self).__init__() self.epsilon = epsilon def forward(self, input, target): logit = input.view(-1, input.size(-1)).float() target = target.view(-1, target.size(-1)).float() bs = logit.size(0) p = F.log_softmax(logit, 1).exp() y = F.log_softmax(target, 1).exp() rp = -(1.0 / (p + self.epsilon) - 1 + self.epsilon).detach().log() ry = -(1.0 / (y + self.epsilon) - 1 + self.epsilon).detach().log() return (p * (rp - ry) * 2).sum() / bs def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp52 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tl.load(in_ptr0 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr0 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tl.load(in_ptr1 + r2, rmask, eviction_policy='evict_first', other=0.0) tmp26 = tl.load(in_ptr1 + 4 * r1, rmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.load(in_ptr1 + (1 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp31 = tl.load(in_ptr1 + (2 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp34 = tl.load(in_ptr1 + (3 + 4 * r1), rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp14 = tl_math.exp(tmp13) tmp15 = 1e-08 tmp16 = tmp14 + tmp15 tmp17 = tl.full([1, 1], 1, tl.int32) tmp18 = tmp17 / tmp16 tmp19 = 1.0 tmp20 = tmp18 * tmp19 tmp21 = tmp20 - tmp19 tmp22 = tmp21 + tmp15 tmp23 = tl_math.log(tmp22) tmp24 = -tmp23 tmp27 = tl_math.exp(tmp26) tmp29 = tl_math.exp(tmp28) tmp30 = tmp27 + tmp29 tmp32 = tl_math.exp(tmp31) tmp33 = tmp30 + tmp32 tmp35 = tl_math.exp(tmp34) tmp36 = tmp33 + tmp35 tmp37 = tl_math.log(tmp36) tmp38 = tmp25 - tmp37 tmp39 = tl_math.exp(tmp38) tmp40 = tmp39 + tmp15 tmp41 = tmp17 / tmp40 tmp42 = tmp41 * tmp19 tmp43 = tmp42 - tmp19 tmp44 = tmp43 + tmp15 tmp45 = tl_math.log(tmp44) tmp46 = -tmp45 tmp47 = tmp24 - tmp46 tmp48 = tmp14 * tmp47 tmp49 = 2.0 tmp50 = tmp48 * tmp49 tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK]) tmp53 = _tmp52 + tmp51 _tmp52 = tl.where(rmask, tmp53, _tmp52) tmp52 = tl.sum(_tmp52, 1)[:, None] tmp54 = 0.015625 tmp55 = tmp52 * tmp54 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp55, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_0[grid(256)](arg1_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf4 = empty_strided_cuda((), (), torch.float32) buf5 = buf4 del buf4 triton_red_fused__log_softmax_add_div_exp_log_mul_neg_reciprocal_sub_sum_1[ grid(1)](buf5, buf0, buf2, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del buf0 del buf2 return buf5, class SKLNew(nn.Module): def __init__(self, epsilon=1e-08): super(SKLNew, self).__init__() self.epsilon = epsilon def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
SKL
false
15,960
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
NetVLAD
import torch import torch.nn.functional as func import torch.nn as nn class NetVLAD(nn.Module): """ NetVLAD layer implementation Credits: https://github.com/lyakaap/NetVLAD-pytorch """ def __init__(self, num_clusters=64, dim=128, alpha=100.0, normalize_input=True): """ Args: num_clusters: number of clusters. dim: dimension of descriptors. alpha: parameter of initialization. Larger is harder assignment. normalize_input: if true, descriptor-wise L2 normalization is applied to input. """ super().__init__() self.num_clusters = num_clusters self.dim = dim self.alpha = alpha self.normalize_input = normalize_input self.conv = nn.Conv2d(dim, num_clusters, kernel_size=(1, 1), bias=True) self.centroids = nn.Parameter(torch.rand(num_clusters, dim)) self._init_params() def _init_params(self): 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 = func.normalize(x, p=2, dim=1) soft_assign = self.conv(x).view(N, self.num_clusters, -1) soft_assign = func.softmax(soft_assign, dim=1) x_flatten = x.view(N, C, -1) residual = x_flatten.expand(self.num_clusters, -1, -1, -1).permute( 1, 0, 2, 3) - self.centroids.expand(x_flatten.size(-1), -1, -1 ).permute(1, 2, 0).unsqueeze(0) residual *= soft_assign.unsqueeze(2) vlad = residual.sum(dim=-1) vlad = func.normalize(vlad, p=2, dim=2) vlad = vlad.view(x.size(0), -1) vlad = func.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 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_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_1(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 512 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y1 = yindex // 128 y0 = yindex % 128 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + (x2 + 4096 * y1), ymask, eviction_policy= 'evict_last') tmp2 = libdevice.sqrt(tmp1) tmp3 = 1e-12 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = tmp0 / tmp4 tl.store(out_ptr0 + (y0 + 128 * x2 + 524288 * y1), tmp5, ymask) @triton.jit def triton_per_fused__softmax_convolution_2(in_out_ptr0, 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) r1 = rindex x0 = xindex tmp0 = tl.load(in_out_ptr0 + (r1 + 64 * x0), None) tmp1 = tl.load(in_ptr0 + r1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = triton_helpers.max2(tmp3, 1)[:, None] tmp6 = tmp2 - tmp5 tmp7 = tl_math.exp(tmp6) tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = tl.sum(tmp8, 1)[:, None] tl.store(in_out_ptr0 + (r1 + 64 * x0), tmp2, None) tl.store(out_ptr0 + x0, tmp5, None) tl.store(out_ptr1 + x0, tmp10, None) @triton.jit def triton_red_fused_mul_sub_sum_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl. constexpr): rnumel = 4096 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 % 128 x2 = xindex // 8192 x4 = xindex % 8192 tmp1 = tl.load(in_ptr1 + x4, None, eviction_policy='evict_last') x1 = xindex // 128 % 64 _tmp11 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) x5 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r3 = rindex tmp0 = tl.load(in_ptr0 + (x0 + 128 * r3 + 524288 * x2), rmask, eviction_policy='evict_last', other=0.0) tmp3 = tl.load(in_ptr2 + (x1 + 64 * r3 + 262144 * x2), rmask, eviction_policy='evict_last', other=0.0) tmp4 = tl.load(in_ptr3 + (r3 + 4096 * x2), rmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tl.load(in_ptr4 + (r3 + 4096 * x2), rmask, 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, tmp12, _tmp11) tmp11 = tl.sum(_tmp11, 1)[:, None] tl.store(out_ptr0 + x5, tmp11, None) @triton.jit def triton_per_fused_linalg_vector_norm_4(in_out_ptr0, in_ptr0, 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) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 128 * x0), xmask, other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = libdevice.sqrt(tmp5) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_red_fused_div_linalg_vector_norm_5(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, primals_4 = 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,), (1,)) assert_size_stride(primals_4, (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, 1, 8192, 128), torch.float32) triton_poi_fused_div_1[grid(512, 4096)](primals_1, buf0, buf1, 512, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, 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, 1, 4096, 64)) buf3 = buf2 del buf2 buf4 = reinterpret_tensor(buf0, (4, 1, 4096), (4096, 4096, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 1, 4096), (4096, 4096, 1), torch.float32) triton_per_fused__softmax_convolution_2[grid(16384)](buf3, primals_3, buf4, buf5, 16384, 64, XBLOCK=32, num_warps=8, num_stages=1) del primals_3 buf6 = empty_strided_cuda((4, 64, 128), (8192, 128, 1), torch.float32) triton_red_fused_mul_sub_sum_3[grid(32768)](buf1, primals_4, buf3, buf4, buf5, buf6, 32768, 4096, XBLOCK=8, RBLOCK=256, num_warps= 16, num_stages=1) buf7 = empty_strided_cuda((4, 64, 1), (64, 1, 256), torch.float32) buf8 = reinterpret_tensor(buf7, (4, 64, 1), (64, 1, 1), 0) del buf7 triton_per_fused_linalg_vector_norm_4[grid(256)](buf8, buf6, 256, 128, XBLOCK=8, num_warps=8, num_stages=1) buf9 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf10 = reinterpret_tensor(buf9, (4, 1), (1, 1), 0) del buf9 buf11 = empty_strided_cuda((4, 8192), (8192, 1), torch.float32) triton_red_fused_div_linalg_vector_norm_5[grid(4)](buf10, buf6, buf8, buf11, 4, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) return (buf11, primals_2, primals_4, buf1, buf3, buf4, buf5, buf6, buf8, buf10) class NetVLADNew(nn.Module): """ NetVLAD layer implementation Credits: https://github.com/lyakaap/NetVLAD-pytorch """ def __init__(self, num_clusters=64, dim=128, alpha=100.0, normalize_input=True): """ Args: num_clusters: number of clusters. dim: dimension of descriptors. alpha: parameter of initialization. Larger is harder assignment. normalize_input: if true, descriptor-wise L2 normalization is applied to input. """ super().__init__() self.num_clusters = num_clusters self.dim = dim self.alpha = alpha self.normalize_input = normalize_input self.conv = nn.Conv2d(dim, num_clusters, kernel_size=(1, 1), bias=True) self.centroids = nn.Parameter(torch.rand(num_clusters, dim)) self._init_params() def _init_params(self): 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_4 = self.centroids primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
liuyuzhenn/LISRD
NetVLAD
false
15,961
[ "MIT" ]
225
bfd890b81defebea971db0b744be617ed58f5ffa
https://github.com/liuyuzhenn/LISRD/tree/bfd890b81defebea971db0b744be617ed58f5ffa
GaussianSmearing
import torch from torch import nn class GaussianSmearing(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0, num_rbf=50, trainable=True): super(GaussianSmearing, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper self.num_rbf = num_rbf self.trainable = trainable offset, coeff = self._initial_params() if trainable: self.register_parameter('coeff', nn.Parameter(coeff)) self.register_parameter('offset', nn.Parameter(offset)) else: self.register_buffer('coeff', coeff) self.register_buffer('offset', offset) def _initial_params(self): offset = torch.linspace(self.cutoff_lower, self.cutoff_upper, self. num_rbf) coeff = -0.5 / (offset[1] - offset[0]) ** 2 return offset, coeff def reset_parameters(self): offset, coeff = self._initial_params() self.offset.data.copy_(offset) self.coeff.data.copy_(coeff) def forward(self, dist): dist = dist.unsqueeze(-1) - self.offset return torch.exp(self.coeff * torch.pow(dist, 2)) 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 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_exp_mul_pow_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 12800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 50 x0 = xindex % 50 x2 = xindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp4 = tmp2 - tmp3 tmp5 = tmp4 * tmp4 tmp6 = tmp1 * tmp5 tmp7 = tl_math.exp(tmp6) tl.store(out_ptr0 + x2, tmp7, 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, (50,), (1,)) assert_size_stride(primals_3, (), ()) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 50), (3200, 800, 200, 50, 1), torch.float32) get_raw_stream(0) triton_poi_fused_exp_mul_pow_sub_0[grid(12800)](primals_3, primals_1, primals_2, buf0, 12800, XBLOCK=128, num_warps=4, num_stages=1) return buf0, primals_1, primals_2, primals_3, buf0 class GaussianSmearingNew(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0, num_rbf=50, trainable=True): super(GaussianSmearingNew, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper self.num_rbf = num_rbf self.trainable = trainable offset, coeff = self._initial_params() if trainable: self.register_parameter('coeff', nn.Parameter(coeff)) self.register_parameter('offset', nn.Parameter(offset)) else: self.register_buffer('coeff', coeff) self.register_buffer('offset', offset) def _initial_params(self): offset = torch.linspace(self.cutoff_lower, self.cutoff_upper, self. num_rbf) coeff = -0.5 / (offset[1] - offset[0]) ** 2 return offset, coeff def reset_parameters(self): offset, coeff = self._initial_params() self.offset.data.copy_(offset) self.coeff.data.copy_(coeff) def forward(self, input_0): primals_3 = self.coeff primals_2 = self.offset primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lsnty5190/torchmd-net
GaussianSmearing
false
15,962
[ "MIT" ]
51
0bedf43801f0c7d38900d8e1db778fe69f3a4d01
https://github.com/lsnty5190/torchmd-net/tree/0bedf43801f0c7d38900d8e1db778fe69f3a4d01
GatedConv1d
import torch import torch.nn as nn class MaskedConv1d(nn.Conv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): if causal: padding = (kernel_size - 1) * dilation else: padding = (kernel_size - 1) * dilation // 2 super(MaskedConv1d, self).__init__(in_channels, out_channels, kernel_size, stride=1, padding=padding, dilation=dilation, groups=groups, bias=bias) def forward(self, inputs): output = super(MaskedConv1d, self).forward(inputs) return output[:, :, :inputs.size(2)] class GatedConv1d(MaskedConv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): super(GatedConv1d, self).__init__(in_channels, 2 * out_channels, kernel_size, dilation, groups, bias, causal) self.sigmoid = nn.Sigmoid() def forward(self, inputs): output = super(GatedConv1d, self).forward(inputs) mask, output = output.chunk(2, 1) mask = self.sigmoid(mask) return output * mask def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 224 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 7 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 7 * x1 + 56 * x2), xmask) tmp2 = tl.load(in_ptr0 + (28 + x0 + 7 * x1 + 56 * x2), xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = tmp2 * tmp1 tl.store(out_ptr0 + x3, tmp1, xmask) tl.store(out_ptr1 + x3, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (8, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,), padding=(3,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 7), (56, 7, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(224)](buf1, primals_2, 224, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_1[grid(64)](buf1, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf3, primals_1, primals_3, reinterpret_tensor(buf1, (4, 4, 4), (56, 7, 1), 28), buf2 class MaskedConv1d(nn.Conv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): if causal: padding = (kernel_size - 1) * dilation else: padding = (kernel_size - 1) * dilation // 2 super(MaskedConv1d, self).__init__(in_channels, out_channels, kernel_size, stride=1, padding=padding, dilation=dilation, groups=groups, bias=bias) def forward(self, inputs): output = super(MaskedConv1d, self).forward(inputs) return output[:, :, :inputs.size(2)] class GatedConv1dNew(MaskedConv1d): def __init__(self, in_channels, out_channels, kernel_size, dilation=1, groups=1, bias=True, causal=True): super(GatedConv1dNew, self).__init__(in_channels, 2 * out_channels, kernel_size, dilation, groups, bias, causal) self.sigmoid = nn.Sigmoid() 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]
lonePatient/TorchBlocks
GatedConv1d
false
15,963
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
ExpNormalSmearing
import math import torch from torch import nn class CosineCutoff(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0): super(CosineCutoff, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper def forward(self, distances): if self.cutoff_lower > 0: cutoffs = 0.5 * (torch.cos(math.pi * (2 * (distances - self. cutoff_lower) / (self.cutoff_upper - self.cutoff_lower) + 1.0)) + 1.0) cutoffs = cutoffs * (distances < self.cutoff_upper).float() cutoffs = cutoffs * (distances > self.cutoff_lower).float() return cutoffs else: cutoffs = 0.5 * (torch.cos(distances * math.pi / self. cutoff_upper) + 1.0) cutoffs = cutoffs * (distances < self.cutoff_upper).float() return cutoffs class ExpNormalSmearing(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0, num_rbf=50, trainable=True): super(ExpNormalSmearing, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper self.num_rbf = num_rbf self.trainable = trainable self.cutoff_fn = CosineCutoff(0, cutoff_upper) self.alpha = 5.0 / (cutoff_upper - cutoff_lower) means, betas = self._initial_params() if trainable: self.register_parameter('means', nn.Parameter(means)) self.register_parameter('betas', nn.Parameter(betas)) else: self.register_buffer('means', means) self.register_buffer('betas', betas) def _initial_params(self): start_value = torch.exp(torch.scalar_tensor(-self.cutoff_upper + self.cutoff_lower)) means = torch.linspace(start_value, 1, self.num_rbf) betas = torch.tensor([(2 / self.num_rbf * (1 - start_value)) ** -2] * self.num_rbf) return means, betas def reset_parameters(self): means, betas = self._initial_params() self.means.data.copy_(means) self.betas.data.copy_(betas) def forward(self, dist): dist = dist.unsqueeze(-1) return self.cutoff_fn(dist) * torch.exp(-self.betas * (torch.exp( self.alpha * (-dist + self.cutoff_lower)) - self.means) ** 2) 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 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_poi_fused__to_copy_add_cos_div_exp_lt_mul_neg_pow_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 12800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 50 x0 = xindex % 50 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp1 = 3.141592653589793 tmp2 = tmp0 * tmp1 tmp3 = 0.2 tmp4 = tmp2 * tmp3 tmp5 = tl_math.cos(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp10 = 5.0 tmp11 = tmp0 < tmp10 tmp12 = tmp11.to(tl.float32) tmp13 = tmp9 * tmp12 tmp15 = -tmp14 tmp16 = -tmp0 tmp17 = 0.0 tmp18 = tmp16 + tmp17 tmp19 = tmp18 * tmp6 tmp20 = tl_math.exp(tmp19) tmp22 = tmp20 - tmp21 tmp23 = tmp22 * tmp22 tmp24 = tmp15 * tmp23 tmp25 = tl_math.exp(tmp24) tmp26 = tmp13 * tmp25 tl.store(out_ptr0 + x2, tmp26, 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, (50,), (1,)) assert_size_stride(primals_3, (50,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 50), (3200, 800, 200, 50, 1), torch.float32) get_raw_stream(0) triton_poi_fused__to_copy_add_cos_div_exp_lt_mul_neg_pow_sub_0[grid (12800)](primals_1, primals_2, primals_3, buf0, 12800, XBLOCK= 256, num_warps=4, num_stages=1) return buf0, primals_1, primals_2, primals_3 class CosineCutoff(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0): super(CosineCutoff, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper def forward(self, distances): if self.cutoff_lower > 0: cutoffs = 0.5 * (torch.cos(math.pi * (2 * (distances - self. cutoff_lower) / (self.cutoff_upper - self.cutoff_lower) + 1.0)) + 1.0) cutoffs = cutoffs * (distances < self.cutoff_upper).float() cutoffs = cutoffs * (distances > self.cutoff_lower).float() return cutoffs else: cutoffs = 0.5 * (torch.cos(distances * math.pi / self. cutoff_upper) + 1.0) cutoffs = cutoffs * (distances < self.cutoff_upper).float() return cutoffs class ExpNormalSmearingNew(nn.Module): def __init__(self, cutoff_lower=0.0, cutoff_upper=5.0, num_rbf=50, trainable=True): super(ExpNormalSmearingNew, self).__init__() self.cutoff_lower = cutoff_lower self.cutoff_upper = cutoff_upper self.num_rbf = num_rbf self.trainable = trainable self.cutoff_fn = CosineCutoff(0, cutoff_upper) self.alpha = 5.0 / (cutoff_upper - cutoff_lower) means, betas = self._initial_params() if trainable: self.register_parameter('means', nn.Parameter(means)) self.register_parameter('betas', nn.Parameter(betas)) else: self.register_buffer('means', means) self.register_buffer('betas', betas) def _initial_params(self): start_value = torch.exp(torch.scalar_tensor(-self.cutoff_upper + self.cutoff_lower)) means = torch.linspace(start_value, 1, self.num_rbf) betas = torch.tensor([(2 / self.num_rbf * (1 - start_value)) ** -2] * self.num_rbf) return means, betas def reset_parameters(self): means, betas = self._initial_params() self.means.data.copy_(means) self.betas.data.copy_(betas) def forward(self, input_0): primals_2 = self.means primals_3 = self.betas primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lsnty5190/torchmd-net
ExpNormalSmearing
false
15,964
[ "MIT" ]
51
0bedf43801f0c7d38900d8e1db778fe69f3a4d01
https://github.com/lsnty5190/torchmd-net/tree/0bedf43801f0c7d38900d8e1db778fe69f3a4d01
TripletLoss
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed import torch.nn.functional as F class TripletLoss(nn.Module): """ Triplet loss Takes embeddings of an anchor sample, a positive sample and a negative sample """ def __init__(self, margin): super(TripletLoss, self).__init__() self.margin = margin def forward(self, anchor, positive, negative, size_average=True): distance_positive = (anchor - positive).pow(2).sum(1) distance_negative = (anchor - negative).pow(2).sum(1) losses = F.relu(distance_positive - distance_negative + self.margin) return losses.mean() if size_average else losses.sum() 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 [[], {'margin': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_mean_pow_relu_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) tmp4 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp5 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp9 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp10 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp14 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp15 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp19 = tl.load(in_ptr2 + (r0 + 64 * r1), None) tmp22 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None) tmp26 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None) tmp30 = tl.load(in_ptr2 + (48 + r0 + 64 * r1), None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp16 * tmp16 tmp18 = tmp13 + tmp17 tmp20 = tmp0 - tmp19 tmp21 = tmp20 * tmp20 tmp23 = tmp4 - tmp22 tmp24 = tmp23 * tmp23 tmp25 = tmp21 + tmp24 tmp27 = tmp9 - tmp26 tmp28 = tmp27 * tmp27 tmp29 = tmp25 + tmp28 tmp31 = tmp14 - tmp30 tmp32 = tmp31 * tmp31 tmp33 = tmp29 + tmp32 tmp34 = tmp18 - tmp33 tmp35 = 4.0 tmp36 = tmp34 + tmp35 tmp37 = tl.full([1, 1], 0, tl.int32) tmp38 = triton_helpers.maximum(tmp37, tmp36) tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = tl.sum(tmp39, 1)[:, None] tmp42 = 64.0 tmp43 = tmp41 / tmp42 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None) def call(args): arg0_1, arg1_1, 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_mean_pow_relu_sub_sum_0[grid(1)](buf2, arg0_1, arg1_1, arg2_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class TripletLossNew(nn.Module): """ Triplet loss Takes embeddings of an anchor sample, a positive sample and a negative sample """ def __init__(self, margin): super(TripletLossNew, self).__init__() self.margin = margin 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]
lxy5513/cvToolkit
TripletLoss
false
15,965
[ "MIT" ]
47
51586c8016b47f5e7852032f9f3211c89d80f537
https://github.com/lxy5513/cvToolkit/tree/51586c8016b47f5e7852032f9f3211c89d80f537
AxialPositionalEmbedding
import torch from torch import nn class AxialPositionalEmbedding(nn.Module): def __init__(self, dim, shape, emb_dim_index=1): super().__init__() total_dimensions = len(shape) + 2 ax_dim_indexes = [i for i in range(1, total_dimensions) if i != emb_dim_index] self.num_axials = len(shape) for i, (axial_dim, axial_dim_index) in enumerate(zip(shape, ax_dim_indexes)): shape = [1] * total_dimensions shape[emb_dim_index] = dim shape[axial_dim_index] = axial_dim parameter = nn.Parameter(torch.randn(*shape)) setattr(self, f'param_{i}', parameter) def forward(self, x): for i in range(self.num_axials): x = x + getattr(self, f'param_{i}') return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4, 'shape': [4, 4]}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x5 = xindex // 4 % 16 x0 = xindex % 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(out_ptr0 + x4, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (1, 4, 4, 1), (16, 4, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (1, 4, 1, 4), (16, 4, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](primals_2, primals_1, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 del primals_3 return buf0, class AxialPositionalEmbeddingNew(nn.Module): def __init__(self, dim, shape, emb_dim_index=1): super().__init__() total_dimensions = len(shape) + 2 ax_dim_indexes = [i for i in range(1, total_dimensions) if i != emb_dim_index] self.num_axials = len(shape) for i, (axial_dim, axial_dim_index) in enumerate(zip(shape, ax_dim_indexes)): shape = [1] * total_dimensions shape[emb_dim_index] = dim shape[axial_dim_index] = axial_dim parameter = nn.Parameter(torch.randn(*shape)) setattr(self, f'param_{i}', parameter) def forward(self, input_0): primals_1 = self.param_0 primals_3 = self.param_1 primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lucidrains/axial-attention
AxialPositionalEmbedding
false
15,966
[ "MIT" ]
189
eff2c10c2e76c735a70a6b995b571213adffbbb7
https://github.com/lucidrains/axial-attention/tree/eff2c10c2e76c735a70a6b995b571213adffbbb7
AttCeMeanLoss
import torch import torch.nn as nn import torch.nn.functional as F class AttCeMeanLoss(nn.Module): def __init__(self): super().__init__() def forward(self, attention_S, attention_T, mask=None): """ Calculate the cross entropy between attention_S and attention_T, the dim of num_heads is averaged :param logits_S: Tensor of shape (batch_size, num_heads, length, length) or (batch_size, length, length) :param logits_T: Tensor of shape (batch_size, num_heads, length, length) or (batch_size, length, length) :param mask: Tensor of shape (batch_size, length) """ if len(attention_S.size()) == 4: attention_S = attention_S.mean(dim=1) attention_T = attention_T.mean(dim=1) probs_T = F.softmax(attention_T, dim=-1) if mask is None: probs_T_select = torch.where(attention_T <= -0.001, torch. zeros_like(attention_T), probs_T) loss = -(probs_T_select * F.log_softmax(attention_S, dim=-1)).sum( dim=-1).mean() else: mask = mask loss = -((probs_T * F.log_softmax(attention_S, dim=-1) * mask. unsqueeze(1)).sum(dim=-1) * mask).sum() / mask.sum() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_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 % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (4 * x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (16 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (32 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (48 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (1 + 4 * x0 + 64 * x1), xmask, eviction_policy ='evict_last') tmp10 = tl.load(in_ptr0 + (17 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (33 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (49 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr0 + (2 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr0 + (18 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr0 + (34 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr0 + (50 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr0 + (3 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr0 + (19 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr0 + (35 + 4 * x0 + 64 * x1), xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr0 + (51 + 4 * x0 + 64 * x1), 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 = triton_helpers.maximum(tmp8, tmp16) tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp24 / tmp7 tmp26 = triton_helpers.maximum(tmp17, tmp25) tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tmp33 = tmp31 + tmp32 tmp34 = tmp33 / tmp7 tmp35 = triton_helpers.maximum(tmp26, tmp34) tl.store(out_ptr0 + x2, tmp35, xmask) @triton.jit def triton_poi_fused__softmax_mean_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 // 16 x3 = xindex % 16 x4 = xindex // 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 64 * x2), xmask) tmp1 = tl.load(in_ptr0 + (16 + x3 + 64 * x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + x3 + 64 * x2), xmask) tmp5 = tl.load(in_ptr0 + (48 + x3 + 64 * x2), xmask) tmp9 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp10 = tmp8 - tmp9 tmp11 = tl_math.exp(tmp10) tl.store(out_ptr0 + x5, tmp11, xmask) @triton.jit def triton_poi_fused__softmax_le_mean_where_zeros_like_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 x2 = xindex // 16 x3 = xindex % 16 x4 = xindex x5 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x3 + 64 * x2), xmask) tmp1 = tl.load(in_ptr0 + (16 + x3 + 64 * x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + x3 + 64 * x2), xmask) tmp5 = tl.load(in_ptr0 + (48 + x3 + 64 * x2), xmask) tmp11 = tl.load(in_ptr1 + x4, xmask) tmp12 = tl.load(in_ptr1 + 4 * x5, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + (1 + 4 * x5), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + (2 + 4 * x5), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (3 + 4 * x5), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = -0.001 tmp10 = tmp8 <= tmp9 tmp14 = tmp12 + tmp13 tmp16 = tmp14 + tmp15 tmp18 = tmp16 + tmp17 tmp19 = tmp11 / tmp18 tmp20 = 0.0 tmp21 = tl.where(tmp10, tmp20, tmp19) tl.store(out_ptr0 + x4, tmp21, xmask) @triton.jit def triton_poi_fused__log_softmax_mean_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 x3 = xindex % 16 x4 = xindex // 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 64 * x2), xmask) tmp1 = tl.load(in_ptr0 + (16 + x3 + 64 * x2), xmask) tmp3 = tl.load(in_ptr0 + (32 + x3 + 64 * x2), xmask) tmp5 = tl.load(in_ptr0 + (48 + x3 + 64 * x2), xmask) tmp9 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp10 = tmp8 - tmp9 tl.store(out_ptr0 + x5, tmp10, xmask) @triton.jit def triton_per_fused__log_softmax_mean_mul_neg_sum_4(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp9 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp15 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp23 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp1 - tmp12 tmp14 = tmp0 * tmp13 tmp16 = tmp3 - tmp12 tmp17 = tmp15 * tmp16 tmp18 = tmp14 + tmp17 tmp20 = tmp6 - tmp12 tmp21 = tmp19 * tmp20 tmp22 = tmp18 + tmp21 tmp24 = tmp9 - tmp12 tmp25 = tmp23 * tmp24 tmp26 = tmp22 + tmp25 tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK]) tmp29 = tl.sum(tmp27, 1)[:, None] tmp30 = 16.0 tmp31 = tmp29 / tmp30 tmp32 = -tmp31 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp32, 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, 1), (4, 1, 16), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_mean_0[grid(16)](arg1_1, buf0, 16, XBLOCK =16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_mean_1[grid(64)](arg1_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_le_mean_where_zeros_like_2[grid(64)](arg1_1, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg1_1 buf3 = buf0 del buf0 triton_poi_fused__softmax_mean_0[grid(16)](arg0_1, buf3, 16, XBLOCK =16, num_warps=1, num_stages=1) buf4 = buf1 del buf1 triton_poi_fused__log_softmax_mean_3[grid(64)](arg0_1, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del buf3 buf5 = empty_strided_cuda((), (), torch.float32) buf6 = buf5 del buf5 triton_per_fused__log_softmax_mean_mul_neg_sum_4[grid(1)](buf6, buf2, buf4, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf2 del buf4 return buf6, class AttCeMeanLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
AttCeMeanLoss
false
15,967
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
LayerNormChan
import torch from torch import nn class LayerNormChan(nn.Module): def __init__(self, dim, eps=1e-05): super().__init__() self.eps = eps self.g = nn.Parameter(torch.ones(1, dim, 1, 1)) self.b = nn.Parameter(torch.zeros(1, dim, 1, 1)) def forward(self, x): var = torch.var(x, dim=1, unbiased=False, keepdim=True) mean = torch.mean(x, dim=1, keepdim=True) return (x - mean) / (var + self.eps).sqrt() * self.g + self.b def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mean_mul_sqrt_sub_var_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 x1 = xindex // 16 % 4 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') tmp27 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp29 = tl.load(in_ptr2 + x1, 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 = tmp21 / tmp8 tmp23 = 1e-05 tmp24 = tmp22 + tmp23 tmp25 = libdevice.sqrt(tmp24) tmp26 = tmp10 / tmp25 tmp28 = tmp26 * tmp27 tmp30 = tmp28 + tmp29 tl.store(out_ptr0 + x3, tmp30, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mean_mul_sqrt_sub_var_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class LayerNormChanNew(nn.Module): def __init__(self, dim, eps=1e-05): super().__init__() self.eps = eps self.g = nn.Parameter(torch.ones(1, dim, 1, 1)) self.b = nn.Parameter(torch.zeros(1, dim, 1, 1)) def forward(self, input_0): primals_2 = self.g primals_3 = self.b primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lucidrains/nuwa-pytorch
LayerNormChan
false
15,968
[ "MIT" ]
310
bf1f3dc1126ba0a24a280bd7412a8082e5013b46
https://github.com/lucidrains/nuwa-pytorch/tree/bf1f3dc1126ba0a24a280bd7412a8082e5013b46
KdCeLoss
import torch import torch.nn as nn import torch.nn.functional as F class KdCeLoss(nn.Module): def __init__(self): super().__init__() def forward(self, logits_S, logits_T, temperature=1): """ Calculate the cross entropy between logits_S and logits_T :param logits_S: Tensor of shape (batch_size, length, num_labels) or (batch_size, num_labels) :param logits_T: Tensor of shape (batch_size, length, num_labels) or (batch_size, num_labels) :param temperature: A float or a tensor of shape (batch_size, length) or (batch_size,) """ if isinstance(temperature, torch.Tensor) and temperature.dim() > 0: temperature = temperature.unsqueeze(-1) beta_logits_T = logits_T / temperature beta_logits_S = logits_S / temperature p_T = F.softmax(beta_logits_T, dim=-1) loss = -(p_T * F.log_softmax(beta_logits_S, dim=-1)).sum(dim=-1).mean() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = tmp14 * tmp1 tmp16 = tl_math.exp(tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = tmp14 * tmp1 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused__log_softmax__softmax_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr1 + x2, xmask) tmp10 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp11 = tl_math.exp(tmp10) tmp13 = tl_math.exp(tmp12) tmp14 = tmp11 + tmp13 tmp16 = tl_math.exp(tmp15) tmp17 = tmp14 + tmp16 tmp19 = tl_math.exp(tmp18) tmp20 = tmp17 + tmp19 tmp21 = tl_math.log(tmp20) tmp22 = tmp9 - tmp21 tmp23 = tmp8 * tmp22 tl.store(out_ptr0 + x2, tmp23, xmask) @triton.jit def triton_per_fused_mean_neg_sum_3(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.sum(tmp7, 1)[:, None] tmp10 = 64.0 tmp11 = tmp9 / tmp10 tmp12 = -tmp11 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp12, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_1[grid(256)](arg1_1, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__softmax_mul_2[grid(256)](buf0, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused_mean_neg_sum_3[grid(1)](buf4, buf2, 1, 64, XBLOCK= 1, num_warps=2, num_stages=1) del buf2 return buf4, class KdCeLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lonePatient/TorchBlocks
KdCeLoss
false
15,969
[ "MIT" ]
82
4a65d746cc8a396cb7df73ed4644d97ddf843e29
https://github.com/lonePatient/TorchBlocks/tree/4a65d746cc8a396cb7df73ed4644d97ddf843e29
BCNN
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed class BCNN(nn.Module): """Bilinear Pool implementation of Bilinear CNN (BCNN) https://arxiv.org/abs/1504.07889v5 Args: thresh: small positive number for computation stability is_vec: whether the output is a vector or not input_dim: the #channel of input feature """ def __init__(self, thresh=1e-08, is_vec=True, input_dim=2048): super(BCNN, self).__init__() self.thresh = thresh self.is_vec = is_vec self.output_dim = input_dim * input_dim def _bilinearpool(self, x): batchSize, dim, h, w = x.data.shape x = x.reshape(batchSize, dim, h * w) x = 1.0 / (h * w) * x.bmm(x.transpose(1, 2)) return x def _signed_sqrt(self, x): x = torch.mul(x.sign(), torch.sqrt(x.abs() + self.thresh)) return x def _l2norm(self, x): x = nn.functional.normalize(x) return x def forward(self, x): x = self._bilinearpool(x) x = self._signed_sqrt(x) if self.is_vec: x = x.view(x.size(0), -1) x = self._l2norm(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._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_div_linalg_vector_norm_0(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = 0.0625 tmp2 = tmp0 * tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = tmp3 < tmp2 tmp5 = tmp4.to(tl.int8) tmp6 = tmp2 < tmp3 tmp7 = tmp6.to(tl.int8) tmp8 = tmp5 - tmp7 tmp9 = tmp8.to(tmp2.dtype) tmp10 = tl_math.abs(tmp2) tmp11 = 1e-08 tmp12 = tmp10 + tmp11 tmp13 = libdevice.sqrt(tmp12) tmp14 = tmp9 * tmp13 tmp15 = tmp14 * tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = tl.where(xmask, tmp16, 0) tmp19 = tl.sum(tmp18, 1)[:, None] tmp20 = libdevice.sqrt(tmp19) tmp21 = 1e-12 tmp22 = triton_helpers.maximum(tmp20, tmp21) tmp23 = tmp14 / tmp22 tl.store(out_ptr1 + (r1 + 16 * x0), tmp23, 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 buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32) get_raw_stream(0) triton_per_fused_div_linalg_vector_norm_0[grid(4)](buf0, buf2, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf0 return buf2, class BCNNNew(nn.Module): """Bilinear Pool implementation of Bilinear CNN (BCNN) https://arxiv.org/abs/1504.07889v5 Args: thresh: small positive number for computation stability is_vec: whether the output is a vector or not input_dim: the #channel of input feature """ def __init__(self, thresh=1e-08, is_vec=True, input_dim=2048): super(BCNNNew, self).__init__() self.thresh = thresh self.is_vec = is_vec self.output_dim = input_dim * input_dim def _bilinearpool(self, x): batchSize, dim, h, w = x.data.shape x = x.reshape(batchSize, dim, h * w) x = 1.0 / (h * w) * x.bmm(x.transpose(1, 2)) return x def _signed_sqrt(self, x): x = torch.mul(x.sign(), torch.sqrt(x.abs() + self.thresh)) return x def _l2norm(self, x): x = nn.functional.normalize(x) return x def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
lvyilin/fast-MPN-COV
BCNN
false
15,970
[ "MIT" ]
257
d21c3fd2863c12f885faf20bd177dc066a25856c
https://github.com/lvyilin/fast-MPN-COV/tree/d21c3fd2863c12f885faf20bd177dc066a25856c
DiceLoss
import torch import torch.nn as nn class DiceLoss(nn.Module): def __init__(self, smooth=1.0, eps=1e-07): super(DiceLoss, self).__init__() self.smooth = smooth self.eps = eps def forward(self, output, target): output = torch.sigmoid(output) if torch.sum(target) == 0: output = 1.0 - output target = 1.0 - target return 1.0 - (2 * torch.sum(output * target) + self.smooth) / ( torch.sum(output) + torch.sum(target) + self.smooth + self.eps) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_sigmoid_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.sigmoid(tmp0) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_per_fused_eq_sum_1(in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = triton_helpers.promote_to_tensor(tl.sum(tmp1, 0)) tmp4 = 0.0 tmp5 = tmp3 == tmp4 tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp5, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((), (), torch.bool) triton_per_fused_eq_sum_1[grid(1)](arg1_1, buf2, 1, 256, num_warps= 2, num_stages=1) del arg1_1 return buf0, buf2 class DiceLossNew(nn.Module): def __init__(self, smooth=1.0, eps=1e-07): super(DiceLossNew, self).__init__() self.smooth = smooth self.eps = eps def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lyakaap/pytorch-template
DiceLoss
false
15,971
[ "MIT" ]
140
eff9f0a4dd50fa49c3b949065247598d5eabc91e
https://github.com/lyakaap/pytorch-template/tree/eff9f0a4dd50fa49c3b949065247598d5eabc91e
Truncation2D
import torch class Truncation2D(torch.nn.Module): """ A module merging the last two dimensions, merging coarse scale in grid of dimensions -4, -3 and finer resolution in dimensions -2, -1 to one fine grained grid with two dimensions less. """ def __init__(self): super().__init__() def forward(self, input: 'torch.Tensor') ->torch.Tensor: """ :param input: input tensor :returns: output tensor """ shape = input.shape outputshape = list(input.shape[:-2]) expsize1 = input.shape[-2] expsize2 = input.shape[-1] outputshape[-2] *= input.shape[-2] outputshape[-1] *= input.shape[-1] baseslice = [slice(None, None, 1) for _ in range(len(outputshape) - 2)] output = torch.zeros(outputshape, device=input.device, requires_grad=False) for i in range(shape[-4]): for j in range(shape[-3]): outslice = tuple(baseslice + [slice(expsize1 * i, expsize1 * (i + 1)), slice(expsize2 * j, expsize2 * (j + 1))]) inslice = tuple(baseslice + [i, j, slice(None, None, 1), slice(None, None, 1)]) output[outslice] += input[inslice] return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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 = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp264 = tl.load(in_ptr0 + (32 + x2), xmask) tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = 8 + x0 tmp4 = tmp3 >= tmp1 tmp5 = tl.full([1], 8, tl.int64) tmp6 = tmp3 < tmp5 tmp7 = tmp4 & tmp6 tmp8 = tmp7 & tmp2 tmp9 = tmp2 & tmp8 tmp10 = tmp7 & tmp9 tmp11 = tmp2 & tmp10 tmp12 = tmp3 < tmp1 tmp13 = tmp12 & tmp11 tmp14 = tmp2 & tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr0 + (8 + x2), tmp15 & xmask, other=0.0) tmp17 = 0.0 tmp18 = tmp17 + tmp16 tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp15, tmp18, tmp19) tmp21 = tl.where(tmp12, tmp20, tmp17) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp14, tmp21, tmp22) tmp24 = tl.where(tmp2, tmp23, tmp17) tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp13, tmp24, tmp25) tmp27 = tmp2 & tmp11 tmp28 = tmp12 & tmp27 tmp29 = tl.load(in_ptr0 + (8 + x2), tmp28 & xmask, other=0.0) tmp30 = tmp17 + tmp29 tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype) tmp32 = tl.where(tmp28, tmp30, tmp31) tmp33 = tl.where(tmp12, tmp32, tmp17) tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp27, tmp33, tmp34) tmp36 = tl.where(tmp2, tmp35, tmp17) tmp37 = tl.where(tmp12, tmp26, tmp36) tmp38 = tl.full(tmp37.shape, 0.0, tmp37.dtype) tmp39 = tl.where(tmp11, tmp37, tmp38) tmp40 = tl.load(in_ptr0 + (8 + x2), tmp13 & xmask, other=0.0) tmp41 = tmp17 + tmp40 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp13, tmp41, tmp42) tmp44 = tl.where(tmp12, tmp43, tmp17) tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype) tmp46 = tl.where(tmp11, tmp44, tmp45) tmp47 = tl.where(tmp2, tmp46, tmp17) tmp48 = tl.where(tmp2, tmp39, tmp47) tmp49 = tl.load(in_ptr0 + (20 + x2), tmp10 & xmask, other=0.0) tmp50 = tmp48 + tmp49 tmp51 = tl.full(tmp50.shape, 0.0, tmp50.dtype) tmp52 = tl.where(tmp10, tmp50, tmp51) tmp53 = tmp2 & tmp9 tmp54 = tmp12 & tmp53 tmp55 = tmp2 & tmp54 tmp56 = tmp12 & tmp55 tmp57 = tl.load(in_ptr0 + (8 + x2), tmp56 & xmask, other=0.0) tmp58 = tmp17 + tmp57 tmp59 = tl.full(tmp58.shape, 0.0, tmp58.dtype) tmp60 = tl.where(tmp56, tmp58, tmp59) tmp61 = tl.where(tmp12, tmp60, tmp17) tmp62 = tl.full(tmp61.shape, 0.0, tmp61.dtype) tmp63 = tl.where(tmp55, tmp61, tmp62) tmp64 = tl.where(tmp2, tmp63, tmp17) tmp65 = tl.full(tmp64.shape, 0.0, tmp64.dtype) tmp66 = tl.where(tmp54, tmp64, tmp65) tmp67 = tmp2 & tmp53 tmp68 = tmp12 & tmp67 tmp69 = tl.load(in_ptr0 + (8 + x2), tmp68 & xmask, other=0.0) tmp70 = tmp17 + tmp69 tmp71 = tl.full(tmp70.shape, 0.0, tmp70.dtype) tmp72 = tl.where(tmp68, tmp70, tmp71) tmp73 = tl.where(tmp12, tmp72, tmp17) tmp74 = tl.full(tmp73.shape, 0.0, tmp73.dtype) tmp75 = tl.where(tmp67, tmp73, tmp74) tmp76 = tl.where(tmp2, tmp75, tmp17) tmp77 = tl.where(tmp12, tmp66, tmp76) tmp78 = tl.full(tmp77.shape, 0.0, tmp77.dtype) tmp79 = tl.where(tmp53, tmp77, tmp78) tmp80 = tl.load(in_ptr0 + (8 + x2), tmp54 & xmask, other=0.0) tmp81 = tmp17 + tmp80 tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype) tmp83 = tl.where(tmp54, tmp81, tmp82) tmp84 = tl.where(tmp12, tmp83, tmp17) tmp85 = tl.full(tmp84.shape, 0.0, tmp84.dtype) tmp86 = tl.where(tmp53, tmp84, tmp85) tmp87 = tl.where(tmp2, tmp86, tmp17) tmp88 = tl.where(tmp2, tmp79, tmp87) tmp89 = tl.where(tmp7, tmp52, tmp88) tmp90 = tl.full(tmp89.shape, 0.0, tmp89.dtype) tmp91 = tl.where(tmp9, tmp89, tmp90) tmp92 = tmp12 & tmp9 tmp93 = tmp2 & tmp92 tmp94 = tmp12 & tmp93 tmp95 = tl.load(in_ptr0 + (8 + x2), tmp94 & xmask, other=0.0) tmp96 = tmp17 + tmp95 tmp97 = tl.full(tmp96.shape, 0.0, tmp96.dtype) tmp98 = tl.where(tmp94, tmp96, tmp97) tmp99 = tl.where(tmp12, tmp98, tmp17) tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype) tmp101 = tl.where(tmp93, tmp99, tmp100) tmp102 = tl.where(tmp2, tmp101, tmp17) tmp103 = tl.full(tmp102.shape, 0.0, tmp102.dtype) tmp104 = tl.where(tmp92, tmp102, tmp103) tmp105 = tl.where(tmp12, tmp104, tmp87) tmp106 = tl.full(tmp105.shape, 0.0, tmp105.dtype) tmp107 = tl.where(tmp9, tmp105, tmp106) tmp108 = tl.load(in_ptr0 + (8 + x2), tmp92 & xmask, other=0.0) tmp109 = tmp17 + tmp108 tmp110 = tl.full(tmp109.shape, 0.0, tmp109.dtype) tmp111 = tl.where(tmp92, tmp109, tmp110) tmp112 = tl.where(tmp12, tmp111, tmp17) tmp113 = tl.full(tmp112.shape, 0.0, tmp112.dtype) tmp114 = tl.where(tmp9, tmp112, tmp113) tmp115 = tl.where(tmp2, tmp114, tmp17) tmp116 = tl.where(tmp2, tmp107, tmp115) tmp117 = tl.where(tmp2, tmp91, tmp116) tmp118 = tl.full(tmp117.shape, 0.0, tmp117.dtype) tmp119 = tl.where(tmp8, tmp117, tmp118) tmp120 = tmp2 & tmp2 tmp121 = tmp7 & tmp120 tmp122 = tmp2 & tmp121 tmp123 = tmp12 & tmp122 tmp124 = tmp2 & tmp123 tmp125 = tmp12 & tmp124 tmp126 = tl.load(in_ptr0 + (8 + x2), tmp125 & xmask, other=0.0) tmp127 = tmp17 + tmp126 tmp128 = tl.full(tmp127.shape, 0.0, tmp127.dtype) tmp129 = tl.where(tmp125, tmp127, tmp128) tmp130 = tl.where(tmp12, tmp129, tmp17) tmp131 = tl.full(tmp130.shape, 0.0, tmp130.dtype) tmp132 = tl.where(tmp124, tmp130, tmp131) tmp133 = tl.where(tmp2, tmp132, tmp17) tmp134 = tl.full(tmp133.shape, 0.0, tmp133.dtype) tmp135 = tl.where(tmp123, tmp133, tmp134) tmp136 = tmp2 & tmp122 tmp137 = tmp12 & tmp136 tmp138 = tl.load(in_ptr0 + (8 + x2), tmp137 & xmask, other=0.0) tmp139 = tmp17 + tmp138 tmp140 = tl.full(tmp139.shape, 0.0, tmp139.dtype) tmp141 = tl.where(tmp137, tmp139, tmp140) tmp142 = tl.where(tmp12, tmp141, tmp17) tmp143 = tl.full(tmp142.shape, 0.0, tmp142.dtype) tmp144 = tl.where(tmp136, tmp142, tmp143) tmp145 = tl.where(tmp2, tmp144, tmp17) tmp146 = tl.where(tmp12, tmp135, tmp145) tmp147 = tl.full(tmp146.shape, 0.0, tmp146.dtype) tmp148 = tl.where(tmp122, tmp146, tmp147) tmp149 = tl.load(in_ptr0 + (8 + x2), tmp123 & xmask, other=0.0) tmp150 = tmp17 + tmp149 tmp151 = tl.full(tmp150.shape, 0.0, tmp150.dtype) tmp152 = tl.where(tmp123, tmp150, tmp151) tmp153 = tl.where(tmp12, tmp152, tmp17) tmp154 = tl.full(tmp153.shape, 0.0, tmp153.dtype) tmp155 = tl.where(tmp122, tmp153, tmp154) tmp156 = tl.where(tmp2, tmp155, tmp17) tmp157 = tl.where(tmp2, tmp148, tmp156) tmp158 = tl.load(in_ptr0 + (20 + x2), tmp121 & xmask, other=0.0) tmp159 = tmp157 + tmp158 tmp160 = tl.full(tmp159.shape, 0.0, tmp159.dtype) tmp161 = tl.where(tmp121, tmp159, tmp160) tmp162 = tmp2 & tmp120 tmp163 = tmp12 & tmp162 tmp164 = tmp2 & tmp163 tmp165 = tmp12 & tmp164 tmp166 = tl.load(in_ptr0 + (8 + x2), tmp165 & xmask, other=0.0) tmp167 = tmp17 + tmp166 tmp168 = tl.full(tmp167.shape, 0.0, tmp167.dtype) tmp169 = tl.where(tmp165, tmp167, tmp168) tmp170 = tl.where(tmp12, tmp169, tmp17) tmp171 = tl.full(tmp170.shape, 0.0, tmp170.dtype) tmp172 = tl.where(tmp164, tmp170, tmp171) tmp173 = tl.where(tmp2, tmp172, tmp17) tmp174 = tl.full(tmp173.shape, 0.0, tmp173.dtype) tmp175 = tl.where(tmp163, tmp173, tmp174) tmp176 = tmp2 & tmp162 tmp177 = tmp12 & tmp176 tmp178 = tl.load(in_ptr0 + (8 + x2), tmp177 & xmask, other=0.0) tmp179 = tmp17 + tmp178 tmp180 = tl.full(tmp179.shape, 0.0, tmp179.dtype) tmp181 = tl.where(tmp177, tmp179, tmp180) tmp182 = tl.where(tmp12, tmp181, tmp17) tmp183 = tl.full(tmp182.shape, 0.0, tmp182.dtype) tmp184 = tl.where(tmp176, tmp182, tmp183) tmp185 = tl.where(tmp2, tmp184, tmp17) tmp186 = tl.where(tmp12, tmp175, tmp185) tmp187 = tl.full(tmp186.shape, 0.0, tmp186.dtype) tmp188 = tl.where(tmp162, tmp186, tmp187) tmp189 = tl.load(in_ptr0 + (8 + x2), tmp163 & xmask, other=0.0) tmp190 = tmp17 + tmp189 tmp191 = tl.full(tmp190.shape, 0.0, tmp190.dtype) tmp192 = tl.where(tmp163, tmp190, tmp191) tmp193 = tl.where(tmp12, tmp192, tmp17) tmp194 = tl.full(tmp193.shape, 0.0, tmp193.dtype) tmp195 = tl.where(tmp162, tmp193, tmp194) tmp196 = tl.where(tmp2, tmp195, tmp17) tmp197 = tl.where(tmp2, tmp188, tmp196) tmp198 = tl.where(tmp7, tmp161, tmp197) tmp199 = tl.full(tmp198.shape, 0.0, tmp198.dtype) tmp200 = tl.where(tmp120, tmp198, tmp199) tmp201 = tmp12 & tmp120 tmp202 = tmp2 & tmp201 tmp203 = tmp12 & tmp202 tmp204 = tl.load(in_ptr0 + (8 + x2), tmp203 & xmask, other=0.0) tmp205 = tmp17 + tmp204 tmp206 = tl.full(tmp205.shape, 0.0, tmp205.dtype) tmp207 = tl.where(tmp203, tmp205, tmp206) tmp208 = tl.where(tmp12, tmp207, tmp17) tmp209 = tl.full(tmp208.shape, 0.0, tmp208.dtype) tmp210 = tl.where(tmp202, tmp208, tmp209) tmp211 = tl.where(tmp2, tmp210, tmp17) tmp212 = tl.full(tmp211.shape, 0.0, tmp211.dtype) tmp213 = tl.where(tmp201, tmp211, tmp212) tmp214 = tl.where(tmp12, tmp213, tmp196) tmp215 = tl.full(tmp214.shape, 0.0, tmp214.dtype) tmp216 = tl.where(tmp120, tmp214, tmp215) tmp217 = tl.load(in_ptr0 + (8 + x2), tmp201 & xmask, other=0.0) tmp218 = tmp17 + tmp217 tmp219 = tl.full(tmp218.shape, 0.0, tmp218.dtype) tmp220 = tl.where(tmp201, tmp218, tmp219) tmp221 = tl.where(tmp12, tmp220, tmp17) tmp222 = tl.full(tmp221.shape, 0.0, tmp221.dtype) tmp223 = tl.where(tmp120, tmp221, tmp222) tmp224 = tl.where(tmp2, tmp223, tmp17) tmp225 = tl.where(tmp2, tmp216, tmp224) tmp226 = tl.where(tmp2, tmp200, tmp225) tmp227 = tl.where(tmp7, tmp119, tmp226) tmp228 = tl.full(tmp227.shape, 0.0, tmp227.dtype) tmp229 = tl.where(tmp2, tmp227, tmp228) tmp230 = tl.load(in_ptr0 + (20 + x2), tmp8 & xmask, other=0.0) tmp231 = tmp116 + tmp230 tmp232 = tl.full(tmp231.shape, 0.0, tmp231.dtype) tmp233 = tl.where(tmp8, tmp231, tmp232) tmp234 = tl.where(tmp7, tmp233, tmp225) tmp235 = tl.full(tmp234.shape, 0.0, tmp234.dtype) tmp236 = tl.where(tmp2, tmp234, tmp235) tmp237 = tmp12 & tmp2 tmp238 = tmp2 & tmp237 tmp239 = tmp12 & tmp238 tmp240 = tl.load(in_ptr0 + (8 + x2), tmp239 & xmask, other=0.0) tmp241 = tmp17 + tmp240 tmp242 = tl.full(tmp241.shape, 0.0, tmp241.dtype) tmp243 = tl.where(tmp239, tmp241, tmp242) tmp244 = tl.where(tmp12, tmp243, tmp17) tmp245 = tl.full(tmp244.shape, 0.0, tmp244.dtype) tmp246 = tl.where(tmp238, tmp244, tmp245) tmp247 = tl.where(tmp2, tmp246, tmp17) tmp248 = tl.full(tmp247.shape, 0.0, tmp247.dtype) tmp249 = tl.where(tmp237, tmp247, tmp248) tmp250 = tl.where(tmp12, tmp249, tmp224) tmp251 = tl.full(tmp250.shape, 0.0, tmp250.dtype) tmp252 = tl.where(tmp2, tmp250, tmp251) tmp253 = tl.load(in_ptr0 + (8 + x2), tmp237 & xmask, other=0.0) tmp254 = tmp17 + tmp253 tmp255 = tl.full(tmp254.shape, 0.0, tmp254.dtype) tmp256 = tl.where(tmp237, tmp254, tmp255) tmp257 = tl.where(tmp12, tmp256, tmp17) tmp258 = tl.full(tmp257.shape, 0.0, tmp257.dtype) tmp259 = tl.where(tmp2, tmp257, tmp258) tmp260 = tl.where(tmp2, tmp259, tmp17) tmp261 = tl.where(tmp2, tmp252, tmp260) tmp262 = tl.where(tmp2, tmp236, tmp261) tmp263 = tl.where(tmp2, tmp229, tmp262) tmp265 = tmp263 + tmp264 tl.store(out_ptr0 + x2, tmp265, xmask) @triton.jit def triton_poi_fused_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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = x0 tmp1 = tl.full([1], 8, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 12, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-8 + x0 + 4 * x1), tmp5 & xmask, other=0.0) tmp7 = x1 tmp8 = tl.full([1], 4, tl.int64) tmp9 = tmp7 < tmp8 tmp10 = tmp0 >= tmp8 tmp11 = tmp0 < tmp1 tmp12 = tmp10 & tmp11 tmp13 = tmp12 & tmp9 tmp14 = tmp9 & tmp13 tmp15 = tmp12 & tmp14 tmp16 = tmp9 & tmp15 tmp17 = tmp0 < tmp8 tmp18 = tmp17 & tmp16 tmp19 = tmp9 & tmp18 tmp20 = tmp17 & tmp19 tmp21 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp20 & xmask, other=0.0) tmp22 = 0.0 tmp23 = tmp22 + tmp21 tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp20, tmp23, tmp24) tmp26 = tl.where(tmp17, tmp25, tmp22) tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype) tmp28 = tl.where(tmp19, tmp26, tmp27) tmp29 = tl.where(tmp9, tmp28, tmp22) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp18, tmp29, tmp30) tmp32 = tmp9 & tmp16 tmp33 = tmp17 & tmp32 tmp34 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp33 & xmask, other=0.0) tmp35 = tmp22 + tmp34 tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype) tmp37 = tl.where(tmp33, tmp35, tmp36) tmp38 = tl.where(tmp17, tmp37, tmp22) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp32, tmp38, tmp39) tmp41 = tl.where(tmp9, tmp40, tmp22) tmp42 = tl.where(tmp17, tmp31, tmp41) tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype) tmp44 = tl.where(tmp16, tmp42, tmp43) tmp45 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp18 & xmask, other=0.0) tmp46 = tmp22 + tmp45 tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype) tmp48 = tl.where(tmp18, tmp46, tmp47) tmp49 = tl.where(tmp17, tmp48, tmp22) tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp16, tmp49, tmp50) tmp52 = tl.where(tmp9, tmp51, tmp22) tmp53 = tl.where(tmp9, tmp44, tmp52) tmp54 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp15 & xmask, other=0.0) tmp55 = tmp53 + tmp54 tmp56 = tl.full(tmp55.shape, 0.0, tmp55.dtype) tmp57 = tl.where(tmp15, tmp55, tmp56) tmp58 = tmp9 & tmp14 tmp59 = tmp17 & tmp58 tmp60 = tmp9 & tmp59 tmp61 = tmp17 & tmp60 tmp62 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp61 & xmask, other=0.0) tmp63 = tmp22 + tmp62 tmp64 = tl.full(tmp63.shape, 0.0, tmp63.dtype) tmp65 = tl.where(tmp61, tmp63, tmp64) tmp66 = tl.where(tmp17, tmp65, tmp22) tmp67 = tl.full(tmp66.shape, 0.0, tmp66.dtype) tmp68 = tl.where(tmp60, tmp66, tmp67) tmp69 = tl.where(tmp9, tmp68, tmp22) tmp70 = tl.full(tmp69.shape, 0.0, tmp69.dtype) tmp71 = tl.where(tmp59, tmp69, tmp70) tmp72 = tmp9 & tmp58 tmp73 = tmp17 & tmp72 tmp74 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp73 & xmask, other=0.0) tmp75 = tmp22 + tmp74 tmp76 = tl.full(tmp75.shape, 0.0, tmp75.dtype) tmp77 = tl.where(tmp73, tmp75, tmp76) tmp78 = tl.where(tmp17, tmp77, tmp22) tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype) tmp80 = tl.where(tmp72, tmp78, tmp79) tmp81 = tl.where(tmp9, tmp80, tmp22) tmp82 = tl.where(tmp17, tmp71, tmp81) tmp83 = tl.full(tmp82.shape, 0.0, tmp82.dtype) tmp84 = tl.where(tmp58, tmp82, tmp83) tmp85 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp59 & xmask, other=0.0) tmp86 = tmp22 + tmp85 tmp87 = tl.full(tmp86.shape, 0.0, tmp86.dtype) tmp88 = tl.where(tmp59, tmp86, tmp87) tmp89 = tl.where(tmp17, tmp88, tmp22) tmp90 = tl.full(tmp89.shape, 0.0, tmp89.dtype) tmp91 = tl.where(tmp58, tmp89, tmp90) tmp92 = tl.where(tmp9, tmp91, tmp22) tmp93 = tl.where(tmp9, tmp84, tmp92) tmp94 = tl.where(tmp12, tmp57, tmp93) tmp95 = tl.full(tmp94.shape, 0.0, tmp94.dtype) tmp96 = tl.where(tmp14, tmp94, tmp95) tmp97 = tmp17 & tmp14 tmp98 = tmp9 & tmp97 tmp99 = tmp17 & tmp98 tmp100 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp99 & xmask, other=0.0) tmp101 = tmp22 + tmp100 tmp102 = tl.full(tmp101.shape, 0.0, tmp101.dtype) tmp103 = tl.where(tmp99, tmp101, tmp102) tmp104 = tl.where(tmp17, tmp103, tmp22) tmp105 = tl.full(tmp104.shape, 0.0, tmp104.dtype) tmp106 = tl.where(tmp98, tmp104, tmp105) tmp107 = tl.where(tmp9, tmp106, tmp22) tmp108 = tl.full(tmp107.shape, 0.0, tmp107.dtype) tmp109 = tl.where(tmp97, tmp107, tmp108) tmp110 = tl.where(tmp17, tmp109, tmp92) tmp111 = tl.full(tmp110.shape, 0.0, tmp110.dtype) tmp112 = tl.where(tmp14, tmp110, tmp111) tmp113 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp97 & xmask, other=0.0) tmp114 = tmp22 + tmp113 tmp115 = tl.full(tmp114.shape, 0.0, tmp114.dtype) tmp116 = tl.where(tmp97, tmp114, tmp115) tmp117 = tl.where(tmp17, tmp116, tmp22) tmp118 = tl.full(tmp117.shape, 0.0, tmp117.dtype) tmp119 = tl.where(tmp14, tmp117, tmp118) tmp120 = tl.where(tmp9, tmp119, tmp22) tmp121 = tl.where(tmp9, tmp112, tmp120) tmp122 = tl.where(tmp9, tmp96, tmp121) tmp123 = tl.full(tmp122.shape, 0.0, tmp122.dtype) tmp124 = tl.where(tmp13, tmp122, tmp123) tmp125 = tmp9 & tmp9 tmp126 = tmp12 & tmp125 tmp127 = tmp9 & tmp126 tmp128 = tmp17 & tmp127 tmp129 = tmp9 & tmp128 tmp130 = tmp17 & tmp129 tmp131 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp130 & xmask, other=0.0) tmp132 = tmp22 + tmp131 tmp133 = tl.full(tmp132.shape, 0.0, tmp132.dtype) tmp134 = tl.where(tmp130, tmp132, tmp133) tmp135 = tl.where(tmp17, tmp134, tmp22) tmp136 = tl.full(tmp135.shape, 0.0, tmp135.dtype) tmp137 = tl.where(tmp129, tmp135, tmp136) tmp138 = tl.where(tmp9, tmp137, tmp22) tmp139 = tl.full(tmp138.shape, 0.0, tmp138.dtype) tmp140 = tl.where(tmp128, tmp138, tmp139) tmp141 = tmp9 & tmp127 tmp142 = tmp17 & tmp141 tmp143 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp142 & xmask, other=0.0) tmp144 = tmp22 + tmp143 tmp145 = tl.full(tmp144.shape, 0.0, tmp144.dtype) tmp146 = tl.where(tmp142, tmp144, tmp145) tmp147 = tl.where(tmp17, tmp146, tmp22) tmp148 = tl.full(tmp147.shape, 0.0, tmp147.dtype) tmp149 = tl.where(tmp141, tmp147, tmp148) tmp150 = tl.where(tmp9, tmp149, tmp22) tmp151 = tl.where(tmp17, tmp140, tmp150) tmp152 = tl.full(tmp151.shape, 0.0, tmp151.dtype) tmp153 = tl.where(tmp127, tmp151, tmp152) tmp154 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp128 & xmask, other=0.0) tmp155 = tmp22 + tmp154 tmp156 = tl.full(tmp155.shape, 0.0, tmp155.dtype) tmp157 = tl.where(tmp128, tmp155, tmp156) tmp158 = tl.where(tmp17, tmp157, tmp22) tmp159 = tl.full(tmp158.shape, 0.0, tmp158.dtype) tmp160 = tl.where(tmp127, tmp158, tmp159) tmp161 = tl.where(tmp9, tmp160, tmp22) tmp162 = tl.where(tmp9, tmp153, tmp161) tmp163 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp126 & xmask, other=0.0) tmp164 = tmp162 + tmp163 tmp165 = tl.full(tmp164.shape, 0.0, tmp164.dtype) tmp166 = tl.where(tmp126, tmp164, tmp165) tmp167 = tmp9 & tmp125 tmp168 = tmp17 & tmp167 tmp169 = tmp9 & tmp168 tmp170 = tmp17 & tmp169 tmp171 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp170 & xmask, other=0.0) tmp172 = tmp22 + tmp171 tmp173 = tl.full(tmp172.shape, 0.0, tmp172.dtype) tmp174 = tl.where(tmp170, tmp172, tmp173) tmp175 = tl.where(tmp17, tmp174, tmp22) tmp176 = tl.full(tmp175.shape, 0.0, tmp175.dtype) tmp177 = tl.where(tmp169, tmp175, tmp176) tmp178 = tl.where(tmp9, tmp177, tmp22) tmp179 = tl.full(tmp178.shape, 0.0, tmp178.dtype) tmp180 = tl.where(tmp168, tmp178, tmp179) tmp181 = tmp9 & tmp167 tmp182 = tmp17 & tmp181 tmp183 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp182 & xmask, other=0.0) tmp184 = tmp22 + tmp183 tmp185 = tl.full(tmp184.shape, 0.0, tmp184.dtype) tmp186 = tl.where(tmp182, tmp184, tmp185) tmp187 = tl.where(tmp17, tmp186, tmp22) tmp188 = tl.full(tmp187.shape, 0.0, tmp187.dtype) tmp189 = tl.where(tmp181, tmp187, tmp188) tmp190 = tl.where(tmp9, tmp189, tmp22) tmp191 = tl.where(tmp17, tmp180, tmp190) tmp192 = tl.full(tmp191.shape, 0.0, tmp191.dtype) tmp193 = tl.where(tmp167, tmp191, tmp192) tmp194 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp168 & xmask, other=0.0) tmp195 = tmp22 + tmp194 tmp196 = tl.full(tmp195.shape, 0.0, tmp195.dtype) tmp197 = tl.where(tmp168, tmp195, tmp196) tmp198 = tl.where(tmp17, tmp197, tmp22) tmp199 = tl.full(tmp198.shape, 0.0, tmp198.dtype) tmp200 = tl.where(tmp167, tmp198, tmp199) tmp201 = tl.where(tmp9, tmp200, tmp22) tmp202 = tl.where(tmp9, tmp193, tmp201) tmp203 = tl.where(tmp12, tmp166, tmp202) tmp204 = tl.full(tmp203.shape, 0.0, tmp203.dtype) tmp205 = tl.where(tmp125, tmp203, tmp204) tmp206 = tmp17 & tmp125 tmp207 = tmp9 & tmp206 tmp208 = tmp17 & tmp207 tmp209 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp208 & xmask, other=0.0) tmp210 = tmp22 + tmp209 tmp211 = tl.full(tmp210.shape, 0.0, tmp210.dtype) tmp212 = tl.where(tmp208, tmp210, tmp211) tmp213 = tl.where(tmp17, tmp212, tmp22) tmp214 = tl.full(tmp213.shape, 0.0, tmp213.dtype) tmp215 = tl.where(tmp207, tmp213, tmp214) tmp216 = tl.where(tmp9, tmp215, tmp22) tmp217 = tl.full(tmp216.shape, 0.0, tmp216.dtype) tmp218 = tl.where(tmp206, tmp216, tmp217) tmp219 = tl.where(tmp17, tmp218, tmp201) tmp220 = tl.full(tmp219.shape, 0.0, tmp219.dtype) tmp221 = tl.where(tmp125, tmp219, tmp220) tmp222 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp206 & xmask, other=0.0) tmp223 = tmp22 + tmp222 tmp224 = tl.full(tmp223.shape, 0.0, tmp223.dtype) tmp225 = tl.where(tmp206, tmp223, tmp224) tmp226 = tl.where(tmp17, tmp225, tmp22) tmp227 = tl.full(tmp226.shape, 0.0, tmp226.dtype) tmp228 = tl.where(tmp125, tmp226, tmp227) tmp229 = tl.where(tmp9, tmp228, tmp22) tmp230 = tl.where(tmp9, tmp221, tmp229) tmp231 = tl.where(tmp9, tmp205, tmp230) tmp232 = tl.where(tmp12, tmp124, tmp231) tmp233 = tl.full(tmp232.shape, 0.0, tmp232.dtype) tmp234 = tl.where(tmp9, tmp232, tmp233) tmp235 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp13 & xmask, other=0.0) tmp236 = tmp121 + tmp235 tmp237 = tl.full(tmp236.shape, 0.0, tmp236.dtype) tmp238 = tl.where(tmp13, tmp236, tmp237) tmp239 = tl.where(tmp12, tmp238, tmp230) tmp240 = tl.full(tmp239.shape, 0.0, tmp239.dtype) tmp241 = tl.where(tmp9, tmp239, tmp240) tmp242 = tmp17 & tmp9 tmp243 = tmp9 & tmp242 tmp244 = tmp17 & tmp243 tmp245 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp244 & xmask, other=0.0) tmp246 = tmp22 + tmp245 tmp247 = tl.full(tmp246.shape, 0.0, tmp246.dtype) tmp248 = tl.where(tmp244, tmp246, tmp247) tmp249 = tl.where(tmp17, tmp248, tmp22) tmp250 = tl.full(tmp249.shape, 0.0, tmp249.dtype) tmp251 = tl.where(tmp243, tmp249, tmp250) tmp252 = tl.where(tmp9, tmp251, tmp22) tmp253 = tl.full(tmp252.shape, 0.0, tmp252.dtype) tmp254 = tl.where(tmp242, tmp252, tmp253) tmp255 = tl.where(tmp17, tmp254, tmp229) tmp256 = tl.full(tmp255.shape, 0.0, tmp255.dtype) tmp257 = tl.where(tmp9, tmp255, tmp256) tmp258 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp242 & xmask, other=0.0) tmp259 = tmp22 + tmp258 tmp260 = tl.full(tmp259.shape, 0.0, tmp259.dtype) tmp261 = tl.where(tmp242, tmp259, tmp260) tmp262 = tl.where(tmp17, tmp261, tmp22) tmp263 = tl.full(tmp262.shape, 0.0, tmp262.dtype) tmp264 = tl.where(tmp9, tmp262, tmp263) tmp265 = tl.where(tmp9, tmp264, tmp22) tmp266 = tl.where(tmp9, tmp257, tmp265) tmp267 = tl.where(tmp9, tmp241, tmp266) tmp268 = tl.where(tmp9, tmp234, tmp267) tmp269 = tl.where(tmp5, tmp6, tmp268) tl.store(out_ptr0 + x2, tmp269, xmask) @triton.jit def triton_poi_fused_add_zeros_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 x2 = xindex x0 = xindex % 16 tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.load(in_ptr0 + x2, tmp2 & xmask, other=0.0) tmp4 = x0 tmp5 = tmp4 >= tmp1 tmp6 = tl.full([1], 8, tl.int64) tmp7 = tmp4 < tmp6 tmp8 = tmp5 & tmp7 tmp9 = tmp8 & tmp2 tmp10 = tmp2 & tmp9 tmp11 = tmp8 & tmp10 tmp12 = tmp2 & tmp11 tmp13 = tmp4 < tmp1 tmp14 = tmp13 & tmp12 tmp15 = tmp2 & tmp14 tmp16 = tmp13 & tmp15 tmp17 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp16 & xmask, other=0.0) tmp18 = 0.0 tmp19 = tmp18 + tmp17 tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp16, tmp19, tmp20) tmp22 = tl.where(tmp13, tmp21, tmp18) tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype) tmp24 = tl.where(tmp15, tmp22, tmp23) tmp25 = tl.where(tmp2, tmp24, tmp18) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp14, tmp25, tmp26) tmp28 = tmp2 & tmp12 tmp29 = tmp13 & tmp28 tmp30 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp29 & xmask, other=0.0) tmp31 = tmp18 + tmp30 tmp32 = tl.full(tmp31.shape, 0.0, tmp31.dtype) tmp33 = tl.where(tmp29, tmp31, tmp32) tmp34 = tl.where(tmp13, tmp33, tmp18) tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp28, tmp34, tmp35) tmp37 = tl.where(tmp2, tmp36, tmp18) tmp38 = tl.where(tmp13, tmp27, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp12, tmp38, tmp39) tmp41 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp14 & xmask, other=0.0) tmp42 = tmp18 + tmp41 tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype) tmp44 = tl.where(tmp14, tmp42, tmp43) tmp45 = tl.where(tmp13, tmp44, tmp18) tmp46 = tl.full(tmp45.shape, 0.0, tmp45.dtype) tmp47 = tl.where(tmp12, tmp45, tmp46) tmp48 = tl.where(tmp2, tmp47, tmp18) tmp49 = tl.where(tmp2, tmp40, tmp48) tmp50 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp11 & xmask, other=0.0) tmp51 = tmp49 + tmp50 tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp11, tmp51, tmp52) tmp54 = tmp2 & tmp10 tmp55 = tmp13 & tmp54 tmp56 = tmp2 & tmp55 tmp57 = tmp13 & tmp56 tmp58 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp57 & xmask, other=0.0) tmp59 = tmp18 + tmp58 tmp60 = tl.full(tmp59.shape, 0.0, tmp59.dtype) tmp61 = tl.where(tmp57, tmp59, tmp60) tmp62 = tl.where(tmp13, tmp61, tmp18) tmp63 = tl.full(tmp62.shape, 0.0, tmp62.dtype) tmp64 = tl.where(tmp56, tmp62, tmp63) tmp65 = tl.where(tmp2, tmp64, tmp18) tmp66 = tl.full(tmp65.shape, 0.0, tmp65.dtype) tmp67 = tl.where(tmp55, tmp65, tmp66) tmp68 = tmp2 & tmp54 tmp69 = tmp13 & tmp68 tmp70 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp69 & xmask, other=0.0) tmp71 = tmp18 + tmp70 tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype) tmp73 = tl.where(tmp69, tmp71, tmp72) tmp74 = tl.where(tmp13, tmp73, tmp18) tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype) tmp76 = tl.where(tmp68, tmp74, tmp75) tmp77 = tl.where(tmp2, tmp76, tmp18) tmp78 = tl.where(tmp13, tmp67, tmp77) tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype) tmp80 = tl.where(tmp54, tmp78, tmp79) tmp81 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp55 & xmask, other=0.0) tmp82 = tmp18 + tmp81 tmp83 = tl.full(tmp82.shape, 0.0, tmp82.dtype) tmp84 = tl.where(tmp55, tmp82, tmp83) tmp85 = tl.where(tmp13, tmp84, tmp18) tmp86 = tl.full(tmp85.shape, 0.0, tmp85.dtype) tmp87 = tl.where(tmp54, tmp85, tmp86) tmp88 = tl.where(tmp2, tmp87, tmp18) tmp89 = tl.where(tmp2, tmp80, tmp88) tmp90 = tl.where(tmp8, tmp53, tmp89) tmp91 = tl.full(tmp90.shape, 0.0, tmp90.dtype) tmp92 = tl.where(tmp10, tmp90, tmp91) tmp93 = tmp13 & tmp10 tmp94 = tmp2 & tmp93 tmp95 = tmp13 & tmp94 tmp96 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp95 & xmask, other=0.0) tmp97 = tmp18 + tmp96 tmp98 = tl.full(tmp97.shape, 0.0, tmp97.dtype) tmp99 = tl.where(tmp95, tmp97, tmp98) tmp100 = tl.where(tmp13, tmp99, tmp18) tmp101 = tl.full(tmp100.shape, 0.0, tmp100.dtype) tmp102 = tl.where(tmp94, tmp100, tmp101) tmp103 = tl.where(tmp2, tmp102, tmp18) tmp104 = tl.full(tmp103.shape, 0.0, tmp103.dtype) tmp105 = tl.where(tmp93, tmp103, tmp104) tmp106 = tl.where(tmp13, tmp105, tmp88) tmp107 = tl.full(tmp106.shape, 0.0, tmp106.dtype) tmp108 = tl.where(tmp10, tmp106, tmp107) tmp109 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp93 & xmask, other=0.0) tmp110 = tmp18 + tmp109 tmp111 = tl.full(tmp110.shape, 0.0, tmp110.dtype) tmp112 = tl.where(tmp93, tmp110, tmp111) tmp113 = tl.where(tmp13, tmp112, tmp18) tmp114 = tl.full(tmp113.shape, 0.0, tmp113.dtype) tmp115 = tl.where(tmp10, tmp113, tmp114) tmp116 = tl.where(tmp2, tmp115, tmp18) tmp117 = tl.where(tmp2, tmp108, tmp116) tmp118 = tl.where(tmp2, tmp92, tmp117) tmp119 = tl.full(tmp118.shape, 0.0, tmp118.dtype) tmp120 = tl.where(tmp9, tmp118, tmp119) tmp121 = tmp2 & tmp2 tmp122 = tmp8 & tmp121 tmp123 = tmp2 & tmp122 tmp124 = tmp13 & tmp123 tmp125 = tmp2 & tmp124 tmp126 = tmp13 & tmp125 tmp127 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp126 & xmask, other=0.0) tmp128 = tmp18 + tmp127 tmp129 = tl.full(tmp128.shape, 0.0, tmp128.dtype) tmp130 = tl.where(tmp126, tmp128, tmp129) tmp131 = tl.where(tmp13, tmp130, tmp18) tmp132 = tl.full(tmp131.shape, 0.0, tmp131.dtype) tmp133 = tl.where(tmp125, tmp131, tmp132) tmp134 = tl.where(tmp2, tmp133, tmp18) tmp135 = tl.full(tmp134.shape, 0.0, tmp134.dtype) tmp136 = tl.where(tmp124, tmp134, tmp135) tmp137 = tmp2 & tmp123 tmp138 = tmp13 & tmp137 tmp139 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp138 & xmask, other=0.0) tmp140 = tmp18 + tmp139 tmp141 = tl.full(tmp140.shape, 0.0, tmp140.dtype) tmp142 = tl.where(tmp138, tmp140, tmp141) tmp143 = tl.where(tmp13, tmp142, tmp18) tmp144 = tl.full(tmp143.shape, 0.0, tmp143.dtype) tmp145 = tl.where(tmp137, tmp143, tmp144) tmp146 = tl.where(tmp2, tmp145, tmp18) tmp147 = tl.where(tmp13, tmp136, tmp146) tmp148 = tl.full(tmp147.shape, 0.0, tmp147.dtype) tmp149 = tl.where(tmp123, tmp147, tmp148) tmp150 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp124 & xmask, other=0.0) tmp151 = tmp18 + tmp150 tmp152 = tl.full(tmp151.shape, 0.0, tmp151.dtype) tmp153 = tl.where(tmp124, tmp151, tmp152) tmp154 = tl.where(tmp13, tmp153, tmp18) tmp155 = tl.full(tmp154.shape, 0.0, tmp154.dtype) tmp156 = tl.where(tmp123, tmp154, tmp155) tmp157 = tl.where(tmp2, tmp156, tmp18) tmp158 = tl.where(tmp2, tmp149, tmp157) tmp159 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp122 & xmask, other=0.0) tmp160 = tmp158 + tmp159 tmp161 = tl.full(tmp160.shape, 0.0, tmp160.dtype) tmp162 = tl.where(tmp122, tmp160, tmp161) tmp163 = tmp2 & tmp121 tmp164 = tmp13 & tmp163 tmp165 = tmp2 & tmp164 tmp166 = tmp13 & tmp165 tmp167 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp166 & xmask, other=0.0) tmp168 = tmp18 + tmp167 tmp169 = tl.full(tmp168.shape, 0.0, tmp168.dtype) tmp170 = tl.where(tmp166, tmp168, tmp169) tmp171 = tl.where(tmp13, tmp170, tmp18) tmp172 = tl.full(tmp171.shape, 0.0, tmp171.dtype) tmp173 = tl.where(tmp165, tmp171, tmp172) tmp174 = tl.where(tmp2, tmp173, tmp18) tmp175 = tl.full(tmp174.shape, 0.0, tmp174.dtype) tmp176 = tl.where(tmp164, tmp174, tmp175) tmp177 = tmp2 & tmp163 tmp178 = tmp13 & tmp177 tmp179 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp178 & xmask, other=0.0) tmp180 = tmp18 + tmp179 tmp181 = tl.full(tmp180.shape, 0.0, tmp180.dtype) tmp182 = tl.where(tmp178, tmp180, tmp181) tmp183 = tl.where(tmp13, tmp182, tmp18) tmp184 = tl.full(tmp183.shape, 0.0, tmp183.dtype) tmp185 = tl.where(tmp177, tmp183, tmp184) tmp186 = tl.where(tmp2, tmp185, tmp18) tmp187 = tl.where(tmp13, tmp176, tmp186) tmp188 = tl.full(tmp187.shape, 0.0, tmp187.dtype) tmp189 = tl.where(tmp163, tmp187, tmp188) tmp190 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp164 & xmask, other=0.0) tmp191 = tmp18 + tmp190 tmp192 = tl.full(tmp191.shape, 0.0, tmp191.dtype) tmp193 = tl.where(tmp164, tmp191, tmp192) tmp194 = tl.where(tmp13, tmp193, tmp18) tmp195 = tl.full(tmp194.shape, 0.0, tmp194.dtype) tmp196 = tl.where(tmp163, tmp194, tmp195) tmp197 = tl.where(tmp2, tmp196, tmp18) tmp198 = tl.where(tmp2, tmp189, tmp197) tmp199 = tl.where(tmp8, tmp162, tmp198) tmp200 = tl.full(tmp199.shape, 0.0, tmp199.dtype) tmp201 = tl.where(tmp121, tmp199, tmp200) tmp202 = tmp13 & tmp121 tmp203 = tmp2 & tmp202 tmp204 = tmp13 & tmp203 tmp205 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp204 & xmask, other=0.0) tmp206 = tmp18 + tmp205 tmp207 = tl.full(tmp206.shape, 0.0, tmp206.dtype) tmp208 = tl.where(tmp204, tmp206, tmp207) tmp209 = tl.where(tmp13, tmp208, tmp18) tmp210 = tl.full(tmp209.shape, 0.0, tmp209.dtype) tmp211 = tl.where(tmp203, tmp209, tmp210) tmp212 = tl.where(tmp2, tmp211, tmp18) tmp213 = tl.full(tmp212.shape, 0.0, tmp212.dtype) tmp214 = tl.where(tmp202, tmp212, tmp213) tmp215 = tl.where(tmp13, tmp214, tmp197) tmp216 = tl.full(tmp215.shape, 0.0, tmp215.dtype) tmp217 = tl.where(tmp121, tmp215, tmp216) tmp218 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp202 & xmask, other=0.0) tmp219 = tmp18 + tmp218 tmp220 = tl.full(tmp219.shape, 0.0, tmp219.dtype) tmp221 = tl.where(tmp202, tmp219, tmp220) tmp222 = tl.where(tmp13, tmp221, tmp18) tmp223 = tl.full(tmp222.shape, 0.0, tmp222.dtype) tmp224 = tl.where(tmp121, tmp222, tmp223) tmp225 = tl.where(tmp2, tmp224, tmp18) tmp226 = tl.where(tmp2, tmp217, tmp225) tmp227 = tl.where(tmp2, tmp201, tmp226) tmp228 = tl.where(tmp8, tmp120, tmp227) tmp229 = tl.full(tmp228.shape, 0.0, tmp228.dtype) tmp230 = tl.where(tmp2, tmp228, tmp229) tmp231 = tl.load(in_ptr1 + (12 + x0 + 4 * x1), tmp9 & xmask, other=0.0) tmp232 = tmp117 + tmp231 tmp233 = tl.full(tmp232.shape, 0.0, tmp232.dtype) tmp234 = tl.where(tmp9, tmp232, tmp233) tmp235 = tl.where(tmp8, tmp234, tmp226) tmp236 = tl.full(tmp235.shape, 0.0, tmp235.dtype) tmp237 = tl.where(tmp2, tmp235, tmp236) tmp238 = tmp13 & tmp2 tmp239 = tmp2 & tmp238 tmp240 = tmp13 & tmp239 tmp241 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp240 & xmask, other=0.0) tmp242 = tmp18 + tmp241 tmp243 = tl.full(tmp242.shape, 0.0, tmp242.dtype) tmp244 = tl.where(tmp240, tmp242, tmp243) tmp245 = tl.where(tmp13, tmp244, tmp18) tmp246 = tl.full(tmp245.shape, 0.0, tmp245.dtype) tmp247 = tl.where(tmp239, tmp245, tmp246) tmp248 = tl.where(tmp2, tmp247, tmp18) tmp249 = tl.full(tmp248.shape, 0.0, tmp248.dtype) tmp250 = tl.where(tmp238, tmp248, tmp249) tmp251 = tl.where(tmp13, tmp250, tmp225) tmp252 = tl.full(tmp251.shape, 0.0, tmp251.dtype) tmp253 = tl.where(tmp2, tmp251, tmp252) tmp254 = tl.load(in_ptr1 + (x0 + 4 * x1), tmp238 & xmask, other=0.0) tmp255 = tmp18 + tmp254 tmp256 = tl.full(tmp255.shape, 0.0, tmp255.dtype) tmp257 = tl.where(tmp238, tmp255, tmp256) tmp258 = tl.where(tmp13, tmp257, tmp18) tmp259 = tl.full(tmp258.shape, 0.0, tmp258.dtype) tmp260 = tl.where(tmp2, tmp258, tmp259) tmp261 = tl.where(tmp2, tmp260, tmp18) tmp262 = tl.where(tmp2, tmp253, tmp261) tmp263 = tl.where(tmp2, tmp237, tmp262) tmp264 = tl.where(tmp2, tmp230, tmp263) tmp265 = tl.where(tmp2, tmp3, tmp264) tmp266 = tmp0 >= tmp1 tmp267 = tmp0 < tmp6 tmp268 = tmp266 & tmp267 tmp269 = tmp13 & tmp268 tmp270 = tmp2 & tmp269 tmp271 = tl.full([1], 12, tl.int64) tmp272 = tmp4 >= tmp271 tmp273 = tmp272 & tmp270 tmp274 = tmp2 & tmp273 tmp275 = tmp272 & tmp274 tmp276 = tmp2 & tmp275 tmp277 = tmp4 >= tmp6 tmp278 = tmp4 < tmp271 tmp279 = tmp277 & tmp278 tmp279 & tmp276 tmp281 = tl.where(tmp279, tmp265, tmp265) tmp282 = tl.full(tmp281.shape, 0.0, tmp281.dtype) tmp283 = tl.where(tmp276, tmp281, tmp282) tmp284 = tl.where(tmp2, tmp283, tmp265) tmp285 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp275 & xmask, other=0.0) tmp286 = tmp284 + tmp285 tmp287 = tl.full(tmp286.shape, 0.0, tmp286.dtype) tmp288 = tl.where(tmp275, tmp286, tmp287) tmp289 = tmp2 & tmp274 tmp279 & tmp289 tmp291 = tl.where(tmp289, tmp281, tmp282) tmp292 = tl.where(tmp2, tmp291, tmp265) tmp293 = tl.where(tmp272, tmp288, tmp292) tmp294 = tl.full(tmp293.shape, 0.0, tmp293.dtype) tmp295 = tl.where(tmp274, tmp293, tmp294) tmp279 & tmp274 tmp297 = tl.where(tmp274, tmp281, tmp282) tmp298 = tl.where(tmp2, tmp297, tmp265) tmp299 = tl.where(tmp2, tmp295, tmp298) tmp300 = tl.full(tmp299.shape, 0.0, tmp299.dtype) tmp301 = tl.where(tmp273, tmp299, tmp300) tmp302 = tmp2 & tmp270 tmp303 = tmp272 & tmp302 tmp304 = tmp2 & tmp303 tmp279 & tmp304 tmp306 = tl.where(tmp304, tmp281, tmp282) tmp307 = tl.where(tmp2, tmp306, tmp265) tmp308 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp303 & xmask, other=0.0) tmp309 = tmp307 + tmp308 tmp310 = tl.full(tmp309.shape, 0.0, tmp309.dtype) tmp311 = tl.where(tmp303, tmp309, tmp310) tmp312 = tmp2 & tmp302 tmp279 & tmp312 tmp314 = tl.where(tmp312, tmp281, tmp282) tmp315 = tl.where(tmp2, tmp314, tmp265) tmp316 = tl.where(tmp272, tmp311, tmp315) tmp317 = tl.full(tmp316.shape, 0.0, tmp316.dtype) tmp318 = tl.where(tmp302, tmp316, tmp317) tmp279 & tmp302 tmp320 = tl.where(tmp302, tmp281, tmp282) tmp321 = tl.where(tmp2, tmp320, tmp265) tmp322 = tl.where(tmp2, tmp318, tmp321) tmp323 = tl.where(tmp272, tmp301, tmp322) tmp324 = tl.full(tmp323.shape, 0.0, tmp323.dtype) tmp325 = tl.where(tmp270, tmp323, tmp324) tmp326 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp273 & xmask, other=0.0) tmp327 = tmp298 + tmp326 tmp328 = tl.full(tmp327.shape, 0.0, tmp327.dtype) tmp329 = tl.where(tmp273, tmp327, tmp328) tmp330 = tl.where(tmp272, tmp329, tmp321) tmp331 = tl.full(tmp330.shape, 0.0, tmp330.dtype) tmp332 = tl.where(tmp270, tmp330, tmp331) tmp279 & tmp270 tmp334 = tl.where(tmp270, tmp281, tmp282) tmp335 = tl.where(tmp2, tmp334, tmp265) tmp336 = tl.where(tmp2, tmp332, tmp335) tmp337 = tl.where(tmp2, tmp325, tmp336) tmp338 = tl.load(in_ptr1 + (48 + x0 + 4 * x1), tmp269 & xmask, other=0.0) tmp339 = tmp337 + tmp338 tmp340 = tl.full(tmp339.shape, 0.0, tmp339.dtype) tmp341 = tl.where(tmp269, tmp339, tmp340) tmp342 = tmp2 & tmp268 tmp343 = tmp272 & tmp342 tmp344 = tmp2 & tmp343 tmp345 = tmp272 & tmp344 tmp346 = tmp2 & tmp345 tmp279 & tmp346 tmp348 = tl.where(tmp346, tmp281, tmp282) tmp349 = tl.where(tmp2, tmp348, tmp265) tmp350 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp345 & xmask, other=0.0) tmp351 = tmp349 + tmp350 tmp352 = tl.full(tmp351.shape, 0.0, tmp351.dtype) tmp353 = tl.where(tmp345, tmp351, tmp352) tmp354 = tmp2 & tmp344 tmp279 & tmp354 tmp356 = tl.where(tmp354, tmp281, tmp282) tmp357 = tl.where(tmp2, tmp356, tmp265) tmp358 = tl.where(tmp272, tmp353, tmp357) tmp359 = tl.full(tmp358.shape, 0.0, tmp358.dtype) tmp360 = tl.where(tmp344, tmp358, tmp359) tmp279 & tmp344 tmp362 = tl.where(tmp344, tmp281, tmp282) tmp363 = tl.where(tmp2, tmp362, tmp265) tmp364 = tl.where(tmp2, tmp360, tmp363) tmp365 = tl.full(tmp364.shape, 0.0, tmp364.dtype) tmp366 = tl.where(tmp343, tmp364, tmp365) tmp367 = tmp2 & tmp342 tmp368 = tmp272 & tmp367 tmp369 = tmp2 & tmp368 tmp279 & tmp369 tmp371 = tl.where(tmp369, tmp281, tmp282) tmp372 = tl.where(tmp2, tmp371, tmp265) tmp373 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp368 & xmask, other=0.0) tmp374 = tmp372 + tmp373 tmp375 = tl.full(tmp374.shape, 0.0, tmp374.dtype) tmp376 = tl.where(tmp368, tmp374, tmp375) tmp377 = tmp2 & tmp367 tmp279 & tmp377 tmp379 = tl.where(tmp377, tmp281, tmp282) tmp380 = tl.where(tmp2, tmp379, tmp265) tmp381 = tl.where(tmp272, tmp376, tmp380) tmp382 = tl.full(tmp381.shape, 0.0, tmp381.dtype) tmp383 = tl.where(tmp367, tmp381, tmp382) tmp279 & tmp367 tmp385 = tl.where(tmp367, tmp281, tmp282) tmp386 = tl.where(tmp2, tmp385, tmp265) tmp387 = tl.where(tmp2, tmp383, tmp386) tmp388 = tl.where(tmp272, tmp366, tmp387) tmp389 = tl.full(tmp388.shape, 0.0, tmp388.dtype) tmp390 = tl.where(tmp342, tmp388, tmp389) tmp391 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp343 & xmask, other=0.0) tmp392 = tmp363 + tmp391 tmp393 = tl.full(tmp392.shape, 0.0, tmp392.dtype) tmp394 = tl.where(tmp343, tmp392, tmp393) tmp395 = tl.where(tmp272, tmp394, tmp386) tmp396 = tl.full(tmp395.shape, 0.0, tmp395.dtype) tmp397 = tl.where(tmp342, tmp395, tmp396) tmp279 & tmp342 tmp399 = tl.where(tmp342, tmp281, tmp282) tmp400 = tl.where(tmp2, tmp399, tmp265) tmp401 = tl.where(tmp2, tmp397, tmp400) tmp402 = tl.where(tmp2, tmp390, tmp401) tmp403 = tl.where(tmp13, tmp341, tmp402) tmp404 = tl.full(tmp403.shape, 0.0, tmp403.dtype) tmp405 = tl.where(tmp268, tmp403, tmp404) tmp406 = tmp272 & tmp2 tmp407 = tmp2 & tmp406 tmp408 = tmp272 & tmp407 tmp409 = tmp2 & tmp408 tmp279 & tmp409 tmp411 = tl.where(tmp409, tmp281, tmp282) tmp412 = tl.where(tmp2, tmp411, tmp265) tmp413 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp408 & xmask, other=0.0) tmp414 = tmp412 + tmp413 tmp415 = tl.full(tmp414.shape, 0.0, tmp414.dtype) tmp416 = tl.where(tmp408, tmp414, tmp415) tmp417 = tmp2 & tmp407 tmp279 & tmp417 tmp419 = tl.where(tmp417, tmp281, tmp282) tmp420 = tl.where(tmp2, tmp419, tmp265) tmp421 = tl.where(tmp272, tmp416, tmp420) tmp422 = tl.full(tmp421.shape, 0.0, tmp421.dtype) tmp423 = tl.where(tmp407, tmp421, tmp422) tmp279 & tmp407 tmp425 = tl.where(tmp407, tmp281, tmp282) tmp426 = tl.where(tmp2, tmp425, tmp265) tmp427 = tl.where(tmp2, tmp423, tmp426) tmp428 = tl.full(tmp427.shape, 0.0, tmp427.dtype) tmp429 = tl.where(tmp406, tmp427, tmp428) tmp430 = tmp272 & tmp121 tmp431 = tmp2 & tmp430 tmp279 & tmp431 tmp433 = tl.where(tmp431, tmp281, tmp282) tmp434 = tl.where(tmp2, tmp433, tmp265) tmp435 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp430 & xmask, other=0.0) tmp436 = tmp434 + tmp435 tmp437 = tl.full(tmp436.shape, 0.0, tmp436.dtype) tmp438 = tl.where(tmp430, tmp436, tmp437) tmp279 & tmp163 tmp440 = tl.where(tmp163, tmp281, tmp282) tmp441 = tl.where(tmp2, tmp440, tmp265) tmp442 = tl.where(tmp272, tmp438, tmp441) tmp443 = tl.full(tmp442.shape, 0.0, tmp442.dtype) tmp444 = tl.where(tmp121, tmp442, tmp443) tmp279 & tmp121 tmp446 = tl.where(tmp121, tmp281, tmp282) tmp447 = tl.where(tmp2, tmp446, tmp265) tmp448 = tl.where(tmp2, tmp444, tmp447) tmp449 = tl.where(tmp272, tmp429, tmp448) tmp450 = tl.full(tmp449.shape, 0.0, tmp449.dtype) tmp451 = tl.where(tmp2, tmp449, tmp450) tmp452 = tl.load(in_ptr1 + (36 + x0 + 4 * x1), tmp406 & xmask, other=0.0) tmp453 = tmp426 + tmp452 tmp454 = tl.full(tmp453.shape, 0.0, tmp453.dtype) tmp455 = tl.where(tmp406, tmp453, tmp454) tmp456 = tl.where(tmp272, tmp455, tmp447) tmp457 = tl.full(tmp456.shape, 0.0, tmp456.dtype) tmp458 = tl.where(tmp2, tmp456, tmp457) tmp279 & tmp2 tmp460 = tl.where(tmp2, tmp281, tmp282) tmp461 = tl.where(tmp2, tmp460, tmp265) tmp462 = tl.where(tmp2, tmp458, tmp461) tmp463 = tl.where(tmp2, tmp451, tmp462) tmp464 = tl.where(tmp268, tmp405, tmp463) tl.store(in_out_ptr0 + x2, tmp464, xmask) @triton.jit def triton_poi_fused_add_3(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 % 16 x1 = xindex // 16 x2 = xindex tmp200 = tl.load(in_ptr0 + (64 + x2), xmask) tmp0 = x0 tmp1 = tl.full([1], 8, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 12, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 4 + x1 tmp7 = tl.full([1], 4, tl.int64) tmp8 = tmp6 >= tmp7 tmp9 = tmp6 < tmp1 tmp10 = tmp8 & tmp9 tmp11 = tmp10 & tmp5 tmp12 = tmp0 >= tmp7 tmp13 = tmp0 < tmp1 tmp14 = tmp12 & tmp13 tmp15 = tmp14 & tmp11 tmp16 = tmp10 & tmp15 tmp17 = tmp14 & tmp16 tmp18 = tmp10 & tmp17 tmp19 = tmp0 < tmp7 tmp20 = tmp19 & tmp18 tmp21 = tl.load(in_ptr0 + (64 + x2), tmp20 & xmask, other=0.0) tmp22 = tl.load(in_ptr0 + (64 + x2), tmp18 & xmask, other=0.0) tmp23 = tl.where(tmp19, tmp21, tmp22) tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp18, tmp23, tmp24) tmp26 = tl.load(in_ptr0 + (64 + x2), tmp17 & xmask, other=0.0) tmp27 = tl.where(tmp10, tmp25, tmp26) tmp28 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp17 & xmask, other=0.0) tmp29 = tmp27 + tmp28 tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp17, tmp29, tmp30) tmp32 = tmp10 & tmp16 tmp33 = tmp19 & tmp32 tmp34 = tl.load(in_ptr0 + (64 + x2), tmp33 & xmask, other=0.0) tmp35 = tl.load(in_ptr0 + (64 + x2), tmp32 & xmask, other=0.0) tmp36 = tl.where(tmp19, tmp34, tmp35) tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp32, tmp36, tmp37) tmp39 = tl.load(in_ptr0 + (64 + x2), tmp16 & xmask, other=0.0) tmp40 = tl.where(tmp10, tmp38, tmp39) tmp41 = tl.where(tmp14, tmp31, tmp40) tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp16, tmp41, tmp42) tmp44 = tmp19 & tmp16 tmp45 = tl.load(in_ptr0 + (64 + x2), tmp44 & xmask, other=0.0) tmp46 = tl.where(tmp19, tmp45, tmp39) tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype) tmp48 = tl.where(tmp16, tmp46, tmp47) tmp49 = tl.load(in_ptr0 + (64 + x2), tmp15 & xmask, other=0.0) tmp50 = tl.where(tmp10, tmp48, tmp49) tmp51 = tl.where(tmp10, tmp43, tmp50) tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp15, tmp51, tmp52) tmp54 = tmp10 & tmp11 tmp55 = tmp14 & tmp54 tmp56 = tmp10 & tmp55 tmp57 = tmp19 & tmp56 tmp58 = tl.load(in_ptr0 + (64 + x2), tmp57 & xmask, other=0.0) tmp59 = tl.load(in_ptr0 + (64 + x2), tmp56 & xmask, other=0.0) tmp60 = tl.where(tmp19, tmp58, tmp59) tmp61 = tl.full(tmp60.shape, 0.0, tmp60.dtype) tmp62 = tl.where(tmp56, tmp60, tmp61) tmp63 = tl.load(in_ptr0 + (64 + x2), tmp55 & xmask, other=0.0) tmp64 = tl.where(tmp10, tmp62, tmp63) tmp65 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp55 & xmask, other=0.0) tmp66 = tmp64 + tmp65 tmp67 = tl.full(tmp66.shape, 0.0, tmp66.dtype) tmp68 = tl.where(tmp55, tmp66, tmp67) tmp69 = tmp10 & tmp54 tmp70 = tmp19 & tmp69 tmp71 = tl.load(in_ptr0 + (64 + x2), tmp70 & xmask, other=0.0) tmp72 = tl.load(in_ptr0 + (64 + x2), tmp69 & xmask, other=0.0) tmp73 = tl.where(tmp19, tmp71, tmp72) tmp74 = tl.full(tmp73.shape, 0.0, tmp73.dtype) tmp75 = tl.where(tmp69, tmp73, tmp74) tmp76 = tl.load(in_ptr0 + (64 + x2), tmp54 & xmask, other=0.0) tmp77 = tl.where(tmp10, tmp75, tmp76) tmp78 = tl.where(tmp14, tmp68, tmp77) tmp79 = tl.full(tmp78.shape, 0.0, tmp78.dtype) tmp80 = tl.where(tmp54, tmp78, tmp79) tmp81 = tmp19 & tmp54 tmp82 = tl.load(in_ptr0 + (64 + x2), tmp81 & xmask, other=0.0) tmp83 = tl.where(tmp19, tmp82, tmp76) tmp84 = tl.full(tmp83.shape, 0.0, tmp83.dtype) tmp85 = tl.where(tmp54, tmp83, tmp84) tmp86 = tl.load(in_ptr0 + (64 + x2), tmp11 & xmask, other=0.0) tmp87 = tl.where(tmp10, tmp85, tmp86) tmp88 = tl.where(tmp10, tmp80, tmp87) tmp89 = tl.where(tmp14, tmp53, tmp88) tmp90 = tl.full(tmp89.shape, 0.0, tmp89.dtype) tmp91 = tl.where(tmp11, tmp89, tmp90) tmp92 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp15 & xmask, other=0.0) tmp93 = tmp50 + tmp92 tmp94 = tl.full(tmp93.shape, 0.0, tmp93.dtype) tmp95 = tl.where(tmp15, tmp93, tmp94) tmp96 = tl.where(tmp14, tmp95, tmp87) tmp97 = tl.full(tmp96.shape, 0.0, tmp96.dtype) tmp98 = tl.where(tmp11, tmp96, tmp97) tmp99 = tmp19 & tmp11 tmp100 = tl.load(in_ptr0 + (64 + x2), tmp99 & xmask, other=0.0) tmp101 = tl.where(tmp19, tmp100, tmp86) tmp102 = tl.full(tmp101.shape, 0.0, tmp101.dtype) tmp103 = tl.where(tmp11, tmp101, tmp102) tmp104 = tl.load(in_ptr0 + (64 + x2), tmp5 & xmask, other=0.0) tmp105 = tl.where(tmp10, tmp103, tmp104) tmp106 = tl.where(tmp10, tmp98, tmp105) tmp107 = tl.where(tmp10, tmp91, tmp106) tmp108 = tl.load(in_ptr1 + (88 + x0 + 4 * x1), tmp5 & xmask, other=0.0) tmp109 = tmp107 + tmp108 tmp110 = tl.full(tmp109.shape, 0.0, tmp109.dtype) tmp111 = tl.where(tmp5, tmp109, tmp110) tmp112 = tmp14 & tmp10 tmp113 = tmp10 & tmp112 tmp114 = tmp14 & tmp113 tmp115 = tmp10 & tmp114 tmp116 = tmp19 & tmp115 tmp117 = tl.load(in_ptr0 + (64 + x2), tmp116 & xmask, other=0.0) tmp118 = tl.load(in_ptr0 + (64 + x2), tmp115 & xmask, other=0.0) tmp119 = tl.where(tmp19, tmp117, tmp118) tmp120 = tl.full(tmp119.shape, 0.0, tmp119.dtype) tmp121 = tl.where(tmp115, tmp119, tmp120) tmp122 = tl.load(in_ptr0 + (64 + x2), tmp114 & xmask, other=0.0) tmp123 = tl.where(tmp10, tmp121, tmp122) tmp124 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp114 & xmask, other=0.0) tmp125 = tmp123 + tmp124 tmp126 = tl.full(tmp125.shape, 0.0, tmp125.dtype) tmp127 = tl.where(tmp114, tmp125, tmp126) tmp128 = tmp10 & tmp113 tmp129 = tmp19 & tmp128 tmp130 = tl.load(in_ptr0 + (64 + x2), tmp129 & xmask, other=0.0) tmp131 = tl.load(in_ptr0 + (64 + x2), tmp128 & xmask, other=0.0) tmp132 = tl.where(tmp19, tmp130, tmp131) tmp133 = tl.full(tmp132.shape, 0.0, tmp132.dtype) tmp134 = tl.where(tmp128, tmp132, tmp133) tmp135 = tl.load(in_ptr0 + (64 + x2), tmp113 & xmask, other=0.0) tmp136 = tl.where(tmp10, tmp134, tmp135) tmp137 = tl.where(tmp14, tmp127, tmp136) tmp138 = tl.full(tmp137.shape, 0.0, tmp137.dtype) tmp139 = tl.where(tmp113, tmp137, tmp138) tmp140 = tmp19 & tmp113 tmp141 = tl.load(in_ptr0 + (64 + x2), tmp140 & xmask, other=0.0) tmp142 = tl.where(tmp19, tmp141, tmp135) tmp143 = tl.full(tmp142.shape, 0.0, tmp142.dtype) tmp144 = tl.where(tmp113, tmp142, tmp143) tmp145 = tl.load(in_ptr0 + (64 + x2), tmp112 & xmask, other=0.0) tmp146 = tl.where(tmp10, tmp144, tmp145) tmp147 = tl.where(tmp10, tmp139, tmp146) tmp148 = tl.full(tmp147.shape, 0.0, tmp147.dtype) tmp149 = tl.where(tmp112, tmp147, tmp148) tmp150 = tmp10 & tmp10 tmp151 = tmp14 & tmp150 tmp152 = tmp10 & tmp151 tmp153 = tmp19 & tmp152 tmp154 = tl.load(in_ptr0 + (64 + x2), tmp153 & xmask, other=0.0) tmp155 = tl.load(in_ptr0 + (64 + x2), tmp152 & xmask, other=0.0) tmp156 = tl.where(tmp19, tmp154, tmp155) tmp157 = tl.full(tmp156.shape, 0.0, tmp156.dtype) tmp158 = tl.where(tmp152, tmp156, tmp157) tmp159 = tl.load(in_ptr0 + (64 + x2), tmp151 & xmask, other=0.0) tmp160 = tl.where(tmp10, tmp158, tmp159) tmp161 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp151 & xmask, other=0.0) tmp162 = tmp160 + tmp161 tmp163 = tl.full(tmp162.shape, 0.0, tmp162.dtype) tmp164 = tl.where(tmp151, tmp162, tmp163) tmp165 = tmp10 & tmp150 tmp166 = tmp19 & tmp165 tmp167 = tl.load(in_ptr0 + (64 + x2), tmp166 & xmask, other=0.0) tmp168 = tl.load(in_ptr0 + (64 + x2), tmp165 & xmask, other=0.0) tmp169 = tl.where(tmp19, tmp167, tmp168) tmp170 = tl.full(tmp169.shape, 0.0, tmp169.dtype) tmp171 = tl.where(tmp165, tmp169, tmp170) tmp172 = tl.load(in_ptr0 + (64 + x2), tmp150 & xmask, other=0.0) tmp173 = tl.where(tmp10, tmp171, tmp172) tmp174 = tl.where(tmp14, tmp164, tmp173) tmp175 = tl.full(tmp174.shape, 0.0, tmp174.dtype) tmp176 = tl.where(tmp150, tmp174, tmp175) tmp177 = tmp19 & tmp150 tmp178 = tl.load(in_ptr0 + (64 + x2), tmp177 & xmask, other=0.0) tmp179 = tl.where(tmp19, tmp178, tmp172) tmp180 = tl.full(tmp179.shape, 0.0, tmp179.dtype) tmp181 = tl.where(tmp150, tmp179, tmp180) tmp182 = tl.load(in_ptr0 + (64 + x2), tmp10 & xmask, other=0.0) tmp183 = tl.where(tmp10, tmp181, tmp182) tmp184 = tl.where(tmp10, tmp176, tmp183) tmp185 = tl.where(tmp14, tmp149, tmp184) tmp186 = tl.full(tmp185.shape, 0.0, tmp185.dtype) tmp187 = tl.where(tmp10, tmp185, tmp186) tmp188 = tl.load(in_ptr1 + (76 + x0 + 4 * x1), tmp112 & xmask, other=0.0) tmp189 = tmp146 + tmp188 tmp190 = tl.full(tmp189.shape, 0.0, tmp189.dtype) tmp191 = tl.where(tmp112, tmp189, tmp190) tmp192 = tl.where(tmp14, tmp191, tmp183) tmp193 = tl.full(tmp192.shape, 0.0, tmp192.dtype) tmp194 = tl.where(tmp10, tmp192, tmp193) tmp195 = tmp19 & tmp10 tmp196 = tl.load(in_ptr0 + (64 + x2), tmp195 & xmask, other=0.0) tmp197 = tl.where(tmp19, tmp196, tmp182) tmp198 = tl.full(tmp197.shape, 0.0, tmp197.dtype) tmp199 = tl.where(tmp10, tmp197, tmp198) tmp201 = tl.where(tmp10, tmp199, tmp200) tmp202 = tl.where(tmp10, tmp194, tmp201) tmp203 = tl.where(tmp10, tmp187, tmp202) tmp204 = tl.where(tmp5, tmp111, tmp203) tmp205 = tl.where(tmp10, tmp204, tmp107) tmp206 = tl.full(tmp205.shape, 0.0, tmp205.dtype) tmp207 = tl.where(tmp5, tmp205, tmp206) tmp208 = tl.where(tmp10, tmp204, tmp203) tmp209 = tl.where(tmp5, tmp207, tmp208) tl.store(out_ptr0 + x2, tmp204, xmask) tl.store(out_ptr1 + x2, tmp209, xmask) @triton.jit def triton_poi_fused_add_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 x2 = xindex x0 = xindex % 16 tmp101 = tl.load(in_out_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-64 + x2), tmp5 & xmask, other=0.0) tmp7 = tl.load(in_ptr1 + (-64 + x2), tmp5 & xmask, other=0.0) tmp8 = x0 tmp9 = tmp8 >= tmp1 tmp10 = tmp8 < tmp3 tmp11 = tmp9 & tmp10 tmp12 = tmp11 & tmp5 tmp13 = tmp5 & tmp12 tmp14 = tmp11 & tmp13 tmp15 = tmp5 & tmp14 tmp16 = tmp8 < tmp1 tmp17 = tmp16 & tmp15 tmp18 = tl.load(in_out_ptr0 + x2, tmp17 & xmask, other=0.0) tmp19 = tl.load(in_out_ptr0 + x2, tmp15 & xmask, other=0.0) tmp20 = tl.where(tmp16, tmp18, tmp19) tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp15, tmp20, tmp21) tmp23 = tl.load(in_out_ptr0 + x2, tmp14 & xmask, other=0.0) tmp24 = tl.where(tmp5, tmp22, tmp23) tmp25 = tl.load(in_ptr2 + (60 + x0 + 4 * x1), tmp14 & xmask, other=0.0) tmp26 = tmp24 + tmp25 tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype) tmp28 = tl.where(tmp14, tmp26, tmp27) tmp29 = tmp5 & tmp13 tmp30 = tmp16 & tmp29 tmp31 = tl.load(in_out_ptr0 + x2, tmp30 & xmask, other=0.0) tmp32 = tl.load(in_out_ptr0 + x2, tmp29 & xmask, other=0.0) tmp33 = tl.where(tmp16, tmp31, tmp32) tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp29, tmp33, tmp34) tmp36 = tl.load(in_out_ptr0 + x2, tmp13 & xmask, other=0.0) tmp37 = tl.where(tmp5, tmp35, tmp36) tmp38 = tl.where(tmp11, tmp28, tmp37) tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype) tmp40 = tl.where(tmp13, tmp38, tmp39) tmp41 = tmp16 & tmp13 tmp42 = tl.load(in_out_ptr0 + x2, tmp41 & xmask, other=0.0) tmp43 = tl.where(tmp16, tmp42, tmp36) tmp44 = tl.full(tmp43.shape, 0.0, tmp43.dtype) tmp45 = tl.where(tmp13, tmp43, tmp44) tmp46 = tl.load(in_out_ptr0 + x2, tmp12 & xmask, other=0.0) tmp47 = tl.where(tmp5, tmp45, tmp46) tmp48 = tl.where(tmp5, tmp40, tmp47) tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype) tmp50 = tl.where(tmp12, tmp48, tmp49) tmp51 = tmp5 & tmp5 tmp52 = tmp11 & tmp51 tmp53 = tmp5 & tmp52 tmp54 = tmp16 & tmp53 tmp55 = tl.load(in_out_ptr0 + x2, tmp54 & xmask, other=0.0) tmp56 = tl.load(in_out_ptr0 + x2, tmp53 & xmask, other=0.0) tmp57 = tl.where(tmp16, tmp55, tmp56) tmp58 = tl.full(tmp57.shape, 0.0, tmp57.dtype) tmp59 = tl.where(tmp53, tmp57, tmp58) tmp60 = tl.load(in_out_ptr0 + x2, tmp52 & xmask, other=0.0) tmp61 = tl.where(tmp5, tmp59, tmp60) tmp62 = tl.load(in_ptr2 + (60 + x0 + 4 * x1), tmp52 & xmask, other=0.0) tmp63 = tmp61 + tmp62 tmp64 = tl.full(tmp63.shape, 0.0, tmp63.dtype) tmp65 = tl.where(tmp52, tmp63, tmp64) tmp66 = tmp5 & tmp51 tmp67 = tmp16 & tmp66 tmp68 = tl.load(in_out_ptr0 + x2, tmp67 & xmask, other=0.0) tmp69 = tl.load(in_out_ptr0 + x2, tmp66 & xmask, other=0.0) tmp70 = tl.where(tmp16, tmp68, tmp69) tmp71 = tl.full(tmp70.shape, 0.0, tmp70.dtype) tmp72 = tl.where(tmp66, tmp70, tmp71) tmp73 = tl.load(in_out_ptr0 + x2, tmp51 & xmask, other=0.0) tmp74 = tl.where(tmp5, tmp72, tmp73) tmp75 = tl.where(tmp11, tmp65, tmp74) tmp76 = tl.full(tmp75.shape, 0.0, tmp75.dtype) tmp77 = tl.where(tmp51, tmp75, tmp76) tmp78 = tmp16 & tmp51 tmp79 = tl.load(in_out_ptr0 + x2, tmp78 & xmask, other=0.0) tmp80 = tl.where(tmp16, tmp79, tmp73) tmp81 = tl.full(tmp80.shape, 0.0, tmp80.dtype) tmp82 = tl.where(tmp51, tmp80, tmp81) tmp83 = tl.load(in_out_ptr0 + x2, tmp5 & xmask, other=0.0) tmp84 = tl.where(tmp5, tmp82, tmp83) tmp85 = tl.where(tmp5, tmp77, tmp84) tmp86 = tl.where(tmp11, tmp50, tmp85) tmp87 = tl.full(tmp86.shape, 0.0, tmp86.dtype) tmp88 = tl.where(tmp5, tmp86, tmp87) tmp89 = tl.load(in_ptr2 + (60 + x0 + 4 * x1), tmp12 & xmask, other=0.0) tmp90 = tmp47 + tmp89 tmp91 = tl.full(tmp90.shape, 0.0, tmp90.dtype) tmp92 = tl.where(tmp12, tmp90, tmp91) tmp93 = tl.where(tmp11, tmp92, tmp84) tmp94 = tl.full(tmp93.shape, 0.0, tmp93.dtype) tmp95 = tl.where(tmp5, tmp93, tmp94) tmp96 = tmp16 & tmp5 tmp97 = tl.load(in_out_ptr0 + x2, tmp96 & xmask, other=0.0) tmp98 = tl.where(tmp16, tmp97, tmp83) tmp99 = tl.full(tmp98.shape, 0.0, tmp98.dtype) tmp100 = tl.where(tmp5, tmp98, tmp99) tmp102 = tl.where(tmp5, tmp100, tmp101) tmp103 = tl.where(tmp5, tmp95, tmp102) tmp104 = tl.where(tmp5, tmp88, tmp103) tmp105 = tl.where(tmp5, tmp7, tmp104) tmp106 = tl.where(tmp5, tmp6, tmp105) tl.store(in_out_ptr0 + x2, tmp106, xmask) @triton.jit def triton_poi_fused_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp287 = tl.load(in_ptr0 + (128 + x2), xmask) tmp0 = x0 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = 8 + x1 tmp4 = tl.full([1], 8, tl.int64) tmp5 = tmp3 >= tmp4 tmp6 = tl.full([1], 12, tl.int64) tmp7 = tmp3 < tmp6 tmp8 = tmp5 & tmp7 tmp9 = tmp8 & tmp2 tmp10 = tmp2 & tmp9 tmp11 = tmp3 >= tmp1 tmp12 = tmp3 < tmp4 tmp13 = tmp11 & tmp12 tmp14 = tmp13 & tmp10 tmp15 = tmp0 >= tmp6 tmp16 = tmp15 & tmp14 tmp17 = tmp13 & tmp16 tmp18 = tmp15 & tmp17 tmp19 = tl.load(in_ptr0 + (128 + x2), tmp18 & xmask, other=0.0) tmp20 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp18 & xmask, other=0.0) tmp21 = tmp19 + tmp20 tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp18, tmp21, tmp22) tmp24 = tl.load(in_ptr0 + (128 + x2), tmp17 & xmask, other=0.0) tmp25 = tl.where(tmp15, tmp23, tmp24) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp17, tmp25, tmp26) tmp28 = tl.load(in_ptr0 + (128 + x2), tmp16 & xmask, other=0.0) tmp29 = tl.where(tmp13, tmp27, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp16, tmp29, tmp30) tmp32 = tmp13 & tmp14 tmp33 = tmp15 & tmp32 tmp34 = tl.load(in_ptr0 + (128 + x2), tmp33 & xmask, other=0.0) tmp35 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp33 & xmask, other=0.0) tmp36 = tmp34 + tmp35 tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp33, tmp36, tmp37) tmp39 = tl.load(in_ptr0 + (128 + x2), tmp32 & xmask, other=0.0) tmp40 = tl.where(tmp15, tmp38, tmp39) tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype) tmp42 = tl.where(tmp32, tmp40, tmp41) tmp43 = tl.load(in_ptr0 + (128 + x2), tmp14 & xmask, other=0.0) tmp44 = tl.where(tmp13, tmp42, tmp43) tmp45 = tl.where(tmp15, tmp31, tmp44) tmp46 = tl.full(tmp45.shape, 0.0, tmp45.dtype) tmp47 = tl.where(tmp14, tmp45, tmp46) tmp48 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp16 & xmask, other=0.0) tmp49 = tmp28 + tmp48 tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp16, tmp49, tmp50) tmp52 = tl.where(tmp15, tmp51, tmp43) tmp53 = tl.full(tmp52.shape, 0.0, tmp52.dtype) tmp54 = tl.where(tmp14, tmp52, tmp53) tmp55 = tl.load(in_ptr0 + (128 + x2), tmp10 & xmask, other=0.0) tmp56 = tl.where(tmp13, tmp54, tmp55) tmp57 = tl.where(tmp13, tmp47, tmp56) tmp58 = tl.load(in_ptr1 + (128 + x0 + 4 * x1), tmp10 & xmask, other=0.0) tmp59 = tmp57 + tmp58 tmp60 = tl.full(tmp59.shape, 0.0, tmp59.dtype) tmp61 = tl.where(tmp10, tmp59, tmp60) tmp62 = tmp13 & tmp9 tmp63 = tmp15 & tmp62 tmp64 = tmp13 & tmp63 tmp65 = tmp15 & tmp64 tmp66 = tl.load(in_ptr0 + (128 + x2), tmp65 & xmask, other=0.0) tmp67 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp65 & xmask, other=0.0) tmp68 = tmp66 + tmp67 tmp69 = tl.full(tmp68.shape, 0.0, tmp68.dtype) tmp70 = tl.where(tmp65, tmp68, tmp69) tmp71 = tl.load(in_ptr0 + (128 + x2), tmp64 & xmask, other=0.0) tmp72 = tl.where(tmp15, tmp70, tmp71) tmp73 = tl.full(tmp72.shape, 0.0, tmp72.dtype) tmp74 = tl.where(tmp64, tmp72, tmp73) tmp75 = tl.load(in_ptr0 + (128 + x2), tmp63 & xmask, other=0.0) tmp76 = tl.where(tmp13, tmp74, tmp75) tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype) tmp78 = tl.where(tmp63, tmp76, tmp77) tmp79 = tmp13 & tmp62 tmp80 = tmp15 & tmp79 tmp81 = tl.load(in_ptr0 + (128 + x2), tmp80 & xmask, other=0.0) tmp82 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp80 & xmask, other=0.0) tmp83 = tmp81 + tmp82 tmp84 = tl.full(tmp83.shape, 0.0, tmp83.dtype) tmp85 = tl.where(tmp80, tmp83, tmp84) tmp86 = tl.load(in_ptr0 + (128 + x2), tmp79 & xmask, other=0.0) tmp87 = tl.where(tmp15, tmp85, tmp86) tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype) tmp89 = tl.where(tmp79, tmp87, tmp88) tmp90 = tl.load(in_ptr0 + (128 + x2), tmp62 & xmask, other=0.0) tmp91 = tl.where(tmp13, tmp89, tmp90) tmp92 = tl.where(tmp15, tmp78, tmp91) tmp93 = tl.full(tmp92.shape, 0.0, tmp92.dtype) tmp94 = tl.where(tmp62, tmp92, tmp93) tmp95 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp63 & xmask, other=0.0) tmp96 = tmp75 + tmp95 tmp97 = tl.full(tmp96.shape, 0.0, tmp96.dtype) tmp98 = tl.where(tmp63, tmp96, tmp97) tmp99 = tl.where(tmp15, tmp98, tmp90) tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype) tmp101 = tl.where(tmp62, tmp99, tmp100) tmp102 = tl.load(in_ptr0 + (128 + x2), tmp9 & xmask, other=0.0) tmp103 = tl.where(tmp13, tmp101, tmp102) tmp104 = tl.where(tmp13, tmp94, tmp103) tmp105 = tl.where(tmp2, tmp61, tmp104) tmp106 = tl.full(tmp105.shape, 0.0, tmp105.dtype) tmp107 = tl.where(tmp9, tmp105, tmp106) tmp108 = tmp13 & tmp2 tmp109 = tmp15 & tmp108 tmp110 = tmp13 & tmp109 tmp111 = tmp15 & tmp110 tmp112 = tl.load(in_ptr0 + (128 + x2), tmp111 & xmask, other=0.0) tmp113 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp111 & xmask, other=0.0) tmp114 = tmp112 + tmp113 tmp115 = tl.full(tmp114.shape, 0.0, tmp114.dtype) tmp116 = tl.where(tmp111, tmp114, tmp115) tmp117 = tl.load(in_ptr0 + (128 + x2), tmp110 & xmask, other=0.0) tmp118 = tl.where(tmp15, tmp116, tmp117) tmp119 = tl.full(tmp118.shape, 0.0, tmp118.dtype) tmp120 = tl.where(tmp110, tmp118, tmp119) tmp121 = tl.load(in_ptr0 + (128 + x2), tmp109 & xmask, other=0.0) tmp122 = tl.where(tmp13, tmp120, tmp121) tmp123 = tl.full(tmp122.shape, 0.0, tmp122.dtype) tmp124 = tl.where(tmp109, tmp122, tmp123) tmp125 = tmp13 & tmp108 tmp126 = tmp15 & tmp125 tmp127 = tl.load(in_ptr0 + (128 + x2), tmp126 & xmask, other=0.0) tmp128 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp126 & xmask, other=0.0) tmp129 = tmp127 + tmp128 tmp130 = tl.full(tmp129.shape, 0.0, tmp129.dtype) tmp131 = tl.where(tmp126, tmp129, tmp130) tmp132 = tl.load(in_ptr0 + (128 + x2), tmp125 & xmask, other=0.0) tmp133 = tl.where(tmp15, tmp131, tmp132) tmp134 = tl.full(tmp133.shape, 0.0, tmp133.dtype) tmp135 = tl.where(tmp125, tmp133, tmp134) tmp136 = tl.load(in_ptr0 + (128 + x2), tmp108 & xmask, other=0.0) tmp137 = tl.where(tmp13, tmp135, tmp136) tmp138 = tl.where(tmp15, tmp124, tmp137) tmp139 = tl.full(tmp138.shape, 0.0, tmp138.dtype) tmp140 = tl.where(tmp108, tmp138, tmp139) tmp141 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp109 & xmask, other=0.0) tmp142 = tmp121 + tmp141 tmp143 = tl.full(tmp142.shape, 0.0, tmp142.dtype) tmp144 = tl.where(tmp109, tmp142, tmp143) tmp145 = tl.where(tmp15, tmp144, tmp136) tmp146 = tl.full(tmp145.shape, 0.0, tmp145.dtype) tmp147 = tl.where(tmp108, tmp145, tmp146) tmp148 = tl.load(in_ptr0 + (128 + x2), tmp2 & xmask, other=0.0) tmp149 = tl.where(tmp13, tmp147, tmp148) tmp150 = tl.where(tmp13, tmp140, tmp149) tmp151 = tl.where(tmp8, tmp107, tmp150) tmp152 = tl.full(tmp151.shape, 0.0, tmp151.dtype) tmp153 = tl.where(tmp2, tmp151, tmp152) tmp154 = tmp2 & tmp8 tmp155 = tmp13 & tmp154 tmp156 = tmp15 & tmp155 tmp157 = tmp13 & tmp156 tmp158 = tmp15 & tmp157 tmp159 = tl.load(in_ptr0 + (128 + x2), tmp158 & xmask, other=0.0) tmp160 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp158 & xmask, other=0.0) tmp161 = tmp159 + tmp160 tmp162 = tl.full(tmp161.shape, 0.0, tmp161.dtype) tmp163 = tl.where(tmp158, tmp161, tmp162) tmp164 = tl.load(in_ptr0 + (128 + x2), tmp157 & xmask, other=0.0) tmp165 = tl.where(tmp15, tmp163, tmp164) tmp166 = tl.full(tmp165.shape, 0.0, tmp165.dtype) tmp167 = tl.where(tmp157, tmp165, tmp166) tmp168 = tl.load(in_ptr0 + (128 + x2), tmp156 & xmask, other=0.0) tmp169 = tl.where(tmp13, tmp167, tmp168) tmp170 = tl.full(tmp169.shape, 0.0, tmp169.dtype) tmp171 = tl.where(tmp156, tmp169, tmp170) tmp172 = tmp13 & tmp155 tmp173 = tmp15 & tmp172 tmp174 = tl.load(in_ptr0 + (128 + x2), tmp173 & xmask, other=0.0) tmp175 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp173 & xmask, other=0.0) tmp176 = tmp174 + tmp175 tmp177 = tl.full(tmp176.shape, 0.0, tmp176.dtype) tmp178 = tl.where(tmp173, tmp176, tmp177) tmp179 = tl.load(in_ptr0 + (128 + x2), tmp172 & xmask, other=0.0) tmp180 = tl.where(tmp15, tmp178, tmp179) tmp181 = tl.full(tmp180.shape, 0.0, tmp180.dtype) tmp182 = tl.where(tmp172, tmp180, tmp181) tmp183 = tl.load(in_ptr0 + (128 + x2), tmp155 & xmask, other=0.0) tmp184 = tl.where(tmp13, tmp182, tmp183) tmp185 = tl.where(tmp15, tmp171, tmp184) tmp186 = tl.full(tmp185.shape, 0.0, tmp185.dtype) tmp187 = tl.where(tmp155, tmp185, tmp186) tmp188 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp156 & xmask, other=0.0) tmp189 = tmp168 + tmp188 tmp190 = tl.full(tmp189.shape, 0.0, tmp189.dtype) tmp191 = tl.where(tmp156, tmp189, tmp190) tmp192 = tl.where(tmp15, tmp191, tmp183) tmp193 = tl.full(tmp192.shape, 0.0, tmp192.dtype) tmp194 = tl.where(tmp155, tmp192, tmp193) tmp195 = tl.load(in_ptr0 + (128 + x2), tmp154 & xmask, other=0.0) tmp196 = tl.where(tmp13, tmp194, tmp195) tmp197 = tl.where(tmp13, tmp187, tmp196) tmp198 = tl.load(in_ptr1 + (128 + x0 + 4 * x1), tmp154 & xmask, other=0.0) tmp199 = tmp197 + tmp198 tmp200 = tl.full(tmp199.shape, 0.0, tmp199.dtype) tmp201 = tl.where(tmp154, tmp199, tmp200) tmp202 = tmp13 & tmp8 tmp203 = tmp15 & tmp202 tmp204 = tmp13 & tmp203 tmp205 = tmp15 & tmp204 tmp206 = tl.load(in_ptr0 + (128 + x2), tmp205 & xmask, other=0.0) tmp207 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp205 & xmask, other=0.0) tmp208 = tmp206 + tmp207 tmp209 = tl.full(tmp208.shape, 0.0, tmp208.dtype) tmp210 = tl.where(tmp205, tmp208, tmp209) tmp211 = tl.load(in_ptr0 + (128 + x2), tmp204 & xmask, other=0.0) tmp212 = tl.where(tmp15, tmp210, tmp211) tmp213 = tl.full(tmp212.shape, 0.0, tmp212.dtype) tmp214 = tl.where(tmp204, tmp212, tmp213) tmp215 = tl.load(in_ptr0 + (128 + x2), tmp203 & xmask, other=0.0) tmp216 = tl.where(tmp13, tmp214, tmp215) tmp217 = tl.full(tmp216.shape, 0.0, tmp216.dtype) tmp218 = tl.where(tmp203, tmp216, tmp217) tmp219 = tmp13 & tmp202 tmp220 = tmp15 & tmp219 tmp221 = tl.load(in_ptr0 + (128 + x2), tmp220 & xmask, other=0.0) tmp222 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp220 & xmask, other=0.0) tmp223 = tmp221 + tmp222 tmp224 = tl.full(tmp223.shape, 0.0, tmp223.dtype) tmp225 = tl.where(tmp220, tmp223, tmp224) tmp226 = tl.load(in_ptr0 + (128 + x2), tmp219 & xmask, other=0.0) tmp227 = tl.where(tmp15, tmp225, tmp226) tmp228 = tl.full(tmp227.shape, 0.0, tmp227.dtype) tmp229 = tl.where(tmp219, tmp227, tmp228) tmp230 = tl.load(in_ptr0 + (128 + x2), tmp202 & xmask, other=0.0) tmp231 = tl.where(tmp13, tmp229, tmp230) tmp232 = tl.where(tmp15, tmp218, tmp231) tmp233 = tl.full(tmp232.shape, 0.0, tmp232.dtype) tmp234 = tl.where(tmp202, tmp232, tmp233) tmp235 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp203 & xmask, other=0.0) tmp236 = tmp215 + tmp235 tmp237 = tl.full(tmp236.shape, 0.0, tmp236.dtype) tmp238 = tl.where(tmp203, tmp236, tmp237) tmp239 = tl.where(tmp15, tmp238, tmp230) tmp240 = tl.full(tmp239.shape, 0.0, tmp239.dtype) tmp241 = tl.where(tmp202, tmp239, tmp240) tmp242 = tl.load(in_ptr0 + (128 + x2), tmp8 & xmask, other=0.0) tmp243 = tl.where(tmp13, tmp241, tmp242) tmp244 = tl.where(tmp13, tmp234, tmp243) tmp245 = tl.where(tmp2, tmp201, tmp244) tmp246 = tl.full(tmp245.shape, 0.0, tmp245.dtype) tmp247 = tl.where(tmp8, tmp245, tmp246) tmp248 = tmp15 & tmp13 tmp249 = tmp13 & tmp248 tmp250 = tmp15 & tmp249 tmp251 = tl.load(in_ptr0 + (128 + x2), tmp250 & xmask, other=0.0) tmp252 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp250 & xmask, other=0.0) tmp253 = tmp251 + tmp252 tmp254 = tl.full(tmp253.shape, 0.0, tmp253.dtype) tmp255 = tl.where(tmp250, tmp253, tmp254) tmp256 = tl.load(in_ptr0 + (128 + x2), tmp249 & xmask, other=0.0) tmp257 = tl.where(tmp15, tmp255, tmp256) tmp258 = tl.full(tmp257.shape, 0.0, tmp257.dtype) tmp259 = tl.where(tmp249, tmp257, tmp258) tmp260 = tl.load(in_ptr0 + (128 + x2), tmp248 & xmask, other=0.0) tmp261 = tl.where(tmp13, tmp259, tmp260) tmp262 = tl.full(tmp261.shape, 0.0, tmp261.dtype) tmp263 = tl.where(tmp248, tmp261, tmp262) tmp264 = tmp13 & tmp13 tmp265 = tmp15 & tmp264 tmp266 = tl.load(in_ptr0 + (128 + x2), tmp265 & xmask, other=0.0) tmp267 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp265 & xmask, other=0.0) tmp268 = tmp266 + tmp267 tmp269 = tl.full(tmp268.shape, 0.0, tmp268.dtype) tmp270 = tl.where(tmp265, tmp268, tmp269) tmp271 = tl.load(in_ptr0 + (128 + x2), tmp264 & xmask, other=0.0) tmp272 = tl.where(tmp15, tmp270, tmp271) tmp273 = tl.full(tmp272.shape, 0.0, tmp272.dtype) tmp274 = tl.where(tmp264, tmp272, tmp273) tmp275 = tl.load(in_ptr0 + (128 + x2), tmp13 & xmask, other=0.0) tmp276 = tl.where(tmp13, tmp274, tmp275) tmp277 = tl.where(tmp15, tmp263, tmp276) tmp278 = tl.full(tmp277.shape, 0.0, tmp277.dtype) tmp279 = tl.where(tmp13, tmp277, tmp278) tmp280 = tl.load(in_ptr1 + (116 + x0 + 4 * x1), tmp248 & xmask, other=0.0) tmp281 = tmp260 + tmp280 tmp282 = tl.full(tmp281.shape, 0.0, tmp281.dtype) tmp283 = tl.where(tmp248, tmp281, tmp282) tmp284 = tl.where(tmp15, tmp283, tmp275) tmp285 = tl.full(tmp284.shape, 0.0, tmp284.dtype) tmp286 = tl.where(tmp13, tmp284, tmp285) tmp288 = tl.where(tmp13, tmp286, tmp287) tmp289 = tl.where(tmp13, tmp279, tmp288) tmp290 = tl.where(tmp8, tmp247, tmp289) tmp291 = tl.where(tmp2, tmp153, tmp290) tl.store(out_ptr0 + x2, tmp291, xmask) @triton.jit def triton_poi_fused_add_6(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 x1 = xindex // 16 x2 = xindex x0 = xindex % 16 tmp147 = tl.load(in_out_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 8, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 12, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-128 + x2), tmp5 & xmask, other=0.0) tmp7 = x0 tmp8 = tl.full([1], 4, tl.int64) tmp9 = tmp7 < tmp8 tmp10 = tmp9 & tmp5 tmp11 = tmp0 >= tmp8 tmp12 = tmp0 < tmp1 tmp13 = tmp11 & tmp12 tmp14 = tmp13 & tmp10 tmp15 = tmp7 >= tmp3 tmp16 = tmp15 & tmp14 tmp17 = tmp13 & tmp16 tmp18 = tmp15 & tmp17 tmp19 = tl.load(in_out_ptr0 + x2, tmp18 & xmask, other=0.0) tmp20 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp18 & xmask, other=0.0) tmp21 = tmp19 + tmp20 tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp18, tmp21, tmp22) tmp24 = tl.load(in_out_ptr0 + x2, tmp17 & xmask, other=0.0) tmp25 = tl.where(tmp15, tmp23, tmp24) tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp17, tmp25, tmp26) tmp28 = tl.load(in_out_ptr0 + x2, tmp16 & xmask, other=0.0) tmp29 = tl.where(tmp13, tmp27, tmp28) tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype) tmp31 = tl.where(tmp16, tmp29, tmp30) tmp32 = tmp13 & tmp14 tmp33 = tmp15 & tmp32 tmp34 = tl.load(in_out_ptr0 + x2, tmp33 & xmask, other=0.0) tmp35 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp33 & xmask, other=0.0) tmp36 = tmp34 + tmp35 tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp33, tmp36, tmp37) tmp39 = tl.load(in_out_ptr0 + x2, tmp32 & xmask, other=0.0) tmp40 = tl.where(tmp15, tmp38, tmp39) tmp41 = tl.full(tmp40.shape, 0.0, tmp40.dtype) tmp42 = tl.where(tmp32, tmp40, tmp41) tmp43 = tl.load(in_out_ptr0 + x2, tmp14 & xmask, other=0.0) tmp44 = tl.where(tmp13, tmp42, tmp43) tmp45 = tl.where(tmp15, tmp31, tmp44) tmp46 = tl.full(tmp45.shape, 0.0, tmp45.dtype) tmp47 = tl.where(tmp14, tmp45, tmp46) tmp48 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp16 & xmask, other=0.0) tmp49 = tmp28 + tmp48 tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp16, tmp49, tmp50) tmp52 = tl.where(tmp15, tmp51, tmp43) tmp53 = tl.full(tmp52.shape, 0.0, tmp52.dtype) tmp54 = tl.where(tmp14, tmp52, tmp53) tmp55 = tl.load(in_out_ptr0 + x2, tmp10 & xmask, other=0.0) tmp56 = tl.where(tmp13, tmp54, tmp55) tmp57 = tl.where(tmp13, tmp47, tmp56) tmp58 = tl.load(in_ptr1 + (96 + x0 + 4 * x1), tmp10 & xmask, other=0.0) tmp59 = tmp57 + tmp58 tmp60 = tl.full(tmp59.shape, 0.0, tmp59.dtype) tmp61 = tl.where(tmp10, tmp59, tmp60) tmp62 = tmp13 & tmp5 tmp63 = tmp15 & tmp62 tmp64 = tmp13 & tmp63 tmp65 = tmp15 & tmp64 tmp66 = tl.load(in_out_ptr0 + x2, tmp65 & xmask, other=0.0) tmp67 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp65 & xmask, other=0.0) tmp68 = tmp66 + tmp67 tmp69 = tl.full(tmp68.shape, 0.0, tmp68.dtype) tmp70 = tl.where(tmp65, tmp68, tmp69) tmp71 = tl.load(in_out_ptr0 + x2, tmp64 & xmask, other=0.0) tmp72 = tl.where(tmp15, tmp70, tmp71) tmp73 = tl.full(tmp72.shape, 0.0, tmp72.dtype) tmp74 = tl.where(tmp64, tmp72, tmp73) tmp75 = tl.load(in_out_ptr0 + x2, tmp63 & xmask, other=0.0) tmp76 = tl.where(tmp13, tmp74, tmp75) tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype) tmp78 = tl.where(tmp63, tmp76, tmp77) tmp79 = tmp13 & tmp62 tmp80 = tmp15 & tmp79 tmp81 = tl.load(in_out_ptr0 + x2, tmp80 & xmask, other=0.0) tmp82 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp80 & xmask, other=0.0) tmp83 = tmp81 + tmp82 tmp84 = tl.full(tmp83.shape, 0.0, tmp83.dtype) tmp85 = tl.where(tmp80, tmp83, tmp84) tmp86 = tl.load(in_out_ptr0 + x2, tmp79 & xmask, other=0.0) tmp87 = tl.where(tmp15, tmp85, tmp86) tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype) tmp89 = tl.where(tmp79, tmp87, tmp88) tmp90 = tl.load(in_out_ptr0 + x2, tmp62 & xmask, other=0.0) tmp91 = tl.where(tmp13, tmp89, tmp90) tmp92 = tl.where(tmp15, tmp78, tmp91) tmp93 = tl.full(tmp92.shape, 0.0, tmp92.dtype) tmp94 = tl.where(tmp62, tmp92, tmp93) tmp95 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp63 & xmask, other=0.0) tmp96 = tmp75 + tmp95 tmp97 = tl.full(tmp96.shape, 0.0, tmp96.dtype) tmp98 = tl.where(tmp63, tmp96, tmp97) tmp99 = tl.where(tmp15, tmp98, tmp90) tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype) tmp101 = tl.where(tmp62, tmp99, tmp100) tmp102 = tl.load(in_out_ptr0 + x2, tmp5 & xmask, other=0.0) tmp103 = tl.where(tmp13, tmp101, tmp102) tmp104 = tl.where(tmp13, tmp94, tmp103) tmp105 = tl.where(tmp9, tmp61, tmp104) tmp106 = tl.full(tmp105.shape, 0.0, tmp105.dtype) tmp107 = tl.where(tmp5, tmp105, tmp106) tmp108 = tmp15 & tmp13 tmp109 = tmp13 & tmp108 tmp110 = tmp15 & tmp109 tmp111 = tl.load(in_out_ptr0 + x2, tmp110 & xmask, other=0.0) tmp112 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp110 & xmask, other=0.0) tmp113 = tmp111 + tmp112 tmp114 = tl.full(tmp113.shape, 0.0, tmp113.dtype) tmp115 = tl.where(tmp110, tmp113, tmp114) tmp116 = tl.load(in_out_ptr0 + x2, tmp109 & xmask, other=0.0) tmp117 = tl.where(tmp15, tmp115, tmp116) tmp118 = tl.full(tmp117.shape, 0.0, tmp117.dtype) tmp119 = tl.where(tmp109, tmp117, tmp118) tmp120 = tl.load(in_out_ptr0 + x2, tmp108 & xmask, other=0.0) tmp121 = tl.where(tmp13, tmp119, tmp120) tmp122 = tl.full(tmp121.shape, 0.0, tmp121.dtype) tmp123 = tl.where(tmp108, tmp121, tmp122) tmp124 = tmp13 & tmp13 tmp125 = tmp15 & tmp124 tmp126 = tl.load(in_out_ptr0 + x2, tmp125 & xmask, other=0.0) tmp127 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp125 & xmask, other=0.0) tmp128 = tmp126 + tmp127 tmp129 = tl.full(tmp128.shape, 0.0, tmp128.dtype) tmp130 = tl.where(tmp125, tmp128, tmp129) tmp131 = tl.load(in_out_ptr0 + x2, tmp124 & xmask, other=0.0) tmp132 = tl.where(tmp15, tmp130, tmp131) tmp133 = tl.full(tmp132.shape, 0.0, tmp132.dtype) tmp134 = tl.where(tmp124, tmp132, tmp133) tmp135 = tl.load(in_out_ptr0 + x2, tmp13 & xmask, other=0.0) tmp136 = tl.where(tmp13, tmp134, tmp135) tmp137 = tl.where(tmp15, tmp123, tmp136) tmp138 = tl.full(tmp137.shape, 0.0, tmp137.dtype) tmp139 = tl.where(tmp13, tmp137, tmp138) tmp140 = tl.load(in_ptr1 + (84 + x0 + 4 * x1), tmp108 & xmask, other=0.0) tmp141 = tmp120 + tmp140 tmp142 = tl.full(tmp141.shape, 0.0, tmp141.dtype) tmp143 = tl.where(tmp108, tmp141, tmp142) tmp144 = tl.where(tmp15, tmp143, tmp135) tmp145 = tl.full(tmp144.shape, 0.0, tmp144.dtype) tmp146 = tl.where(tmp13, tmp144, tmp145) tmp148 = tl.where(tmp13, tmp146, tmp147) tmp149 = tl.where(tmp13, tmp139, tmp148) tmp150 = tl.where(tmp5, tmp107, tmp149) tmp151 = tl.where(tmp5, tmp6, tmp150) tmp152 = tmp7 >= tmp1 tmp153 = tmp7 < tmp3 tmp154 = tmp152 & tmp153 tmp155 = tmp154 & tmp5 tmp156 = tmp5 & tmp155 tmp157 = tmp7 >= tmp8 tmp158 = tmp7 < tmp1 tmp159 = tmp157 & tmp158 tmp160 = tmp159 & tmp156 tmp161 = tmp5 & tmp160 tmp162 = tmp159 & tmp161 tmp163 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp162 & xmask, other=0.0) tmp164 = tmp151 + tmp163 tmp165 = tl.full(tmp164.shape, 0.0, tmp164.dtype) tmp166 = tl.where(tmp162, tmp164, tmp165) tmp167 = tl.where(tmp159, tmp166, tmp151) tmp168 = tl.full(tmp167.shape, 0.0, tmp167.dtype) tmp169 = tl.where(tmp161, tmp167, tmp168) tmp170 = tl.where(tmp5, tmp169, tmp151) tmp171 = tl.full(tmp170.shape, 0.0, tmp170.dtype) tmp172 = tl.where(tmp160, tmp170, tmp171) tmp173 = tmp5 & tmp156 tmp174 = tmp159 & tmp173 tmp175 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp174 & xmask, other=0.0) tmp176 = tmp151 + tmp175 tmp177 = tl.full(tmp176.shape, 0.0, tmp176.dtype) tmp178 = tl.where(tmp174, tmp176, tmp177) tmp179 = tl.where(tmp159, tmp178, tmp151) tmp180 = tl.full(tmp179.shape, 0.0, tmp179.dtype) tmp181 = tl.where(tmp173, tmp179, tmp180) tmp182 = tl.where(tmp5, tmp181, tmp151) tmp183 = tl.where(tmp159, tmp172, tmp182) tmp184 = tl.full(tmp183.shape, 0.0, tmp183.dtype) tmp185 = tl.where(tmp156, tmp183, tmp184) tmp186 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp160 & xmask, other=0.0) tmp187 = tmp151 + tmp186 tmp188 = tl.full(tmp187.shape, 0.0, tmp187.dtype) tmp189 = tl.where(tmp160, tmp187, tmp188) tmp190 = tl.where(tmp159, tmp189, tmp151) tmp191 = tl.full(tmp190.shape, 0.0, tmp190.dtype) tmp192 = tl.where(tmp156, tmp190, tmp191) tmp193 = tl.where(tmp5, tmp192, tmp151) tmp194 = tl.where(tmp5, tmp185, tmp193) tmp195 = tl.load(in_ptr1 + (120 + x0 + 4 * x1), tmp155 & xmask, other=0.0) tmp196 = tmp194 + tmp195 tmp197 = tl.full(tmp196.shape, 0.0, tmp196.dtype) tmp198 = tl.where(tmp155, tmp196, tmp197) tmp199 = tmp5 & tmp5 tmp200 = tmp159 & tmp199 tmp201 = tmp5 & tmp200 tmp202 = tmp159 & tmp201 tmp203 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp202 & xmask, other=0.0) tmp204 = tmp151 + tmp203 tmp205 = tl.full(tmp204.shape, 0.0, tmp204.dtype) tmp206 = tl.where(tmp202, tmp204, tmp205) tmp207 = tl.where(tmp159, tmp206, tmp151) tmp208 = tl.full(tmp207.shape, 0.0, tmp207.dtype) tmp209 = tl.where(tmp201, tmp207, tmp208) tmp210 = tl.where(tmp5, tmp209, tmp151) tmp211 = tl.full(tmp210.shape, 0.0, tmp210.dtype) tmp212 = tl.where(tmp200, tmp210, tmp211) tmp213 = tmp5 & tmp199 tmp214 = tmp159 & tmp213 tmp215 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp214 & xmask, other=0.0) tmp216 = tmp151 + tmp215 tmp217 = tl.full(tmp216.shape, 0.0, tmp216.dtype) tmp218 = tl.where(tmp214, tmp216, tmp217) tmp219 = tl.where(tmp159, tmp218, tmp151) tmp220 = tl.full(tmp219.shape, 0.0, tmp219.dtype) tmp221 = tl.where(tmp213, tmp219, tmp220) tmp222 = tl.where(tmp5, tmp221, tmp151) tmp223 = tl.where(tmp159, tmp212, tmp222) tmp224 = tl.full(tmp223.shape, 0.0, tmp223.dtype) tmp225 = tl.where(tmp199, tmp223, tmp224) tmp226 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp200 & xmask, other=0.0) tmp227 = tmp151 + tmp226 tmp228 = tl.full(tmp227.shape, 0.0, tmp227.dtype) tmp229 = tl.where(tmp200, tmp227, tmp228) tmp230 = tl.where(tmp159, tmp229, tmp151) tmp231 = tl.full(tmp230.shape, 0.0, tmp230.dtype) tmp232 = tl.where(tmp199, tmp230, tmp231) tmp233 = tl.where(tmp5, tmp232, tmp151) tmp234 = tl.where(tmp5, tmp225, tmp233) tmp235 = tl.where(tmp154, tmp198, tmp234) tmp236 = tl.full(tmp235.shape, 0.0, tmp235.dtype) tmp237 = tl.where(tmp5, tmp235, tmp236) tmp238 = tmp159 & tmp5 tmp239 = tmp5 & tmp238 tmp240 = tmp159 & tmp239 tmp241 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp240 & xmask, other=0.0) tmp242 = tmp151 + tmp241 tmp243 = tl.full(tmp242.shape, 0.0, tmp242.dtype) tmp244 = tl.where(tmp240, tmp242, tmp243) tmp245 = tl.where(tmp159, tmp244, tmp151) tmp246 = tl.full(tmp245.shape, 0.0, tmp245.dtype) tmp247 = tl.where(tmp239, tmp245, tmp246) tmp248 = tl.where(tmp5, tmp247, tmp151) tmp249 = tl.full(tmp248.shape, 0.0, tmp248.dtype) tmp250 = tl.where(tmp238, tmp248, tmp249) tmp251 = tl.where(tmp159, tmp250, tmp233) tmp252 = tl.full(tmp251.shape, 0.0, tmp251.dtype) tmp253 = tl.where(tmp5, tmp251, tmp252) tmp254 = tl.load(in_ptr1 + (108 + x0 + 4 * x1), tmp238 & xmask, other=0.0) tmp255 = tmp151 + tmp254 tmp256 = tl.full(tmp255.shape, 0.0, tmp255.dtype) tmp257 = tl.where(tmp238, tmp255, tmp256) tmp258 = tl.where(tmp159, tmp257, tmp151) tmp259 = tl.full(tmp258.shape, 0.0, tmp258.dtype) tmp260 = tl.where(tmp5, tmp258, tmp259) tmp261 = tl.where(tmp5, tmp260, tmp151) tmp262 = tl.where(tmp5, tmp253, tmp261) tmp263 = tl.where(tmp5, tmp237, tmp262) tl.store(in_out_ptr0 + x2, tmp263, xmask) @triton.jit def triton_poi_fused_add_7(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 % 16 x1 = xindex // 16 x2 = xindex tmp198 = tl.load(in_ptr0 + (192 + x2), xmask) tmp0 = x0 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = 12 + x1 tmp4 = tl.full([1], 8, tl.int64) tmp5 = tmp3 >= tmp4 tmp6 = tl.full([1], 12, tl.int64) tmp7 = tmp3 < tmp6 tmp8 = tmp5 & tmp7 tmp9 = tmp8 & tmp2 tmp10 = tmp0 >= tmp6 tmp11 = tmp10 & tmp9 tmp12 = tmp8 & tmp11 tmp13 = tmp10 & tmp12 tmp14 = tmp8 & tmp13 tmp15 = tmp0 >= tmp4 tmp16 = tmp0 < tmp6 tmp17 = tmp15 & tmp16 tmp18 = tmp17 & tmp14 tmp19 = tl.load(in_ptr0 + (192 + x2), tmp18 & xmask, other=0.0) tmp20 = tl.load(in_ptr0 + (192 + x2), tmp14 & xmask, other=0.0) tmp21 = tl.where(tmp17, tmp19, tmp20) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp14, tmp21, tmp22) tmp24 = tl.load(in_ptr0 + (192 + x2), tmp13 & xmask, other=0.0) tmp25 = tl.where(tmp8, tmp23, tmp24) tmp26 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp13 & xmask, other=0.0) tmp27 = tmp25 + tmp26 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp13, tmp27, tmp28) tmp30 = tmp8 & tmp12 tmp31 = tmp17 & tmp30 tmp32 = tl.load(in_ptr0 + (192 + x2), tmp31 & xmask, other=0.0) tmp33 = tl.load(in_ptr0 + (192 + x2), tmp30 & xmask, other=0.0) tmp34 = tl.where(tmp17, tmp32, tmp33) tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp30, tmp34, tmp35) tmp37 = tl.load(in_ptr0 + (192 + x2), tmp12 & xmask, other=0.0) tmp38 = tl.where(tmp8, tmp36, tmp37) tmp39 = tl.where(tmp10, tmp29, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp12, tmp39, tmp40) tmp42 = tmp17 & tmp12 tmp43 = tl.load(in_ptr0 + (192 + x2), tmp42 & xmask, other=0.0) tmp44 = tl.where(tmp17, tmp43, tmp37) tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype) tmp46 = tl.where(tmp12, tmp44, tmp45) tmp47 = tl.load(in_ptr0 + (192 + x2), tmp11 & xmask, other=0.0) tmp48 = tl.where(tmp8, tmp46, tmp47) tmp49 = tl.where(tmp8, tmp41, tmp48) tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp11, tmp49, tmp50) tmp52 = tmp8 & tmp9 tmp53 = tmp10 & tmp52 tmp54 = tmp8 & tmp53 tmp55 = tmp17 & tmp54 tmp56 = tl.load(in_ptr0 + (192 + x2), tmp55 & xmask, other=0.0) tmp57 = tl.load(in_ptr0 + (192 + x2), tmp54 & xmask, other=0.0) tmp58 = tl.where(tmp17, tmp56, tmp57) tmp59 = tl.full(tmp58.shape, 0.0, tmp58.dtype) tmp60 = tl.where(tmp54, tmp58, tmp59) tmp61 = tl.load(in_ptr0 + (192 + x2), tmp53 & xmask, other=0.0) tmp62 = tl.where(tmp8, tmp60, tmp61) tmp63 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp53 & xmask, other=0.0) tmp64 = tmp62 + tmp63 tmp65 = tl.full(tmp64.shape, 0.0, tmp64.dtype) tmp66 = tl.where(tmp53, tmp64, tmp65) tmp67 = tmp8 & tmp52 tmp68 = tmp17 & tmp67 tmp69 = tl.load(in_ptr0 + (192 + x2), tmp68 & xmask, other=0.0) tmp70 = tl.load(in_ptr0 + (192 + x2), tmp67 & xmask, other=0.0) tmp71 = tl.where(tmp17, tmp69, tmp70) tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype) tmp73 = tl.where(tmp67, tmp71, tmp72) tmp74 = tl.load(in_ptr0 + (192 + x2), tmp52 & xmask, other=0.0) tmp75 = tl.where(tmp8, tmp73, tmp74) tmp76 = tl.where(tmp10, tmp66, tmp75) tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype) tmp78 = tl.where(tmp52, tmp76, tmp77) tmp79 = tmp17 & tmp52 tmp80 = tl.load(in_ptr0 + (192 + x2), tmp79 & xmask, other=0.0) tmp81 = tl.where(tmp17, tmp80, tmp74) tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype) tmp83 = tl.where(tmp52, tmp81, tmp82) tmp84 = tl.load(in_ptr0 + (192 + x2), tmp9 & xmask, other=0.0) tmp85 = tl.where(tmp8, tmp83, tmp84) tmp86 = tl.where(tmp8, tmp78, tmp85) tmp87 = tl.where(tmp10, tmp51, tmp86) tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype) tmp89 = tl.where(tmp9, tmp87, tmp88) tmp90 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp11 & xmask, other=0.0) tmp91 = tmp48 + tmp90 tmp92 = tl.full(tmp91.shape, 0.0, tmp91.dtype) tmp93 = tl.where(tmp11, tmp91, tmp92) tmp94 = tl.where(tmp10, tmp93, tmp85) tmp95 = tl.full(tmp94.shape, 0.0, tmp94.dtype) tmp96 = tl.where(tmp9, tmp94, tmp95) tmp97 = tmp17 & tmp9 tmp98 = tl.load(in_ptr0 + (192 + x2), tmp97 & xmask, other=0.0) tmp99 = tl.where(tmp17, tmp98, tmp84) tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype) tmp101 = tl.where(tmp9, tmp99, tmp100) tmp102 = tl.load(in_ptr0 + (192 + x2), tmp2 & xmask, other=0.0) tmp103 = tl.where(tmp8, tmp101, tmp102) tmp104 = tl.where(tmp8, tmp96, tmp103) tmp105 = tl.where(tmp8, tmp89, tmp104) tmp106 = tl.load(in_ptr1 + (192 + x0 + 4 * x1), tmp2 & xmask, other=0.0) tmp107 = tmp105 + tmp106 tmp108 = tl.full(tmp107.shape, 0.0, tmp107.dtype) tmp109 = tl.where(tmp2, tmp107, tmp108) tmp110 = tmp10 & tmp8 tmp111 = tmp8 & tmp110 tmp112 = tmp10 & tmp111 tmp113 = tmp8 & tmp112 tmp114 = tmp17 & tmp113 tmp115 = tl.load(in_ptr0 + (192 + x2), tmp114 & xmask, other=0.0) tmp116 = tl.load(in_ptr0 + (192 + x2), tmp113 & xmask, other=0.0) tmp117 = tl.where(tmp17, tmp115, tmp116) tmp118 = tl.full(tmp117.shape, 0.0, tmp117.dtype) tmp119 = tl.where(tmp113, tmp117, tmp118) tmp120 = tl.load(in_ptr0 + (192 + x2), tmp112 & xmask, other=0.0) tmp121 = tl.where(tmp8, tmp119, tmp120) tmp122 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp112 & xmask, other=0.0) tmp123 = tmp121 + tmp122 tmp124 = tl.full(tmp123.shape, 0.0, tmp123.dtype) tmp125 = tl.where(tmp112, tmp123, tmp124) tmp126 = tmp8 & tmp111 tmp127 = tmp17 & tmp126 tmp128 = tl.load(in_ptr0 + (192 + x2), tmp127 & xmask, other=0.0) tmp129 = tl.load(in_ptr0 + (192 + x2), tmp126 & xmask, other=0.0) tmp130 = tl.where(tmp17, tmp128, tmp129) tmp131 = tl.full(tmp130.shape, 0.0, tmp130.dtype) tmp132 = tl.where(tmp126, tmp130, tmp131) tmp133 = tl.load(in_ptr0 + (192 + x2), tmp111 & xmask, other=0.0) tmp134 = tl.where(tmp8, tmp132, tmp133) tmp135 = tl.where(tmp10, tmp125, tmp134) tmp136 = tl.full(tmp135.shape, 0.0, tmp135.dtype) tmp137 = tl.where(tmp111, tmp135, tmp136) tmp138 = tmp17 & tmp111 tmp139 = tl.load(in_ptr0 + (192 + x2), tmp138 & xmask, other=0.0) tmp140 = tl.where(tmp17, tmp139, tmp133) tmp141 = tl.full(tmp140.shape, 0.0, tmp140.dtype) tmp142 = tl.where(tmp111, tmp140, tmp141) tmp143 = tl.load(in_ptr0 + (192 + x2), tmp110 & xmask, other=0.0) tmp144 = tl.where(tmp8, tmp142, tmp143) tmp145 = tl.where(tmp8, tmp137, tmp144) tmp146 = tl.full(tmp145.shape, 0.0, tmp145.dtype) tmp147 = tl.where(tmp110, tmp145, tmp146) tmp148 = tmp8 & tmp8 tmp149 = tmp10 & tmp148 tmp150 = tmp8 & tmp149 tmp151 = tmp17 & tmp150 tmp152 = tl.load(in_ptr0 + (192 + x2), tmp151 & xmask, other=0.0) tmp153 = tl.load(in_ptr0 + (192 + x2), tmp150 & xmask, other=0.0) tmp154 = tl.where(tmp17, tmp152, tmp153) tmp155 = tl.full(tmp154.shape, 0.0, tmp154.dtype) tmp156 = tl.where(tmp150, tmp154, tmp155) tmp157 = tl.load(in_ptr0 + (192 + x2), tmp149 & xmask, other=0.0) tmp158 = tl.where(tmp8, tmp156, tmp157) tmp159 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp149 & xmask, other=0.0) tmp160 = tmp158 + tmp159 tmp161 = tl.full(tmp160.shape, 0.0, tmp160.dtype) tmp162 = tl.where(tmp149, tmp160, tmp161) tmp163 = tmp8 & tmp148 tmp164 = tmp17 & tmp163 tmp165 = tl.load(in_ptr0 + (192 + x2), tmp164 & xmask, other=0.0) tmp166 = tl.load(in_ptr0 + (192 + x2), tmp163 & xmask, other=0.0) tmp167 = tl.where(tmp17, tmp165, tmp166) tmp168 = tl.full(tmp167.shape, 0.0, tmp167.dtype) tmp169 = tl.where(tmp163, tmp167, tmp168) tmp170 = tl.load(in_ptr0 + (192 + x2), tmp148 & xmask, other=0.0) tmp171 = tl.where(tmp8, tmp169, tmp170) tmp172 = tl.where(tmp10, tmp162, tmp171) tmp173 = tl.full(tmp172.shape, 0.0, tmp172.dtype) tmp174 = tl.where(tmp148, tmp172, tmp173) tmp175 = tmp17 & tmp148 tmp176 = tl.load(in_ptr0 + (192 + x2), tmp175 & xmask, other=0.0) tmp177 = tl.where(tmp17, tmp176, tmp170) tmp178 = tl.full(tmp177.shape, 0.0, tmp177.dtype) tmp179 = tl.where(tmp148, tmp177, tmp178) tmp180 = tl.load(in_ptr0 + (192 + x2), tmp8 & xmask, other=0.0) tmp181 = tl.where(tmp8, tmp179, tmp180) tmp182 = tl.where(tmp8, tmp174, tmp181) tmp183 = tl.where(tmp10, tmp147, tmp182) tmp184 = tl.full(tmp183.shape, 0.0, tmp183.dtype) tmp185 = tl.where(tmp8, tmp183, tmp184) tmp186 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp110 & xmask, other=0.0) tmp187 = tmp144 + tmp186 tmp188 = tl.full(tmp187.shape, 0.0, tmp187.dtype) tmp189 = tl.where(tmp110, tmp187, tmp188) tmp190 = tl.where(tmp10, tmp189, tmp181) tmp191 = tl.full(tmp190.shape, 0.0, tmp190.dtype) tmp192 = tl.where(tmp8, tmp190, tmp191) tmp193 = tmp17 & tmp8 tmp194 = tl.load(in_ptr0 + (192 + x2), tmp193 & xmask, other=0.0) tmp195 = tl.where(tmp17, tmp194, tmp180) tmp196 = tl.full(tmp195.shape, 0.0, tmp195.dtype) tmp197 = tl.where(tmp8, tmp195, tmp196) tmp199 = tl.where(tmp8, tmp197, tmp198) tmp200 = tl.where(tmp8, tmp192, tmp199) tmp201 = tl.where(tmp8, tmp185, tmp200) tmp202 = tl.where(tmp2, tmp109, tmp201) tmp203 = tmp3 >= tmp6 tmp203 & tmp2 tmp205 = tl.where(tmp203, tmp202, tmp105) tmp206 = tl.full(tmp205.shape, 0.0, tmp205.dtype) tmp207 = tl.where(tmp2, tmp205, tmp206) tmp208 = tl.where(tmp203, tmp202, tmp201) tmp209 = tl.where(tmp2, tmp207, tmp208) tl.store(out_ptr0 + x2, tmp202, xmask) tl.store(out_ptr1 + x2, tmp209, xmask) @triton.jit def triton_poi_fused_add_8(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 x2 = xindex x0 = xindex % 16 tmp102 = tl.load(in_out_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 12, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.load(in_ptr0 + (-192 + x2), tmp2 & xmask, other=0.0) tmp4 = tl.load(in_ptr1 + (-192 + x2), tmp2 & xmask, other=0.0) tmp5 = tl.full([1], 8, tl.int64) tmp6 = tmp0 >= tmp5 tmp7 = tmp0 < tmp1 tmp8 = tmp6 & tmp7 tmp9 = x0 tmp10 = tmp9 >= tmp1 tmp11 = tmp10 & tmp8 tmp12 = tmp8 & tmp11 tmp13 = tmp10 & tmp12 tmp14 = tmp8 & tmp13 tmp15 = tmp9 >= tmp5 tmp16 = tmp9 < tmp1 tmp17 = tmp15 & tmp16 tmp18 = tmp17 & tmp14 tmp19 = tl.load(in_out_ptr0 + x2, tmp18 & xmask, other=0.0) tmp20 = tl.load(in_out_ptr0 + x2, tmp14 & xmask, other=0.0) tmp21 = tl.where(tmp17, tmp19, tmp20) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp14, tmp21, tmp22) tmp24 = tl.load(in_out_ptr0 + x2, tmp13 & xmask, other=0.0) tmp25 = tl.where(tmp8, tmp23, tmp24) tmp26 = tl.load(in_ptr2 + (132 + x0 + 4 * x1), tmp13 & xmask, other=0.0) tmp27 = tmp25 + tmp26 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp13, tmp27, tmp28) tmp30 = tmp8 & tmp12 tmp31 = tmp17 & tmp30 tmp32 = tl.load(in_out_ptr0 + x2, tmp31 & xmask, other=0.0) tmp33 = tl.load(in_out_ptr0 + x2, tmp30 & xmask, other=0.0) tmp34 = tl.where(tmp17, tmp32, tmp33) tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp30, tmp34, tmp35) tmp37 = tl.load(in_out_ptr0 + x2, tmp12 & xmask, other=0.0) tmp38 = tl.where(tmp8, tmp36, tmp37) tmp39 = tl.where(tmp10, tmp29, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp12, tmp39, tmp40) tmp42 = tmp17 & tmp12 tmp43 = tl.load(in_out_ptr0 + x2, tmp42 & xmask, other=0.0) tmp44 = tl.where(tmp17, tmp43, tmp37) tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype) tmp46 = tl.where(tmp12, tmp44, tmp45) tmp47 = tl.load(in_out_ptr0 + x2, tmp11 & xmask, other=0.0) tmp48 = tl.where(tmp8, tmp46, tmp47) tmp49 = tl.where(tmp8, tmp41, tmp48) tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype) tmp51 = tl.where(tmp11, tmp49, tmp50) tmp52 = tmp8 & tmp8 tmp53 = tmp10 & tmp52 tmp54 = tmp8 & tmp53 tmp55 = tmp17 & tmp54 tmp56 = tl.load(in_out_ptr0 + x2, tmp55 & xmask, other=0.0) tmp57 = tl.load(in_out_ptr0 + x2, tmp54 & xmask, other=0.0) tmp58 = tl.where(tmp17, tmp56, tmp57) tmp59 = tl.full(tmp58.shape, 0.0, tmp58.dtype) tmp60 = tl.where(tmp54, tmp58, tmp59) tmp61 = tl.load(in_out_ptr0 + x2, tmp53 & xmask, other=0.0) tmp62 = tl.where(tmp8, tmp60, tmp61) tmp63 = tl.load(in_ptr2 + (132 + x0 + 4 * x1), tmp53 & xmask, other=0.0) tmp64 = tmp62 + tmp63 tmp65 = tl.full(tmp64.shape, 0.0, tmp64.dtype) tmp66 = tl.where(tmp53, tmp64, tmp65) tmp67 = tmp8 & tmp52 tmp68 = tmp17 & tmp67 tmp69 = tl.load(in_out_ptr0 + x2, tmp68 & xmask, other=0.0) tmp70 = tl.load(in_out_ptr0 + x2, tmp67 & xmask, other=0.0) tmp71 = tl.where(tmp17, tmp69, tmp70) tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype) tmp73 = tl.where(tmp67, tmp71, tmp72) tmp74 = tl.load(in_out_ptr0 + x2, tmp52 & xmask, other=0.0) tmp75 = tl.where(tmp8, tmp73, tmp74) tmp76 = tl.where(tmp10, tmp66, tmp75) tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype) tmp78 = tl.where(tmp52, tmp76, tmp77) tmp79 = tmp17 & tmp52 tmp80 = tl.load(in_out_ptr0 + x2, tmp79 & xmask, other=0.0) tmp81 = tl.where(tmp17, tmp80, tmp74) tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype) tmp83 = tl.where(tmp52, tmp81, tmp82) tmp84 = tl.load(in_out_ptr0 + x2, tmp8 & xmask, other=0.0) tmp85 = tl.where(tmp8, tmp83, tmp84) tmp86 = tl.where(tmp8, tmp78, tmp85) tmp87 = tl.where(tmp10, tmp51, tmp86) tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype) tmp89 = tl.where(tmp8, tmp87, tmp88) tmp90 = tl.load(in_ptr2 + (132 + x0 + 4 * x1), tmp11 & xmask, other=0.0) tmp91 = tmp48 + tmp90 tmp92 = tl.full(tmp91.shape, 0.0, tmp91.dtype) tmp93 = tl.where(tmp11, tmp91, tmp92) tmp94 = tl.where(tmp10, tmp93, tmp85) tmp95 = tl.full(tmp94.shape, 0.0, tmp94.dtype) tmp96 = tl.where(tmp8, tmp94, tmp95) tmp97 = tmp17 & tmp8 tmp98 = tl.load(in_out_ptr0 + x2, tmp97 & xmask, other=0.0) tmp99 = tl.where(tmp17, tmp98, tmp84) tmp100 = tl.full(tmp99.shape, 0.0, tmp99.dtype) tmp101 = tl.where(tmp8, tmp99, tmp100) tmp103 = tl.where(tmp8, tmp101, tmp102) tmp104 = tl.where(tmp8, tmp96, tmp103) tmp105 = tl.where(tmp8, tmp89, tmp104) tmp106 = tl.where(tmp2, tmp4, tmp105) tmp107 = tl.where(tmp2, tmp3, tmp106) tl.store(in_out_ptr0 + x2, tmp107, xmask) @triton.jit def triton_poi_fused_9(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 x1 = xindex // 16 x2 = xindex tmp259 = tl.load(in_ptr0 + (192 + x2), xmask) tmp0 = x0 tmp1 = tl.full([1], 8, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 12, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = 12 + x1 tmp7 = tmp6 >= tmp3 tmp8 = tmp7 & tmp5 tmp9 = tmp5 & tmp8 tmp10 = tmp7 & tmp9 tmp11 = tl.full([1], 4, tl.int64) tmp12 = tmp0 >= tmp11 tmp13 = tmp0 < tmp1 tmp14 = tmp12 & tmp13 tmp15 = tmp14 & tmp10 tmp16 = tmp7 & tmp15 tmp17 = tmp14 & tmp16 tmp18 = tl.load(in_ptr0 + (192 + x2), tmp17 & xmask, other=0.0) tmp19 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp17 & xmask, other=0.0) tmp20 = tmp18 + tmp19 tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp17, tmp20, tmp21) tmp23 = tl.load(in_ptr0 + (192 + x2), tmp16 & xmask, other=0.0) tmp24 = tl.where(tmp14, tmp22, tmp23) tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp16, tmp24, tmp25) tmp27 = tl.load(in_ptr0 + (192 + x2), tmp15 & xmask, other=0.0) tmp28 = tl.where(tmp7, tmp26, tmp27) tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype) tmp30 = tl.where(tmp15, tmp28, tmp29) tmp31 = tmp7 & tmp10 tmp32 = tmp14 & tmp31 tmp33 = tl.load(in_ptr0 + (192 + x2), tmp32 & xmask, other=0.0) tmp34 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp32 & xmask, other=0.0) tmp35 = tmp33 + tmp34 tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype) tmp37 = tl.where(tmp32, tmp35, tmp36) tmp38 = tl.load(in_ptr0 + (192 + x2), tmp31 & xmask, other=0.0) tmp39 = tl.where(tmp14, tmp37, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp31, tmp39, tmp40) tmp42 = tl.load(in_ptr0 + (192 + x2), tmp10 & xmask, other=0.0) tmp43 = tl.where(tmp7, tmp41, tmp42) tmp44 = tl.where(tmp14, tmp30, tmp43) tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype) tmp46 = tl.where(tmp10, tmp44, tmp45) tmp47 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp15 & xmask, other=0.0) tmp48 = tmp27 + tmp47 tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype) tmp50 = tl.where(tmp15, tmp48, tmp49) tmp51 = tl.where(tmp14, tmp50, tmp42) tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp10, tmp51, tmp52) tmp54 = tl.load(in_ptr0 + (192 + x2), tmp9 & xmask, other=0.0) tmp55 = tl.where(tmp7, tmp53, tmp54) tmp56 = tl.where(tmp7, tmp46, tmp55) tmp57 = tl.load(in_ptr1 + (216 + x0 + 4 * x1), tmp9 & xmask, other=0.0) tmp58 = tmp56 + tmp57 tmp59 = tl.full(tmp58.shape, 0.0, tmp58.dtype) tmp60 = tl.where(tmp9, tmp58, tmp59) tmp61 = tmp7 & tmp8 tmp62 = tmp14 & tmp61 tmp63 = tmp7 & tmp62 tmp64 = tmp14 & tmp63 tmp65 = tl.load(in_ptr0 + (192 + x2), tmp64 & xmask, other=0.0) tmp66 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp64 & xmask, other=0.0) tmp67 = tmp65 + tmp66 tmp68 = tl.full(tmp67.shape, 0.0, tmp67.dtype) tmp69 = tl.where(tmp64, tmp67, tmp68) tmp70 = tl.load(in_ptr0 + (192 + x2), tmp63 & xmask, other=0.0) tmp71 = tl.where(tmp14, tmp69, tmp70) tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype) tmp73 = tl.where(tmp63, tmp71, tmp72) tmp74 = tl.load(in_ptr0 + (192 + x2), tmp62 & xmask, other=0.0) tmp75 = tl.where(tmp7, tmp73, tmp74) tmp76 = tl.full(tmp75.shape, 0.0, tmp75.dtype) tmp77 = tl.where(tmp62, tmp75, tmp76) tmp78 = tmp7 & tmp61 tmp79 = tmp14 & tmp78 tmp80 = tl.load(in_ptr0 + (192 + x2), tmp79 & xmask, other=0.0) tmp81 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp79 & xmask, other=0.0) tmp82 = tmp80 + tmp81 tmp83 = tl.full(tmp82.shape, 0.0, tmp82.dtype) tmp84 = tl.where(tmp79, tmp82, tmp83) tmp85 = tl.load(in_ptr0 + (192 + x2), tmp78 & xmask, other=0.0) tmp86 = tl.where(tmp14, tmp84, tmp85) tmp87 = tl.full(tmp86.shape, 0.0, tmp86.dtype) tmp88 = tl.where(tmp78, tmp86, tmp87) tmp89 = tl.load(in_ptr0 + (192 + x2), tmp61 & xmask, other=0.0) tmp90 = tl.where(tmp7, tmp88, tmp89) tmp91 = tl.where(tmp14, tmp77, tmp90) tmp92 = tl.full(tmp91.shape, 0.0, tmp91.dtype) tmp93 = tl.where(tmp61, tmp91, tmp92) tmp94 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp62 & xmask, other=0.0) tmp95 = tmp74 + tmp94 tmp96 = tl.full(tmp95.shape, 0.0, tmp95.dtype) tmp97 = tl.where(tmp62, tmp95, tmp96) tmp98 = tl.where(tmp14, tmp97, tmp89) tmp99 = tl.full(tmp98.shape, 0.0, tmp98.dtype) tmp100 = tl.where(tmp61, tmp98, tmp99) tmp101 = tl.load(in_ptr0 + (192 + x2), tmp8 & xmask, other=0.0) tmp102 = tl.where(tmp7, tmp100, tmp101) tmp103 = tl.where(tmp7, tmp93, tmp102) tmp104 = tl.where(tmp5, tmp60, tmp103) tmp105 = tl.full(tmp104.shape, 0.0, tmp104.dtype) tmp106 = tl.where(tmp8, tmp104, tmp105) tmp107 = tmp14 & tmp8 tmp108 = tmp7 & tmp107 tmp109 = tmp14 & tmp108 tmp110 = tl.load(in_ptr0 + (192 + x2), tmp109 & xmask, other=0.0) tmp111 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp109 & xmask, other=0.0) tmp112 = tmp110 + tmp111 tmp113 = tl.full(tmp112.shape, 0.0, tmp112.dtype) tmp114 = tl.where(tmp109, tmp112, tmp113) tmp115 = tl.load(in_ptr0 + (192 + x2), tmp108 & xmask, other=0.0) tmp116 = tl.where(tmp14, tmp114, tmp115) tmp117 = tl.full(tmp116.shape, 0.0, tmp116.dtype) tmp118 = tl.where(tmp108, tmp116, tmp117) tmp119 = tl.load(in_ptr0 + (192 + x2), tmp107 & xmask, other=0.0) tmp120 = tl.where(tmp7, tmp118, tmp119) tmp121 = tl.full(tmp120.shape, 0.0, tmp120.dtype) tmp122 = tl.where(tmp107, tmp120, tmp121) tmp123 = tl.where(tmp14, tmp122, tmp102) tmp124 = tl.full(tmp123.shape, 0.0, tmp123.dtype) tmp125 = tl.where(tmp8, tmp123, tmp124) tmp126 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp107 & xmask, other=0.0) tmp127 = tmp119 + tmp126 tmp128 = tl.full(tmp127.shape, 0.0, tmp127.dtype) tmp129 = tl.where(tmp107, tmp127, tmp128) tmp130 = tl.where(tmp14, tmp129, tmp101) tmp131 = tl.full(tmp130.shape, 0.0, tmp130.dtype) tmp132 = tl.where(tmp8, tmp130, tmp131) tmp133 = tl.load(in_ptr0 + (192 + x2), tmp5 & xmask, other=0.0) tmp134 = tl.where(tmp7, tmp132, tmp133) tmp135 = tl.where(tmp7, tmp125, tmp134) tmp136 = tl.where(tmp7, tmp106, tmp135) tmp137 = tl.full(tmp136.shape, 0.0, tmp136.dtype) tmp138 = tl.where(tmp5, tmp136, tmp137) tmp139 = tmp5 & tmp7 tmp140 = tmp7 & tmp139 tmp141 = tmp14 & tmp140 tmp142 = tmp7 & tmp141 tmp143 = tmp14 & tmp142 tmp144 = tl.load(in_ptr0 + (192 + x2), tmp143 & xmask, other=0.0) tmp145 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp143 & xmask, other=0.0) tmp146 = tmp144 + tmp145 tmp147 = tl.full(tmp146.shape, 0.0, tmp146.dtype) tmp148 = tl.where(tmp143, tmp146, tmp147) tmp149 = tl.load(in_ptr0 + (192 + x2), tmp142 & xmask, other=0.0) tmp150 = tl.where(tmp14, tmp148, tmp149) tmp151 = tl.full(tmp150.shape, 0.0, tmp150.dtype) tmp152 = tl.where(tmp142, tmp150, tmp151) tmp153 = tl.load(in_ptr0 + (192 + x2), tmp141 & xmask, other=0.0) tmp154 = tl.where(tmp7, tmp152, tmp153) tmp155 = tl.full(tmp154.shape, 0.0, tmp154.dtype) tmp156 = tl.where(tmp141, tmp154, tmp155) tmp157 = tmp7 & tmp140 tmp158 = tmp14 & tmp157 tmp159 = tl.load(in_ptr0 + (192 + x2), tmp158 & xmask, other=0.0) tmp160 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp158 & xmask, other=0.0) tmp161 = tmp159 + tmp160 tmp162 = tl.full(tmp161.shape, 0.0, tmp161.dtype) tmp163 = tl.where(tmp158, tmp161, tmp162) tmp164 = tl.load(in_ptr0 + (192 + x2), tmp157 & xmask, other=0.0) tmp165 = tl.where(tmp14, tmp163, tmp164) tmp166 = tl.full(tmp165.shape, 0.0, tmp165.dtype) tmp167 = tl.where(tmp157, tmp165, tmp166) tmp168 = tl.load(in_ptr0 + (192 + x2), tmp140 & xmask, other=0.0) tmp169 = tl.where(tmp7, tmp167, tmp168) tmp170 = tl.where(tmp14, tmp156, tmp169) tmp171 = tl.full(tmp170.shape, 0.0, tmp170.dtype) tmp172 = tl.where(tmp140, tmp170, tmp171) tmp173 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp141 & xmask, other=0.0) tmp174 = tmp153 + tmp173 tmp175 = tl.full(tmp174.shape, 0.0, tmp174.dtype) tmp176 = tl.where(tmp141, tmp174, tmp175) tmp177 = tl.where(tmp14, tmp176, tmp168) tmp178 = tl.full(tmp177.shape, 0.0, tmp177.dtype) tmp179 = tl.where(tmp140, tmp177, tmp178) tmp180 = tl.load(in_ptr0 + (192 + x2), tmp139 & xmask, other=0.0) tmp181 = tl.where(tmp7, tmp179, tmp180) tmp182 = tl.where(tmp7, tmp172, tmp181) tmp183 = tl.load(in_ptr1 + (216 + x0 + 4 * x1), tmp139 & xmask, other=0.0) tmp184 = tmp182 + tmp183 tmp185 = tl.full(tmp184.shape, 0.0, tmp184.dtype) tmp186 = tl.where(tmp139, tmp184, tmp185) tmp187 = tmp7 & tmp7 tmp188 = tmp14 & tmp187 tmp189 = tmp7 & tmp188 tmp190 = tmp14 & tmp189 tmp191 = tl.load(in_ptr0 + (192 + x2), tmp190 & xmask, other=0.0) tmp192 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp190 & xmask, other=0.0) tmp193 = tmp191 + tmp192 tmp194 = tl.full(tmp193.shape, 0.0, tmp193.dtype) tmp195 = tl.where(tmp190, tmp193, tmp194) tmp196 = tl.load(in_ptr0 + (192 + x2), tmp189 & xmask, other=0.0) tmp197 = tl.where(tmp14, tmp195, tmp196) tmp198 = tl.full(tmp197.shape, 0.0, tmp197.dtype) tmp199 = tl.where(tmp189, tmp197, tmp198) tmp200 = tl.load(in_ptr0 + (192 + x2), tmp188 & xmask, other=0.0) tmp201 = tl.where(tmp7, tmp199, tmp200) tmp202 = tl.full(tmp201.shape, 0.0, tmp201.dtype) tmp203 = tl.where(tmp188, tmp201, tmp202) tmp204 = tmp7 & tmp187 tmp205 = tmp14 & tmp204 tmp206 = tl.load(in_ptr0 + (192 + x2), tmp205 & xmask, other=0.0) tmp207 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp205 & xmask, other=0.0) tmp208 = tmp206 + tmp207 tmp209 = tl.full(tmp208.shape, 0.0, tmp208.dtype) tmp210 = tl.where(tmp205, tmp208, tmp209) tmp211 = tl.load(in_ptr0 + (192 + x2), tmp204 & xmask, other=0.0) tmp212 = tl.where(tmp14, tmp210, tmp211) tmp213 = tl.full(tmp212.shape, 0.0, tmp212.dtype) tmp214 = tl.where(tmp204, tmp212, tmp213) tmp215 = tl.load(in_ptr0 + (192 + x2), tmp187 & xmask, other=0.0) tmp216 = tl.where(tmp7, tmp214, tmp215) tmp217 = tl.where(tmp14, tmp203, tmp216) tmp218 = tl.full(tmp217.shape, 0.0, tmp217.dtype) tmp219 = tl.where(tmp187, tmp217, tmp218) tmp220 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp188 & xmask, other=0.0) tmp221 = tmp200 + tmp220 tmp222 = tl.full(tmp221.shape, 0.0, tmp221.dtype) tmp223 = tl.where(tmp188, tmp221, tmp222) tmp224 = tl.where(tmp14, tmp223, tmp215) tmp225 = tl.full(tmp224.shape, 0.0, tmp224.dtype) tmp226 = tl.where(tmp187, tmp224, tmp225) tmp227 = tl.load(in_ptr0 + (192 + x2), tmp7 & xmask, other=0.0) tmp228 = tl.where(tmp7, tmp226, tmp227) tmp229 = tl.where(tmp7, tmp219, tmp228) tmp230 = tl.where(tmp5, tmp186, tmp229) tmp231 = tl.full(tmp230.shape, 0.0, tmp230.dtype) tmp232 = tl.where(tmp7, tmp230, tmp231) tmp233 = tmp14 & tmp7 tmp234 = tmp7 & tmp233 tmp235 = tmp14 & tmp234 tmp236 = tl.load(in_ptr0 + (192 + x2), tmp235 & xmask, other=0.0) tmp237 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp235 & xmask, other=0.0) tmp238 = tmp236 + tmp237 tmp239 = tl.full(tmp238.shape, 0.0, tmp238.dtype) tmp240 = tl.where(tmp235, tmp238, tmp239) tmp241 = tl.load(in_ptr0 + (192 + x2), tmp234 & xmask, other=0.0) tmp242 = tl.where(tmp14, tmp240, tmp241) tmp243 = tl.full(tmp242.shape, 0.0, tmp242.dtype) tmp244 = tl.where(tmp234, tmp242, tmp243) tmp245 = tl.load(in_ptr0 + (192 + x2), tmp233 & xmask, other=0.0) tmp246 = tl.where(tmp7, tmp244, tmp245) tmp247 = tl.full(tmp246.shape, 0.0, tmp246.dtype) tmp248 = tl.where(tmp233, tmp246, tmp247) tmp249 = tl.where(tmp14, tmp248, tmp228) tmp250 = tl.full(tmp249.shape, 0.0, tmp249.dtype) tmp251 = tl.where(tmp7, tmp249, tmp250) tmp252 = tl.load(in_ptr1 + (204 + x0 + 4 * x1), tmp233 & xmask, other=0.0) tmp253 = tmp245 + tmp252 tmp254 = tl.full(tmp253.shape, 0.0, tmp253.dtype) tmp255 = tl.where(tmp233, tmp253, tmp254) tmp256 = tl.where(tmp14, tmp255, tmp227) tmp257 = tl.full(tmp256.shape, 0.0, tmp256.dtype) tmp258 = tl.where(tmp7, tmp256, tmp257) tmp260 = tl.where(tmp7, tmp258, tmp259) tmp261 = tl.where(tmp7, tmp251, tmp260) tmp262 = tl.where(tmp7, tmp232, tmp261) tmp263 = tl.where(tmp5, tmp138, tmp262) tl.store(out_ptr0 + x2, tmp263, xmask) @triton.jit def triton_poi_fused_add_10(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 x1 = xindex // 16 x2 = xindex x0 = xindex % 16 tmp133 = tl.load(in_out_ptr0 + x2, xmask) tmp0 = x1 tmp1 = tl.full([1], 12, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.load(in_ptr0 + (-192 + x2), tmp2 & xmask, other=0.0) tmp4 = x0 tmp5 = tl.full([1], 8, tl.int64) tmp6 = tmp4 >= tmp5 tmp7 = tmp4 < tmp1 tmp8 = tmp6 & tmp7 tmp9 = tmp8 & tmp2 tmp10 = tmp2 & tmp9 tmp11 = tl.full([1], 4, tl.int64) tmp12 = tmp4 >= tmp11 tmp13 = tmp4 < tmp5 tmp14 = tmp12 & tmp13 tmp15 = tmp14 & tmp10 tmp16 = tmp2 & tmp15 tmp17 = tmp14 & tmp16 tmp18 = tl.load(in_out_ptr0 + x2, tmp17 & xmask, other=0.0) tmp19 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp17 & xmask, other=0.0) tmp20 = tmp18 + tmp19 tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp17, tmp20, tmp21) tmp23 = tl.load(in_out_ptr0 + x2, tmp16 & xmask, other=0.0) tmp24 = tl.where(tmp14, tmp22, tmp23) tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp16, tmp24, tmp25) tmp27 = tl.load(in_out_ptr0 + x2, tmp15 & xmask, other=0.0) tmp28 = tl.where(tmp2, tmp26, tmp27) tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype) tmp30 = tl.where(tmp15, tmp28, tmp29) tmp31 = tmp2 & tmp10 tmp32 = tmp14 & tmp31 tmp33 = tl.load(in_out_ptr0 + x2, tmp32 & xmask, other=0.0) tmp34 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp32 & xmask, other=0.0) tmp35 = tmp33 + tmp34 tmp36 = tl.full(tmp35.shape, 0.0, tmp35.dtype) tmp37 = tl.where(tmp32, tmp35, tmp36) tmp38 = tl.load(in_out_ptr0 + x2, tmp31 & xmask, other=0.0) tmp39 = tl.where(tmp14, tmp37, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp31, tmp39, tmp40) tmp42 = tl.load(in_out_ptr0 + x2, tmp10 & xmask, other=0.0) tmp43 = tl.where(tmp2, tmp41, tmp42) tmp44 = tl.where(tmp14, tmp30, tmp43) tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype) tmp46 = tl.where(tmp10, tmp44, tmp45) tmp47 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp15 & xmask, other=0.0) tmp48 = tmp27 + tmp47 tmp49 = tl.full(tmp48.shape, 0.0, tmp48.dtype) tmp50 = tl.where(tmp15, tmp48, tmp49) tmp51 = tl.where(tmp14, tmp50, tmp42) tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp10, tmp51, tmp52) tmp54 = tl.load(in_out_ptr0 + x2, tmp9 & xmask, other=0.0) tmp55 = tl.where(tmp2, tmp53, tmp54) tmp56 = tl.where(tmp2, tmp46, tmp55) tmp57 = tl.load(in_ptr1 + (168 + x0 + 4 * x1), tmp9 & xmask, other=0.0) tmp58 = tmp56 + tmp57 tmp59 = tl.full(tmp58.shape, 0.0, tmp58.dtype) tmp60 = tl.where(tmp9, tmp58, tmp59) tmp61 = tmp2 & tmp2 tmp62 = tmp14 & tmp61 tmp63 = tmp2 & tmp62 tmp64 = tmp14 & tmp63 tmp65 = tl.load(in_out_ptr0 + x2, tmp64 & xmask, other=0.0) tmp66 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp64 & xmask, other=0.0) tmp67 = tmp65 + tmp66 tmp68 = tl.full(tmp67.shape, 0.0, tmp67.dtype) tmp69 = tl.where(tmp64, tmp67, tmp68) tmp70 = tl.load(in_out_ptr0 + x2, tmp63 & xmask, other=0.0) tmp71 = tl.where(tmp14, tmp69, tmp70) tmp72 = tl.full(tmp71.shape, 0.0, tmp71.dtype) tmp73 = tl.where(tmp63, tmp71, tmp72) tmp74 = tl.load(in_out_ptr0 + x2, tmp62 & xmask, other=0.0) tmp75 = tl.where(tmp2, tmp73, tmp74) tmp76 = tl.full(tmp75.shape, 0.0, tmp75.dtype) tmp77 = tl.where(tmp62, tmp75, tmp76) tmp78 = tmp2 & tmp61 tmp79 = tmp14 & tmp78 tmp80 = tl.load(in_out_ptr0 + x2, tmp79 & xmask, other=0.0) tmp81 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp79 & xmask, other=0.0) tmp82 = tmp80 + tmp81 tmp83 = tl.full(tmp82.shape, 0.0, tmp82.dtype) tmp84 = tl.where(tmp79, tmp82, tmp83) tmp85 = tl.load(in_out_ptr0 + x2, tmp78 & xmask, other=0.0) tmp86 = tl.where(tmp14, tmp84, tmp85) tmp87 = tl.full(tmp86.shape, 0.0, tmp86.dtype) tmp88 = tl.where(tmp78, tmp86, tmp87) tmp89 = tl.load(in_out_ptr0 + x2, tmp61 & xmask, other=0.0) tmp90 = tl.where(tmp2, tmp88, tmp89) tmp91 = tl.where(tmp14, tmp77, tmp90) tmp92 = tl.full(tmp91.shape, 0.0, tmp91.dtype) tmp93 = tl.where(tmp61, tmp91, tmp92) tmp94 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp62 & xmask, other=0.0) tmp95 = tmp74 + tmp94 tmp96 = tl.full(tmp95.shape, 0.0, tmp95.dtype) tmp97 = tl.where(tmp62, tmp95, tmp96) tmp98 = tl.where(tmp14, tmp97, tmp89) tmp99 = tl.full(tmp98.shape, 0.0, tmp98.dtype) tmp100 = tl.where(tmp61, tmp98, tmp99) tmp101 = tl.load(in_out_ptr0 + x2, tmp2 & xmask, other=0.0) tmp102 = tl.where(tmp2, tmp100, tmp101) tmp103 = tl.where(tmp2, tmp93, tmp102) tmp104 = tl.where(tmp8, tmp60, tmp103) tmp105 = tl.full(tmp104.shape, 0.0, tmp104.dtype) tmp106 = tl.where(tmp2, tmp104, tmp105) tmp107 = tmp14 & tmp2 tmp108 = tmp2 & tmp107 tmp109 = tmp14 & tmp108 tmp110 = tl.load(in_out_ptr0 + x2, tmp109 & xmask, other=0.0) tmp111 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp109 & xmask, other=0.0) tmp112 = tmp110 + tmp111 tmp113 = tl.full(tmp112.shape, 0.0, tmp112.dtype) tmp114 = tl.where(tmp109, tmp112, tmp113) tmp115 = tl.load(in_out_ptr0 + x2, tmp108 & xmask, other=0.0) tmp116 = tl.where(tmp14, tmp114, tmp115) tmp117 = tl.full(tmp116.shape, 0.0, tmp116.dtype) tmp118 = tl.where(tmp108, tmp116, tmp117) tmp119 = tl.load(in_out_ptr0 + x2, tmp107 & xmask, other=0.0) tmp120 = tl.where(tmp2, tmp118, tmp119) tmp121 = tl.full(tmp120.shape, 0.0, tmp120.dtype) tmp122 = tl.where(tmp107, tmp120, tmp121) tmp123 = tl.where(tmp14, tmp122, tmp102) tmp124 = tl.full(tmp123.shape, 0.0, tmp123.dtype) tmp125 = tl.where(tmp2, tmp123, tmp124) tmp126 = tl.load(in_ptr1 + (156 + x0 + 4 * x1), tmp107 & xmask, other=0.0) tmp127 = tmp119 + tmp126 tmp128 = tl.full(tmp127.shape, 0.0, tmp127.dtype) tmp129 = tl.where(tmp107, tmp127, tmp128) tmp130 = tl.where(tmp14, tmp129, tmp101) tmp131 = tl.full(tmp130.shape, 0.0, tmp130.dtype) tmp132 = tl.where(tmp2, tmp130, tmp131) tmp134 = tl.where(tmp2, tmp132, tmp133) tmp135 = tl.where(tmp2, tmp125, tmp134) tmp136 = tl.where(tmp2, tmp106, tmp135) tmp137 = tl.where(tmp2, tmp3, tmp136) tmp138 = tmp4 >= tmp1 tmp139 = tmp138 & tmp2 tmp140 = tmp2 & tmp139 tmp141 = tmp138 & tmp140 tmp142 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp141 & xmask, other=0.0) tmp143 = tmp137 + tmp142 tmp144 = tl.full(tmp143.shape, 0.0, tmp143.dtype) tmp145 = tl.where(tmp141, tmp143, tmp144) tmp146 = tl.where(tmp138, tmp145, tmp137) tmp147 = tl.full(tmp146.shape, 0.0, tmp146.dtype) tmp148 = tl.where(tmp140, tmp146, tmp147) tmp149 = tl.where(tmp2, tmp148, tmp137) tmp150 = tl.full(tmp149.shape, 0.0, tmp149.dtype) tmp151 = tl.where(tmp139, tmp149, tmp150) tmp152 = tmp138 & tmp61 tmp153 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp152 & xmask, other=0.0) tmp154 = tmp137 + tmp153 tmp155 = tl.full(tmp154.shape, 0.0, tmp154.dtype) tmp156 = tl.where(tmp152, tmp154, tmp155) tmp157 = tl.where(tmp138, tmp156, tmp137) tmp158 = tl.full(tmp157.shape, 0.0, tmp157.dtype) tmp159 = tl.where(tmp61, tmp157, tmp158) tmp160 = tl.where(tmp2, tmp159, tmp137) tmp161 = tl.where(tmp138, tmp151, tmp160) tmp162 = tl.full(tmp161.shape, 0.0, tmp161.dtype) tmp163 = tl.where(tmp2, tmp161, tmp162) tmp164 = tl.load(in_ptr1 + (180 + x0 + 4 * x1), tmp139 & xmask, other=0.0) tmp165 = tmp137 + tmp164 tmp166 = tl.full(tmp165.shape, 0.0, tmp165.dtype) tmp167 = tl.where(tmp139, tmp165, tmp166) tmp168 = tl.where(tmp138, tmp167, tmp137) tmp169 = tl.full(tmp168.shape, 0.0, tmp168.dtype) tmp170 = tl.where(tmp2, tmp168, tmp169) tmp171 = tl.where(tmp2, tmp170, tmp137) tmp172 = tl.where(tmp2, tmp163, tmp171) tl.store(in_out_ptr0 + x2, tmp172, 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_add_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32) triton_poi_fused_1[grid(64)](buf0, arg0_1, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 buf2 = empty_strided_cuda((16, 16), (16, 1), torch.float32) buf3 = buf2 del buf2 triton_poi_fused_add_zeros_2[grid(256)](buf3, buf1, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf4 = buf1 del buf1 buf5 = empty_strided_cuda((4, 16), (16, 1), torch.float32) triton_poi_fused_add_3[grid(64)](buf3, arg0_1, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = buf3 del buf3 triton_poi_fused_add_4[grid(256)](buf6, buf5, buf4, arg0_1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf7 = buf5 del buf5 triton_poi_fused_5[grid(64)](buf6, arg0_1, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = buf6 del buf6 buf9 = buf8 del buf8 triton_poi_fused_add_6[grid(256)](buf9, buf7, arg0_1, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf10 = buf7 del buf7 buf11 = buf4 del buf4 triton_poi_fused_add_7[grid(64)](buf9, arg0_1, buf10, buf11, 64, XBLOCK=64, num_warps=1, num_stages=1) buf12 = buf9 del buf9 triton_poi_fused_add_8[grid(256)](buf12, buf11, buf10, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf10 buf13 = buf11 del buf11 triton_poi_fused_9[grid(64)](buf12, arg0_1, buf13, 64, XBLOCK=64, num_warps=1, num_stages=1) buf14 = buf12 del buf12 buf15 = buf14 del buf14 triton_poi_fused_add_10[grid(256)](buf15, buf13, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del buf13 return buf15, class Truncation2DNew(torch.nn.Module): """ A module merging the last two dimensions, merging coarse scale in grid of dimensions -4, -3 and finer resolution in dimensions -2, -1 to one fine grained grid with two dimensions less. """ def __init__(self): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
kpoeppel/pytorch_probgraph
Truncation2D
false
15,972
[ "BSD-3-Clause" ]
47
b78595ab03bbe92595ad2f6b35f5dd8bf84d6da0
https://github.com/kpoeppel/pytorch_probgraph/tree/b78595ab03bbe92595ad2f6b35f5dd8bf84d6da0
PAM_Module
import torch import torch.utils.data from torch import nn class PAM_Module(nn.Module): """ Position attention module""" def __init__(self, in_dim): super(PAM_Module, self).__init__() self.chanel_in = in_dim self.query_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.key_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.value_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.W = nn.Conv2d(in_channels=in_dim // 4, out_channels=in_dim, kernel_size=1) self.softmax = nn.Softmax(dim=-1) def forward(self, x): """ inputs : x : input feature maps( B X C X H X W) returns : out : attention value + input feature attention: B X (HxW) X (HxW) """ m_batchsize, _C, height, width = x.size() proj_query = self.query_conv(x).view(m_batchsize, -1, width * height ).permute(0, 2, 1) proj_key = self.key_conv(x).view(m_batchsize, -1, width * height) energy = torch.bmm(proj_query, proj_key) attention = self.softmax(energy) proj_value = self.value_conv(x).view(m_batchsize, -1, width * height) out = torch.bmm(proj_value, attention.permute(0, 2, 1)) out = out.view(m_batchsize, -1, height, width) out = self.W(out) out = out + x return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_per_fused__softmax_1(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tmp6 / tmp10 tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) 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, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_7, (1,), (1,)) assert_size_stride(primals_8, (4, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 1, 4, 4), (16, 16, 4, 1)) buf1 = extern_kernels.convolution(primals_1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 1, 4, 4), (16, 16, 4, 1)) buf2 = reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 1, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(64)](buf2, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf3 = reinterpret_tensor(buf1, (4, 1, 4, 4), (16, 1, 4, 1), 0) del buf1 triton_poi_fused_convolution_0[grid(64)](buf3, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf2, (4, 16, 1), (16, 1, 0), 0), reinterpret_tensor(buf3, (4, 1, 16), (16, 0, 1), 0), out=buf4) buf7 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) triton_per_fused__softmax_1[grid(64)](buf4, buf7, 64, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf4 buf8 = extern_kernels.convolution(primals_1, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 1, 4, 4), (16, 16, 4, 1)) buf9 = reinterpret_tensor(buf8, (4, 1, 4, 4), (16, 1, 4, 1), 0) del buf8 triton_poi_fused_convolution_0[grid(64)](buf9, primals_7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf9, (4, 1, 16), (16, 0, 1), 0), reinterpret_tensor(buf7, (4, 16, 16), (256, 1, 16), 0), out =buf10) buf11 = extern_kernels.convolution(reinterpret_tensor(buf10, (4, 1, 4, 4), (16, 16, 4, 1), 0), primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 4, 4, 4), (64, 16, 4, 1)) buf12 = buf11 del buf11 triton_poi_fused_add_convolution_2[grid(256)](buf12, primals_9, primals_1, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 return (buf12, primals_1, primals_2, primals_4, primals_6, primals_8, buf7, reinterpret_tensor(buf10, (4, 1, 4, 4), (16, 16, 4, 1), 0), reinterpret_tensor(buf9, (4, 16, 1), (16, 1, 16), 0), reinterpret_tensor(buf2, (4, 1, 16), (16, 16, 1), 0), reinterpret_tensor(buf3, (4, 16, 1), (16, 1, 16), 0)) class PAM_ModuleNew(nn.Module): """ Position attention module""" def __init__(self, in_dim): super(PAM_ModuleNew, self).__init__() self.chanel_in = in_dim self.query_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.key_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.value_conv = nn.Conv2d(in_channels=in_dim, out_channels=in_dim // 4, kernel_size=1) self.W = nn.Conv2d(in_channels=in_dim // 4, out_channels=in_dim, kernel_size=1) self.softmax = nn.Softmax(dim=-1) def forward(self, input_0): primals_2 = self.query_conv.weight primals_3 = self.query_conv.bias primals_4 = self.key_conv.weight primals_5 = self.key_conv.bias primals_6 = self.value_conv.weight primals_7 = self.value_conv.bias primals_8 = self.W.weight primals_9 = self.W.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]
lzrobots/dgmn
PAM_Module
false
15,973
[ "MIT" ]
54
515476b5c6a07dcc3b7a4d2243c541377624bb33
https://github.com/lzrobots/dgmn/tree/515476b5c6a07dcc3b7a4d2243c541377624bb33
resnet_block
import torch import torch.nn as nn import torch.nn.functional as F class resnet_block(nn.Module): def __init__(self, ef_dim): super(resnet_block, self).__init__() self.ef_dim = ef_dim self.conv_1 = nn.Conv3d(self.ef_dim, self.ef_dim, 1, stride=1, padding=0, bias=True) self.conv_2 = nn.Conv3d(self.ef_dim, self.ef_dim, 1, stride=1, padding=0, bias=True) def forward(self, input): output = self.conv_1(input) output = F.leaky_relu(output, negative_slope=0.01, inplace=True) output = self.conv_2(output) output = output + input output = F.leaky_relu(output, negative_slope=0.01, inplace=True) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'ef_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_leaky_relu_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 x1 = xindex // 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_add_leaky_relu_leaky_relu_backward_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp7 = 0.01 tmp8 = tmp4 * tmp7 tmp9 = tl.where(tmp6, tmp4, tmp8) tmp10 = tmp9 > tmp5 tl.store(in_out_ptr0 + x2, tmp9, xmask) tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 1, 1, 1), (4, 1, 1, 1, 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_3, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0), primals_1, stride=(1, 1, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1)) buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_leaky_relu_leaky_relu_backward_0[grid(256)](buf1, primals_2, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (1, 4, 4, 4, 4), (0, 64, 16, 4, 1), 0), primals_4, stride=(1, 1, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1)) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_leaky_relu_leaky_relu_backward_1[grid(256)](buf3, primals_5, primals_3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_4, reinterpret_tensor(primals_3, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0), reinterpret_tensor(buf1, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0), buf4, buf5 class resnet_blockNew(nn.Module): def __init__(self, ef_dim): super(resnet_blockNew, self).__init__() self.ef_dim = ef_dim self.conv_1 = nn.Conv3d(self.ef_dim, self.ef_dim, 1, stride=1, padding=0, bias=True) self.conv_2 = nn.Conv3d(self.ef_dim, self.ef_dim, 1, stride=1, padding=0, bias=True) def forward(self, input_0): primals_1 = self.conv_1.weight primals_2 = self.conv_1.bias primals_4 = self.conv_2.weight primals_5 = self.conv_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
lwkobe/NMC
resnet_block
false
15,974
[ "MIT" ]
74
a59c187d35b2f929ea3a94fc2b434061d7f7993a
https://github.com/lwkobe/NMC/tree/a59c187d35b2f929ea3a94fc2b434061d7f7993a
StableLayerNorm
import torch from torch import nn class StableLayerNorm(nn.Module): def __init__(self, dim): super().__init__() self.norm = nn.LayerNorm(dim) def forward(self, x): x = x / x.amax(dim=-1, keepdim=True).detach() return self.norm(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_amax_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 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_native_layer_norm_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(in_out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_amax_div_0[grid(256)](primals_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](buf0, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf0 del buf0 triton_poi_fused_native_layer_norm_2[grid(256)](buf3, buf1, buf2, primals_2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del buf2 del primals_2 del primals_3 return buf3, primals_1 class StableLayerNormNew(nn.Module): def __init__(self, dim): super().__init__() self.norm = nn.LayerNorm(dim) def forward(self, input_0): primals_2 = self.norm.weight primals_3 = self.norm.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lucidrains/nuwa-pytorch
StableLayerNorm
false
15,975
[ "MIT" ]
310
bf1f3dc1126ba0a24a280bd7412a8082e5013b46
https://github.com/lucidrains/nuwa-pytorch/tree/bf1f3dc1126ba0a24a280bd7412a8082e5013b46
DDM_Decoder
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class DDM_Decoder(torch.nn.Module): def __init__(self, obs_space, dim): super(DDM_Decoder, self).__init__() self.fc = nn.Linear(dim, 32 * 3 * 3) self.linear1 = nn.Linear(32 * 3 * 3, dim) self.linear2 = nn.Linear(dim, obs_space) self.apply(weights_init) self.train() def forward(self, inputs): x = F.elu(self.fc(inputs)) x = F.elu(self.linear1(x)) x = self.linear2(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'obs_space': 4, 'dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, None) @triton.jit def triton_poi_fused_elu_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (288, 4), (4, 1)) assert_size_stride(primals_2, (288,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 288), (288, 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, 288), (288, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 288), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 288), (4608, 1152, 288, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(18432)](buf0, buf1, 18432, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 288), (288, 1), 0), reinterpret_tensor(primals_4, (288, 4), (1, 288), 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_elu_1[grid(256)](buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 288), (288, 1), 0 ), buf2, reinterpret_tensor(buf3, (64, 4), (4, 1), 0 ), primals_6, primals_4 def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class DDM_DecoderNew(torch.nn.Module): def __init__(self, obs_space, dim): super(DDM_DecoderNew, self).__init__() self.fc = nn.Linear(dim, 32 * 3 * 3) self.linear1 = nn.Linear(32 * 3 * 3, dim) self.linear2 = nn.Linear(dim, obs_space) self.apply(weights_init) self.train() def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_4 = self.linear1.weight primals_5 = self.linear1.bias primals_6 = self.linear2.weight primals_7 = self.linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
lysuk96/rl_representations
DDM_Decoder
false
15,976
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
FinalTanh
import torch class FinalTanh(torch.nn.Module): def __init__(self, input_channels, hidden_channels, hidden_hidden_channels, num_hidden_layers): super(FinalTanh, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.hidden_hidden_channels = hidden_hidden_channels self.num_hidden_layers = num_hidden_layers self.linear_in = torch.nn.Linear(hidden_channels, hidden_hidden_channels) self.linears = torch.nn.ModuleList(torch.nn.Linear( hidden_hidden_channels, hidden_hidden_channels) for _ in range( num_hidden_layers - 1)) self.linear_out = torch.nn.Linear(hidden_hidden_channels, input_channels * hidden_channels) def extra_repr(self): return ( 'input_channels: {}, hidden_channels: {}, hidden_hidden_channels: {}, num_hidden_layers: {}' .format(self.input_channels, self.hidden_channels, self. hidden_hidden_channels, self.num_hidden_layers)) def forward(self, z): z = self.linear_in(z) z = z.relu() for linear in self.linears: z = linear(z) z = z.relu() z = self.linear_out(z).view(*z.shape[:-1], self.hidden_channels, self.input_channels) z = z.tanh() return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4, 'hidden_hidden_channels': 4, 'num_hidden_layers': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice 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_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16,), (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 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)](buf1, primals_2, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ) del buf2 triton_poi_fused_tanh_1[grid(1024)](buf3, primals_5, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), buf3, primals_4, buf4 class FinalTanhNew(torch.nn.Module): def __init__(self, input_channels, hidden_channels, hidden_hidden_channels, num_hidden_layers): super(FinalTanhNew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.hidden_hidden_channels = hidden_hidden_channels self.num_hidden_layers = num_hidden_layers self.linear_in = torch.nn.Linear(hidden_channels, hidden_hidden_channels) self.linears = torch.nn.ModuleList(torch.nn.Linear( hidden_hidden_channels, hidden_hidden_channels) for _ in range( num_hidden_layers - 1)) self.linear_out = torch.nn.Linear(hidden_hidden_channels, input_channels * hidden_channels) def extra_repr(self): return ( 'input_channels: {}, hidden_channels: {}, hidden_hidden_channels: {}, num_hidden_layers: {}' .format(self.input_channels, self.hidden_channels, self. hidden_hidden_channels, self.num_hidden_layers)) def forward(self, input_0): primals_1 = self.linear_in.weight primals_2 = self.linear_in.bias primals_4 = self.linear_out.weight primals_5 = self.linear_out.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
lysuk96/rl_representations
FinalTanh
false
15,977
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
MixLoss
import torch import torch.nn as nn import torch.nn.functional as F from itertools import filterfalse def flatten_binary_scores(scores, labels, ignore=None): """ Flattens predictions in the batch (binary case) Remove labels equal to 'ignore' """ scores = scores.view(-1) labels = labels.view(-1) if ignore is None: return scores, labels valid = labels != ignore vscores = scores[valid] vlabels = labels[valid] return vscores, vlabels def lovasz_grad(gt_sorted): """ Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper """ p = len(gt_sorted) gts = gt_sorted.sum() intersection = gts - gt_sorted.float().cumsum(0) union = gts + (1 - gt_sorted).float().cumsum(0) jaccard = 1.0 - intersection / union if p > 1: jaccard[1:p] = jaccard[1:p] - jaccard[0:-1] return jaccard def isnan(x): return x != x def mean(l, ignore_nan=True, empty=0): """ nanmean compatible with generators. """ l = iter(l) if ignore_nan: l = filterfalse(isnan, l) try: n = 1 acc = next(l) except StopIteration: if empty == 'raise': raise ValueError('Empty mean') return empty for n, v in enumerate(l, 2): acc += v if n == 1: return acc return acc / n class DiceLoss(nn.Module): def __init__(self, smooth=1.0, eps=1e-07): super(DiceLoss, self).__init__() self.smooth = smooth self.eps = eps def forward(self, output, target): output = torch.sigmoid(output) if torch.sum(target) == 0: output = 1.0 - output target = 1.0 - target return 1.0 - (2 * torch.sum(output * target) + self.smooth) / ( torch.sum(output) + torch.sum(target) + self.smooth + self.eps) class FocalLoss(nn.Module): def __init__(self, gamma=2, eps=1e-07): super(FocalLoss, self).__init__() self.gamma = gamma self.eps = eps def forward(self, logit, target): prob = torch.sigmoid(logit) prob = prob.clamp(self.eps, 1.0 - self.eps) loss = -1 * target * torch.log(prob) loss = loss * (1 - logit) ** self.gamma return loss.sum() class LovaszHinge(nn.Module): def __init__(self, activation=lambda x: F.elu(x, inplace=True) + 1.0, per_image=True, ignore=None): super(LovaszHinge, self).__init__() self.activation = activation self.per_image = per_image self.ignore = ignore def lovasz_hinge_flat(self, logits, labels): """ Binary Lovasz hinge loss logits: [P] Variable, logits at each prediction (between -\\infty and +\\infty) labels: [P] Tensor, binary ground truth labels (0 or 1) ignore: label to ignore """ if len(labels) == 0: return logits.sum() * 0.0 signs = 2.0 * labels.float() - 1.0 errors = 1.0 - logits * signs errors_sorted, perm = torch.sort(errors, dim=0, descending=True) perm = perm.data gt_sorted = labels[perm] grad = lovasz_grad(gt_sorted) loss = torch.dot(self.activation(errors_sorted), grad) return loss def forward(self, logits, labels): if self.per_image: loss = mean(self.lovasz_hinge_flat(*flatten_binary_scores(log. unsqueeze(0), lab.unsqueeze(0), self.ignore)) for log, lab in zip(logits, labels)) else: loss = self.lovasz_hinge_flat(*flatten_binary_scores(logits, labels, self.ignore)) return loss class MixLoss(nn.Module): def __init__(self, bce_w=1.0, dice_w=0.0, focal_w=0.0, lovasz_w=0.0, bce_kwargs={}, dice_kwargs={}, focal_kwargs={}, lovasz_kwargs={}): super(MixLoss, self).__init__() self.bce_w = bce_w self.dice_w = dice_w self.focal_w = focal_w self.lovasz_w = lovasz_w self.bce_loss = nn.BCEWithLogitsLoss(**bce_kwargs) self.dice_loss = DiceLoss(**dice_kwargs) self.focal_loss = FocalLoss(**focal_kwargs) self.lovasz_loss = LovaszHinge(**lovasz_kwargs) def forward(self, output, target): loss = 0.0 if self.bce_w: loss += self.bce_w * self.bce_loss(output, target) if self.dice_w: loss += self.dice_w * self.dice_loss(output, target) if self.focal_w: loss += self.focal_w * self.focal_loss(output, target) if self.lovasz_w: loss += self.lovasz_w * self.lovasz_loss(output, target) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.nn.functional as F from itertools import filterfalse assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_binary_cross_entropy_with_logits_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp2 * tmp3 tmp5 = 0.0 tmp6 = triton_helpers.minimum(tmp5, tmp3) tmp7 = tl_math.abs(tmp3) tmp8 = -tmp7 tmp9 = tl_math.exp(tmp8) tmp10 = libdevice.log1p(tmp9) tmp11 = tmp6 - tmp10 tmp12 = tmp4 - tmp11 tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tmp16 = 256.0 tmp17 = tmp15 / tmp16 tmp18 = tmp17 * tmp1 tmp19 = tmp18 + tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp19, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_binary_cross_entropy_with_logits_mul_0[grid(1)]( buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, def flatten_binary_scores(scores, labels, ignore=None): """ Flattens predictions in the batch (binary case) Remove labels equal to 'ignore' """ scores = scores.view(-1) labels = labels.view(-1) if ignore is None: return scores, labels valid = labels != ignore vscores = scores[valid] vlabels = labels[valid] return vscores, vlabels def lovasz_grad(gt_sorted): """ Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper """ p = len(gt_sorted) gts = gt_sorted.sum() intersection = gts - gt_sorted.float().cumsum(0) union = gts + (1 - gt_sorted).float().cumsum(0) jaccard = 1.0 - intersection / union if p > 1: jaccard[1:p] = jaccard[1:p] - jaccard[0:-1] return jaccard def isnan(x): return x != x def mean(l, ignore_nan=True, empty=0): """ nanmean compatible with generators. """ l = iter(l) if ignore_nan: l = filterfalse(isnan, l) try: n = 1 acc = next(l) except StopIteration: if empty == 'raise': raise ValueError('Empty mean') return empty for n, v in enumerate(l, 2): acc += v if n == 1: return acc return acc / n class DiceLoss(nn.Module): def __init__(self, smooth=1.0, eps=1e-07): super(DiceLoss, self).__init__() self.smooth = smooth self.eps = eps def forward(self, output, target): output = torch.sigmoid(output) if torch.sum(target) == 0: output = 1.0 - output target = 1.0 - target return 1.0 - (2 * torch.sum(output * target) + self.smooth) / ( torch.sum(output) + torch.sum(target) + self.smooth + self.eps) class FocalLoss(nn.Module): def __init__(self, gamma=2, eps=1e-07): super(FocalLoss, self).__init__() self.gamma = gamma self.eps = eps def forward(self, logit, target): prob = torch.sigmoid(logit) prob = prob.clamp(self.eps, 1.0 - self.eps) loss = -1 * target * torch.log(prob) loss = loss * (1 - logit) ** self.gamma return loss.sum() class LovaszHinge(nn.Module): def __init__(self, activation=lambda x: F.elu(x, inplace=True) + 1.0, per_image=True, ignore=None): super(LovaszHinge, self).__init__() self.activation = activation self.per_image = per_image self.ignore = ignore def lovasz_hinge_flat(self, logits, labels): """ Binary Lovasz hinge loss logits: [P] Variable, logits at each prediction (between -\\infty and +\\infty) labels: [P] Tensor, binary ground truth labels (0 or 1) ignore: label to ignore """ if len(labels) == 0: return logits.sum() * 0.0 signs = 2.0 * labels.float() - 1.0 errors = 1.0 - logits * signs errors_sorted, perm = torch.sort(errors, dim=0, descending=True) perm = perm.data gt_sorted = labels[perm] grad = lovasz_grad(gt_sorted) loss = torch.dot(self.activation(errors_sorted), grad) return loss def forward(self, logits, labels): if self.per_image: loss = mean(self.lovasz_hinge_flat(*flatten_binary_scores(log. unsqueeze(0), lab.unsqueeze(0), self.ignore)) for log, lab in zip(logits, labels)) else: loss = self.lovasz_hinge_flat(*flatten_binary_scores(logits, labels, self.ignore)) return loss class MixLossNew(nn.Module): def __init__(self, bce_w=1.0, dice_w=0.0, focal_w=0.0, lovasz_w=0.0, bce_kwargs={}, dice_kwargs={}, focal_kwargs={}, lovasz_kwargs={}): super(MixLossNew, self).__init__() self.bce_w = bce_w self.dice_w = dice_w self.focal_w = focal_w self.lovasz_w = lovasz_w self.bce_loss = nn.BCEWithLogitsLoss(**bce_kwargs) self.dice_loss = DiceLoss(**dice_kwargs) self.focal_loss = FocalLoss(**focal_kwargs) self.lovasz_loss = LovaszHinge(**lovasz_kwargs) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lyakaap/pytorch-template
MixLoss
false
15,978
[ "MIT" ]
140
eff9f0a4dd50fa49c3b949065247598d5eabc91e
https://github.com/lyakaap/pytorch-template/tree/eff9f0a4dd50fa49c3b949065247598d5eabc91e
ResidualBlockNoBN
import torch import torch.nn as nn from torch.nn import init as init from torch.nn.modules.batchnorm import _BatchNorm @torch.no_grad() def default_init_weights(module_list, scale=1, bias_fill=0, **kwargs): """Initialize network weights. Args: module_list (list[nn.Module] | nn.Module): Modules to be initialized. scale (float): Scale initialized weights, especially for residual blocks. Default: 1. bias_fill (float): The value to fill bias. Default: 0 kwargs (dict): Other arguments for initialization function. """ if not isinstance(module_list, list): module_list = [module_list] for module in module_list: for m in module.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, **kwargs) m.weight.data *= scale if m.bias is not None: m.bias.data.fill_(bias_fill) elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, **kwargs) m.weight.data *= scale if m.bias is not None: m.bias.data.fill_(bias_fill) elif isinstance(m, _BatchNorm): init.constant_(m.weight, 1) if m.bias is not None: m.bias.data.fill_(bias_fill) class ResidualBlockNoBN(nn.Module): """Residual block without BN. It has a style of: ---Conv-ReLU-Conv-+- |________________| Args: num_feat (int): Channel number of intermediate features. Default: 64. res_scale (float): Residual scale. Default: 1. pytorch_init (bool): If set to True, use pytorch default init, otherwise, use default_init_weights. Default: False. """ def __init__(self, num_feat=64, res_scale=1, pytorch_init=False): super(ResidualBlockNoBN, self).__init__() self.res_scale = res_scale self.conv1 = nn.Conv2d(num_feat, num_feat, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(num_feat, num_feat, 3, 1, 1, bias=True) self.relu = nn.ReLU(inplace=True) if not pytorch_init: default_init_weights([self.conv1, self.conv2], 0.1) def forward(self, x): identity = x out = self.conv2(self.relu(self.conv1(x))) return identity + out * self.res_scale def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch.nn import init as init from torch.nn.modules.batchnorm import _BatchNorm assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_add_convolution_mul_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_out_ptr0 + x3, None) tmp2 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp6 = tmp0 + tmp5 tl.store(in_out_ptr0 + x3, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_2, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1048576)](buf1, primals_3, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_mul_1[grid(1048576)](buf3, primals_1, primals_5, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1 @torch.no_grad() def default_init_weights(module_list, scale=1, bias_fill=0, **kwargs): """Initialize network weights. Args: module_list (list[nn.Module] | nn.Module): Modules to be initialized. scale (float): Scale initialized weights, especially for residual blocks. Default: 1. bias_fill (float): The value to fill bias. Default: 0 kwargs (dict): Other arguments for initialization function. """ if not isinstance(module_list, list): module_list = [module_list] for module in module_list: for m in module.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, **kwargs) m.weight.data *= scale if m.bias is not None: m.bias.data.fill_(bias_fill) elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, **kwargs) m.weight.data *= scale if m.bias is not None: m.bias.data.fill_(bias_fill) elif isinstance(m, _BatchNorm): init.constant_(m.weight, 1) if m.bias is not None: m.bias.data.fill_(bias_fill) class ResidualBlockNoBNNew(nn.Module): """Residual block without BN. It has a style of: ---Conv-ReLU-Conv-+- |________________| Args: num_feat (int): Channel number of intermediate features. Default: 64. res_scale (float): Residual scale. Default: 1. pytorch_init (bool): If set to True, use pytorch default init, otherwise, use default_init_weights. Default: False. """ def __init__(self, num_feat=64, res_scale=1, pytorch_init=False): super(ResidualBlockNoBNNew, self).__init__() self.res_scale = res_scale self.conv1 = nn.Conv2d(num_feat, num_feat, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(num_feat, num_feat, 3, 1, 1, bias=True) self.relu = nn.ReLU(inplace=True) if not pytorch_init: default_init_weights([self.conv1, self.conv2], 0.1) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ljzycmd/SimDeblur
ResidualBlockNoBN
false
15,979
[ "MIT" ]
190
dd2f60c41176b75c4eaf80d740f547c206aa8227
https://github.com/ljzycmd/SimDeblur/tree/dd2f60c41176b75c4eaf80d740f547c206aa8227
_GRU_ODE
import torch class _GRU_ODE(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(_GRU_ODE, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.W_r = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_z = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_h = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.U_r = torch.nn.Linear(hidden_channels, hidden_channels) self.U_z = torch.nn.Linear(hidden_channels, hidden_channels) self.U_h = torch.nn.Linear(hidden_channels, hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, x, h): r = self.W_r(x) + self.U_r(h) r = r.sigmoid() z = self.W_z(x) + self.U_z(h) z = z.sigmoid() g = self.W_h(x) + self.U_h(r * h) g = g.tanh() return (1 - z) * (g - h) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_sigmoid_sigmoid_backward_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x2, xmask) tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp5 = tl.sigmoid(tmp4) tmp7 = tmp5 * tmp6 tmp8 = 1.0 tmp9 = tmp8 - tmp5 tmp10 = tmp5 * tmp9 tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_sigmoid_sub_tanh_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr1 + x2, xmask) tmp7 = tl.load(in_ptr2 + x2, xmask) tmp8 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x2, xmask) tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp5 = tl.sigmoid(tmp4) tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp11 = libdevice.tanh(tmp10) tmp12 = 1.0 tmp13 = tmp12 - tmp5 tmp15 = tmp11 - tmp14 tmp16 = tmp13 * tmp15 tl.store(in_out_ptr0 + x2, tmp5, xmask) tl.store(in_out_ptr1 + x2, tmp11, xmask) tl.store(out_ptr0 + 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, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4, 4), (4, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf3) del primals_7 buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf5) del primals_9 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sigmoid_sigmoid_backward_0[grid(256)](buf0, buf1, primals_4, primals_5, buf6, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf7 = buf1 del buf1 extern_kernels.mm(reinterpret_tensor(buf6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf7) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf8 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 buf9 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_add_mul_rsub_sigmoid_sub_tanh_1[grid(256)](buf4, buf8, buf3, primals_8, buf7, primals_11, primals_5, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf3 del buf7 del primals_11 del primals_8 return buf9, primals_5, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), buf4, reinterpret_tensor(buf6, (64, 4), (4, 1), 0 ), buf8, primals_10, buf10 class _GRU_ODENew(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(_GRU_ODENew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.W_r = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_z = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_h = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.U_r = torch.nn.Linear(hidden_channels, hidden_channels) self.U_z = torch.nn.Linear(hidden_channels, hidden_channels) self.U_h = torch.nn.Linear(hidden_channels, hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, input_0, input_1): primals_1 = self.W_r.weight primals_3 = self.W_z.weight primals_6 = self.W_h.weight primals_7 = self.U_r.weight primals_4 = self.U_r.bias primals_9 = self.U_z.weight primals_8 = self.U_z.bias primals_10 = self.U_h.weight primals_11 = self.U_h.bias primals_2 = input_0 primals_5 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
lysuk96/rl_representations
_GRU_ODE
false
15,980
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
baseRNN_predict
import torch import numpy as np import torch.nn as nn import torch.nn.init as init def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class baseRNN_predict(nn.Module): def __init__(self, h_size, obs_dim, num_actions, context_input=False): super(baseRNN_predict, self).__init__() self.l1 = nn.Linear(h_size, 64) self.l2 = nn.Linear(64, 128) self.l3 = nn.Linear(128, obs_dim) self.apply(weights_init) def forward(self, h): h = torch.relu(self.l1(h)) h = torch.relu(self.l2(h)) obs = self.l3(h) return obs def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'h_size': 4, 'obs_dim': 4, 'num_actions': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import numpy as np import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, 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_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) 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, 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, (128, 64), (64, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (4, 128), (128, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_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 buf6 = 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, buf6, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 128), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf2 buf5 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf3, primals_5, buf5, 8192, 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, 128), (128, 1), 0), reinterpret_tensor(primals_6, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf4) del primals_7 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor( buf3, (64, 128), (128, 1), 0), primals_6, buf5, primals_4, buf6 def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class baseRNN_predictNew(nn.Module): def __init__(self, h_size, obs_dim, num_actions, context_input=False): super(baseRNN_predictNew, self).__init__() self.l1 = nn.Linear(h_size, 64) self.l2 = nn.Linear(64, 128) self.l3 = nn.Linear(128, obs_dim) self.apply(weights_init) def forward(self, input_0): primals_1 = self.l1.weight primals_2 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_6 = self.l3.weight primals_7 = self.l3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
lysuk96/rl_representations
baseRNN_predict
false
15,981
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
SparseDownSampleClose
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data class SparseDownSampleClose(nn.Module): def __init__(self, stride): super(SparseDownSampleClose, self).__init__() self.pooling = nn.MaxPool2d(stride, stride) self.large_number = 600 def forward(self, d, mask): encode_d = -(1 - mask) * self.large_number - d d = -self.pooling(encode_d) mask_result = self.pooling(mask) d_result = d - (1 - mask_result) * self.large_number return d_result, mask_result def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 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_max_pool2d_with_indices_mul_neg_rsub_sub_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp6 = tl.load(in_ptr1 + x0, xmask) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp3 = -tmp2 tmp4 = 600.0 tmp5 = tmp3 * tmp4 tmp7 = tmp5 - tmp6 tmp8 = -tmp7 tmp9 = tmp2 * tmp4 tmp10 = tmp8 - tmp9 tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + x0, tmp10, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_max_pool2d_with_indices_mul_neg_rsub_sub_0[grid(256)]( buf2, arg0_1, arg1_1, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf2, buf1 class SparseDownSampleCloseNew(nn.Module): def __init__(self, stride): super(SparseDownSampleCloseNew, self).__init__() self.pooling = nn.MaxPool2d(stride, stride) self.large_number = 600 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0], output[1]
maciej-3/PENet_ICRA2021
SparseDownSampleClose
false
15,982
[ "MIT" ]
155
40b5b20fb5d64455f8964045204fa9e7629d0c8c
https://github.com/maciej-3/PENet_ICRA2021/tree/40b5b20fb5d64455f8964045204fa9e7629d0c8c
DynamicWeights
import torch import torch.utils.data from torch import nn class DynamicWeights(nn.Module): def __init__(self, channels): super(DynamicWeights, self).__init__() self.cata = nn.Conv2d(channels, 9, 3, padding=1, bias=False) self.softmax = nn.Softmax(dim=-1) self.unfold1 = nn.Unfold(kernel_size=(3, 3), padding=1) self.gamma = nn.Parameter(torch.zeros(1)) def forward(self, x): blur_depth = x dynamic_filter1 = self.cata(blur_depth) N, _C, H, W = blur_depth.size() dynamic_filter1 = self.softmax(dynamic_filter1.permute(0, 2, 3, 1). contiguous().view(N * H * W, -1)) xd_unfold1 = self.unfold1(blur_depth) xd_unfold1 = xd_unfold1.contiguous().view(N, blur_depth.size()[1], 9, H * W).permute(0, 3, 1, 2).contiguous().view(N * H * W, blur_depth.size()[1], 9) out1 = torch.bmm(xd_unfold1, dynamic_filter1.unsqueeze(2)) out1 = out1.view(N, H, W, blur_depth.size()[1]).permute(0, 3, 1, 2 ).contiguous() out = self.gamma * out1 + x 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 math as tl_math import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__softmax_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 rnumel = 9 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (16 * r1 + 144 * (x0 // 16) + x0 % 16), rmask & xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(rmask & xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(rmask & xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tmp6 / tmp10 tl.store(out_ptr2 + (r1 + 9 * x0), tmp11, rmask & xmask) @triton.jit def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 36 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 % 9 y0 = yindex % 16 x3 = xindex // 9 y1 = yindex // 16 x5 = xindex y4 = yindex tmp0 = -1 + x2 // 3 + y0 // 4 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 % 3 + y0 % 4 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + y0 + 4 * (x2 // 3) + 16 * x3 + 64 * y1 + x2 % 3), tmp10 & xmask & ymask, eviction_policy='evict_last', other=0.0 ) tl.store(out_ptr0 + (x5 + 36 * y4), tmp11, xmask & ymask) @triton.jit def triton_poi_fused_add_clone_mul_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, YBLOCK]) tmp2 = tl.load(in_ptr1 + (y0 + 4 * x2 + 64 * y1), xmask & ymask) tmp4 = tl.load(in_ptr2 + (x2 + 16 * y3), xmask & ymask) tmp3 = tmp1 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + (x2 + 16 * y3), tmp5, xmask & ymask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (9, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 9, 4, 4), (144, 16, 4, 1)) buf3 = empty_strided_cuda((64, 9), (9, 1), torch.float32) get_raw_stream(0) triton_per_fused__softmax_0[grid(64)](buf0, buf3, 64, 9, XBLOCK=32, num_warps=4, num_stages=1) del buf0 buf4 = empty_strided_cuda((4, 16, 4, 9), (576, 36, 9, 1), torch.float32 ) triton_poi_fused_clone_1[grid(64, 36)](primals_1, buf4, 64, 36, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((64, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (64, 4, 9), (36, 9, 1), 0), reinterpret_tensor(buf3, (64, 9, 1), (9, 1, 1), 0), out=buf5) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_clone_mul_2[grid(16, 16)](primals_3, buf5, primals_1, buf6, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) return (buf6, primals_1, primals_2, primals_3, buf3, buf5, reinterpret_tensor(buf4, (64, 9, 4), (36, 1, 9), 0)) class DynamicWeightsNew(nn.Module): def __init__(self, channels): super(DynamicWeightsNew, self).__init__() self.cata = nn.Conv2d(channels, 9, 3, padding=1, bias=False) self.softmax = nn.Softmax(dim=-1) self.unfold1 = nn.Unfold(kernel_size=(3, 3), padding=1) self.gamma = nn.Parameter(torch.zeros(1)) def forward(self, input_0): primals_3 = self.gamma primals_2 = self.cata.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
lzrobots/dgmn
DynamicWeights
false
15,983
[ "MIT" ]
54
515476b5c6a07dcc3b7a4d2243c541377624bb33
https://github.com/lzrobots/dgmn/tree/515476b5c6a07dcc3b7a4d2243c541377624bb33
DDM_Encoder
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class DDM_Encoder(torch.nn.Module): def __init__(self, obs_space, dim, context_input=False, context_dim=0): """ architecture should be input, so that we can pass multiple jobs ! """ super(DDM_Encoder, self).__init__() if context_input: self.linear1 = nn.Linear(obs_space + context_dim, dim) else: self.linear1 = nn.Linear(obs_space, dim) self.linear2 = nn.Linear(dim, 32 * 3 * 3) self.fc = nn.Linear(32 * 3 * 3, dim) self.apply(weights_init) self.train() def forward(self, inputs): x = F.elu(self.linear1(inputs)) x = F.elu(self.linear2(x)) x = F.tanh(self.fc(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'obs_space': 4, 'dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn import torch.nn.init as init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_elu_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, None) @triton.jit def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = 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, (288, 4), (4, 1)) assert_size_stride(primals_5, (288,), (1,)) assert_size_stride(primals_6, (4, 288), (288, 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.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 288), (288, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 288), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 4, 4, 288), (4608, 1152, 288, 1), torch.float32) triton_poi_fused_elu_1[grid(18432)](buf2, buf3, 18432, XBLOCK=128, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 288), (288, 1), 0), reinterpret_tensor(primals_6, (288, 4), (1, 288), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused_tanh_2[grid(256)](buf5, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0 ), buf2, reinterpret_tensor(buf3, (64, 288), (288, 1), 0 ), buf5, primals_6, primals_4 def weights_init(m): classname = m.__class__.__name__ if classname.find('Conv') != -1: weight_shape = list(m.weight.data.size()) fan_in = np.prod(weight_shape[1:4]) fan_out = np.prod(weight_shape[2:4]) * weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('Linear') != -1: weight_shape = list(m.weight.data.size()) fan_in = weight_shape[1] fan_out = weight_shape[0] w_bound = np.sqrt(6.0 / (fan_in + fan_out)) m.weight.data.uniform_(-w_bound, w_bound) m.bias.data.fill_(0) elif classname.find('GRUCell') != -1: for param in m.parameters(): if len(param.shape) >= 2: init.orthogonal_(param.data) else: init.normal_(param.data) class DDM_EncoderNew(torch.nn.Module): def __init__(self, obs_space, dim, context_input=False, context_dim=0): """ architecture should be input, so that we can pass multiple jobs ! """ super(DDM_EncoderNew, self).__init__() if context_input: self.linear1 = nn.Linear(obs_space + context_dim, dim) else: self.linear1 = nn.Linear(obs_space, dim) self.linear2 = nn.Linear(dim, 32 * 3 * 3) self.fc = nn.Linear(32 * 3 * 3, dim) self.apply(weights_init) self.train() def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.fc.weight primals_7 = self.fc.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
lysuk96/rl_representations
DDM_Encoder
false
15,984
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
SingleHiddenLayer
import torch class SingleHiddenLayer(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(SingleHiddenLayer, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, z): z = self.linear1(z) z = torch.relu(z) z = self.linear2(z) z = z.view(*z.shape[:-1], self.hidden_channels, self.input_channels) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (128, 4), (4, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 128), (128, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1, primals_2, buf3, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 16), (1, 128), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 128), (128, 1), 0), primals_4, buf3 class SingleHiddenLayerNew(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(SingleHiddenLayerNew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
lysuk96/rl_representations
SingleHiddenLayer
false
15,985
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
GeometryFeature
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data class GeometryFeature(nn.Module): def __init__(self): super(GeometryFeature, self).__init__() def forward(self, z, vnorm, unorm, h, w, ch, cw, fh, fw): x = z * (0.5 * h * (vnorm + 1) - ch) / fh y = z * (0.5 * w * (unorm + 1) - cw) / fw return torch.cat((x, y, z), 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]), 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 [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data 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, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 768 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 12 x0 = xindex % 16 x2 = xindex // 192 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tl.load(in_ptr1 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp7 = 0.5 tmp8 = tmp6 * tmp7 tmp9 = tl.load(in_ptr2 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp10 = 1.0 tmp11 = tmp9 + tmp10 tmp12 = tmp8 * tmp11 tmp13 = tl.load(in_ptr3 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0 ) tmp14 = tmp12 - tmp13 tmp15 = tmp5 * tmp14 tmp16 = tl.load(in_ptr4 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0 ) tmp17 = tmp15 / tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp4, tmp17, tmp18) tmp20 = tmp0 >= tmp3 tmp21 = tl.full([1], 8, tl.int64) tmp22 = tmp0 < tmp21 tmp23 = tmp20 & tmp22 tmp24 = tl.load(in_ptr0 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp23 & xmask, other=0.0) tmp25 = tl.load(in_ptr5 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp23 & xmask, other=0.0) tmp26 = tmp25 * tmp7 tmp27 = tl.load(in_ptr6 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp23 & xmask, other=0.0) tmp28 = tmp27 + tmp10 tmp29 = tmp26 * tmp28 tmp30 = tl.load(in_ptr7 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp23 & xmask, other=0.0) tmp31 = tmp29 - tmp30 tmp32 = tmp24 * tmp31 tmp33 = tl.load(in_ptr8 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp23 & xmask, other=0.0) tmp34 = tmp32 / tmp33 tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp23, tmp34, tmp35) tmp37 = tmp0 >= tmp21 tl.full([1], 12, tl.int64) tmp40 = tl.load(in_ptr0 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp37 & xmask, other=0.0) tmp41 = tl.where(tmp23, tmp36, tmp40) tmp42 = tl.where(tmp4, tmp19, tmp41) tl.store(out_ptr0 + x3, tmp42, xmask) def call(args): (arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_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)) assert_size_stride(arg5_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg6_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg7_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg8_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.float32 ) get_raw_stream(0) triton_poi_fused_cat_0[grid(768)](arg3_1, arg0_1, arg1_1, arg2_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1, buf0, 768, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 del arg3_1 del arg4_1 del arg5_1 del arg6_1 del arg7_1 del arg8_1 return buf0, class GeometryFeatureNew(nn.Module): def __init__(self): super(GeometryFeatureNew, self).__init__() def forward(self, input_0, input_1, input_2, input_3, input_4, input_5, input_6, input_7, input_8): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 arg4_1 = input_4 arg5_1 = input_5 arg6_1 = input_6 arg7_1 = input_7 arg8_1 = input_8 output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1, arg6_1, arg7_1, arg8_1]) return output[0]
maciej-3/PENet_ICRA2021
GeometryFeature
false
15,986
[ "MIT" ]
155
40b5b20fb5d64455f8964045204fa9e7629d0c8c
https://github.com/maciej-3/PENet_ICRA2021/tree/40b5b20fb5d64455f8964045204fa9e7629d0c8c
SelfAttention
import torch import torch.nn as nn import torch.nn.functional as F class SelfAttention(nn.Module): def __init__(self, hidden_size, attention_size=100, n_attention_heads=1): super().__init__() self.hidden_size = hidden_size self.attention_size = attention_size self.n_attention_heads = n_attention_heads self.W1 = nn.Linear(hidden_size, attention_size, bias=False) self.W2 = nn.Linear(attention_size, n_attention_heads, bias=False) def forward(self, hidden): hidden = hidden.transpose(0, 1) x = torch.tanh(self.W1(hidden)) x = F.softmax(self.W2(x), dim=1) A = x.transpose(1, 2) M = A @ hidden return M, A def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 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 = libdevice.tanh(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) 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, (100, 4), (4, 1)) assert_size_stride(primals_3, (1, 100), (100, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((16, 100), (100, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 100), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 100), (400, 100, 1), 0) del buf1 triton_poi_fused_tanh_1[grid(1600)](buf2, 1600, XBLOCK=256, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 100), (100, 1), 0), reinterpret_tensor(primals_3, (100, 1), (1, 100), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_2[grid(16)](buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 4, 1), (4, 1, 1), 0) del buf3 triton_poi_fused__softmax_3[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 1, 4), (4, 4, 1), 0) del buf4 extern_kernels.bmm(reinterpret_tensor(buf5, (4, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(primals_1, (4, 4, 4), (4, 16, 1), 0), out =buf6) return buf6, reinterpret_tensor(buf5, (4, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0 ), buf2, buf5, reinterpret_tensor(primals_1, (4, 4, 4), (4, 1, 16), 0 ), primals_3 class SelfAttentionNew(nn.Module): def __init__(self, hidden_size, attention_size=100, n_attention_heads=1): super().__init__() self.hidden_size = hidden_size self.attention_size = attention_size self.n_attention_heads = n_attention_heads self.W1 = nn.Linear(hidden_size, attention_size, bias=False) self.W2 = nn.Linear(attention_size, n_attention_heads, bias=False) def forward(self, input_0): primals_2 = self.W1.weight primals_3 = self.W2.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
maltevogl/CVDD-PyTorch
SelfAttention
false
15,987
[ "MIT" ]
48
9299894720a8d3d0a329d92c9d2702f43112ff63
https://github.com/maltevogl/CVDD-PyTorch/tree/9299894720a8d3d0a329d92c9d2702f43112ff63
MLP
from _paritybench_helpers import _mock_config import math import torch from torch import nn from torch.nn import Parameter from torch.nn.parameter import Parameter def gelu(x): return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) class Conv1D(nn.Module): def __init__(self, nf, nx): super(Conv1D, self).__init__() self.nf = nf w = torch.empty(nx, nf) nn.init.normal_(w, std=0.02) self.weight = Parameter(w) self.bias = Parameter(torch.zeros(nf)) def forward(self, x): size_out = x.size()[:-1] + (self.nf,) x.contiguous().view(-1, x.size(-1)) x = torch.addmm(self.bias, x.contiguous().view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class MLP(nn.Module): def __init__(self, n_state, config): super(MLP, self).__init__() nx = config.n_embd self.c_fc = Conv1D(n_state, nx) self.c_proj = Conv1D(nx, n_state) self.act = gelu def forward(self, x): h = self.act(self.c_fc(x)) h2 = self.c_proj(h) return h2 def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_state': 4, 'config': _mock_config(n_embd=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math from torch import nn from torch.nn 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_pow_tanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = tmp0 * tmp0 tmp4 = tmp3 * tmp0 tmp5 = 0.044715 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + tmp6 tmp8 = 0.7978845608028654 tmp9 = tmp7 * tmp8 tmp10 = libdevice.tanh(tmp9) tmp11 = 1.0 tmp12 = tmp10 + tmp11 tmp13 = tmp2 * tmp12 tl.store(out_ptr0 + x0, tmp13, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), primals_3, alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_pow_tanh_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), primals_5, alpha=1, beta=1, out=buf2) del primals_4 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), buf0, reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), reinterpret_tensor(buf1, (4, 64), (1, 4), 0), reinterpret_tensor( primals_1, (4, 64), (1, 4), 0) def gelu(x): return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) class Conv1D(nn.Module): def __init__(self, nf, nx): super(Conv1D, self).__init__() self.nf = nf w = torch.empty(nx, nf) nn.init.normal_(w, std=0.02) self.weight = Parameter(w) self.bias = Parameter(torch.zeros(nf)) def forward(self, x): size_out = x.size()[:-1] + (self.nf,) x.contiguous().view(-1, x.size(-1)) x = torch.addmm(self.bias, x.contiguous().view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class MLPNew(nn.Module): def __init__(self, n_state, config): super(MLPNew, self).__init__() nx = config.n_embd self.c_fc = Conv1D(n_state, nx) self.c_proj = Conv1D(nx, n_state) self.act = gelu def forward(self, input_0): primals_3 = self.c_fc.weight primals_2 = self.c_fc.bias primals_5 = self.c_proj.weight primals_4 = self.c_proj.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
mandaltanmoy1938/VisualGPT
MLP
false
15,988
[ "MIT" ]
86
9ba78948282fdca502d5030f4eccc3df562982c3
https://github.com/mandaltanmoy1938/VisualGPT/tree/9ba78948282fdca502d5030f4eccc3df562982c3
FC_Q
import torch import torch.nn as nn import torch.nn.functional as F class FC_Q(nn.Module): def __init__(self, state_dim, num_actions, num_nodes=128): super(FC_Q, self).__init__() self.q1 = nn.Linear(state_dim, num_nodes) self.q2 = nn.Linear(num_nodes, num_nodes) self.q3 = nn.Linear(num_nodes, num_actions) self.i1 = nn.Linear(state_dim, num_nodes) self.i2 = nn.Linear(num_nodes, num_nodes) self.i3 = nn.Linear(num_nodes, num_actions) def forward(self, state): q = F.relu(self.q1(state)) q = F.relu(self.q2(q)) i = F.relu(self.i1(state)) i = F.relu(self.i2(i)) i = F.relu(self.i3(i)) return self.q3(q), F.log_softmax(i, dim=1), i def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'num_actions': 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): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__log_softmax_threshold_backward_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = 0.0 tmp10 = tmp0 <= tmp9 tl.store(out_ptr0 + x3, tmp8, xmask) tl.store(out_ptr1 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__log_softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (128, 4), (4, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (128, 128), (128, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (128, 4), (4, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128), (128, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (4, 128), (128, 1)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (4, 128), (128, 1)) assert_size_stride(primals_13, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf0 buf17 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1, primals_2, buf17, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 128), (1, 128), 0), out=buf2) buf3 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 128), (1, 4), 0), out=buf3) del primals_6 buf4 = reinterpret_tensor(buf3, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf3 buf15 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf4, primals_7, buf15, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf5 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf4, (64, 128), (128, 1), 0), reinterpret_tensor(primals_8, (128, 128), (1, 128), 0), out=buf5) buf6 = reinterpret_tensor(buf5, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf5 buf14 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf6, primals_9, buf14, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf7 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf6, (64, 128), (128, 1), 0), reinterpret_tensor(primals_10, (128, 4), (1, 128), 0), out=buf7) buf8 = reinterpret_tensor(buf7, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf7 triton_poi_fused_relu_1[grid(256)](buf8, primals_11, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_11 buf9 = reinterpret_tensor(buf2, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf2 buf16 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf9, primals_5, buf16, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf10 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_13, reinterpret_tensor(buf9, (64, 128), (128, 1), 0), reinterpret_tensor(primals_12, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf10) del primals_13 buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused__log_softmax_threshold_backward_2[grid(256)](buf8, buf11, buf13, 256, XBLOCK=256, num_warps=4, num_stages=1) buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_3[grid(256)](buf11, buf12, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf11 return (reinterpret_tensor(buf10, (4, 4, 4, 4), (64, 16, 4, 1), 0), buf12, buf8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(buf4, (64, 128), (128, 1), 0), reinterpret_tensor(buf6, (64, 128), (128, 1), 0), reinterpret_tensor(buf9, (64, 128), (128, 1), 0), buf12, primals_12, buf13, primals_10, buf14, primals_8, buf15, buf16, primals_4, buf17) class FC_QNew(nn.Module): def __init__(self, state_dim, num_actions, num_nodes=128): super(FC_QNew, self).__init__() self.q1 = nn.Linear(state_dim, num_nodes) self.q2 = nn.Linear(num_nodes, num_nodes) self.q3 = nn.Linear(num_nodes, num_actions) self.i1 = nn.Linear(state_dim, num_nodes) self.i2 = nn.Linear(num_nodes, num_nodes) self.i3 = nn.Linear(num_nodes, num_actions) def forward(self, input_0): primals_1 = self.q1.weight primals_2 = self.q1.bias primals_4 = self.q2.weight primals_5 = self.q2.bias primals_10 = self.q3.weight primals_11 = self.q3.bias primals_6 = self.i1.weight primals_7 = self.i1.bias primals_8 = self.i2.weight primals_9 = self.i2.bias primals_12 = self.i3.weight primals_13 = self.i3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0], output[1], output[2]
lysuk96/rl_representations
FC_Q
false
15,989
[ "MIT" ]
438
19de69305e40c9b3a1d746a7af26d232c9fb3f6f
https://github.com/lysuk96/rl_representations/tree/19de69305e40c9b3a1d746a7af26d232c9fb3f6f
KLDivLoss
import torch from torchvision.transforms import * import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable class KLDivLoss(nn.Module): def __init__(self): super(KLDivLoss, self).__init__() def forward(self, pred, label): T = 3 predict = F.log_softmax(pred / T, dim=1) target_data = F.softmax(label / T, dim=1) target_data = target_data + 10 ** -7 target = Variable(target_data.data, requires_grad=False) loss = T * T * ((target * (target.log() - predict)).sum(1).sum() / target.size()[0]) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torchvision.transforms 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__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.3333333333333333 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x3, tmp17, xmask) @triton.jit def triton_poi_fused__softmax_add_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = 1e-07 tmp10 = tmp8 + tmp9 tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_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) tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.3333333333333333 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x3, tmp16, xmask) @triton.jit def triton_poi_fused__log_softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_add_1[grid(256)](buf0, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused_2[grid(256)](arg0_1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_3[grid(256)](buf2, buf3, 256, XBLOCK= 256, num_warps=4, num_stages=1) del buf2 return buf1, buf3 class KLDivLossNew(nn.Module): def __init__(self): super(KLDivLossNew, 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]
mangye16/Cross-Modal-Re-ID-baseline
KLDivLoss
false
15,990
[ "MIT" ]
249
26bc0ce088eb97867ff489dceda386b8092b9fde
https://github.com/mangye16/Cross-Modal-Re-ID-baseline/tree/26bc0ce088eb97867ff489dceda386b8092b9fde
DRS
import torch import torch.nn as nn class DRS(nn.Module): """ DRS non-learnable setting hyperparameter O , additional training paramters X """ def __init__(self, delta): super(DRS, self).__init__() self.relu = nn.ReLU() self.delta = delta self.global_max_pool = nn.AdaptiveMaxPool2d(1) def forward(self, x): b, c, _, _ = x.size() x = self.relu(x) """ 1: max extractor """ x_max = self.global_max_pool(x).view(b, c, 1, 1) x_max = x_max.expand_as(x) """ 2: suppression controller""" control = self.delta """ 3: suppressor""" x = torch.min(x, x_max * control) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'delta': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_adaptive_max_pool2d_relu_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') tmp3 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp6 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp24 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp30 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp33 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp36 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp39 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp42 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp45 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp1, tmp3) tmp5 = triton_helpers.maximum(tmp4, tmp2) tmp7 = triton_helpers.maximum(tmp1, tmp6) tmp8 = triton_helpers.maximum(tmp7, tmp5) tmp10 = triton_helpers.maximum(tmp1, tmp9) tmp11 = triton_helpers.maximum(tmp10, tmp8) tmp13 = triton_helpers.maximum(tmp1, tmp12) tmp14 = triton_helpers.maximum(tmp13, tmp11) tmp16 = triton_helpers.maximum(tmp1, tmp15) tmp17 = triton_helpers.maximum(tmp16, tmp14) tmp19 = triton_helpers.maximum(tmp1, tmp18) tmp20 = triton_helpers.maximum(tmp19, tmp17) tmp22 = triton_helpers.maximum(tmp1, tmp21) tmp23 = triton_helpers.maximum(tmp22, tmp20) tmp25 = triton_helpers.maximum(tmp1, tmp24) tmp26 = triton_helpers.maximum(tmp25, tmp23) tmp28 = triton_helpers.maximum(tmp1, tmp27) tmp29 = triton_helpers.maximum(tmp28, tmp26) tmp31 = triton_helpers.maximum(tmp1, tmp30) tmp32 = triton_helpers.maximum(tmp31, tmp29) tmp34 = triton_helpers.maximum(tmp1, tmp33) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp37 = triton_helpers.maximum(tmp1, tmp36) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp40 = triton_helpers.maximum(tmp1, tmp39) tmp41 = triton_helpers.maximum(tmp40, tmp38) tmp43 = triton_helpers.maximum(tmp1, tmp42) tmp44 = triton_helpers.maximum(tmp43, tmp41) tmp46 = triton_helpers.maximum(tmp1, tmp45) tmp47 = triton_helpers.maximum(tmp46, tmp44) tl.store(out_ptr0 + x0, tmp47, xmask) @triton.jit def triton_poi_fused_minimum_mul_relu_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) tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = 4.0 tmp5 = tmp3 * tmp4 tmp6 = triton_helpers.minimum(tmp2, tmp5) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) get_raw_stream(0) triton_poi_fused_adaptive_max_pool2d_relu_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_minimum_mul_relu_1[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del buf0 return buf1, class DRSNew(nn.Module): """ DRS non-learnable setting hyperparameter O , additional training paramters X """ def __init__(self, delta): super(DRSNew, self).__init__() self.relu = nn.ReLU() self.delta = delta self.global_max_pool = nn.AdaptiveMaxPool2d(1) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
manideep1108/DRS
DRS
false
15,991
[ "MIT" ]
62
0858c3ffea310e9d504b7c2b06db5f281273df56
https://github.com/manideep1108/DRS/tree/0858c3ffea310e9d504b7c2b06db5f281273df56
VGG16
import torch import numpy as np import torchvision.transforms.functional as F import torch.nn as nn import torch.nn.functional as F class Normalize: def __init__(self, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)): self.mean = mean self.std = std def undo(self, imgarr): proc_img = imgarr.copy() proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0] ) * 255.0 proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1] ) * 255.0 proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2] ) * 255.0 return proc_img def __call__(self, img): imgarr = np.asarray(img) proc_img = np.empty_like(imgarr, np.float32) proc_img[..., 0] = (imgarr[..., 0] / 255.0 - self.mean[0]) / self.std[0 ] proc_img[..., 1] = (imgarr[..., 1] / 255.0 - self.mean[1]) / self.std[1 ] proc_img[..., 2] = (imgarr[..., 2] / 255.0 - self.mean[2]) / self.std[2 ] return proc_img class BaseNet(nn.Module): def __init__(self): super().__init__() self.normalize = Normalize() self.NormLayer = nn.BatchNorm2d self.not_training = [] self.bn_frozen = [] self.from_scratch_layers = [] def _init_weights(self, path_to_weights): None weights_dict = torch.load(path_to_weights) self.load_state_dict(weights_dict, strict=False) def fan_out(self): raise NotImplementedError def fixed_layers(self): return self.not_training def _fix_running_stats(self, layer, fix_params=False): if isinstance(layer, self.NormLayer): self.bn_frozen.append(layer) if fix_params and layer not in self.not_training: self.not_training.append(layer) elif isinstance(layer, list): for m in layer: self._fix_running_stats(m, fix_params) else: for m in layer.children(): self._fix_running_stats(m, fix_params) def _fix_params(self, layer): if isinstance(layer, nn.Conv2d) or isinstance(layer, self.NormLayer ) or isinstance(layer, nn.Linear): self.not_training.append(layer) if isinstance(layer, self.NormLayer): self.bn_frozen.append(layer) elif isinstance(layer, list): for m in layer: self._fix_params(m) elif isinstance(layer, nn.Module): if hasattr(layer, 'weight') or hasattr(layer, 'bias'): None for m in layer.children(): self._fix_params(m) def _freeze_bn(self, layer): if isinstance(layer, self.NormLayer): layer.eval() elif isinstance(layer, nn.Module): for m in layer.children(): self._freeze_bn(m) def train(self, mode=True): super().train(mode) for layer in self.not_training: if hasattr(layer, 'weight') and layer.weight is not None: layer.weight.requires_grad = False if hasattr(layer, 'bias') and layer.bias is not None: layer.bias.requires_grad = False elif isinstance(layer, torch.nn.Module): None for bn_layer in self.bn_frozen: self._freeze_bn(bn_layer) def _lr_mult(self): return 1.0, 2.0, 10.0, 20 def parameter_groups(self, base_lr, wd): w_old, b_old, w_new, b_new = self._lr_mult() groups = {'params': [], 'weight_decay': wd, 'lr': w_old * base_lr}, { 'params': [], 'weight_decay': 0.0, 'lr': b_old * base_lr}, { 'params': [], 'weight_decay': wd, 'lr': w_new * base_lr}, {'params' : [], 'weight_decay': 0.0, 'lr': b_new * base_lr} fixed_layers = self.fixed_layers() for m in self.modules(): if m in fixed_layers: continue if isinstance(m, nn.Conv2d) or isinstance(m, nn.Linear ) or isinstance(m, self.NormLayer): if m.weight is not None: if m in self.from_scratch_layers: groups[2]['params'].append(m.weight) else: groups[0]['params'].append(m.weight) if m.bias is not None: if m in self.from_scratch_layers: groups[3]['params'].append(m.bias) else: groups[1]['params'].append(m.bias) elif hasattr(m, 'weight'): None for i, g in enumerate(groups): None return groups class VGG16(BaseNet): def __init__(self, fc6_dilation=1): super(VGG16, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, 3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, 3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv2_1 = nn.Conv2d(64, 128, 3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, 3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv3_1 = nn.Conv2d(128, 256, 3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, 3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, 3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv4_1 = nn.Conv2d(256, 512, 3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, 3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, 3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv5_1 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.conv5_2 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.conv5_3 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.fc6 = nn.Conv2d(512, 1024, 3, padding=fc6_dilation, dilation= fc6_dilation) self.drop6 = nn.Dropout2d(p=0.5) self.fc7 = nn.Conv2d(1024, 1024, 1) self._fix_params([self.conv1_1, self.conv1_2]) def fan_out(self): return 1024 def forward(self, x): return self.forward_as_dict(x)['conv6'] def forward_as_dict(self, x): x = F.relu(self.conv1_1(x), inplace=True) x = F.relu(self.conv1_2(x), inplace=True) x = self.pool1(x) x = F.relu(self.conv2_1(x), inplace=True) x = F.relu(self.conv2_2(x), inplace=True) x = self.pool2(x) x = F.relu(self.conv3_1(x), inplace=True) x = F.relu(self.conv3_2(x), inplace=True) x = F.relu(self.conv3_3(x), inplace=True) conv3 = x x = self.pool3(x) x = F.relu(self.conv4_1(x), inplace=True) x = F.relu(self.conv4_2(x), inplace=True) x = F.relu(self.conv4_3(x), inplace=True) x = self.pool4(x) x = F.relu(self.conv5_1(x), inplace=True) x = F.relu(self.conv5_2(x), inplace=True) x = F.relu(self.conv5_3(x), inplace=True) x = F.relu(self.fc6(x), inplace=True) x = self.drop6(x) x = F.relu(self.fc7(x), inplace=True) conv6 = x return dict({'conv3': conv3, 'conv6': conv6}) 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 numpy as np import torchvision.transforms.functional as F import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_7(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_convolution_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 192 xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 27 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_10(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_11(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 // 2048 % 32 x1 = xindex // 64 % 32 x0 = xindex % 64 x5 = xindex // 2048 x6 = xindex tmp0 = -1 + 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-4160 + x0 + 128 * x1 + 8192 * x5), tmp10, other=float('-inf')) tmp12 = 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-4096 + x0 + 128 * x1 + 8192 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-4032 + x0 + 128 * x1 + 8192 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-64 + x0 + 128 * x1 + 8192 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (x0 + 128 * x1 + 8192 * x5), tmp33, other= float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (64 + x0 + 128 * x1 + 8192 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (4032 + x0 + 128 * x1 + 8192 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4096 + x0 + 128 * x1 + 8192 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (4160 + x0 + 128 * x1 + 8192 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tl.store(out_ptr0 + x6, tmp51, None) @triton.jit def triton_poi_fused_convolution_relu_12(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_13(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 2048 % 16 x1 = xindex // 128 % 16 x0 = xindex % 128 x5 = xindex // 2048 x6 = xindex tmp0 = -1 + 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-4224 + x0 + 256 * x1 + 8192 * x5), tmp10, other=float('-inf')) tmp12 = 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-4096 + x0 + 256 * x1 + 8192 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-3968 + x0 + 256 * x1 + 8192 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-128 + x0 + 256 * x1 + 8192 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (x0 + 256 * x1 + 8192 * x5), tmp33, other= float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (128 + x0 + 256 * x1 + 8192 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (3968 + x0 + 256 * x1 + 8192 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4096 + x0 + 256 * x1 + 8192 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (4224 + x0 + 256 * x1 + 8192 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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_max_pool2d_with_indices_15(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 2048 % 8 x1 = xindex // 256 % 8 x0 = xindex % 256 x5 = xindex // 2048 x6 = xindex tmp0 = -1 + 2 * x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 16, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + 2 * x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-4352 + x0 + 512 * x1 + 8192 * x5), tmp10, other=float('-inf')) tmp12 = 2 * x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-4096 + x0 + 512 * x1 + 8192 * x5), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-3840 + x0 + 512 * x1 + 8192 * x5), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-256 + x0 + 512 * x1 + 8192 * x5), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (x0 + 512 * x1 + 8192 * x5), tmp33, other= float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 8192 * x5), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (3840 + x0 + 512 * x1 + 8192 * x5), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4096 + x0 + 512 * x1 + 8192 * x5), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (4352 + x0 + 512 * x1 + 8192 * x5), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_16(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_17(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 4096 % 8 x1 = xindex // 512 % 8 x6 = xindex tmp0 = -1 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 8, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + x1 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-4608 + x6), tmp10, other=float('-inf')) tmp12 = x1 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-4096 + x6), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x1 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-3584 + x6), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x2 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-512 + x6), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x6, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (512 + x6), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x2 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (3584 + x6), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4096 + x6), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (4608 + x6), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x6, tmp51, None) tl.store(out_ptr1 + x6, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_18(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 1024 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_19(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 64 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 1024 y1 = yindex // 1024 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 1024 * x2 + 65536 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 64 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 1024 * x2 + 65536 * y1), tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31) = args args.clear() assert_size_stride(primals_1, (64, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_15, (256,), (1,)) assert_size_stride(primals_16, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_17, (512,), (1,)) assert_size_stride(primals_18, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_19, (512,), (1,)) assert_size_stride(primals_20, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_21, (512,), (1,)) assert_size_stride(primals_22, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_23, (512,), (1,)) assert_size_stride(primals_24, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_25, (512,), (1,)) assert_size_stride(primals_26, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_27, (512,), (1,)) assert_size_stride(primals_28, (1024, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_29, (1024,), (1,)) assert_size_stride(primals_30, (1024, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_31, (1024,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((128, 64, 3, 3), (576, 1, 192, 64), torch .float32) get_raw_stream(0) triton_poi_fused_0[grid(8192, 9)](primals_6, buf0, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf1 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_1[grid(16384, 9)](primals_8, buf1, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf2 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_2[grid(32768, 9)](primals_10, buf2, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_10 buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_3[grid(65536, 9)](primals_12, buf3, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_3[grid(65536, 9)](primals_14, buf4, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_14 buf5 = empty_strided_cuda((512, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_4[grid(131072, 9)](primals_16, buf5, 131072, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_16 buf6 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_18, buf6, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_18 buf7 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_20, buf7, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_20 buf8 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_22, buf8, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_22 buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_24, buf9, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_24 buf10 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_26, buf10, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_26 buf11 = empty_strided_cuda((1024, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_6[grid(524288, 9)](primals_28, buf11, 524288, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_28 buf12 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch.float32) triton_poi_fused_convolution_7[grid(12, 4096)](primals_3, buf12, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf13 = empty_strided_cuda((64, 3, 3, 3), (27, 1, 9, 3), torch.float32) triton_poi_fused_convolution_8[grid(192, 9)](primals_1, buf13, 192, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 buf14 = extern_kernels.convolution(buf12, buf13, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 64, 64, 64), (262144, 1, 4096, 64)) del buf12 del buf13 buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_9[grid(1048576)](buf15, primals_2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf16 = empty_strided_cuda((64, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_convolution_relu_10[grid(4096, 9)](primals_4, buf16, 4096, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf17 = extern_kernels.convolution(buf15, buf16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf17, (4, 64, 64, 64), (262144, 1, 4096, 64)) del buf15 del buf16 buf18 = buf17 del buf17 triton_poi_fused_convolution_relu_9[grid(1048576)](buf18, primals_5, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf19 = empty_strided_cuda((4, 64, 32, 32), (65536, 1, 2048, 64), torch.float32) triton_poi_fused_max_pool2d_with_indices_11[grid(262144)](buf18, buf19, 262144, XBLOCK=512, num_warps=8, num_stages=1) del buf18 buf20 = extern_kernels.convolution(buf19, buf0, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_12[grid(524288)](buf21, primals_7, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf22 = extern_kernels.convolution(buf21, buf1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_12[grid(524288)](buf23, primals_9, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf24 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.float32) buf25 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.int8) triton_poi_fused_max_pool2d_with_indices_13[grid(131072)](buf23, buf24, buf25, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf26 = extern_kernels.convolution(buf24, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf27 = buf26 del buf26 triton_poi_fused_convolution_relu_14[grid(262144)](buf27, primals_11, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf28 = extern_kernels.convolution(buf27, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_14[grid(262144)](buf29, primals_13, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_13 buf30 = extern_kernels.convolution(buf29, buf4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf31 = buf30 del buf30 triton_poi_fused_convolution_relu_14[grid(262144)](buf31, primals_15, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf32 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.float32) buf33 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.int8) triton_poi_fused_max_pool2d_with_indices_15[grid(65536)](buf31, buf32, buf33, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf34 = extern_kernels.convolution(buf32, buf5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf34, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf35 = buf34 del buf34 triton_poi_fused_convolution_relu_16[grid(131072)](buf35, primals_17, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf36 = extern_kernels.convolution(buf35, buf6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf37 = buf36 del buf36 triton_poi_fused_convolution_relu_16[grid(131072)](buf37, primals_19, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_19 buf38 = extern_kernels.convolution(buf37, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_16[grid(131072)](buf39, primals_21, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_21 buf40 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) buf41 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.int8) triton_poi_fused_max_pool2d_with_indices_17[grid(131072)](buf39, buf40, buf41, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf42 = extern_kernels.convolution(buf40, buf8, stride=(1, 1), padding=(2, 2), dilation=(2, 2), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf42, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf43 = buf42 del buf42 triton_poi_fused_convolution_relu_16[grid(131072)](buf43, primals_23, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_23 buf44 = extern_kernels.convolution(buf43, buf9, stride=(1, 1), padding=(2, 2), dilation=(2, 2), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf45 = buf44 del buf44 triton_poi_fused_convolution_relu_16[grid(131072)](buf45, primals_25, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_25 buf46 = extern_kernels.convolution(buf45, buf10, stride=(1, 1), padding=(2, 2), dilation=(2, 2), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf47 = buf46 del buf46 triton_poi_fused_convolution_relu_16[grid(131072)](buf47, primals_27, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_27 buf48 = extern_kernels.convolution(buf47, buf11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 1024, 8, 8), (65536, 1, 8192, 1024)) buf49 = buf48 del buf48 triton_poi_fused_convolution_relu_18[grid(262144)](buf49, primals_29, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_29 buf50 = extern_kernels.convolution(buf49, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf50, (4, 1024, 8, 8), (65536, 1, 8192, 1024)) buf51 = empty_strided_cuda((4, 1024, 8, 8), (65536, 64, 8, 1), torch.float32) buf52 = empty_strided_cuda((4, 1024, 8, 8), (65536, 1, 8192, 1024), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_19[grid(4096, 64) ](buf50, primals_31, buf51, buf52, 4096, 64, XBLOCK=32, YBLOCK= 32, num_warps=4, num_stages=1) del buf50 del primals_31 return (buf51, buf0, buf1, buf2, buf3, buf4, buf5, buf6, buf7, buf8, buf9, buf10, buf11, primals_30, buf19, buf21, buf23, buf24, buf25, buf27, buf29, buf31, buf32, buf33, buf35, buf37, buf39, buf40, buf41, buf43, buf45, buf47, buf49, buf52) class Normalize: def __init__(self, mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)): self.mean = mean self.std = std def undo(self, imgarr): proc_img = imgarr.copy() proc_img[..., 0] = (self.std[0] * imgarr[..., 0] + self.mean[0] ) * 255.0 proc_img[..., 1] = (self.std[1] * imgarr[..., 1] + self.mean[1] ) * 255.0 proc_img[..., 2] = (self.std[2] * imgarr[..., 2] + self.mean[2] ) * 255.0 return proc_img def __call__(self, img): imgarr = np.asarray(img) proc_img = np.empty_like(imgarr, np.float32) proc_img[..., 0] = (imgarr[..., 0] / 255.0 - self.mean[0]) / self.std[0 ] proc_img[..., 1] = (imgarr[..., 1] / 255.0 - self.mean[1]) / self.std[1 ] proc_img[..., 2] = (imgarr[..., 2] / 255.0 - self.mean[2]) / self.std[2 ] return proc_img class BaseNet(nn.Module): def __init__(self): super().__init__() self.normalize = Normalize() self.NormLayer = nn.BatchNorm2d self.not_training = [] self.bn_frozen = [] self.from_scratch_layers = [] def _init_weights(self, path_to_weights): None weights_dict = torch.load(path_to_weights) self.load_state_dict(weights_dict, strict=False) def fan_out(self): raise NotImplementedError def fixed_layers(self): return self.not_training def _fix_running_stats(self, layer, fix_params=False): if isinstance(layer, self.NormLayer): self.bn_frozen.append(layer) if fix_params and layer not in self.not_training: self.not_training.append(layer) elif isinstance(layer, list): for m in layer: self._fix_running_stats(m, fix_params) else: for m in layer.children(): self._fix_running_stats(m, fix_params) def _fix_params(self, layer): if isinstance(layer, nn.Conv2d) or isinstance(layer, self.NormLayer ) or isinstance(layer, nn.Linear): self.not_training.append(layer) if isinstance(layer, self.NormLayer): self.bn_frozen.append(layer) elif isinstance(layer, list): for m in layer: self._fix_params(m) elif isinstance(layer, nn.Module): if hasattr(layer, 'weight') or hasattr(layer, 'bias'): None for m in layer.children(): self._fix_params(m) def _freeze_bn(self, layer): if isinstance(layer, self.NormLayer): layer.eval() elif isinstance(layer, nn.Module): for m in layer.children(): self._freeze_bn(m) def train(self, mode=True): super().train(mode) for layer in self.not_training: if hasattr(layer, 'weight') and layer.weight is not None: layer.weight.requires_grad = False if hasattr(layer, 'bias') and layer.bias is not None: layer.bias.requires_grad = False elif isinstance(layer, torch.nn.Module): None for bn_layer in self.bn_frozen: self._freeze_bn(bn_layer) def _lr_mult(self): return 1.0, 2.0, 10.0, 20 def parameter_groups(self, base_lr, wd): w_old, b_old, w_new, b_new = self._lr_mult() groups = {'params': [], 'weight_decay': wd, 'lr': w_old * base_lr}, { 'params': [], 'weight_decay': 0.0, 'lr': b_old * base_lr}, { 'params': [], 'weight_decay': wd, 'lr': w_new * base_lr}, {'params' : [], 'weight_decay': 0.0, 'lr': b_new * base_lr} fixed_layers = self.fixed_layers() for m in self.modules(): if m in fixed_layers: continue if isinstance(m, nn.Conv2d) or isinstance(m, nn.Linear ) or isinstance(m, self.NormLayer): if m.weight is not None: if m in self.from_scratch_layers: groups[2]['params'].append(m.weight) else: groups[0]['params'].append(m.weight) if m.bias is not None: if m in self.from_scratch_layers: groups[3]['params'].append(m.bias) else: groups[1]['params'].append(m.bias) elif hasattr(m, 'weight'): None for i, g in enumerate(groups): None return groups class VGG16New(BaseNet): def __init__(self, fc6_dilation=1): super(VGG16New, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, 3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, 3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv2_1 = nn.Conv2d(64, 128, 3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, 3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv3_1 = nn.Conv2d(128, 256, 3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, 3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, 3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.conv4_1 = nn.Conv2d(256, 512, 3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, 3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, 3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv5_1 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.conv5_2 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.conv5_3 = nn.Conv2d(512, 512, 3, padding=2, dilation=2) self.fc6 = nn.Conv2d(512, 1024, 3, padding=fc6_dilation, dilation= fc6_dilation) self.drop6 = nn.Dropout2d(p=0.5) self.fc7 = nn.Conv2d(1024, 1024, 1) self._fix_params([self.conv1_1, self.conv1_2]) def fan_out(self): return 1024 def forward_as_dict(self, x): x = F.relu(self.conv1_1(x), inplace=True) x = F.relu(self.conv1_2(x), inplace=True) x = self.pool1(x) x = F.relu(self.conv2_1(x), inplace=True) x = F.relu(self.conv2_2(x), inplace=True) x = self.pool2(x) x = F.relu(self.conv3_1(x), inplace=True) x = F.relu(self.conv3_2(x), inplace=True) x = F.relu(self.conv3_3(x), inplace=True) conv3 = x x = self.pool3(x) x = F.relu(self.conv4_1(x), inplace=True) x = F.relu(self.conv4_2(x), inplace=True) x = F.relu(self.conv4_3(x), inplace=True) x = self.pool4(x) x = F.relu(self.conv5_1(x), inplace=True) x = F.relu(self.conv5_2(x), inplace=True) x = F.relu(self.conv5_3(x), inplace=True) x = F.relu(self.fc6(x), inplace=True) x = self.drop6(x) x = F.relu(self.fc7(x), inplace=True) conv6 = x return dict({'conv3': conv3, 'conv6': conv6}) def forward(self, input_0): primals_1 = self.conv1_1.weight primals_2 = self.conv1_1.bias primals_4 = self.conv1_2.weight primals_5 = self.conv1_2.bias primals_6 = self.conv2_1.weight primals_7 = self.conv2_1.bias primals_8 = self.conv2_2.weight primals_9 = self.conv2_2.bias primals_10 = self.conv3_1.weight primals_11 = self.conv3_1.bias primals_12 = self.conv3_2.weight primals_13 = self.conv3_2.bias primals_14 = self.conv3_3.weight primals_15 = self.conv3_3.bias primals_16 = self.conv4_1.weight primals_17 = self.conv4_1.bias primals_18 = self.conv4_2.weight primals_19 = self.conv4_2.bias primals_20 = self.conv4_3.weight primals_21 = self.conv4_3.bias primals_22 = self.conv5_1.weight primals_23 = self.conv5_1.bias primals_24 = self.conv5_2.weight primals_25 = self.conv5_2.bias primals_26 = self.conv5_3.weight primals_27 = self.conv5_3.bias primals_28 = self.fc6.weight primals_29 = self.fc6.bias primals_30 = self.fc7.weight primals_31 = self.fc7.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31]) return output[0]
loserbbb/1-stage-wseg
VGG16
false
15,992
[ "Apache-2.0" ]
364
f1579be241986c1e19420bfbf6711b6c2208d99a
https://github.com/loserbbb/1-stage-wseg/tree/f1579be241986c1e19420bfbf6711b6c2208d99a
CrossPooling
import torch import torch.nn as nn class CrossPooling(nn.Module): """ Cross pooling """ def forward(self, x): """ Forward function of CrossPooling module. Args: x: a stack of (batch x channel x height x width) tensors on the last axis. Returns: A (batch x channel x height x width) tensor after applying max-pooling over the last axis. """ x, _ = torch.max(x, dim=-1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, tmp5) tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf0, class CrossPoolingNew(nn.Module): """ Cross pooling """ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
manipopopo/C5
CrossPooling
false
15,993
[ "Apache-2.0" ]
51
154eb38c330e65476ddb77836948a28237f23c88
https://github.com/manipopopo/C5/tree/154eb38c330e65476ddb77836948a28237f23c88
CausalAttentionSortNet
import torch from torch.nn import functional as F from torch import nn def bucket(buckets, t, dim=1): shape = list(t.shape) shape[dim:dim + 1] = [buckets, -1] return t.reshape(*shape) def differentiable_topk(x, k, temperature=1.0): *_, n, dim = x.shape topk_tensors = [] for i in range(k): is_last = i == k - 1 values, indices = (x / temperature).softmax(dim=-1).topk(1, dim=-1) topks = torch.zeros_like(x).scatter_(-1, indices, values) topk_tensors.append(topks) if not is_last: x.scatter_(-1, indices, float('-inf')) topks = torch.cat(topk_tensors, dim=-1) return topks.reshape(*_, k * n, dim) def max_neg_value(tensor): return -torch.finfo(tensor.dtype).max def cumavg(t, dim): r = torch.arange(1, t.shape[dim] + 1, device=t.device, dtype=t.dtype) expand_slice = [None] * len(t.shape) expand_slice[dim] = slice(None, None) return t.cumsum(dim=dim) / r[tuple(expand_slice)] def mask_reordering_matrix(R, topk, temperature): buckets = R.shape[1] mask_value = max_neg_value(R) mask = torch.zeros(R.shape, device=R.device).bool() i, j = torch.triu_indices(buckets, buckets) mask[:, i, j + topk] = True R.masked_fill_(mask, mask_value) return differentiable_topk(R, topk, temperature) class CausalAttentionSortNet(nn.Module): def __init__(self, heads, bucket_size, dim, temperature): super().__init__() self.heads = heads self.bucket_size = bucket_size self.dim = dim self.temperature = temperature def forward(self, q, k, topk=1): bh, *_, h, dim = *q.shape, self.heads, self.dim bh // h buckets = q.shape[1] // self.bucket_size kv_buckets = k.shape[1] // self.bucket_size q_r = bucket(buckets, cumavg(q, dim=1)) k_r = bucket(kv_buckets, cumavg(k, dim=1)) sq = q_r[:, :, 0] sk = k_r.sum(dim=2) sk = F.pad(sk, (0, 0, topk, 0)) R = torch.einsum('bie,bje->bij', sq, sk) * dim ** -0.5 return mask_reordering_matrix(R, topk, self.temperature) def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'heads': 4, 'bucket_size': 4, 'dim': 4, 'temperature': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_triu_indices_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp0.to(tl.float64) tmp6 = tl.full([1], 2.0, tl.float64) tmp7 = tmp5 * tmp6 tmp8 = tl.full([1], 2.25, tl.float64) tmp9 = tmp8 - tmp7 tmp10 = libdevice.sqrt(tmp9) tmp11 = tl.full([1], 1.5, tl.float64) tmp12 = tmp11 - tmp10 tmp13 = libdevice.floor(tmp12) tmp14 = tmp13.to(tl.int64) tmp15 = tmp14 + tmp1 tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp4, tmp15, tmp16) tmp18 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp21 = -1 + x0 tmp22 = tmp21.to(tl.float64) tmp23 = tmp22 * tmp6 tmp24 = tmp8 - tmp23 tmp25 = libdevice.sqrt(tmp24) tmp26 = tmp11 - tmp25 tmp27 = libdevice.floor(tmp26) tmp28 = tl.full([1], 1.0, tl.float64) tmp29 = tmp28 - tmp27 tmp30 = tmp29 * tmp27 tmp31 = tl.full([1], 0.5, tl.float64) tmp32 = tmp30 * tmp31 tmp33 = tmp22 - tmp32 tmp34 = libdevice.floor(tmp33) tmp35 = tmp34.to(tl.int64) tmp36 = tmp35 + tmp1 tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp18, tmp36, tmp37) tmp39 = tl.where(tmp4, tmp17, tmp38) tl.store(out_ptr0 + x0, tmp39, xmask) @triton.jit def triton_poi_fused__to_copy_1(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.full([1], False, tl.int1) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused__to_copy_index_put_lift_fresh_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 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp7 = tl.load(in_ptr0 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp2 = tl.full([XBLOCK], 1, tl.int32) tmp3 = tmp1 + tmp2 tmp4 = tmp1 < 0 tmp5 = tl.where(tmp4, tmp3, tmp1) tl.device_assert((0 <= tmp5) & (tmp5 < 1), 'index out of bounds: 0 <= tmp5 < 1') tmp9 = tl.full([1], 1, tl.int64) tmp10 = tmp8 + tmp9 tmp11 = tl.full([XBLOCK], 2, tl.int32) tmp12 = tmp10 + tmp11 tmp13 = tmp10 < 0 tmp14 = tl.where(tmp13, tmp12, tmp10) tl.device_assert((0 <= tmp14) & (tmp14 < 2), 'index out of bounds: 0 <= tmp14 < 2') tmp16 = tl.full([1], True, tl.int1) tl.store(out_ptr0 + (tmp14 + 2 * x0), tmp16, xmask) @triton.jit def _triton_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_3(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl .constexpr): xnumel = 16 RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x0 + 4 * r2 + 16 * x1), xmask, other=0.0) tmp1 = tmp0.to(tl.float32) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp3, = tl.associative_scan((tmp2,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (x0 + 4 * r2 + 16 * x1), tmp3, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_sum_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 2 x0 = xindex % 4 x2 = xindex // 8 x3 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp2 & xmask, eviction_policy= 'evict_last', other=0.0) tmp4 = 1.0 tmp5 = tmp3 / tmp4 tmp6 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), tmp2 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = 2.0 tmp8 = tmp6 / tmp7 tmp9 = tmp5 + tmp8 tmp10 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), tmp2 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = 3.0 tmp12 = tmp10 / tmp11 tmp13 = tmp9 + tmp12 tmp14 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), tmp2 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp13 + tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp2, tmp17, tmp18) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused_div_5(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = 1 + x1 tmp2 = tmp1.to(tl.float32) tmp3 = tmp0 / tmp2 tl.store(in_out_ptr0 + x3, tmp3, xmask) @triton.jit def triton_poi_fused__softmax_masked_fill_mul_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 2 tmp0 = tl.load(in_ptr0 + x2, xmask).to(tl.int1) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp8 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last').to(tl .int1) tmp9 = tl.load(in_ptr1 + 2 * x1, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp14 = tl.load(in_ptr1 + (1 + 2 * x1), xmask, eviction_policy='evict_last' ) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = -3.4028234663852886e+38 tmp5 = tl.where(tmp0, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp10 = tmp9 * tmp2 tmp11 = tl.where(tmp8, tmp4, tmp10) tmp12 = tmp11 * tmp6 tmp15 = tmp14 * tmp2 tmp16 = tl.where(tmp13, tmp4, tmp15) tmp17 = tmp16 * tmp6 tmp18 = triton_helpers.maximum(tmp12, tmp17) tmp19 = tmp7 - tmp18 tmp20 = 0.25 tmp21 = tmp19 * tmp20 tmp22 = tl_math.exp(tmp21) tl.store(out_ptr0 + x2, tmp22, xmask) @triton.jit def triton_poi_fused__softmax_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 2 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 / tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_scatter_zeros_like_8(out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_scatter_zeros_like_9(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tl.device_assert((0 <= tmp0) & (tmp0 < 2) | ~xmask, 'index out of bounds: 0 <= tmp0 < 2') tl.store(out_ptr0 + (tmp0 + 2 * x0), tmp2, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((2,), (1,), torch.int64) get_raw_stream(0) triton_poi_fused_triu_indices_0[grid(2)](buf0, 2, XBLOCK=2, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 1, 2), (2, 2, 1), torch.bool) triton_poi_fused__to_copy_1[grid(8)](buf1, 8, XBLOCK=8, num_warps=1, num_stages=1) triton_poi_fused__to_copy_index_put_lift_fresh_2[grid(4)](buf0, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf0 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_per_fused_cumsum_3[grid(16)](arg0_1, buf3, 16, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_per_fused_cumsum_3[grid(16)](arg1_1, buf4, 16, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg1_1 buf5 = empty_strided_cuda((4, 2, 4), (8, 4, 1), torch.float32) triton_poi_fused_constant_pad_nd_sum_4[grid(32)](buf4, buf5, 32, XBLOCK=32, num_warps=1, num_stages=1) del buf4 buf6 = buf3 del buf3 triton_poi_fused_div_5[grid(64)](buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 1, 2), (2, 2, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf6, (4, 1, 4), (16, 0, 1), 0), reinterpret_tensor(buf5, (4, 4, 2), (8, 1, 4), 0), out=buf7) del buf5 del buf6 buf8 = empty_strided_cuda((4, 1, 2), (2, 8, 1), torch.float32) triton_poi_fused__softmax_masked_fill_mul_6[grid(8)](buf1, buf7, buf8, 8, XBLOCK=8, num_warps=1, num_stages=1) del buf1 buf9 = reinterpret_tensor(buf7, (4, 1, 2), (2, 8, 1), 0) del buf7 triton_poi_fused__softmax_7[grid(8)](buf8, buf9, 8, XBLOCK=8, num_warps=1, num_stages=1) del buf8 buf10 = torch.ops.aten.topk.default(buf9, 1) buf11 = buf10[0] buf12 = buf10[1] del buf10 buf13 = reinterpret_tensor(buf9, (4, 1, 2), (2, 2, 1), 0) del buf9 triton_poi_fused_scatter_zeros_like_8[grid(8)](buf13, 8, XBLOCK=8, num_warps=1, num_stages=1) triton_poi_fused_scatter_zeros_like_9[grid(4)](buf12, buf11, buf13, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf11 del buf12 return buf13, def bucket(buckets, t, dim=1): shape = list(t.shape) shape[dim:dim + 1] = [buckets, -1] return t.reshape(*shape) def differentiable_topk(x, k, temperature=1.0): *_, n, dim = x.shape topk_tensors = [] for i in range(k): is_last = i == k - 1 values, indices = (x / temperature).softmax(dim=-1).topk(1, dim=-1) topks = torch.zeros_like(x).scatter_(-1, indices, values) topk_tensors.append(topks) if not is_last: x.scatter_(-1, indices, float('-inf')) topks = torch.cat(topk_tensors, dim=-1) return topks.reshape(*_, k * n, dim) def max_neg_value(tensor): return -torch.finfo(tensor.dtype).max def cumavg(t, dim): r = torch.arange(1, t.shape[dim] + 1, device=t.device, dtype=t.dtype) expand_slice = [None] * len(t.shape) expand_slice[dim] = slice(None, None) return t.cumsum(dim=dim) / r[tuple(expand_slice)] def mask_reordering_matrix(R, topk, temperature): buckets = R.shape[1] mask_value = max_neg_value(R) mask = torch.zeros(R.shape, device=R.device).bool() i, j = torch.triu_indices(buckets, buckets) mask[:, i, j + topk] = True R.masked_fill_(mask, mask_value) return differentiable_topk(R, topk, temperature) class CausalAttentionSortNetNew(nn.Module): def __init__(self, heads, bucket_size, dim, temperature): super().__init__() self.heads = heads self.bucket_size = bucket_size self.dim = dim self.temperature = temperature def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
lucidrains/sinkhorn-transformer
CausalAttentionSortNet
false
15,994
[ "MIT" ]
216
531bdbe46dfc2abd20183dbcede669bc9df567c6
https://github.com/lucidrains/sinkhorn-transformer/tree/531bdbe46dfc2abd20183dbcede669bc9df567c6