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
FocalLoss
import torch import torch.nn.functional as F class FocalLoss(torch.nn.Module): def __init__(self, gamma=2): super().__init__() self.gamma = gamma def forward(self, input, target): if not target.size() == input.size(): raise ValueError( 'Target size ({}) must be the same as input size ({})'. format(target.size(), input.size())) max_val = (-input).clamp(min=0) loss = input - input * target + max_val + ((-max_val).exp() + (- input - max_val).exp()).log() invprobs = F.logsigmoid(-input * (target * 2.0 - 1.0)) loss = (invprobs * self.gamma).exp() * loss return loss.sum(dim=1).mean() 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 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_exp_log_log_sigmoid_forward_mean_mul_neg_sub_sum_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp2 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp29 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp31 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp56 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp58 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp83 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp85 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp1 = -tmp0 tmp3 = 2.0 tmp4 = tmp2 * tmp3 tmp5 = 1.0 tmp6 = tmp4 - tmp5 tmp7 = tmp1 * tmp6 tmp8 = 0.0 tmp9 = triton_helpers.minimum(tmp8, tmp7) tmp10 = tl_math.abs(tmp7) tmp11 = -tmp10 tmp12 = tl_math.exp(tmp11) tmp13 = libdevice.log1p(tmp12) tmp14 = tmp9 - tmp13 tmp15 = tmp14 * tmp3 tmp16 = tl_math.exp(tmp15) tmp17 = tmp0 * tmp2 tmp18 = tmp0 - tmp17 tmp19 = triton_helpers.maximum(tmp1, tmp8) tmp20 = tmp18 + tmp19 tmp21 = -tmp19 tmp22 = tl_math.exp(tmp21) tmp23 = tmp1 - tmp19 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = tl_math.log(tmp25) tmp27 = tmp20 + tmp26 tmp28 = tmp16 * tmp27 tmp30 = -tmp29 tmp32 = tmp31 * tmp3 tmp33 = tmp32 - tmp5 tmp34 = tmp30 * tmp33 tmp35 = triton_helpers.minimum(tmp8, tmp34) tmp36 = tl_math.abs(tmp34) tmp37 = -tmp36 tmp38 = tl_math.exp(tmp37) tmp39 = libdevice.log1p(tmp38) tmp40 = tmp35 - tmp39 tmp41 = tmp40 * tmp3 tmp42 = tl_math.exp(tmp41) tmp43 = tmp29 * tmp31 tmp44 = tmp29 - tmp43 tmp45 = triton_helpers.maximum(tmp30, tmp8) tmp46 = tmp44 + tmp45 tmp47 = -tmp45 tmp48 = tl_math.exp(tmp47) tmp49 = tmp30 - tmp45 tmp50 = tl_math.exp(tmp49) tmp51 = tmp48 + tmp50 tmp52 = tl_math.log(tmp51) tmp53 = tmp46 + tmp52 tmp54 = tmp42 * tmp53 tmp55 = tmp28 + tmp54 tmp57 = -tmp56 tmp59 = tmp58 * tmp3 tmp60 = tmp59 - tmp5 tmp61 = tmp57 * tmp60 tmp62 = triton_helpers.minimum(tmp8, tmp61) tmp63 = tl_math.abs(tmp61) tmp64 = -tmp63 tmp65 = tl_math.exp(tmp64) tmp66 = libdevice.log1p(tmp65) tmp67 = tmp62 - tmp66 tmp68 = tmp67 * tmp3 tmp69 = tl_math.exp(tmp68) tmp70 = tmp56 * tmp58 tmp71 = tmp56 - tmp70 tmp72 = triton_helpers.maximum(tmp57, tmp8) tmp73 = tmp71 + tmp72 tmp74 = -tmp72 tmp75 = tl_math.exp(tmp74) tmp76 = tmp57 - tmp72 tmp77 = tl_math.exp(tmp76) tmp78 = tmp75 + tmp77 tmp79 = tl_math.log(tmp78) tmp80 = tmp73 + tmp79 tmp81 = tmp69 * tmp80 tmp82 = tmp55 + tmp81 tmp84 = -tmp83 tmp86 = tmp85 * tmp3 tmp87 = tmp86 - tmp5 tmp88 = tmp84 * tmp87 tmp89 = triton_helpers.minimum(tmp8, tmp88) tmp90 = tl_math.abs(tmp88) tmp91 = -tmp90 tmp92 = tl_math.exp(tmp91) tmp93 = libdevice.log1p(tmp92) tmp94 = tmp89 - tmp93 tmp95 = tmp94 * tmp3 tmp96 = tl_math.exp(tmp95) tmp97 = tmp83 * tmp85 tmp98 = tmp83 - tmp97 tmp99 = triton_helpers.maximum(tmp84, tmp8) tmp100 = tmp98 + tmp99 tmp101 = -tmp99 tmp102 = tl_math.exp(tmp101) tmp103 = tmp84 - tmp99 tmp104 = tl_math.exp(tmp103) tmp105 = tmp102 + tmp104 tmp106 = tl_math.log(tmp105) tmp107 = tmp100 + tmp106 tmp108 = tmp96 * tmp107 tmp109 = tmp82 + tmp108 tmp110 = tl.broadcast_to(tmp109, [XBLOCK, RBLOCK]) tmp112 = tl.sum(tmp110, 1)[:, None] tmp113 = 64.0 tmp114 = tmp112 / tmp113 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp114, 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_exp_log_log_sigmoid_forward_mean_mul_neg_sub_sum_0[ grid(1)](buf2, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class FocalLossNew(torch.nn.Module): def __init__(self, gamma=2): super().__init__() self.gamma = gamma def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
rskmoi/kaggle-imet
FocalLoss
false
7,582
[ "MIT" ]
1
483e9e6dbae5b1d8e023e0812c4b990afca874bc
https://github.com/rskmoi/kaggle-imet/tree/483e9e6dbae5b1d8e023e0812c4b990afca874bc
ECToCA3
import torch import torch.nn as nn import torch.nn.functional as F class ECToCA3(nn.Module): def __init__(self, D_in, D_out): super(ECToCA3, self).__init__() self.fc1 = nn.Linear(D_in, 800) self.fc2 = nn.Linear(800, D_out) def forward(self, x): x = F.leaky_relu(self.fc1(x), 0.1618) x = torch.sigmoid(self.fc2(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'D_in': 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 800 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1618 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_sigmoid_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.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (800, 4), (4, 1)) assert_size_stride(primals_2, (800,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 800), (800, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 800), (800, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 800), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 800), (12800, 3200, 800, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 800), (12800, 3200, 800, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(51200)](buf0, primals_2, buf1, buf2, 51200, XBLOCK=512, num_warps=4, num_stages=1) del buf0 del primals_2 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (64, 800), (800, 1), 0), reinterpret_tensor(primals_4, (800, 4), (1, 800), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused_sigmoid_1[grid(256)](buf4, primals_5, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 800), (800, 1), 0 ), buf4, primals_4 class ECToCA3New(nn.Module): def __init__(self, D_in, D_out): super(ECToCA3New, self).__init__() self.fc1 = nn.Linear(D_in, 800) self.fc2 = nn.Linear(800, D_out) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
sachio222/aha4
ECToCA3
false
7,583
[ "MIT" ]
1
ec378fe1bace85e325ad7cb8686b8ba321dc97d0
https://github.com/sachio222/aha4/tree/ec378fe1bace85e325ad7cb8686b8ba321dc97d0
n_to_one
import torch from torch import nn class n_to_one(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(3, 3, 1, 1, bias=False) self.conv2 = nn.Conv2d(3, 3, 1, 1, bias=False) def forward(self, x1, x2): y1 = self.conv1(x1) y2 = self.conv2(x2) return y1 + y2 def get_inputs(): return [torch.rand([4, 3, 64, 64]), torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (3, 3, 1, 1), (3, 1, 1, 1)) assert_size_stride(primals_2, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_3, (3, 3, 1, 1), (3, 1, 1, 1)) assert_size_stride(primals_4, (4, 3, 64, 64), (12288, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 3, 64, 64), (12288, 4096, 64, 1)) buf1 = extern_kernels.convolution(primals_4, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 3, 64, 64), (12288, 4096, 64, 1)) buf2 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_0[grid(49152)](buf2, buf1, 49152, XBLOCK=256, num_warps=4, num_stages=1) del buf1 return buf2, primals_1, primals_2, primals_3, primals_4 class n_to_oneNew(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(3, 3, 1, 1, bias=False) self.conv2 = nn.Conv2d(3, 3, 1, 1, bias=False) def forward(self, input_0, input_1): primals_1 = self.conv1.weight primals_3 = self.conv2.weight primals_2 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
sailfish009/torch-toolbox
n_to_one
false
7,584
[ "BSD-3-Clause" ]
1
80dfc22c697b9f323e097de72af04f0e5435d7b4
https://github.com/sailfish009/torch-toolbox/tree/80dfc22c697b9f323e097de72af04f0e5435d7b4
ActorDDPGNonConvNetwork
import torch import numpy as np import torch.nn as nn from numpy import * def fanin_init(size, fanin=None): fanin = fanin or size[0] v = 1.0 / np.sqrt(fanin) return torch.Tensor(size).uniform_(-v, v) class ActorDDPGNonConvNetwork(nn.Module): def __init__(self, num_hidden_layers, output_action, input): super(ActorDDPGNonConvNetwork, self).__init__() self.num_hidden_layers = num_hidden_layers self.input = input self.output_action = output_action self.init_w = 0.003 self.dense_1 = nn.Linear(self.input, self.num_hidden_layers) self.relu1 = nn.ReLU(inplace=True) self.dense_2 = nn.Linear(self.num_hidden_layers, self.num_hidden_layers ) self.relu2 = nn.ReLU(inplace=True) self.output = nn.Linear(self.num_hidden_layers, self.output_action) self.tanh = nn.Tanh() def init_weights(self, init_w): self.dense_1.weight.data = fanin_init(self.dense_1.weight.data.size()) self.dense_2.weight.data = fanin_init(self.dense_2.weight.data.size()) self.output.weight.data.uniform_(-init_w, init_w) def forward(self, input): x = self.dense_1(input) x = self.relu1(x) x = self.dense_2(x) x = self.relu2(x) output = self.output(x) output = self.tanh(output) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_hidden_layers': 1, 'output_action': 4, 'input': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn from numpy import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = 0.0 tmp7 = tmp5 <= tmp6 tl.store(in_out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x0 % 4 // 4) + 16 * ((4 * (x0 // 4 % 4) + x0 % 4) // 16)), xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) 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, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 1), (1, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4, 1), (1, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf1, primals_2, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused_view_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (64, 1), (1, 1), 0) del buf1 extern_kernels.mm(buf2, primals_4, out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf3 buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf4, primals_5, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused_view_1[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf4 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_6, (1, 4), (1, 1 ), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused_tanh_2[grid(256)](buf7, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 return buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, buf5, buf7, primals_6, buf8, primals_4, buf9 def fanin_init(size, fanin=None): fanin = fanin or size[0] v = 1.0 / np.sqrt(fanin) return torch.Tensor(size).uniform_(-v, v) class ActorDDPGNonConvNetworkNew(nn.Module): def __init__(self, num_hidden_layers, output_action, input): super(ActorDDPGNonConvNetworkNew, self).__init__() self.num_hidden_layers = num_hidden_layers self.input = input self.output_action = output_action self.init_w = 0.003 self.dense_1 = nn.Linear(self.input, self.num_hidden_layers) self.relu1 = nn.ReLU(inplace=True) self.dense_2 = nn.Linear(self.num_hidden_layers, self.num_hidden_layers ) self.relu2 = nn.ReLU(inplace=True) self.output = nn.Linear(self.num_hidden_layers, self.output_action) self.tanh = nn.Tanh() def init_weights(self, init_w): self.dense_1.weight.data = fanin_init(self.dense_1.weight.data.size()) self.dense_2.weight.data = fanin_init(self.dense_2.weight.data.size()) self.output.weight.data.uniform_(-init_w, init_w) def forward(self, input_0): primals_1 = self.dense_1.weight primals_2 = self.dense_1.bias primals_4 = self.dense_2.weight primals_5 = self.dense_2.bias primals_6 = self.output.weight primals_7 = self.output.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
ruyueshuo/MaskTrackRCNN
ActorDDPGNonConvNetwork
false
7,585
[ "Apache-2.0" ]
1
3c6ada36be3c2b2df32176349ec5c0ee5b24e724
https://github.com/ruyueshuo/MaskTrackRCNN/tree/3c6ada36be3c2b2df32176349ec5c0ee5b24e724
CA1
import torch import torch.nn as nn import torch.nn.functional as F class CA1(nn.Module): """Reconstructs the inputs that originated from EC network. Consists of 2 fully connected layers, recieving inputs from CA3 and outputs to EC. """ def __init__(self, N, D_in, D_out, resize_dim): super(CA1, self).__init__() self.N, self.resize_dim = N, resize_dim self.fc1 = nn.Linear(D_in, 100) self.fc2 = nn.Linear(100, D_out) nn.init.xavier_uniform_(self.fc1.weight) def forward(self, x): x = F.leaky_relu(self.fc1(x), 0.1) x = F.leaky_relu(self.fc2(x), 0.1) x = x.view(self.N, 1, self.resize_dim, self.resize_dim) return x def get_inputs(): return [torch.rand([4, 1, 4, 4])] def get_init_inputs(): return [[], {'N': 4, 'D_in': 4, 'D_out': 4, 'resize_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_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 100 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (100, 4), (4, 1)) assert_size_stride(primals_2, (100,), (1,)) assert_size_stride(primals_3, (4, 1, 4, 4), (16, 16, 4, 1)) assert_size_stride(primals_4, (4, 100), (100, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 100), (100, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 100), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 1, 4, 100), (400, 400, 100, 1), torch .bool) buf2 = empty_strided_cuda((4, 1, 4, 100), (400, 1, 100, 1), torch. float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(1600)](buf0, primals_2, buf1, buf2, 1600, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 100), (100, 1), 0), reinterpret_tensor(primals_4, (100, 4), (1, 100), 0), out=buf3) buf4 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.bool) buf5 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) triton_poi_fused_leaky_relu_1[grid(64)](buf3, primals_5, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 del primals_5 return buf5, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (16, 100), (100, 1), 0 ), buf4, primals_4 class CA1New(nn.Module): """Reconstructs the inputs that originated from EC network. Consists of 2 fully connected layers, recieving inputs from CA3 and outputs to EC. """ def __init__(self, N, D_in, D_out, resize_dim): super(CA1New, self).__init__() self.N, self.resize_dim = N, resize_dim self.fc1 = nn.Linear(D_in, 100) self.fc2 = nn.Linear(100, D_out) nn.init.xavier_uniform_(self.fc1.weight) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
sachio222/aha4
CA1
false
7,586
[ "MIT" ]
1
ec378fe1bace85e325ad7cb8686b8ba321dc97d0
https://github.com/sachio222/aha4/tree/ec378fe1bace85e325ad7cb8686b8ba321dc97d0
Sparsemax
from torch.autograd import Function import torch import torch.nn as nn def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _sparsemax_threshold_and_support(X, dim=-1, k=None): """Core computation for sparsemax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: topk, _ = torch.sort(X, dim=dim, descending=True) else: topk, _ = torch.topk(X, k=k, dim=dim) topk_cumsum = topk.cumsum(dim) - 1 rhos = _make_ix_like(topk, dim) support = rhos * topk > topk_cumsum support_size = support.sum(dim=dim).unsqueeze(dim) tau = topk_cumsum.gather(dim, support_size - 1) tau /= support_size if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): in_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _sparsemax_threshold_and_support(in_, dim=-1, k=2 * k) _roll_last(tau, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau, support_size def sparsemax(X, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxFunction.apply(X, dim, k) class SparsemaxFunction(Function): @classmethod def forward(cls, ctx, X, dim=-1, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val tau, supp_size = _sparsemax_threshold_and_support(X, dim=dim, k=k) output = torch.clamp(X - tau, min=0) ctx.save_for_backward(supp_size, output) return output @classmethod def backward(cls, ctx, grad_output): supp_size, output = ctx.saved_tensors dim = ctx.dim grad_input = grad_output.clone() grad_input[output == 0] = 0 v_hat = grad_input.sum(dim=dim) / supp_size.squeeze() v_hat = v_hat.unsqueeze(dim) grad_input = torch.where(output != 0, grad_input - v_hat, grad_input) return grad_input, None, None class Sparsemax(nn.Module): def __init__(self, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Sparsemax, self).__init__() def forward(self, X): return sparsemax(X, dim=self.dim, k=self.k) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch.autograd import Function import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def _triton_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_max_sort_sub_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = r1 tmp10 = tmp9.to(tl.int16) tmp11 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp12 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13, _tmp14 = triton_helpers.sort_with_index(tmp11, tmp12, None, 1, stable=False, descending=True) tmp15 = tmp13.to(tl.float32) tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp17, = tl.associative_scan((tmp16,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (r1 + 4 * x0), tmp8, xmask) tl.store(out_ptr1 + (r1 + 4 * x0), tmp13, xmask) tl.store(out_ptr2 + (r1 + 4 * x0), tmp17, xmask) @triton.jit def triton_poi_fused_gt_mul_sub_sum_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp23 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp26 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp1 * tmp0 tmp4 = tmp3 - tmp1 tmp5 = tmp2 > tmp4 tmp6 = tmp5.to(tl.int64) tmp8 = 2.0 tmp9 = tmp8 * tmp7 tmp11 = tmp10 - tmp1 tmp12 = tmp9 > tmp11 tmp13 = tmp12.to(tl.int64) tmp14 = tmp6 + tmp13 tmp16 = 3.0 tmp17 = tmp16 * tmp15 tmp19 = tmp18 - tmp1 tmp20 = tmp17 > tmp19 tmp21 = tmp20.to(tl.int64) tmp22 = tmp14 + tmp21 tmp24 = 4.0 tmp25 = tmp24 * tmp23 tmp27 = tmp26 - tmp1 tmp28 = tmp25 > tmp27 tmp29 = tmp28.to(tl.int64) tmp30 = tmp22 + tmp29 tl.store(out_ptr0 + x0, tmp30, xmask) @triton.jit def triton_poi_fused_clamp_div_gather_sub_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) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.full([1], 1, tl.int64) tmp3 = tmp1 - tmp2 tmp4 = tl.full([XBLOCK], 4, tl.int32) tmp5 = tmp3 + tmp4 tmp6 = tmp3 < 0 tmp7 = tl.where(tmp6, tmp5, tmp3) tl.device_assert((0 <= tmp7) & (tmp7 < 4) | ~xmask, 'index out of bounds: 0 <= tmp7 < 4') tmp9 = tl.load(in_ptr2 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp10 = 1.0 tmp11 = tmp9 - tmp10 tmp12 = tmp1.to(tl.float32) tmp13 = tmp11 / tmp12 tmp14 = tmp0 - tmp13 tmp15 = 0.0 tmp16 = triton_helpers.maximum(tmp14, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_cumsum_max_sort_sub_0[grid(64)](arg0_1, buf0, buf1, buf3, 64, 4, XBLOCK=32, num_warps=2, num_stages=1) del arg0_1 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) triton_poi_fused_gt_mul_sub_sum_1[grid(64)](buf1, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf1 del buf1 triton_poi_fused_clamp_div_gather_sub_2[grid(256)](buf0, buf4, buf3, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del buf3 del buf4 return buf5, def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _sparsemax_threshold_and_support(X, dim=-1, k=None): """Core computation for sparsemax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: topk, _ = torch.sort(X, dim=dim, descending=True) else: topk, _ = torch.topk(X, k=k, dim=dim) topk_cumsum = topk.cumsum(dim) - 1 rhos = _make_ix_like(topk, dim) support = rhos * topk > topk_cumsum support_size = support.sum(dim=dim).unsqueeze(dim) tau = topk_cumsum.gather(dim, support_size - 1) tau /= support_size if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): in_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _sparsemax_threshold_and_support(in_, dim=-1, k=2 * k) _roll_last(tau, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau, support_size def sparsemax(X, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxFunction.apply(X, dim, k) class SparsemaxFunction(Function): @classmethod def forward(cls, ctx, X, dim=-1, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val tau, supp_size = _sparsemax_threshold_and_support(X, dim=dim, k=k) output = torch.clamp(X - tau, min=0) ctx.save_for_backward(supp_size, output) return output @classmethod def backward(cls, ctx, grad_output): supp_size, output = ctx.saved_tensors dim = ctx.dim grad_input = grad_output.clone() grad_input[output == 0] = 0 v_hat = grad_input.sum(dim=dim) / supp_size.squeeze() v_hat = v_hat.unsqueeze(dim) grad_input = torch.where(output != 0, grad_input - v_hat, grad_input) return grad_input, None, None class SparsemaxNew(nn.Module): def __init__(self, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(SparsemaxNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
roholazandie/entmax
Sparsemax
false
7,587
[ "MIT" ]
1
657374e6a792ec6840b6f78bc759cc1f51570aad
https://github.com/roholazandie/entmax/tree/657374e6a792ec6840b6f78bc759cc1f51570aad
L0Loss
import torch from torch import nn class L0Loss(nn.Module): """L0loss from "Noise2Noise: Learning Image Restoration without Clean Data" <https://arxiv.org/pdf/1803.04189>`_ paper. """ def __init__(self, gamma=2, eps=1e-08): super(L0Loss, self).__init__() self.gamma = gamma self.eps = eps def forward(self, pred, target): loss = (torch.abs(pred - target) + self.eps).pow(self.gamma) return torch.mean(loss) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_mean_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 1e-08 tmp5 = tmp3 + 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_abs_add_mean_pow_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class L0LossNew(nn.Module): """L0loss from "Noise2Noise: Learning Image Restoration without Clean Data" <https://arxiv.org/pdf/1803.04189>`_ paper. """ def __init__(self, gamma=2, eps=1e-08): super(L0LossNew, self).__init__() self.gamma = gamma 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]
sailfish009/torch-toolbox
L0Loss
false
7,588
[ "BSD-3-Clause" ]
1
80dfc22c697b9f323e097de72af04f0e5435d7b4
https://github.com/sailfish009/torch-toolbox/tree/80dfc22c697b9f323e097de72af04f0e5435d7b4
BertSelfOutput
from _paritybench_helpers import _mock_config import torch from torch import nn class BertLayerNorm(nn.Module): def __init__(self, config, variance_epsilon=1e-12): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.gamma = nn.Parameter(torch.ones(config.hidden_size)) self.beta = nn.Parameter(torch.zeros(config.hidden_size)) self.variance_epsilon = variance_epsilon def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.gamma * x + self.beta class BertSelfOutput(nn.Module): def __init__(self, config): super(BertSelfOutput, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, hidden_dropout_prob= 0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mean_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp10 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + 2) tmp15 = tl.broadcast_to(tmp14, [XBLOCK]) tmp17 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp21 = tl.load(in_ptr1 + 3) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp24 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tmp0 + tmp2 tmp5 = tmp3 + tmp4 tmp9 = tmp6 + tmp8 tmp11 = tmp9 + tmp10 tmp12 = tmp5 + tmp11 tmp16 = tmp13 + tmp15 tmp18 = tmp16 + tmp17 tmp19 = tmp12 + tmp18 tmp23 = tmp20 + tmp22 tmp25 = tmp23 + tmp24 tmp26 = tmp19 + tmp25 tmp27 = 4.0 tmp28 = tmp26 / tmp27 tl.store(out_ptr0 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_sub_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = 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) tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 - tmp5 tl.store(in_out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_pow_sqrt_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp2 * tmp2 tmp5 = tmp4 * tmp4 tmp6 = tmp3 + tmp5 tmp8 = tmp7 * tmp7 tmp9 = tmp6 + tmp8 tmp11 = tmp10 * tmp10 tmp12 = tmp9 + tmp11 tmp13 = 4.0 tmp14 = tmp12 / tmp13 tmp15 = 1e-12 tmp16 = tmp14 + tmp15 tmp17 = libdevice.sqrt(tmp16) tmp18 = tmp1 / tmp17 tmp19 = tmp0 * tmp18 tmp21 = tmp19 + tmp20 tl.store(out_ptr0 + x2, tmp21, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_mean_0[grid(64)](buf0, primals_2, primals_4, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_add_sub_1[grid(256)](buf2, primals_2, primals_4, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_2 del primals_4 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_pow_sqrt_2[grid(256)](primals_5, buf2, primals_6, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_6 return buf3, primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2 class BertLayerNorm(nn.Module): def __init__(self, config, variance_epsilon=1e-12): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.gamma = nn.Parameter(torch.ones(config.hidden_size)) self.beta = nn.Parameter(torch.zeros(config.hidden_size)) self.variance_epsilon = variance_epsilon def forward(self, x): u = x.mean(-1, keepdim=True) s = (x - u).pow(2).mean(-1, keepdim=True) x = (x - u) / torch.sqrt(s + self.variance_epsilon) return self.gamma * x + self.beta class BertSelfOutputNew(nn.Module): def __init__(self, config): super(BertSelfOutputNew, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, input_0, input_1): primals_1 = self.dense.weight primals_2 = self.dense.bias primals_5 = self.LayerNorm.gamma primals_6 = self.LayerNorm.beta primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
BLimmie/pytorch-pretrained-BERT
BertSelfOutput
false
7,589
[ "Apache-2.0" ]
1
2ac4b29641e569020ed2acc28016f481f617052b
https://github.com/BLimmie/pytorch-pretrained-BERT/tree/2ac4b29641e569020ed2acc28016f481f617052b
LossPredictionLoss
import torch import torch.nn as nn class LossPredictionLoss(nn.Module): def __init__(self, margin=1.0): super(LossPredictionLoss, self).__init__() self.margin = margin def forward(self, input, target): input = (input - input.flip(0))[:len(input) // 2] target = (target - target.flip(0))[:len(target) // 2] target = target.detach() one = 2 * torch.sign(torch.clamp(target, min=0)) - 1 loss = torch.sum(torch.clamp(self.margin - one * input, min=0)) loss = loss / input.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 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_clamp_div_mul_rsub_sign_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 128 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex r0 = rindex % 64 r1 = rindex // 64 tmp0 = tl.load(in_ptr0 + r2, None) tmp1 = tl.load(in_ptr0 + (192 + r0 + -64 * r1), None) tmp16 = tl.load(in_ptr1 + r2, None) tmp17 = tl.load(in_ptr1 + (192 + r0 + -64 * r1), None) tmp2 = tmp0 - tmp1 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = tl.full([1, 1], 0, tl.int32) tmp6 = tmp5 < tmp4 tmp7 = tmp6.to(tl.int8) tmp8 = tmp4 < tmp5 tmp9 = tmp8.to(tl.int8) tmp10 = tmp7 - tmp9 tmp11 = tmp10.to(tmp4.dtype) tmp12 = 2.0 tmp13 = tmp11 * tmp12 tmp14 = 1.0 tmp15 = tmp13 - tmp14 tmp18 = tmp16 - tmp17 tmp19 = tmp15 * tmp18 tmp20 = tmp14 - tmp19 tmp21 = triton_helpers.maximum(tmp20, tmp3) tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp24 = tl.sum(tmp22, 1)[:, None] tmp25 = 0.5 tmp26 = tmp24 * tmp25 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp26, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_clamp_div_mul_rsub_sign_sub_sum_0[grid(1)](buf1, arg1_1, arg0_1, 1, 128, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class LossPredictionLossNew(nn.Module): def __init__(self, margin=1.0): super(LossPredictionLossNew, self).__init__() self.margin = margin def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
saksman/deepfish_adaptation
LossPredictionLoss
false
7,590
[ "MIT" ]
1
0413def87ec1d3cb67fa043a2fb60ef7e0d73539
https://github.com/saksman/deepfish_adaptation/tree/0413def87ec1d3cb67fa043a2fb60ef7e0d73539
SmallMaskNet
import torch import torch.nn as nn import torch.nn.functional as F class SmallMaskNet(nn.Module): """A three-layer network for predicting mask""" def __init__(self, input, output): super(SmallMaskNet, self).__init__() self.conv1 = nn.Conv2d(input, 32, 5, padding=2) self.conv2 = nn.Conv2d(32, 16, 3, padding=1) self.conv3 = nn.Conv2d(16, output, 3, padding=1) def forward(self, x): x = F.leaky_relu(self.conv1(x), negative_slope=0.1) x = F.leaky_relu(self.conv2(x), negative_slope=0.1) x = self.conv3(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input': 4, 'output': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 32 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.1 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (32, 4, 5, 5), (100, 25, 5, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (4, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 4, 4), (512, 16, 4, 1)) buf1 = empty_strided_cuda((4, 32, 4, 4), (512, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 32, 4, 4), (512, 16, 4, 1), torch.float32 ) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(2048)](buf0, primals_2, buf1, buf2, 2048, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_2 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 16, 4, 4), (256, 16, 4, 1)) buf4 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.bool) buf5 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.float32 ) triton_poi_fused_convolution_leaky_relu_1[grid(1024)](buf3, primals_5, buf4, buf5, 1024, XBLOCK=128, num_warps=4, num_stages=1) del buf3 del primals_5 buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_2[grid(256)](buf7, primals_7, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return (buf7, primals_1, primals_3, primals_4, primals_6, buf1, buf2, buf4, buf5) class SmallMaskNetNew(nn.Module): """A three-layer network for predicting mask""" def __init__(self, input, output): super(SmallMaskNetNew, self).__init__() self.conv1 = nn.Conv2d(input, 32, 5, padding=2) self.conv2 = nn.Conv2d(32, 16, 3, padding=1) self.conv3 = nn.Conv2d(16, output, 3, padding=1) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
saikatdutta/NME-VFI
SmallMaskNet
false
7,591
[ "Apache-2.0" ]
1
5915e2336ea3ed7113a9c6a91bbc7f6b5deaac17
https://github.com/saikatdutta/NME-VFI/tree/5915e2336ea3ed7113a9c6a91bbc7f6b5deaac17
ContinuousEmbeddings
import math import torch from torch import Tensor from torch import nn import torch.nn.functional as F def _get_activation_fn(activation): if activation == 'relu': return nn.ReLU(inplace=True) if activation == 'leaky_relu': return nn.LeakyReLU(inplace=True) elif activation == 'gelu': return nn.GELU() elif activation == 'geglu': return GEGLU() class GEGLU(nn.Module): def forward(self, x): x, gates = x.chunk(2, dim=-1) return x * F.gelu(gates) class ContinuousEmbeddings(nn.Module): def __init__(self, n_cont_cols: 'int', embed_dim: 'int', activation: 'str'=None, bias: 'bool'=True): super(ContinuousEmbeddings, self).__init__() self.n_cont_cols = n_cont_cols self.embed_dim = embed_dim self.activation = activation self.weight = nn.Parameter(torch.Tensor(n_cont_cols, embed_dim)) self.bias = nn.Parameter(torch.Tensor(n_cont_cols, embed_dim) ) if bias else None self._reset_parameters() self.act_fn = _get_activation_fn(activation) if activation else None def _reset_parameters(self) ->None: nn.init.kaiming_uniform_(self.weight, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight) bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0 nn.init.uniform_(self.bias, -bound, bound) def forward(self, X: 'Tensor') ->Tensor: x = self.weight.unsqueeze(0) * X.unsqueeze(2) if self.bias is not None: x = x + self.bias.unsqueeze(0) if self.act_fn is not None: x = self.act_fn(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_cont_cols': 4, 'embed_dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math from torch import nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp2 + tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 4, 4), (64, 16, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_3 return buf0, primals_2 def _get_activation_fn(activation): if activation == 'relu': return nn.ReLU(inplace=True) if activation == 'leaky_relu': return nn.LeakyReLU(inplace=True) elif activation == 'gelu': return nn.GELU() elif activation == 'geglu': return GEGLU() class GEGLU(nn.Module): def forward(self, x): x, gates = x.chunk(2, dim=-1) return x * F.gelu(gates) class ContinuousEmbeddingsNew(nn.Module): def __init__(self, n_cont_cols: 'int', embed_dim: 'int', activation: 'str'=None, bias: 'bool'=True): super(ContinuousEmbeddingsNew, self).__init__() self.n_cont_cols = n_cont_cols self.embed_dim = embed_dim self.activation = activation self.weight = nn.Parameter(torch.Tensor(n_cont_cols, embed_dim)) self.bias = nn.Parameter(torch.Tensor(n_cont_cols, embed_dim) ) if bias else None self._reset_parameters() self.act_fn = _get_activation_fn(activation) if activation else None def _reset_parameters(self) ->None: nn.init.kaiming_uniform_(self.weight, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight) bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0 nn.init.uniform_(self.bias, -bound, bound) def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
sallypannn/pytorch-widedeep
ContinuousEmbeddings
false
7,592
[ "MIT" ]
1
ab4a209a2a3bff539f543a66ac51306042ed6693
https://github.com/sallypannn/pytorch-widedeep/tree/ab4a209a2a3bff539f543a66ac51306042ed6693
Net
import torch import torch.nn as nn import torch.nn.functional class Net(nn.Module): def __init__(self, num_inputs=784, num_outputs=10, num_hiddens=256, is_training=True): super(Net, self).__init__() self.num_inputs = num_inputs self.num_outputs = num_outputs self.num_hiddens = num_hiddens self.linear_1 = nn.Linear(num_inputs, num_hiddens) self.linear_2 = nn.Linear(num_hiddens, num_outputs) self.relu = nn.ReLU() def forward(self, X): X = X.reshape((-1, self.num_inputs)) H1 = self.relu(self.linear_1(X)) out = self.linear_2(H1) return out def get_inputs(): return [torch.rand([4, 784])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.nn.functional 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 = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 784), (784, 1)) assert_size_stride(primals_2, (256, 784), (784, 1)) assert_size_stride(primals_3, (256,), (1,)) assert_size_stride(primals_4, (10, 256), (256, 1)) assert_size_stride(primals_5, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 256), (256, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (784, 256), (1, 784), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(1024)](buf1, primals_3, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_5, buf1, reinterpret_tensor(primals_4, (256, 10), (1, 256), 0), alpha=1, beta=1, out=buf2) del primals_5 return buf2, primals_1, buf1, primals_4 class NetNew(nn.Module): def __init__(self, num_inputs=784, num_outputs=10, num_hiddens=256, is_training=True): super(NetNew, self).__init__() self.num_inputs = num_inputs self.num_outputs = num_outputs self.num_hiddens = num_hiddens self.linear_1 = nn.Linear(num_inputs, num_hiddens) self.linear_2 = nn.Linear(num_hiddens, num_outputs) self.relu = nn.ReLU() def forward(self, input_0): primals_2 = self.linear_1.weight primals_3 = self.linear_1.bias primals_4 = self.linear_2.weight primals_5 = self.linear_2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
samjz06/d2l-pytorch
Net
false
7,593
[ "Apache-2.0" ]
1
80eca3f7d217eefb4f6ae08aae24c6a3c2714898
https://github.com/samjz06/d2l-pytorch/tree/80eca3f7d217eefb4f6ae08aae24c6a3c2714898
L2Softmax
import math import torch from torch.nn import functional as F from torch.nn.modules.loss import _WeightedLoss class L2Softmax(_WeightedLoss): """L2Softmax from `"L2-constrained Softmax Loss for Discriminative Face Verification" <https://arxiv.org/abs/1703.09507>`_ paper. Parameters ---------- classes: int. Number of classes. alpha: float. The scaling parameter, a hypersphere with small alpha will limit surface area for embedding features. p: float, default is 0.9. The expected average softmax probability for correctly classifying a feature. from_normx: bool, default is False. Whether input has already been normalized. Outputs: - **loss**: loss tensor with shape (batch_size,). Dimensions other than batch_axis are averaged out. """ def __init__(self, classes, alpha, p=0.9, from_normx=False, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction='mean'): super(L2Softmax, self).__init__(weight, size_average, reduce, reduction ) alpha_low = math.log(p * (classes - 2) / (1 - p)) assert alpha > alpha_low, 'For given probability of p={}, alpha should higher than {}.'.format( p, alpha_low) self.ignore_index = ignore_index self.alpha = alpha self.from_normx = from_normx def forward(self, x, target): if not self.from_normx: x = F.normalize(x, 2, dim=-1) x = x * self.alpha return F.cross_entropy(x, target, weight=self.weight, ignore_index= self.ignore_index, reduction=self.reduction) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'classes': 4, 'alpha': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math from torch.nn.modules.loss import _WeightedLoss 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 = 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 tmp16 = 1.0 tmp17 = tmp15 * tmp16 tl.store(out_ptr0 + x2, tmp17, 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 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 = 4.0 tmp10 = tmp8 * tmp9 tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_per_fused__log_softmax_div_mul_neg_sum_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r3 = rindex r0 = rindex % 16 r2 = rindex // 64 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr1 + r3, None) tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp15 = tmp13 * tmp14 tmp16 = tl.broadcast_to(tmp15, [RBLOCK]) tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0)) tmp19 = -tmp18 tmp20 = 0.015625 tmp21 = tmp19 * tmp20 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None) def call(args): 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_div_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_1[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 triton_per_fused__log_softmax_div_mul_neg_sum_2[grid(1)](buf3, buf1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg1_1 del buf1 return buf3, class L2SoftmaxNew(_WeightedLoss): """L2Softmax from `"L2-constrained Softmax Loss for Discriminative Face Verification" <https://arxiv.org/abs/1703.09507>`_ paper. Parameters ---------- classes: int. Number of classes. alpha: float. The scaling parameter, a hypersphere with small alpha will limit surface area for embedding features. p: float, default is 0.9. The expected average softmax probability for correctly classifying a feature. from_normx: bool, default is False. Whether input has already been normalized. Outputs: - **loss**: loss tensor with shape (batch_size,). Dimensions other than batch_axis are averaged out. """ def __init__(self, classes, alpha, p=0.9, from_normx=False, weight=None, size_average=None, ignore_index=-100, reduce=None, reduction='mean'): super(L2SoftmaxNew, self).__init__(weight, size_average, reduce, reduction) alpha_low = math.log(p * (classes - 2) / (1 - p)) assert alpha > alpha_low, 'For given probability of p={}, alpha should higher than {}.'.format( p, alpha_low) self.ignore_index = ignore_index self.alpha = alpha self.from_normx = from_normx def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
sailfish009/torch-toolbox
L2Softmax
false
7,594
[ "BSD-3-Clause" ]
1
80dfc22c697b9f323e097de72af04f0e5435d7b4
https://github.com/sailfish009/torch-toolbox/tree/80dfc22c697b9f323e097de72af04f0e5435d7b4
Conv
import torch from torch import nn from torch.nn.functional import interpolate from typing import cast class Interpolate(nn.Module): def __init__(self, scale_factor: 'float'=1.0, mode: 'str'='nearest' ) ->None: super().__init__() self.scale_factor = scale_factor self.mode = mode def forward(self, input: 'torch.Tensor') ->torch.Tensor: return cast(torch.Tensor, interpolate(input, scale_factor=self. scale_factor, mode=self.mode)) def extra_repr(self) ->str: extras = [f'scale_factor={self.scale_factor}'] if self.mode != 'nearest': extras.append(f'mode={self.mode}') return ', '.join(extras) class Conv(nn.Module): def __init__(self, in_channels: 'int', out_channels: 'int', kernel_size: 'int', *, stride: int=1, upsample: bool=False, norm: bool=True, activation: bool=True): super().__init__() self.upsample = Interpolate(scale_factor=stride) if upsample else None self.pad = nn.ReflectionPad2d(kernel_size // 2) self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1 if upsample else stride) self.norm = nn.InstanceNorm2d(out_channels, affine=True ) if norm else None self.activation = nn.ReLU() if activation else None def forward(self, input: 'torch.Tensor') ->torch.Tensor: if self.upsample: input = self.upsample(input) output = self.conv(self.pad(input)) if self.norm: output = self.norm(output) if self.activation: output = self.activation(output) return cast(torch.Tensor, output) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn from torch.nn.functional import interpolate from typing import cast 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 = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 % 8 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-2 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-2 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_convolution_relu_repeat_threshold_backward_1( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, out_ptr4, out_ptr5, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 rnumel = 25 RBLOCK: tl.constexpr = 32 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 x0 = xindex r3 = rindex x1 = xindex % 4 tmp0 = tl.load(in_ptr0 + x0 % 4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_out_ptr0 + (r3 + 25 * x0), rmask & xmask, other=0.0) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tl.where(rmask & xmask, tmp4, 0) tmp7 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK]) tmp9 = tl.where(rmask & xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tl.full([XBLOCK, 1], 25, tl.int32) tmp12 = tmp11.to(tl.float32) tmp13 = tmp10 / tmp12 tmp14 = tmp4 - tmp13 tmp15 = tmp14 * tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = tl.where(rmask & xmask, tmp16, 0) tmp19 = tl.sum(tmp18, 1)[:, None] tmp20 = tmp3 - tmp13 tmp21 = 25.0 tmp22 = tmp19 / tmp21 tmp23 = 1e-05 tmp24 = tmp22 + tmp23 tmp25 = libdevice.rsqrt(tmp24) tmp26 = tmp20 * tmp25 tmp27 = tmp26 * tmp0 tmp29 = tmp27 + tmp28 tmp30 = tl.full([1, 1], 0, tl.int32) tmp31 = triton_helpers.maximum(tmp30, tmp29) tmp32 = 0.0 tmp33 = tmp31 <= tmp32 tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + (r3 + 25 * x0), tmp3, rmask & xmask) tl.store(out_ptr3 + (r3 + 25 * x0), tmp31, rmask & xmask) tl.store(out_ptr4 + (r3 + 25 * x0), tmp33, rmask & xmask) tl.store(out_ptr5 + x0, tmp25, xmask) tl.store(out_ptr1 + 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, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf3 = empty_strided_cuda((16,), (1,), torch.float32) buf2 = buf1 del buf1 buf4 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf8 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.float32) buf9 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.bool) buf7 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) triton_per_fused__native_batch_norm_legit_convolution_relu_repeat_threshold_backward_1[ grid(16)](buf2, primals_4, primals_3, primals_5, buf3, buf4, buf8, buf9, buf7, 16, 25, XBLOCK=1, num_warps=2, num_stages=1) del primals_3 del primals_4 del primals_5 return buf8, primals_2, buf0, buf2, buf3, reinterpret_tensor(buf7, (16, ), (1,), 0), buf9, reinterpret_tensor(buf4, (1, 16, 1, 1), (16, 1, 1, 1), 0) class Interpolate(nn.Module): def __init__(self, scale_factor: 'float'=1.0, mode: 'str'='nearest' ) ->None: super().__init__() self.scale_factor = scale_factor self.mode = mode def forward(self, input: 'torch.Tensor') ->torch.Tensor: return cast(torch.Tensor, interpolate(input, scale_factor=self. scale_factor, mode=self.mode)) def extra_repr(self) ->str: extras = [f'scale_factor={self.scale_factor}'] if self.mode != 'nearest': extras.append(f'mode={self.mode}') return ', '.join(extras) class ConvNew(nn.Module): def __init__(self, in_channels: 'int', out_channels: 'int', kernel_size: 'int', *, stride: int=1, upsample: bool=False, norm: bool=True, activation: bool=True): super().__init__() self.upsample = Interpolate(scale_factor=stride) if upsample else None self.pad = nn.ReflectionPad2d(kernel_size // 2) self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1 if upsample else stride) self.norm = nn.InstanceNorm2d(out_channels, affine=True ) if norm else None self.activation = nn.ReLU() if activation else None def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.conv.bias primals_4 = self.norm.weight primals_5 = self.norm.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
sakshi-06/pystiche
Conv
false
7,595
[ "BSD-3-Clause" ]
1
21a67364b332a34a2308a929f200900c76be5b73
https://github.com/sakshi-06/pystiche/tree/21a67364b332a34a2308a929f200900c76be5b73
Wide
import math import torch from torch import Tensor from torch import nn class Wide(nn.Module): """wide (linear) component Linear model implemented via an Embedding layer connected to the output neuron(s). Parameters ----------- wide_dim: int size of the Embedding layer. `wide_dim` is the summation of all the individual values for all the features that go through the wide component. For example, if the wide component receives 2 features with 5 individual values each, `wide_dim = 10` pred_dim: int, default = 1 size of the ouput tensor containing the predictions Attributes ----------- wide_linear: ``nn.Module`` the linear layer that comprises the wide branch of the model Examples -------- >>> import torch >>> from pytorch_widedeep.models import Wide >>> X = torch.empty(4, 4).random_(6) >>> wide = Wide(wide_dim=X.unique().size(0), pred_dim=1) >>> out = wide(X) """ def __init__(self, wide_dim: 'int', pred_dim: 'int'=1): super(Wide, self).__init__() self.wide_linear = nn.Embedding(wide_dim + 1, pred_dim, padding_idx=0) self.bias = nn.Parameter(torch.zeros(pred_dim)) self._reset_parameters() def _reset_parameters(self) ->None: """initialize Embedding and bias like nn.Linear. See `original implementation <https://pytorch.org/docs/stable/_modules/torch/nn/modules/linear.html#Linear>`_. """ nn.init.kaiming_uniform_(self.wide_linear.weight, a=math.sqrt(5)) fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.wide_linear. weight) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def forward(self, X: 'Tensor') ->Tensor: """Forward pass. Simply connecting the Embedding layer with the ouput neuron(s)""" out = self.wide_linear(X.long()).sum(dim=1) + self.bias return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'wide_dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import 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_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.int64) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_add_embedding_sum_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp7 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp14 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp21 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp28 = tl.load(in_ptr2 + 0) tmp29 = tl.broadcast_to(tmp28, [XBLOCK]) tmp1 = tl.full([XBLOCK], 5, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 5) | ~xmask, 'index out of bounds: 0 <= tmp4 < 5') tmp6 = tl.load(in_ptr1 + tmp4, xmask, eviction_policy='evict_last') tmp8 = tmp7 + tmp1 tmp9 = tmp7 < 0 tmp10 = tl.where(tmp9, tmp8, tmp7) tl.device_assert((0 <= tmp10) & (tmp10 < 5) | ~xmask, 'index out of bounds: 0 <= tmp10 < 5') tmp12 = tl.load(in_ptr1 + tmp10, xmask, eviction_policy='evict_last') tmp13 = tmp6 + tmp12 tmp15 = tmp14 + tmp1 tmp16 = tmp14 < 0 tmp17 = tl.where(tmp16, tmp15, tmp14) tl.device_assert((0 <= tmp17) & (tmp17 < 5) | ~xmask, 'index out of bounds: 0 <= tmp17 < 5') tmp19 = tl.load(in_ptr1 + tmp17, xmask, eviction_policy='evict_last') tmp20 = tmp13 + tmp19 tmp22 = tmp21 + tmp1 tmp23 = tmp21 < 0 tmp24 = tl.where(tmp23, tmp22, tmp21) tl.device_assert((0 <= tmp24) & (tmp24 < 5) | ~xmask, 'index out of bounds: 0 <= tmp24 < 5') tmp26 = tl.load(in_ptr1 + tmp24, xmask, eviction_policy='evict_last') tmp27 = tmp20 + tmp26 tmp30 = tmp27 + tmp29 tl.store(out_ptr0 + x2, 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, (5, 1), (1, 1)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.int64) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(256)](primals_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_add_embedding_sum_1[grid(64)](buf0, primals_2, primals_3, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 del primals_3 return buf1, buf0 class WideNew(nn.Module): """wide (linear) component Linear model implemented via an Embedding layer connected to the output neuron(s). Parameters ----------- wide_dim: int size of the Embedding layer. `wide_dim` is the summation of all the individual values for all the features that go through the wide component. For example, if the wide component receives 2 features with 5 individual values each, `wide_dim = 10` pred_dim: int, default = 1 size of the ouput tensor containing the predictions Attributes ----------- wide_linear: ``nn.Module`` the linear layer that comprises the wide branch of the model Examples -------- >>> import torch >>> from pytorch_widedeep.models import Wide >>> X = torch.empty(4, 4).random_(6) >>> wide = Wide(wide_dim=X.unique().size(0), pred_dim=1) >>> out = wide(X) """ def __init__(self, wide_dim: 'int', pred_dim: 'int'=1): super(WideNew, self).__init__() self.wide_linear = nn.Embedding(wide_dim + 1, pred_dim, padding_idx=0) self.bias = nn.Parameter(torch.zeros(pred_dim)) self._reset_parameters() def _reset_parameters(self) ->None: """initialize Embedding and bias like nn.Linear. See `original implementation <https://pytorch.org/docs/stable/_modules/torch/nn/modules/linear.html#Linear>`_. """ nn.init.kaiming_uniform_(self.wide_linear.weight, a=math.sqrt(5)) fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.wide_linear. weight) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def forward(self, input_0): primals_3 = self.bias primals_2 = self.wide_linear.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
sallypannn/pytorch-widedeep
Wide
false
7,596
[ "MIT" ]
1
ab4a209a2a3bff539f543a66ac51306042ed6693
https://github.com/sallypannn/pytorch-widedeep/tree/ab4a209a2a3bff539f543a66ac51306042ed6693
ConvMeanPool
import torch import torch.nn as nn class ConvMeanPool(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True, adjust_padding=False): super().__init__() if not adjust_padding: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = conv else: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = nn.Sequential(nn.ZeroPad2d((1, 0, 1, 0)), conv) def forward(self, inputs): output = self.conv(inputs) output = sum([output[:, :, ::2, ::2], output[:, :, 1::2, ::2], output[:, :, ::2, 1::2], output[:, :, 1::2, 1::2]]) / 4.0 return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x4 = xindex // 2 x2 = xindex // 4 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 8 * x4), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x4), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x4), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x4), xmask, eviction_policy ='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 + tmp3 tmp6 = tmp5 + tmp1 tmp7 = tmp4 + tmp6 tmp9 = tmp8 + tmp1 tmp10 = tmp7 + tmp9 tmp12 = tmp11 + tmp1 tmp13 = tmp10 + tmp12 tmp14 = 0.25 tmp15 = tmp13 * tmp14 tl.store(out_ptr0 + x5, tmp15, 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, 2, 2), (16, 4, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_0[grid(64)](buf0, primals_2, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del primals_2 return buf1, primals_1, primals_3 class ConvMeanPoolNew(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True, adjust_padding=False): super().__init__() if not adjust_padding: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = conv else: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = nn.Sequential(nn.ZeroPad2d((1, 0, 1, 0)), conv) 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]
samsartor/score_sde
ConvMeanPool
false
7,597
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
UpsampleConv
import torch import torch.nn as nn class UpsampleConv(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True): super().__init__() self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.pixelshuffle = nn.PixelShuffle(upscale_factor=2) def forward(self, inputs): output = inputs output = torch.cat([output, output, output, output], dim=1) output = self.pixelshuffle(output) return self.conv(output) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_pixel_shuffle_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 % 4 x2 = xindex // 8 % 2 x3 = xindex // 16 % 4 x5 = xindex // 256 x6 = xindex tmp0 = tl.load(in_ptr0 + (x1 + 4 * x3 + 16 * x0 + 32 * x2 + 64 * x5), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x6, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 2, 4, 2), (256, 64, 16, 8, 2, 1 ), torch.float32) get_raw_stream(0) triton_poi_fused_pixel_shuffle_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (4, 4, 8, 8), (256, 64, 8, 1), 0), primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 8, 8), (256, 64, 8, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(1024)](buf2, primals_3, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, reinterpret_tensor(buf0, (4, 4, 8, 8), (256, 64, 8, 1), 0) class UpsampleConvNew(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True): super().__init__() self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.pixelshuffle = nn.PixelShuffle(upscale_factor=2) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
samsartor/score_sde
UpsampleConv
false
7,598
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
MeanPoolConv
import torch import torch.nn as nn class MeanPoolConv(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True): super().__init__() self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) def forward(self, inputs): output = inputs output = sum([output[:, :, ::2, ::2], output[:, :, 1::2, ::2], output[:, :, ::2, 1::2], output[:, :, 1::2, 1::2]]) / 4.0 return self.conv(output) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_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 % 2 x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 8 * x1), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x1), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x1), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x1), xmask, eviction_policy= 'evict_last') tmp1 = 0.0 tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp9 = 0.25 tmp10 = tmp8 * tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_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 x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 2, 2), (16, 4, 2, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(64)](buf2, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf2, primals_2, buf0 class MeanPoolConvNew(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True): super().__init__() self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
samsartor/score_sde
MeanPoolConv
false
7,599
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
MultiHeadAttentionLayer
import math import torch import torch.nn as nn class MultiHeadAttentionLayer(nn.Module): def __init__(self, d_model, n_heads, dropout): super().__init__() assert d_model % n_heads == 0 self.d_model = d_model self.n_heads = n_heads self.head_dim = d_model // n_heads self.fc_q = nn.Linear(d_model, d_model) self.fc_k = nn.Linear(d_model, d_model) self.fc_v = nn.Linear(d_model, d_model) self.fc_o = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.scale = math.sqrt(d_model) def forward(self, query, key, value, mask=None): batch_size = query.shape[0] Q = self.fc_q(query) K = self.fc_k(key) V = self.fc_v(value) Q = Q.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K = K.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) V = V.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K_t = K.permute(0, 1, 3, 2) energy = torch.matmul(Q, K_t) / self.scale if mask is not None: energy = energy.masked_fill(mask == 0, -1e+18) attention = torch.softmax(energy, dim=-1) x = torch.matmul(self.dropout(attention), V) x = x.permute(0, 2, 1, 3).contiguous() x = x.view(batch_size, -1, self.d_model) x = self.fc_o(x) return x, attention 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_model': 4, 'n_heads': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 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__softmax_1(in_ptr0, out_ptr2, 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 = 1.0 tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tmp7 = tmp2 - tmp6 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp10 = tl_math.exp(tmp9) tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13 = tl.where(xmask, tmp11, 0) tmp14 = tl.sum(tmp13, 1)[:, None] tmp15 = tmp10 / tmp14 tl.store(out_ptr2 + (r1 + 16 * x0), tmp15, 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, primals_8, primals_9, primals_10, primals_11) = 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, 4), (64, 16, 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, 4), (64, 16, 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_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_6, (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_9, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2) del primals_7 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) buf8 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch .float32) triton_per_fused__softmax_1[grid(256)](buf5, buf8, 256, 16, XBLOCK= 8, num_warps=2, num_stages=1) del buf5 buf9 = reinterpret_tensor(buf1, (4, 4, 16, 1), (64, 16, 1, 1), 0) del buf1 triton_poi_fused_clone_0[grid(16, 16)](buf2, primals_8, buf9, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_8 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) buf12 = reinterpret_tensor(buf10, (64, 4), (4, 1), 0) del buf10 extern_kernels.addmm(primals_11, reinterpret_tensor(buf11, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_11 return reinterpret_tensor(buf12, (4, 16, 4), (64, 4, 1), 0 ), buf8, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_6, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0 ), buf8, reinterpret_tensor(buf11, (64, 4), (4, 1), 0 ), primals_10, 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 MultiHeadAttentionLayerNew(nn.Module): def __init__(self, d_model, n_heads, dropout): super().__init__() assert d_model % n_heads == 0 self.d_model = d_model self.n_heads = n_heads self.head_dim = d_model // n_heads self.fc_q = nn.Linear(d_model, d_model) self.fc_k = nn.Linear(d_model, d_model) self.fc_v = nn.Linear(d_model, d_model) self.fc_o = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.scale = math.sqrt(d_model) def forward(self, input_0, input_1, input_2): primals_2 = self.fc_q.weight primals_3 = self.fc_q.bias primals_4 = self.fc_k.weight primals_5 = self.fc_k.bias primals_7 = self.fc_v.weight primals_8 = self.fc_v.bias primals_10 = self.fc_o.weight primals_11 = self.fc_o.bias primals_1 = input_0 primals_6 = input_1 primals_9 = input_2 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]
salvacarrion/nmt-continual-learning
MultiHeadAttentionLayer
false
7,600
[ "MIT" ]
1
302147ac9c270f3341a68a72c803c457f05ff37b
https://github.com/salvacarrion/nmt-continual-learning/tree/302147ac9c270f3341a68a72c803c457f05ff37b
VarianceNorm2d
import torch import torch.nn as nn class VarianceNorm2d(nn.Module): def __init__(self, num_features, bias=False): super().__init__() self.num_features = num_features self.bias = bias self.alpha = nn.Parameter(torch.zeros(num_features)) self.alpha.data.normal_(1, 0.02) def forward(self, x): vars = torch.var(x, dim=(2, 3), keepdim=True) h = x / torch.sqrt(vars + 1e-05) out = self.alpha.view(-1, self.num_features, 1, 1) * h return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._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_add_div_mul_sqrt_var_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp22 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 15.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.sqrt(tmp20) tmp23 = tmp0 / tmp21 tmp24 = tmp22 * tmp23 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp24, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf3 = reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mul_sqrt_var_0[grid(16)](buf3, primals_1, primals_2, buf4, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_2 return buf4, primals_1, buf3 class VarianceNorm2dNew(nn.Module): def __init__(self, num_features, bias=False): super().__init__() self.num_features = num_features self.bias = bias self.alpha = nn.Parameter(torch.zeros(num_features)) self.alpha.data.normal_(1, 0.02) def forward(self, input_0): primals_2 = self.alpha primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
samsartor/score_sde
VarianceNorm2d
false
7,601
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
INDeConv
import torch import torch.nn as nn class INDeConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, out_padding=0, dilation=1, groups=1, relu=True, ins_n= True, bias=False): super(INDeConv, self).__init__() self.out_channels = out_planes self.conv = nn.ConvTranspose2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, output_padding= out_padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, x): x = self.conv(x) if self.ins_n is not None: x = self.ins_n(x) if self.relu is not None: x = self.relu(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_planes': 4, 'out_planes': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_batch_norm_legit_relu_repeat_threshold_backward_0( in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, out_ptr4, out_ptr5, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 rnumel = 49 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, :] rmask = rindex < rnumel x0 = xindex r1 = rindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + x0 % 4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 49 * x0), rmask & xmask, other=0.0) tmp26 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tl.where(rmask & xmask, tmp2, 0) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(rmask & xmask, tmp5, 0) tmp8 = tl.sum(tmp7, 1)[:, None] tmp9 = tl.full([XBLOCK, 1], 49, tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 / tmp10 tmp12 = tmp2 - tmp11 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(rmask & xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp18 = tmp1 - tmp11 tmp19 = 49.0 tmp20 = tmp17 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp18 * tmp23 tmp25 = tmp24 * tmp0 tmp27 = tmp25 + tmp26 tmp28 = tl.full([1, 1], 0, tl.int32) tmp29 = triton_helpers.maximum(tmp28, tmp27) tmp30 = 0.0 tmp31 = tmp29 <= tmp30 tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(out_ptr3 + (r1 + 49 * x0), tmp29, rmask & xmask) tl.store(out_ptr4 + (r1 + 49 * x0), tmp31, rmask & xmask) tl.store(out_ptr5 + x0, tmp23, xmask) tl.store(out_ptr1 + x0, tmp11, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 7, 7), (196, 49, 7, 1)) buf1 = empty_strided_cuda((16,), (1,), torch.float32) buf2 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf6 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.bool) buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_relu_repeat_threshold_backward_0[ grid(16)](primals_3, buf0, primals_4, buf1, buf2, buf6, buf7, buf5, 16, 49, XBLOCK=1, num_warps=2, num_stages=1) del primals_3 del primals_4 return buf6, primals_1, primals_2, buf0, buf1, reinterpret_tensor(buf5, (16,), (1,), 0), buf7, reinterpret_tensor(buf2, (1, 16, 1, 1), (16, 1, 1, 1), 0) class INDeConvNew(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, out_padding=0, dilation=1, groups=1, relu=True, ins_n= True, bias=False): super(INDeConvNew, self).__init__() self.out_channels = out_planes self.conv = nn.ConvTranspose2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, output_padding= out_padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.ins_n.weight primals_4 = self.ins_n.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
samsgood0310/Unsupervised-Defect-Segmentation
INDeConv
false
7,602
[ "Apache-2.0" ]
1
66af32506cd6e60c356890616e28d679622fd8e6
https://github.com/samsgood0310/Unsupervised-Defect-Segmentation/tree/66af32506cd6e60c356890616e28d679622fd8e6
PlainRefiner
import torch import torch.nn as nn class PlainRefiner(nn.Module): """Simple refiner from Deep Image Matting. Args: conv_channels (int): Number of channels produced by the three main convolutional layer. loss_refine (dict): Config of the loss of the refiner. Default: None. pretrained (str): Name of pretrained model. Default: None. """ def __init__(self, conv_channels=64, pretrained=None): super(PlainRefiner, self).__init__() self.refine_conv1 = nn.Conv2d(4, conv_channels, kernel_size=3, padding=1) self.refine_conv2 = nn.Conv2d(conv_channels, conv_channels, kernel_size=3, padding=1) self.refine_conv3 = nn.Conv2d(conv_channels, conv_channels, kernel_size=3, padding=1) self.refine_pred = nn.Conv2d(conv_channels, 1, kernel_size=3, padding=1 ) self.relu = nn.ReLU(inplace=True) def init_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): xavier_init(m) def forward(self, x, raw_alpha): """Forward function. Args: x (Tensor): The input feature map of refiner. raw_alpha (Tensor): The raw predicted alpha matte. Returns: Tensor: The refined alpha matte. """ out = self.relu(self.refine_conv1(x)) out = self.relu(self.refine_conv2(out)) out = self.relu(self.refine_conv3(out)) raw_refine = self.refine_pred(out) pred_refine = torch.sigmoid(raw_alpha + raw_refine) return pred_refine def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_add_convolution_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp4 = tmp1 + tmp3 tmp5 = tmp0 + tmp4 tmp6 = tl.sigmoid(tmp5) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10) = args args.clear() assert_size_stride(primals_1, (64, 4, 3, 3), (36, 9, 3, 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, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (1, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (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, 64, 4, 4), (1024, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(4096)](buf1, primals_2, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 4, 4), (1024, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(4096)](buf3, primals_5, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 4, 4), (1024, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_0[grid(4096)](buf5, primals_7, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 1, 4, 4), (16, 16, 4, 1)) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_sigmoid_1[grid(256)](primals_10, buf6, primals_9, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del primals_10 del primals_9 return (buf7, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf3, buf5, buf7) class PlainRefinerNew(nn.Module): """Simple refiner from Deep Image Matting. Args: conv_channels (int): Number of channels produced by the three main convolutional layer. loss_refine (dict): Config of the loss of the refiner. Default: None. pretrained (str): Name of pretrained model. Default: None. """ def __init__(self, conv_channels=64, pretrained=None): super(PlainRefinerNew, self).__init__() self.refine_conv1 = nn.Conv2d(4, conv_channels, kernel_size=3, padding=1) self.refine_conv2 = nn.Conv2d(conv_channels, conv_channels, kernel_size=3, padding=1) self.refine_conv3 = nn.Conv2d(conv_channels, conv_channels, kernel_size=3, padding=1) self.refine_pred = nn.Conv2d(conv_channels, 1, kernel_size=3, padding=1 ) self.relu = nn.ReLU(inplace=True) def init_weights(self): for m in self.modules(): if isinstance(m, nn.Conv2d): xavier_init(m) def forward(self, input_0, input_1): primals_1 = self.refine_conv1.weight primals_2 = self.refine_conv1.bias primals_4 = self.refine_conv2.weight primals_5 = self.refine_conv2.bias primals_6 = self.refine_conv3.weight primals_7 = self.refine_conv3.bias primals_8 = self.refine_pred.weight primals_9 = self.refine_pred.bias primals_3 = input_0 primals_10 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10]) return output[0]
rivergold/mmediting
PlainRefiner
false
7,603
[ "Apache-2.0" ]
1
fd972635c48bb065db29d1b5090592a87c7263d2
https://github.com/rivergold/mmediting/tree/fd972635c48bb065db29d1b5090592a87c7263d2
InstanceNorm2dPlus
import torch import torch.nn as nn class InstanceNorm2dPlus(nn.Module): def __init__(self, num_features, bias=True): super().__init__() self.num_features = num_features self.bias = bias self.instance_norm = nn.InstanceNorm2d(num_features, affine=False, track_running_stats=False) self.alpha = nn.Parameter(torch.zeros(num_features)) self.gamma = nn.Parameter(torch.zeros(num_features)) self.alpha.data.normal_(1, 0.02) self.gamma.data.normal_(1, 0.02) if bias: self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): means = torch.mean(x, dim=(2, 3)) m = torch.mean(means, dim=-1, keepdim=True) v = torch.var(means, dim=-1, keepdim=True) means = (means - m) / torch.sqrt(v + 1e-05) h = self.instance_norm(x) if self.bias: h = h + means[..., None, None] * self.alpha[..., None, None] out = self.gamma.view(-1, self.num_features, 1, 1 ) * h + self.beta.view(-1, self.num_features, 1, 1) else: h = h + means[..., None, None] * self.alpha[..., None, None] out = self.gamma.view(-1, self.num_features, 1, 1) * h return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._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_batch_norm_legit_mean_0(in_out_ptr0, in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex 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] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp23, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) tl.store(out_ptr1 + x0, tmp12, xmask) @triton.jit def triton_poi_fused_add_div_mean_sqrt_sub_var_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) 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 = 16.0 tmp2 = tmp0 / tmp1 tmp4 = tmp3 / tmp1 tmp6 = tmp5 / tmp1 tmp7 = tmp4 + tmp6 tmp9 = tmp8 / tmp1 tmp10 = tmp7 + tmp9 tmp12 = tmp11 / tmp1 tmp13 = tmp10 + tmp12 tmp14 = 4.0 tmp15 = tmp13 / tmp14 tmp16 = tmp2 - tmp15 tmp17 = tmp4 - tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp6 - tmp15 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp15 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp12 - tmp15 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = 3.0 tmp29 = tmp27 / tmp28 tmp30 = 1e-05 tmp31 = tmp29 + tmp30 tmp32 = libdevice.sqrt(tmp31) tmp33 = tmp16 / tmp32 tl.store(out_ptr0 + x2, tmp33, xmask) @triton.jit def triton_poi_fused_add_mul_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 4 x3 = xindex x4 = xindex // 16 tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x3, xmask) tmp2 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr4 + x4, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 - tmp2 tmp5 = tmp3 * tmp4 tmp8 = tmp6 * tmp7 tmp9 = tmp5 + tmp8 tmp10 = tmp0 * tmp9 tmp12 = tmp10 + tmp11 tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf2 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32) buf3 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf5 = reinterpret_tensor(buf3, (1, 16, 1, 1), (16, 1, 1, 1), 0) del buf3 get_raw_stream(0) triton_per_fused__native_batch_norm_legit_mean_0[grid(16)](buf5, primals_1, buf0, buf2, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_div_mean_sqrt_sub_var_1[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_2[grid(256)](primals_3, primals_1, buf2, buf5, buf1, primals_2, primals_4, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_4 return (buf6, primals_1, primals_2, primals_3, buf2, buf5, reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0)) class InstanceNorm2dPlusNew(nn.Module): def __init__(self, num_features, bias=True): super().__init__() self.num_features = num_features self.bias = bias self.instance_norm = nn.InstanceNorm2d(num_features, affine=False, track_running_stats=False) self.alpha = nn.Parameter(torch.zeros(num_features)) self.gamma = nn.Parameter(torch.zeros(num_features)) self.alpha.data.normal_(1, 0.02) self.gamma.data.normal_(1, 0.02) if bias: self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, input_0): primals_2 = self.alpha primals_3 = self.gamma primals_4 = self.beta primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
samsartor/score_sde
InstanceNorm2dPlus
false
7,604
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
BiaffineAttention
import torch import torch.utils.checkpoint import torch.utils.data class BiaffineAttention(torch.nn.Module): """Implements a biaffine attention operator for binary relation classification. PyTorch implementation of the biaffine attention operator from "End-to-end neural relation extraction using deep biaffine attention" (https://arxiv.org/abs/1812.11275) which can be used as a classifier for binary relation classification. Args: in_features (int): The size of the feature dimension of the inputs. out_features (int): The size of the feature dimension of the output. Shape: - x_1: `(N, *, in_features)` where `N` is the batch dimension and `*` means any number of additional dimensisons. - x_2: `(N, *, in_features)`, where `N` is the batch dimension and `*` means any number of additional dimensions. - Output: `(N, *, out_features)`, where `N` is the batch dimension and `*` means any number of additional dimensions. Examples: >>> batch_size, in_features, out_features = 32, 100, 4 >>> biaffine_attention = BiaffineAttention(in_features, out_features) >>> x_1 = torch.randn(batch_size, in_features) >>> x_2 = torch.randn(batch_size, in_features) >>> output = biaffine_attention(x_1, x_2) >>> print(output.size()) torch.Size([32, 4]) """ def __init__(self, in_features, out_features): super(BiaffineAttention, self).__init__() self.in_features = in_features self.out_features = out_features self.bilinear = torch.nn.Bilinear(in_features, in_features, out_features, bias=False) self.linear = torch.nn.Linear(2 * in_features, out_features, bias=True) self.reset_parameters() def forward(self, x_1, x_2): return self.bilinear(x_1, x_2) + self.linear(torch.cat((x_1, x_2), dim=-1)) def reset_parameters(self): self.bilinear.reset_parameters() self.linear.reset_parameters() def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.utils.checkpoint 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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 8), (8, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten._trilinear.default(reinterpret_tensor( primals_3, (64, 4), (4, 1), 0), primals_1, reinterpret_tensor( primals_2, (64, 4), (4, 1), 0), [1, 3], [0], [1, 2], [2, 3]) del primals_1 buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](primals_3, primals_2, buf2, 512, XBLOCK=256, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf3) del primals_4 buf4 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_add_1[grid(256)](buf4, buf3, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del primals_5 return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf2, (64, 8), (8, 1), 0) class BiaffineAttentionNew(torch.nn.Module): """Implements a biaffine attention operator for binary relation classification. PyTorch implementation of the biaffine attention operator from "End-to-end neural relation extraction using deep biaffine attention" (https://arxiv.org/abs/1812.11275) which can be used as a classifier for binary relation classification. Args: in_features (int): The size of the feature dimension of the inputs. out_features (int): The size of the feature dimension of the output. Shape: - x_1: `(N, *, in_features)` where `N` is the batch dimension and `*` means any number of additional dimensisons. - x_2: `(N, *, in_features)`, where `N` is the batch dimension and `*` means any number of additional dimensions. - Output: `(N, *, out_features)`, where `N` is the batch dimension and `*` means any number of additional dimensions. Examples: >>> batch_size, in_features, out_features = 32, 100, 4 >>> biaffine_attention = BiaffineAttention(in_features, out_features) >>> x_1 = torch.randn(batch_size, in_features) >>> x_2 = torch.randn(batch_size, in_features) >>> output = biaffine_attention(x_1, x_2) >>> print(output.size()) torch.Size([32, 4]) """ def __init__(self, in_features, out_features): super(BiaffineAttentionNew, self).__init__() self.in_features = in_features self.out_features = out_features self.bilinear = torch.nn.Bilinear(in_features, in_features, out_features, bias=False) self.linear = torch.nn.Linear(2 * in_features, out_features, bias=True) self.reset_parameters() def reset_parameters(self): self.bilinear.reset_parameters() self.linear.reset_parameters() def forward(self, input_0, input_1): primals_1 = self.bilinear.weight primals_4 = self.linear.weight primals_5 = self.linear.bias primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
rushabh-v/unilm
BiaffineAttention
false
7,605
[ "MIT" ]
1
a62a023bd5d3500c23ac454be0a8b0107e18a6ce
https://github.com/rushabh-v/unilm/tree/a62a023bd5d3500c23ac454be0a8b0107e18a6ce
SSD300
import torch import torchvision from torch import nn import torch.nn.functional as F from math import sqrt from itertools import product as product import torch.optim import torch.utils.data def decimate(tensor, m): """ Decimate a tensor by a factor 'm', i.e. downsample by keeping every 'm'th value. This is used when we convert FC layers to equivalent Convolutional layers, BUT of a smaller size. :param tensor: tensor to be decimated :param m: list of decimation factors for each dimension of the tensor; None if not to be decimated along a dimension :return: decimated tensor """ assert tensor.dim() == len(m) for d in range(tensor.dim()): if m[d] is not None: tensor = tensor.index_select(dim=d, index=torch.arange(start=0, end=tensor.size(d), step=m[d]).long()) return tensor def cxcy_to_xy(cxcy): """ Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max). :param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4) :return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4) """ return torch.cat([cxcy[:, :2] - cxcy[:, 2:] / 2, cxcy[:, :2] + cxcy[:, 2:] / 2], 1) def find_intersection(set_1, set_2): """ Find the intersection of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: intersection of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2]. unsqueeze(0)) upper_bounds = torch.min(set_1[:, 2:].unsqueeze(1), set_2[:, 2:]. unsqueeze(0)) intersection_dims = torch.clamp(upper_bounds - lower_bounds, min=0) return intersection_dims[:, :, 0] * intersection_dims[:, :, 1] def find_jaccard_overlap(set_1, set_2): """ Find the Jaccard Overlap (IoU) of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: Jaccard Overlap of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ intersection = find_intersection(set_1, set_2) areas_set_1 = (set_1[:, 2] - set_1[:, 0]) * (set_1[:, 3] - set_1[:, 1]) areas_set_2 = (set_2[:, 2] - set_2[:, 0]) * (set_2[:, 3] - set_2[:, 1]) union = areas_set_1.unsqueeze(1) + areas_set_2.unsqueeze(0) - intersection return intersection / union def gcxgcy_to_cxcy(gcxgcy, priors_cxcy): """ Decode bounding box coordinates predicted by the model, since they are encoded in the form mentioned above. They are decoded into center-size coordinates. This is the inverse of the function above. :param gcxgcy: encoded bounding boxes, i.e. output of the model, a tensor of size (n_priors, 4) :param priors_cxcy: prior boxes with respect to which the encoding is defined, a tensor of size (n_priors, 4) :return: decoded bounding boxes in center-size form, a tensor of size (n_priors, 4) """ return torch.cat([gcxgcy[:, :2] * priors_cxcy[:, 2:] / 10 + priors_cxcy [:, :2], torch.exp(gcxgcy[:, 2:] / 5) * priors_cxcy[:, 2:]], 1) class VGGBase(nn.Module): """ VGG base convolutions to produce lower-level feature maps. """ def __init__(self): super(VGGBase, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool5 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) self.conv7 = nn.Conv2d(1024, 1024, kernel_size=1) self.load_pretrained_layers() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: lower-level feature maps conv4_3 and conv7 """ out = F.relu(self.conv1_1(image)) out = F.relu(self.conv1_2(out)) out = self.pool1(out) out = F.relu(self.conv2_1(out)) out = F.relu(self.conv2_2(out)) out = self.pool2(out) out = F.relu(self.conv3_1(out)) out = F.relu(self.conv3_2(out)) out = F.relu(self.conv3_3(out)) out = self.pool3(out) out = F.relu(self.conv4_1(out)) out = F.relu(self.conv4_2(out)) out = F.relu(self.conv4_3(out)) conv4_3_feats = out out = self.pool4(out) out = F.relu(self.conv5_1(out)) out = F.relu(self.conv5_2(out)) out = F.relu(self.conv5_3(out)) out = self.pool5(out) out = F.relu(self.conv6(out)) conv7_feats = F.relu(self.conv7(out)) return conv4_3_feats, conv7_feats def load_pretrained_layers(self): """ As in the paper, we use a VGG-16 pretrained on the ImageNet task as the base network. There's one available in PyTorch, see https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.vgg16 We copy these parameters into our network. It's straightforward for conv1 to conv5. However, the original VGG-16 does not contain the conv6 and con7 layers. Therefore, we convert fc6 and fc7 into convolutional layers, and subsample by decimation. See 'decimate' in utils.py. """ state_dict = self.state_dict() param_names = list(state_dict.keys()) pretrained_state_dict = torchvision.models.vgg16(pretrained=True ).state_dict() pretrained_param_names = list(pretrained_state_dict.keys()) for i, param in enumerate(param_names[:-4]): state_dict[param] = pretrained_state_dict[pretrained_param_names[i] ] conv_fc6_weight = pretrained_state_dict['classifier.0.weight'].view( 4096, 512, 7, 7) conv_fc6_bias = pretrained_state_dict['classifier.0.bias'] state_dict['conv6.weight'] = decimate(conv_fc6_weight, m=[4, None, 3, 3]) state_dict['conv6.bias'] = decimate(conv_fc6_bias, m=[4]) conv_fc7_weight = pretrained_state_dict['classifier.3.weight'].view( 4096, 4096, 1, 1) conv_fc7_bias = pretrained_state_dict['classifier.3.bias'] state_dict['conv7.weight'] = decimate(conv_fc7_weight, m=[4, 4, None, None]) state_dict['conv7.bias'] = decimate(conv_fc7_bias, m=[4]) self.load_state_dict(state_dict) None class AuxiliaryConvolutions(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutions, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv7_feats): """ Forward propagation. :param conv7_feats: lower-level conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :return: higher-level feature maps conv8_2, conv9_2, conv10_2, and conv11_2 """ out = F.relu(self.conv8_1(conv7_feats)) out = F.relu(self.conv8_2(out)) conv8_2_feats = out out = F.relu(self.conv9_1(out)) out = F.relu(self.conv9_2(out)) conv9_2_feats = out out = F.relu(self.conv10_1(out)) out = F.relu(self.conv10_2(out)) conv10_2_feats = out out = F.relu(self.conv11_1(out)) conv11_2_feats = F.relu(self.conv11_2(out)) return conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats class PredictionConvolutions(nn.Module): """ Convolutions to predict class scores and bounding boxes using lower and higher-level feature maps. The bounding boxes (locations) are predicted as encoded offsets w.r.t each of the 8732 prior (default) boxes. See 'cxcy_to_gcxgcy' in utils.py for the encoding definition. The class scores represent the scores of each object class in each of the 8732 bounding boxes located. A high score for 'background' = no object. """ def __init__(self, n_classes): """ :param n_classes: number of different types of objects """ super(PredictionConvolutions, self).__init__() self.n_classes = n_classes n_boxes = {'conv4_3': 4, 'conv7': 6, 'conv8_2': 6, 'conv9_2': 6, 'conv10_2': 4, 'conv11_2': 4} self.loc_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * 4, kernel_size=3, padding=1) self.loc_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * 4, kernel_size= 3, padding=1) self.loc_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * 4, kernel_size=3, padding=1) self.loc_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * 4, kernel_size=3, padding=1) self.loc_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * 4, kernel_size=3, padding=1) self.loc_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * 4, kernel_size=3, padding=1) self.cl_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * n_classes, kernel_size=3, padding=1) self.cl_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * n_classes, kernel_size=3, padding=1) self.cl_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * n_classes, kernel_size=3, padding=1) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats): """ Forward propagation. :param conv4_3_feats: conv4_3 feature map, a tensor of dimensions (N, 512, 38, 38) :param conv7_feats: conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :param conv8_2_feats: conv8_2 feature map, a tensor of dimensions (N, 512, 10, 10) :param conv9_2_feats: conv9_2 feature map, a tensor of dimensions (N, 256, 5, 5) :param conv10_2_feats: conv10_2 feature map, a tensor of dimensions (N, 256, 3, 3) :param conv11_2_feats: conv11_2 feature map, a tensor of dimensions (N, 256, 1, 1) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ batch_size = conv4_3_feats.size(0) l_conv4_3 = self.loc_conv4_3(conv4_3_feats) l_conv4_3 = l_conv4_3.permute(0, 2, 3, 1).contiguous() l_conv4_3 = l_conv4_3.view(batch_size, -1, 4) l_conv7 = self.loc_conv7(conv7_feats) l_conv7 = l_conv7.permute(0, 2, 3, 1).contiguous() l_conv7 = l_conv7.view(batch_size, -1, 4) l_conv8_2 = self.loc_conv8_2(conv8_2_feats) l_conv8_2 = l_conv8_2.permute(0, 2, 3, 1).contiguous() l_conv8_2 = l_conv8_2.view(batch_size, -1, 4) l_conv9_2 = self.loc_conv9_2(conv9_2_feats) l_conv9_2 = l_conv9_2.permute(0, 2, 3, 1).contiguous() l_conv9_2 = l_conv9_2.view(batch_size, -1, 4) l_conv10_2 = self.loc_conv10_2(conv10_2_feats) l_conv10_2 = l_conv10_2.permute(0, 2, 3, 1).contiguous() l_conv10_2 = l_conv10_2.view(batch_size, -1, 4) l_conv11_2 = self.loc_conv11_2(conv11_2_feats) l_conv11_2 = l_conv11_2.permute(0, 2, 3, 1).contiguous() l_conv11_2 = l_conv11_2.view(batch_size, -1, 4) c_conv4_3 = self.cl_conv4_3(conv4_3_feats) c_conv4_3 = c_conv4_3.permute(0, 2, 3, 1).contiguous() c_conv4_3 = c_conv4_3.view(batch_size, -1, self.n_classes) c_conv7 = self.cl_conv7(conv7_feats) c_conv7 = c_conv7.permute(0, 2, 3, 1).contiguous() c_conv7 = c_conv7.view(batch_size, -1, self.n_classes) c_conv8_2 = self.cl_conv8_2(conv8_2_feats) c_conv8_2 = c_conv8_2.permute(0, 2, 3, 1).contiguous() c_conv8_2 = c_conv8_2.view(batch_size, -1, self.n_classes) c_conv9_2 = self.cl_conv9_2(conv9_2_feats) c_conv9_2 = c_conv9_2.permute(0, 2, 3, 1).contiguous() c_conv9_2 = c_conv9_2.view(batch_size, -1, self.n_classes) c_conv10_2 = self.cl_conv10_2(conv10_2_feats) c_conv10_2 = c_conv10_2.permute(0, 2, 3, 1).contiguous() c_conv10_2 = c_conv10_2.view(batch_size, -1, self.n_classes) c_conv11_2 = self.cl_conv11_2(conv11_2_feats) c_conv11_2 = c_conv11_2.permute(0, 2, 3, 1).contiguous() c_conv11_2 = c_conv11_2.view(batch_size, -1, self.n_classes) locs = torch.cat([l_conv4_3, l_conv7, l_conv8_2, l_conv9_2, l_conv10_2, l_conv11_2], dim=1) classes_scores = torch.cat([c_conv4_3, c_conv7, c_conv8_2, c_conv9_2, c_conv10_2, c_conv11_2], dim=1) return locs, classes_scores class SSD300(nn.Module): """ The SSD300 network - encapsulates the base VGG network, auxiliary, and prediction convolutions. """ def __init__(self, n_classes): super(SSD300, self).__init__() self.n_classes = n_classes self.base = VGGBase() self.aux_convs = AuxiliaryConvolutions() self.pred_convs = PredictionConvolutions(n_classes) self.rescale_factors = nn.Parameter(torch.FloatTensor(1, 512, 1, 1)) nn.init.constant_(self.rescale_factors, 20) self.priors_cxcy = self.create_prior_boxes() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ conv4_3_feats, conv7_feats = self.base(image) norm = conv4_3_feats.pow(2).sum(dim=1, keepdim=True).sqrt() conv4_3_feats = conv4_3_feats / norm conv4_3_feats = conv4_3_feats * self.rescale_factors conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats = (self .aux_convs(conv7_feats)) locs, classes_scores = self.pred_convs(conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats) return locs, classes_scores def create_prior_boxes(self): """ Create the 8732 prior (default) boxes for the SSD300, as defined in the paper. :return: prior boxes in center-size coordinates, a tensor of dimensions (8732, 4) """ fmap_dims = {'conv4_3': 38, 'conv7': 19, 'conv8_2': 10, 'conv9_2': 5, 'conv10_2': 3, 'conv11_2': 1} obj_scales = {'conv4_3': 0.1, 'conv7': 0.2, 'conv8_2': 0.375, 'conv9_2': 0.55, 'conv10_2': 0.725, 'conv11_2': 0.9} aspect_ratios = {'conv4_3': [1.0, 2.0, 0.5], 'conv7': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv8_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv9_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv10_2': [1.0, 2.0, 0.5], 'conv11_2': [1.0, 2.0, 0.5]} fmaps = list(fmap_dims.keys()) prior_boxes = [] for k, fmap in enumerate(fmaps): for i in range(fmap_dims[fmap]): for j in range(fmap_dims[fmap]): cx = (j + 0.5) / fmap_dims[fmap] cy = (i + 0.5) / fmap_dims[fmap] for ratio in aspect_ratios[fmap]: prior_boxes.append([cx, cy, obj_scales[fmap] * sqrt (ratio), obj_scales[fmap] / sqrt(ratio)]) if ratio == 1.0: try: additional_scale = sqrt(obj_scales[fmap] * obj_scales[fmaps[k + 1]]) except IndexError: additional_scale = 1.0 prior_boxes.append([cx, cy, additional_scale, additional_scale]) prior_boxes = torch.FloatTensor(prior_boxes) prior_boxes.clamp_(0, 1) return prior_boxes def detect_objects(self, predicted_locs, predicted_scores, min_score, max_overlap, top_k): """ Decipher the 8732 locations and class scores (output of ths SSD300) to detect objects. For each class, perform Non-Maximum Suppression (NMS) on boxes that are above a minimum threshold. :param predicted_locs: predicted locations/boxes w.r.t the 8732 prior boxes, a tensor of dimensions (N, 8732, 4) :param predicted_scores: class scores for each of the encoded locations/boxes, a tensor of dimensions (N, 8732, n_classes) :param min_score: minimum threshold for a box to be considered a match for a certain class :param max_overlap: maximum overlap two boxes can have so that the one with the lower score is not suppressed via NMS :param top_k: if there are a lot of resulting detection across all classes, keep only the top 'k' :return: detections (boxes, labels, and scores), lists of length batch_size """ batch_size = predicted_locs.size(0) n_priors = self.priors_cxcy.size(0) predicted_scores = F.softmax(predicted_scores, dim=2) all_images_boxes = list() all_images_labels = list() all_images_scores = list() assert n_priors == predicted_locs.size(1) == predicted_scores.size(1) for i in range(batch_size): decoded_locs = cxcy_to_xy(gcxgcy_to_cxcy(predicted_locs[i], self.priors_cxcy)) image_boxes = list() image_labels = list() image_scores = list() _max_scores, _best_label = predicted_scores[i].max(dim=1) for c in range(1, self.n_classes): class_scores = predicted_scores[i][:, c] score_above_min_score = class_scores > min_score n_above_min_score = score_above_min_score.sum().item() if n_above_min_score == 0: continue class_scores = class_scores[score_above_min_score] class_decoded_locs = decoded_locs[score_above_min_score] class_scores, sort_ind = class_scores.sort(dim=0, descending=True) class_decoded_locs = class_decoded_locs[sort_ind] overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs) suppress = torch.zeros(n_above_min_score, dtype=torch.bool) for box in range(class_decoded_locs.size(0)): if suppress[box] == 1: continue suppress = suppress | (overlap[box] > max_overlap) suppress[box] = 0 image_boxes.append(class_decoded_locs[~suppress]) image_labels.append(torch.LongTensor((~suppress).sum().item () * [c])) image_scores.append(class_scores[~suppress]) if len(image_boxes) == 0: image_boxes.append(torch.FloatTensor([[0.0, 0.0, 1.0, 1.0]])) image_labels.append(torch.LongTensor([0])) image_scores.append(torch.FloatTensor([0.0])) image_boxes = torch.cat(image_boxes, dim=0) image_labels = torch.cat(image_labels, dim=0) image_scores = torch.cat(image_scores, dim=0) n_objects = image_scores.size(0) if n_objects > top_k: image_scores, sort_ind = image_scores.sort(dim=0, descending=True) image_scores = image_scores[:top_k] image_boxes = image_boxes[sort_ind][:top_k] image_labels = image_labels[sort_ind][:top_k] all_images_boxes.append(image_boxes) all_images_labels.append(image_labels) all_images_scores.append(image_scores) return all_images_boxes, all_images_labels, all_images_scores def get_inputs(): return [torch.rand([4, 3, 512, 512])] def get_init_inputs(): return [[], {'n_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torchvision from torch import nn import torch.nn.functional as F from math import sqrt from itertools import product as product 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 262144 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 256 x1 = xindex // 256 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 1024 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (512 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (513 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 65536 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 512 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 512 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (256 + 2 * x0 + 512 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (257 + 2 * x0 + 512 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16384 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 64 x1 = xindex // 64 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 256 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 256 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (128 + 2 * x0 + 256 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (129 + 2 * x0 + 256 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_9(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) x1 = xindex // 32 % 32 x0 = xindex % 32 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + x0 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-33 + x4), tmp10, other=float('-inf')) tmp12 = x0 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-32 + x4), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-31 + x4), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x1 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-1 + x4), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x4, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (1 + x4), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x1 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (31 + x4), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (32 + x4), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (33 + x4), 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 + x4, tmp51, None) tl.store(out_ptr1 + x4, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 1024 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_red_fused_pow_sqrt_sum_11(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 512 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 + 2097152 * x1), rmask, eviction_policy='evict_first', 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] tmp5 = libdevice.sqrt(tmp3) tl.debug_barrier() tl.store(in_out_ptr0 + x3, tmp5, None) @triton.jit def triton_poi_fused_div_mul_12(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 4096 x2 = xindex // 2097152 x1 = xindex // 4096 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 / tmp1 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x3, tmp2, None) tl.store(out_ptr1 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_13(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_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) x3 = xindex x1 = xindex // 256 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_15(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_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) x3 = xindex x1 = xindex // 64 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_17(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_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) x3 = xindex x1 = xindex // 36 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_19(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 36 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_20(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_cat_21(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 394496 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 24656 x0 = xindex % 4 x2 = xindex // 98624 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 16384, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4096 * ((x0 + 4 * x1) % 16) + 65536 * ((x0 + 4 * x1 + 65536 * x2) // 65536 % 4) + (x0 + 4 * x1) // 16 % 4096), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + (x0 + 4 * x1) % 16, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tmp11 = tl.full([1], 22528, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (1024 * ((x0 + 4 * (-16384 + x1)) % 24) + 24576 * ((x0 + 4 * (-16384 + x1) + 24576 * x2) // 24576 % 4) + (x0 + 4 * (-16384 + x1)) // 24 % 1024), tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.load(in_ptr3 + (x0 + 4 * (-16384 + x1)) % 24, tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tmp20 = tl.full([1], 24064, tl.int64) tmp21 = tmp0 < tmp20 tmp22 = tmp19 & tmp21 tmp23 = tl.load(in_ptr4 + (256 * ((x0 + 4 * (-22528 + x1)) % 24) + 6144 * ((x0 + 4 * (-22528 + x1) + 6144 * x2) // 6144 % 4) + (x0 + 4 * (- 22528 + x1)) // 24 % 256), tmp22 & xmask, eviction_policy= 'evict_last', other=0.0) tmp24 = tl.load(in_ptr5 + (x0 + 4 * (-22528 + x1)) % 24, tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = tmp23 + tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp22, tmp25, tmp26) tmp28 = tmp0 >= tmp20 tmp29 = tl.full([1], 24448, tl.int64) tmp30 = tmp0 < tmp29 tmp31 = tmp28 & tmp30 tmp32 = tl.load(in_ptr6 + (64 * ((x0 + 4 * (-24064 + x1)) % 24) + 1536 * ((x0 + 4 * (-24064 + x1) + 1536 * x2) // 1536 % 4) + (x0 + 4 * (- 24064 + x1)) // 24 % 64), tmp31 & xmask, eviction_policy= 'evict_last', other=0.0) tmp33 = tl.load(in_ptr7 + (x0 + 4 * (-24064 + x1)) % 24, tmp31 & xmask, eviction_policy='evict_last', other=0.0) tmp34 = tmp32 + tmp33 tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp31, tmp34, tmp35) tmp37 = tmp0 >= tmp29 tmp38 = tl.full([1], 24592, tl.int64) tmp39 = tmp0 < tmp38 tmp40 = tmp37 & tmp39 tmp41 = tl.load(in_ptr8 + (36 * ((x0 + 4 * (-24448 + x1)) % 16) + 576 * ((x0 + 4 * (-24448 + x1) + 576 * x2) // 576 % 4) + (x0 + 4 * (- 24448 + x1)) // 16 % 36), tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp42 = tl.load(in_ptr9 + (x0 + 4 * (-24448 + x1)) % 16, tmp40 & xmask, eviction_policy='evict_last', other=0.0) tmp43 = tmp41 + tmp42 tmp44 = tl.full(tmp43.shape, 0.0, tmp43.dtype) tmp45 = tl.where(tmp40, tmp43, tmp44) tmp46 = tmp0 >= tmp38 tl.full([1], 24656, tl.int64) tmp49 = tl.load(in_ptr10 + (16 * ((x0 + 4 * (-24592 + x1)) % 16) + 256 * ((x0 + 4 * (-24592 + x1) + 256 * x2) // 256 % 4) + (x0 + 4 * (- 24592 + x1)) // 16 % 16), tmp46 & xmask, eviction_policy= 'evict_last', other=0.0) tmp50 = tl.load(in_ptr11 + (x0 + 4 * (-24592 + x1)) % 16, tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp51 = tmp49 + tmp50 tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp46, tmp51, tmp52) tmp54 = tl.where(tmp40, tmp45, tmp53) tmp55 = tl.where(tmp31, tmp36, tmp54) tmp56 = tl.where(tmp22, tmp27, tmp55) tmp57 = tl.where(tmp13, tmp18, tmp56) tmp58 = tl.where(tmp4, tmp9, tmp57) tl.store(out_ptr0 + x3, tmp58, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72) = 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, 512, 512), (786432, 262144, 512, 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,)) assert_size_stride(primals_32, (1, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_33, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_34, (256,), (1,)) assert_size_stride(primals_35, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_36, (512,), (1,)) assert_size_stride(primals_37, (128, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_38, (128,), (1,)) assert_size_stride(primals_39, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_40, (256,), (1,)) assert_size_stride(primals_41, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_42, (128,), (1,)) assert_size_stride(primals_43, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_44, (256,), (1,)) assert_size_stride(primals_45, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_46, (128,), (1,)) assert_size_stride(primals_47, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_48, (256,), (1,)) assert_size_stride(primals_49, (16, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_50, (16,), (1,)) assert_size_stride(primals_51, (24, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_52, (24,), (1,)) assert_size_stride(primals_53, (24, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_54, (24,), (1,)) assert_size_stride(primals_55, (24, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_56, (24,), (1,)) assert_size_stride(primals_57, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_58, (16,), (1,)) assert_size_stride(primals_59, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_60, (16,), (1,)) assert_size_stride(primals_61, (16, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_62, (16,), (1,)) assert_size_stride(primals_63, (24, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_64, (24,), (1,)) assert_size_stride(primals_65, (24, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_66, (24,), (1,)) assert_size_stride(primals_67, (24, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_68, (24,), (1,)) assert_size_stride(primals_69, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_70, (16,), (1,)) assert_size_stride(primals_71, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_72, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 512, 512), (16777216, 262144, 512, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(67108864)](buf1, primals_2, 67108864, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 512, 512), (16777216, 262144, 512, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(67108864)](buf3, primals_5, 67108864, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 64, 256, 256), (4194304, 65536, 256, 1), torch.float32) buf5 = empty_strided_cuda((4, 64, 256, 256), (4194304, 65536, 256, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(16777216)](buf3, buf4, buf5, 16777216, XBLOCK=512, num_warps=8, num_stages=1) buf6 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 256, 256), (8388608, 65536, 256, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_2[grid(33554432)](buf7, primals_7, 33554432, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 128, 256, 256), (8388608, 65536, 256, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_2[grid(33554432)](buf9, primals_9, 33554432, XBLOCK=512, num_warps=8, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 128, 128, 128), (2097152, 16384, 128, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 128, 128), (2097152, 16384, 128, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(8388608)](buf9, buf10, buf11, 8388608, XBLOCK=512, num_warps=8, num_stages=1) buf12 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_4[grid(16777216)](buf13, primals_11, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_11 buf14 = extern_kernels.convolution(buf13, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_4[grid(16777216)](buf15, primals_13, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_13 buf16 = extern_kernels.convolution(buf15, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf17 = buf16 del buf16 triton_poi_fused_convolution_relu_4[grid(16777216)](buf17, primals_15, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_15 buf18 = empty_strided_cuda((4, 256, 64, 64), (1048576, 4096, 64, 1), torch.float32) buf19 = empty_strided_cuda((4, 256, 64, 64), (1048576, 4096, 64, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(4194304)](buf17, buf18, buf19, 4194304, XBLOCK=512, num_warps=8, num_stages=1) buf20 = extern_kernels.convolution(buf18, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_6[grid(8388608)](buf21, primals_17, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_17 buf22 = extern_kernels.convolution(buf21, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_6[grid(8388608)](buf23, primals_19, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_19 buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf25 = buf24 del buf24 triton_poi_fused_convolution_relu_6[grid(8388608)](buf25, primals_21, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_21 buf26 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.float32) buf27 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_7[grid(2097152)](buf25, buf26, buf27, 2097152, XBLOCK=512, num_warps=8, num_stages=1) buf28 = extern_kernels.convolution(buf26, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_8[grid(2097152)](buf29, primals_23, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_23 buf30 = extern_kernels.convolution(buf29, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf31 = buf30 del buf30 triton_poi_fused_convolution_relu_8[grid(2097152)](buf31, primals_25, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_25 buf32 = extern_kernels.convolution(buf31, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf33 = buf32 del buf32 triton_poi_fused_convolution_relu_8[grid(2097152)](buf33, primals_27, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_27 buf34 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.float32) buf35 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_9[grid(2097152)](buf33, buf34, buf35, 2097152, XBLOCK=512, num_warps=8, num_stages=1) buf36 = extern_kernels.convolution(buf34, primals_28, stride=(1, 1), padding=(6, 6), dilation=(6, 6), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 1024, 32, 32), (1048576, 1024, 32, 1)) buf37 = buf36 del buf36 triton_poi_fused_convolution_relu_10[grid(4194304)](buf37, primals_29, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_29 buf38 = extern_kernels.convolution(buf37, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 1024, 32, 32), (1048576, 1024, 32, 1)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_10[grid(4194304)](buf39, primals_31, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_31 buf40 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) buf41 = reinterpret_tensor(buf40, (4, 1, 64, 64), (4096, 4096, 64, 1), 0) del buf40 triton_red_fused_pow_sqrt_sum_11[grid(16384)](buf41, buf25, 16384, 512, XBLOCK=64, RBLOCK=8, num_warps=4, num_stages=1) buf42 = empty_strided_cuda((4, 512, 64, 64), (2097152, 4096, 64, 1), torch.float32) buf43 = empty_strided_cuda((4, 512, 64, 64), (2097152, 4096, 64, 1), torch.float32) triton_poi_fused_div_mul_12[grid(8388608)](buf25, buf41, primals_32, buf42, buf43, 8388608, XBLOCK=1024, num_warps=4, num_stages=1) buf44 = extern_kernels.convolution(buf39, primals_33, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 256, 32, 32), (262144, 1024, 32, 1)) buf45 = buf44 del buf44 triton_poi_fused_convolution_relu_13[grid(1048576)](buf45, primals_34, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_34 buf46 = extern_kernels.convolution(buf45, primals_35, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 512, 16, 16), (131072, 256, 16, 1)) buf47 = buf46 del buf46 triton_poi_fused_convolution_relu_14[grid(524288)](buf47, primals_36, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_36 buf48 = extern_kernels.convolution(buf47, primals_37, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 128, 16, 16), (32768, 256, 16, 1)) buf49 = buf48 del buf48 triton_poi_fused_convolution_relu_15[grid(131072)](buf49, primals_38, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_38 buf50 = extern_kernels.convolution(buf49, primals_39, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf50, (4, 256, 8, 8), (16384, 64, 8, 1)) buf51 = buf50 del buf50 triton_poi_fused_convolution_relu_16[grid(65536)](buf51, primals_40, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_40 buf52 = extern_kernels.convolution(buf51, primals_41, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf52, (4, 128, 8, 8), (8192, 64, 8, 1)) buf53 = buf52 del buf52 triton_poi_fused_convolution_relu_17[grid(32768)](buf53, primals_42, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_42 buf54 = extern_kernels.convolution(buf53, primals_43, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 256, 6, 6), (9216, 36, 6, 1)) buf55 = buf54 del buf54 triton_poi_fused_convolution_relu_18[grid(36864)](buf55, primals_44, 36864, XBLOCK=512, num_warps=4, num_stages=1) del primals_44 buf56 = extern_kernels.convolution(buf55, primals_45, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 128, 6, 6), (4608, 36, 6, 1)) buf57 = buf56 del buf56 triton_poi_fused_convolution_relu_19[grid(18432)](buf57, primals_46, 18432, XBLOCK=128, num_warps=4, num_stages=1) del primals_46 buf58 = extern_kernels.convolution(buf57, primals_47, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf58, (4, 256, 4, 4), (4096, 16, 4, 1)) buf59 = buf58 del buf58 triton_poi_fused_convolution_relu_20[grid(16384)](buf59, primals_48, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_48 buf60 = extern_kernels.convolution(buf43, primals_49, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf60, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf61 = extern_kernels.convolution(buf39, primals_51, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 24, 32, 32), (24576, 1024, 32, 1)) buf62 = extern_kernels.convolution(buf47, primals_53, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 24, 16, 16), (6144, 256, 16, 1)) buf63 = extern_kernels.convolution(buf51, primals_55, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf63, (4, 24, 8, 8), (1536, 64, 8, 1)) buf64 = extern_kernels.convolution(buf55, primals_57, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 16, 6, 6), (576, 36, 6, 1)) buf65 = extern_kernels.convolution(buf59, primals_59, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf65, (4, 16, 4, 4), (256, 16, 4, 1)) buf66 = extern_kernels.convolution(buf43, primals_61, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf66, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf67 = extern_kernels.convolution(buf39, primals_63, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf67, (4, 24, 32, 32), (24576, 1024, 32, 1)) buf68 = extern_kernels.convolution(buf47, primals_65, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf68, (4, 24, 16, 16), (6144, 256, 16, 1)) buf69 = extern_kernels.convolution(buf51, primals_67, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf69, (4, 24, 8, 8), (1536, 64, 8, 1)) buf70 = extern_kernels.convolution(buf55, primals_69, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 16, 6, 6), (576, 36, 6, 1)) buf71 = extern_kernels.convolution(buf59, primals_71, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf71, (4, 16, 4, 4), (256, 16, 4, 1)) buf72 = empty_strided_cuda((4, 24656, 4), (98624, 4, 1), torch.float32) triton_poi_fused_cat_21[grid(394496)](buf60, primals_50, buf61, primals_52, buf62, primals_54, buf63, primals_56, buf64, primals_58, buf65, primals_60, buf72, 394496, XBLOCK=512, num_warps=8, num_stages=1) del buf60 del buf61 del buf62 del buf63 del buf64 del buf65 del primals_50 del primals_52 del primals_54 del primals_56 del primals_58 del primals_60 buf73 = empty_strided_cuda((4, 24656, 4), (98624, 4, 1), torch.float32) triton_poi_fused_cat_21[grid(394496)](buf66, primals_62, buf67, primals_64, buf68, primals_66, buf69, primals_68, buf70, primals_70, buf71, primals_72, buf73, 394496, XBLOCK=512, num_warps=8, num_stages=1) del buf66 del buf67 del buf68 del buf69 del buf70 del buf71 del primals_62 del primals_64 del primals_66 del primals_68 del primals_70 del primals_72 return (buf72, buf73, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, primals_28, primals_30, primals_32, primals_33, primals_35, primals_37, primals_39, primals_41, primals_43, primals_45, primals_47, primals_49, primals_51, primals_53, primals_55, primals_57, primals_59, primals_61, primals_63, primals_65, primals_67, primals_69, primals_71, buf1, buf3, buf4, buf5, buf7, buf9, buf10, buf11, buf13, buf15, buf17, buf18, buf19, buf21, buf23, buf25, buf26, buf27, buf29, buf31, buf33, buf34, buf35, buf37, buf39, buf41, buf42, buf43, buf45, buf47, buf49, buf51, buf53, buf55, buf57, buf59) def decimate(tensor, m): """ Decimate a tensor by a factor 'm', i.e. downsample by keeping every 'm'th value. This is used when we convert FC layers to equivalent Convolutional layers, BUT of a smaller size. :param tensor: tensor to be decimated :param m: list of decimation factors for each dimension of the tensor; None if not to be decimated along a dimension :return: decimated tensor """ assert tensor.dim() == len(m) for d in range(tensor.dim()): if m[d] is not None: tensor = tensor.index_select(dim=d, index=torch.arange(start=0, end=tensor.size(d), step=m[d]).long()) return tensor def cxcy_to_xy(cxcy): """ Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max). :param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4) :return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4) """ return torch.cat([cxcy[:, :2] - cxcy[:, 2:] / 2, cxcy[:, :2] + cxcy[:, 2:] / 2], 1) def find_intersection(set_1, set_2): """ Find the intersection of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: intersection of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2]. unsqueeze(0)) upper_bounds = torch.min(set_1[:, 2:].unsqueeze(1), set_2[:, 2:]. unsqueeze(0)) intersection_dims = torch.clamp(upper_bounds - lower_bounds, min=0) return intersection_dims[:, :, 0] * intersection_dims[:, :, 1] def find_jaccard_overlap(set_1, set_2): """ Find the Jaccard Overlap (IoU) of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: Jaccard Overlap of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ intersection = find_intersection(set_1, set_2) areas_set_1 = (set_1[:, 2] - set_1[:, 0]) * (set_1[:, 3] - set_1[:, 1]) areas_set_2 = (set_2[:, 2] - set_2[:, 0]) * (set_2[:, 3] - set_2[:, 1]) union = areas_set_1.unsqueeze(1) + areas_set_2.unsqueeze(0) - intersection return intersection / union def gcxgcy_to_cxcy(gcxgcy, priors_cxcy): """ Decode bounding box coordinates predicted by the model, since they are encoded in the form mentioned above. They are decoded into center-size coordinates. This is the inverse of the function above. :param gcxgcy: encoded bounding boxes, i.e. output of the model, a tensor of size (n_priors, 4) :param priors_cxcy: prior boxes with respect to which the encoding is defined, a tensor of size (n_priors, 4) :return: decoded bounding boxes in center-size form, a tensor of size (n_priors, 4) """ return torch.cat([gcxgcy[:, :2] * priors_cxcy[:, 2:] / 10 + priors_cxcy [:, :2], torch.exp(gcxgcy[:, 2:] / 5) * priors_cxcy[:, 2:]], 1) class VGGBase(nn.Module): """ VGG base convolutions to produce lower-level feature maps. """ def __init__(self): super(VGGBase, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool5 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) self.conv7 = nn.Conv2d(1024, 1024, kernel_size=1) self.load_pretrained_layers() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: lower-level feature maps conv4_3 and conv7 """ out = F.relu(self.conv1_1(image)) out = F.relu(self.conv1_2(out)) out = self.pool1(out) out = F.relu(self.conv2_1(out)) out = F.relu(self.conv2_2(out)) out = self.pool2(out) out = F.relu(self.conv3_1(out)) out = F.relu(self.conv3_2(out)) out = F.relu(self.conv3_3(out)) out = self.pool3(out) out = F.relu(self.conv4_1(out)) out = F.relu(self.conv4_2(out)) out = F.relu(self.conv4_3(out)) conv4_3_feats = out out = self.pool4(out) out = F.relu(self.conv5_1(out)) out = F.relu(self.conv5_2(out)) out = F.relu(self.conv5_3(out)) out = self.pool5(out) out = F.relu(self.conv6(out)) conv7_feats = F.relu(self.conv7(out)) return conv4_3_feats, conv7_feats def load_pretrained_layers(self): """ As in the paper, we use a VGG-16 pretrained on the ImageNet task as the base network. There's one available in PyTorch, see https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.vgg16 We copy these parameters into our network. It's straightforward for conv1 to conv5. However, the original VGG-16 does not contain the conv6 and con7 layers. Therefore, we convert fc6 and fc7 into convolutional layers, and subsample by decimation. See 'decimate' in utils.py. """ state_dict = self.state_dict() param_names = list(state_dict.keys()) pretrained_state_dict = torchvision.models.vgg16(pretrained=True ).state_dict() pretrained_param_names = list(pretrained_state_dict.keys()) for i, param in enumerate(param_names[:-4]): state_dict[param] = pretrained_state_dict[pretrained_param_names[i] ] conv_fc6_weight = pretrained_state_dict['classifier.0.weight'].view( 4096, 512, 7, 7) conv_fc6_bias = pretrained_state_dict['classifier.0.bias'] state_dict['conv6.weight'] = decimate(conv_fc6_weight, m=[4, None, 3, 3]) state_dict['conv6.bias'] = decimate(conv_fc6_bias, m=[4]) conv_fc7_weight = pretrained_state_dict['classifier.3.weight'].view( 4096, 4096, 1, 1) conv_fc7_bias = pretrained_state_dict['classifier.3.bias'] state_dict['conv7.weight'] = decimate(conv_fc7_weight, m=[4, 4, None, None]) state_dict['conv7.bias'] = decimate(conv_fc7_bias, m=[4]) self.load_state_dict(state_dict) None class AuxiliaryConvolutions(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutions, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv7_feats): """ Forward propagation. :param conv7_feats: lower-level conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :return: higher-level feature maps conv8_2, conv9_2, conv10_2, and conv11_2 """ out = F.relu(self.conv8_1(conv7_feats)) out = F.relu(self.conv8_2(out)) conv8_2_feats = out out = F.relu(self.conv9_1(out)) out = F.relu(self.conv9_2(out)) conv9_2_feats = out out = F.relu(self.conv10_1(out)) out = F.relu(self.conv10_2(out)) conv10_2_feats = out out = F.relu(self.conv11_1(out)) conv11_2_feats = F.relu(self.conv11_2(out)) return conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats class PredictionConvolutions(nn.Module): """ Convolutions to predict class scores and bounding boxes using lower and higher-level feature maps. The bounding boxes (locations) are predicted as encoded offsets w.r.t each of the 8732 prior (default) boxes. See 'cxcy_to_gcxgcy' in utils.py for the encoding definition. The class scores represent the scores of each object class in each of the 8732 bounding boxes located. A high score for 'background' = no object. """ def __init__(self, n_classes): """ :param n_classes: number of different types of objects """ super(PredictionConvolutions, self).__init__() self.n_classes = n_classes n_boxes = {'conv4_3': 4, 'conv7': 6, 'conv8_2': 6, 'conv9_2': 6, 'conv10_2': 4, 'conv11_2': 4} self.loc_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * 4, kernel_size=3, padding=1) self.loc_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * 4, kernel_size= 3, padding=1) self.loc_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * 4, kernel_size=3, padding=1) self.loc_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * 4, kernel_size=3, padding=1) self.loc_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * 4, kernel_size=3, padding=1) self.loc_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * 4, kernel_size=3, padding=1) self.cl_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * n_classes, kernel_size=3, padding=1) self.cl_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * n_classes, kernel_size=3, padding=1) self.cl_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * n_classes, kernel_size=3, padding=1) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats): """ Forward propagation. :param conv4_3_feats: conv4_3 feature map, a tensor of dimensions (N, 512, 38, 38) :param conv7_feats: conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :param conv8_2_feats: conv8_2 feature map, a tensor of dimensions (N, 512, 10, 10) :param conv9_2_feats: conv9_2 feature map, a tensor of dimensions (N, 256, 5, 5) :param conv10_2_feats: conv10_2 feature map, a tensor of dimensions (N, 256, 3, 3) :param conv11_2_feats: conv11_2 feature map, a tensor of dimensions (N, 256, 1, 1) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ batch_size = conv4_3_feats.size(0) l_conv4_3 = self.loc_conv4_3(conv4_3_feats) l_conv4_3 = l_conv4_3.permute(0, 2, 3, 1).contiguous() l_conv4_3 = l_conv4_3.view(batch_size, -1, 4) l_conv7 = self.loc_conv7(conv7_feats) l_conv7 = l_conv7.permute(0, 2, 3, 1).contiguous() l_conv7 = l_conv7.view(batch_size, -1, 4) l_conv8_2 = self.loc_conv8_2(conv8_2_feats) l_conv8_2 = l_conv8_2.permute(0, 2, 3, 1).contiguous() l_conv8_2 = l_conv8_2.view(batch_size, -1, 4) l_conv9_2 = self.loc_conv9_2(conv9_2_feats) l_conv9_2 = l_conv9_2.permute(0, 2, 3, 1).contiguous() l_conv9_2 = l_conv9_2.view(batch_size, -1, 4) l_conv10_2 = self.loc_conv10_2(conv10_2_feats) l_conv10_2 = l_conv10_2.permute(0, 2, 3, 1).contiguous() l_conv10_2 = l_conv10_2.view(batch_size, -1, 4) l_conv11_2 = self.loc_conv11_2(conv11_2_feats) l_conv11_2 = l_conv11_2.permute(0, 2, 3, 1).contiguous() l_conv11_2 = l_conv11_2.view(batch_size, -1, 4) c_conv4_3 = self.cl_conv4_3(conv4_3_feats) c_conv4_3 = c_conv4_3.permute(0, 2, 3, 1).contiguous() c_conv4_3 = c_conv4_3.view(batch_size, -1, self.n_classes) c_conv7 = self.cl_conv7(conv7_feats) c_conv7 = c_conv7.permute(0, 2, 3, 1).contiguous() c_conv7 = c_conv7.view(batch_size, -1, self.n_classes) c_conv8_2 = self.cl_conv8_2(conv8_2_feats) c_conv8_2 = c_conv8_2.permute(0, 2, 3, 1).contiguous() c_conv8_2 = c_conv8_2.view(batch_size, -1, self.n_classes) c_conv9_2 = self.cl_conv9_2(conv9_2_feats) c_conv9_2 = c_conv9_2.permute(0, 2, 3, 1).contiguous() c_conv9_2 = c_conv9_2.view(batch_size, -1, self.n_classes) c_conv10_2 = self.cl_conv10_2(conv10_2_feats) c_conv10_2 = c_conv10_2.permute(0, 2, 3, 1).contiguous() c_conv10_2 = c_conv10_2.view(batch_size, -1, self.n_classes) c_conv11_2 = self.cl_conv11_2(conv11_2_feats) c_conv11_2 = c_conv11_2.permute(0, 2, 3, 1).contiguous() c_conv11_2 = c_conv11_2.view(batch_size, -1, self.n_classes) locs = torch.cat([l_conv4_3, l_conv7, l_conv8_2, l_conv9_2, l_conv10_2, l_conv11_2], dim=1) classes_scores = torch.cat([c_conv4_3, c_conv7, c_conv8_2, c_conv9_2, c_conv10_2, c_conv11_2], dim=1) return locs, classes_scores class SSD300New(nn.Module): """ The SSD300 network - encapsulates the base VGG network, auxiliary, and prediction convolutions. """ def __init__(self, n_classes): super(SSD300New, self).__init__() self.n_classes = n_classes self.base = VGGBase() self.aux_convs = AuxiliaryConvolutions() self.pred_convs = PredictionConvolutions(n_classes) self.rescale_factors = nn.Parameter(torch.FloatTensor(1, 512, 1, 1)) nn.init.constant_(self.rescale_factors, 20) self.priors_cxcy = self.create_prior_boxes() def create_prior_boxes(self): """ Create the 8732 prior (default) boxes for the SSD300, as defined in the paper. :return: prior boxes in center-size coordinates, a tensor of dimensions (8732, 4) """ fmap_dims = {'conv4_3': 38, 'conv7': 19, 'conv8_2': 10, 'conv9_2': 5, 'conv10_2': 3, 'conv11_2': 1} obj_scales = {'conv4_3': 0.1, 'conv7': 0.2, 'conv8_2': 0.375, 'conv9_2': 0.55, 'conv10_2': 0.725, 'conv11_2': 0.9} aspect_ratios = {'conv4_3': [1.0, 2.0, 0.5], 'conv7': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv8_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv9_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv10_2': [1.0, 2.0, 0.5], 'conv11_2': [1.0, 2.0, 0.5]} fmaps = list(fmap_dims.keys()) prior_boxes = [] for k, fmap in enumerate(fmaps): for i in range(fmap_dims[fmap]): for j in range(fmap_dims[fmap]): cx = (j + 0.5) / fmap_dims[fmap] cy = (i + 0.5) / fmap_dims[fmap] for ratio in aspect_ratios[fmap]: prior_boxes.append([cx, cy, obj_scales[fmap] * sqrt (ratio), obj_scales[fmap] / sqrt(ratio)]) if ratio == 1.0: try: additional_scale = sqrt(obj_scales[fmap] * obj_scales[fmaps[k + 1]]) except IndexError: additional_scale = 1.0 prior_boxes.append([cx, cy, additional_scale, additional_scale]) prior_boxes = torch.FloatTensor(prior_boxes) prior_boxes.clamp_(0, 1) return prior_boxes def detect_objects(self, predicted_locs, predicted_scores, min_score, max_overlap, top_k): """ Decipher the 8732 locations and class scores (output of ths SSD300) to detect objects. For each class, perform Non-Maximum Suppression (NMS) on boxes that are above a minimum threshold. :param predicted_locs: predicted locations/boxes w.r.t the 8732 prior boxes, a tensor of dimensions (N, 8732, 4) :param predicted_scores: class scores for each of the encoded locations/boxes, a tensor of dimensions (N, 8732, n_classes) :param min_score: minimum threshold for a box to be considered a match for a certain class :param max_overlap: maximum overlap two boxes can have so that the one with the lower score is not suppressed via NMS :param top_k: if there are a lot of resulting detection across all classes, keep only the top 'k' :return: detections (boxes, labels, and scores), lists of length batch_size """ batch_size = predicted_locs.size(0) n_priors = self.priors_cxcy.size(0) predicted_scores = F.softmax(predicted_scores, dim=2) all_images_boxes = list() all_images_labels = list() all_images_scores = list() assert n_priors == predicted_locs.size(1) == predicted_scores.size(1) for i in range(batch_size): decoded_locs = cxcy_to_xy(gcxgcy_to_cxcy(predicted_locs[i], self.priors_cxcy)) image_boxes = list() image_labels = list() image_scores = list() _max_scores, _best_label = predicted_scores[i].max(dim=1) for c in range(1, self.n_classes): class_scores = predicted_scores[i][:, c] score_above_min_score = class_scores > min_score n_above_min_score = score_above_min_score.sum().item() if n_above_min_score == 0: continue class_scores = class_scores[score_above_min_score] class_decoded_locs = decoded_locs[score_above_min_score] class_scores, sort_ind = class_scores.sort(dim=0, descending=True) class_decoded_locs = class_decoded_locs[sort_ind] overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs) suppress = torch.zeros(n_above_min_score, dtype=torch.bool) for box in range(class_decoded_locs.size(0)): if suppress[box] == 1: continue suppress = suppress | (overlap[box] > max_overlap) suppress[box] = 0 image_boxes.append(class_decoded_locs[~suppress]) image_labels.append(torch.LongTensor((~suppress).sum().item () * [c])) image_scores.append(class_scores[~suppress]) if len(image_boxes) == 0: image_boxes.append(torch.FloatTensor([[0.0, 0.0, 1.0, 1.0]])) image_labels.append(torch.LongTensor([0])) image_scores.append(torch.FloatTensor([0.0])) image_boxes = torch.cat(image_boxes, dim=0) image_labels = torch.cat(image_labels, dim=0) image_scores = torch.cat(image_scores, dim=0) n_objects = image_scores.size(0) if n_objects > top_k: image_scores, sort_ind = image_scores.sort(dim=0, descending=True) image_scores = image_scores[:top_k] image_boxes = image_boxes[sort_ind][:top_k] image_labels = image_labels[sort_ind][:top_k] all_images_boxes.append(image_boxes) all_images_labels.append(image_labels) all_images_scores.append(image_scores) return all_images_boxes, all_images_labels, all_images_scores def forward(self, input_0): primals_32 = self.rescale_factors primals_1 = self.base.conv1_1.weight primals_2 = self.base.conv1_1.bias primals_4 = self.base.conv1_2.weight primals_5 = self.base.conv1_2.bias primals_6 = self.base.conv2_1.weight primals_7 = self.base.conv2_1.bias primals_8 = self.base.conv2_2.weight primals_9 = self.base.conv2_2.bias primals_10 = self.base.conv3_1.weight primals_11 = self.base.conv3_1.bias primals_12 = self.base.conv3_2.weight primals_13 = self.base.conv3_2.bias primals_14 = self.base.conv3_3.weight primals_15 = self.base.conv3_3.bias primals_16 = self.base.conv4_1.weight primals_17 = self.base.conv4_1.bias primals_18 = self.base.conv4_2.weight primals_19 = self.base.conv4_2.bias primals_20 = self.base.conv4_3.weight primals_21 = self.base.conv4_3.bias primals_22 = self.base.conv5_1.weight primals_23 = self.base.conv5_1.bias primals_24 = self.base.conv5_2.weight primals_25 = self.base.conv5_2.bias primals_26 = self.base.conv5_3.weight primals_27 = self.base.conv5_3.bias primals_28 = self.base.conv6.weight primals_29 = self.base.conv6.bias primals_30 = self.base.conv7.weight primals_31 = self.base.conv7.bias primals_33 = self.aux_convs.conv8_1.weight primals_34 = self.aux_convs.conv8_1.bias primals_35 = self.aux_convs.conv8_2.weight primals_36 = self.aux_convs.conv8_2.bias primals_37 = self.aux_convs.conv9_1.weight primals_38 = self.aux_convs.conv9_1.bias primals_39 = self.aux_convs.conv9_2.weight primals_40 = self.aux_convs.conv9_2.bias primals_41 = self.aux_convs.conv10_1.weight primals_42 = self.aux_convs.conv10_1.bias primals_43 = self.aux_convs.conv10_2.weight primals_44 = self.aux_convs.conv10_2.bias primals_45 = self.aux_convs.conv11_1.weight primals_46 = self.aux_convs.conv11_1.bias primals_47 = self.aux_convs.conv11_2.weight primals_48 = self.aux_convs.conv11_2.bias primals_49 = self.pred_convs.loc_conv4_3.weight primals_50 = self.pred_convs.loc_conv4_3.bias primals_51 = self.pred_convs.loc_conv7.weight primals_52 = self.pred_convs.loc_conv7.bias primals_53 = self.pred_convs.loc_conv8_2.weight primals_54 = self.pred_convs.loc_conv8_2.bias primals_55 = self.pred_convs.loc_conv9_2.weight primals_56 = self.pred_convs.loc_conv9_2.bias primals_57 = self.pred_convs.loc_conv10_2.weight primals_58 = self.pred_convs.loc_conv10_2.bias primals_59 = self.pred_convs.loc_conv11_2.weight primals_60 = self.pred_convs.loc_conv11_2.bias primals_61 = self.pred_convs.cl_conv4_3.weight primals_62 = self.pred_convs.cl_conv4_3.bias primals_63 = self.pred_convs.cl_conv7.weight primals_64 = self.pred_convs.cl_conv7.bias primals_65 = self.pred_convs.cl_conv8_2.weight primals_66 = self.pred_convs.cl_conv8_2.bias primals_67 = self.pred_convs.cl_conv9_2.weight primals_68 = self.pred_convs.cl_conv9_2.bias primals_69 = self.pred_convs.cl_conv10_2.weight primals_70 = self.pred_convs.cl_conv10_2.bias primals_71 = self.pred_convs.cl_conv11_2.weight primals_72 = self.pred_convs.cl_conv11_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72]) return output[0], output[1]
dee-walia20/SSD-Implementation-using-Pytorch
SSD300
false
7,606
[ "MIT" ]
1
2a7dcdcea2787f4bffd45f335819f08af2b525dd
https://github.com/dee-walia20/SSD-Implementation-using-Pytorch/tree/2a7dcdcea2787f4bffd45f335819f08af2b525dd
ResidualBlock
import torch import torch.nn as nn from functools import partial def ncsn_conv3x3(in_planes, out_planes, stride=1, bias=True, dilation=1, init_scale=1.0, padding=1): """3x3 convolution with PyTorch initialization. Same as NCSNv1/NCSNv2.""" init_scale = 1e-10 if init_scale == 0 else init_scale conv = nn.Conv2d(in_planes, out_planes, stride=stride, bias=bias, dilation=dilation, padding=padding, kernel_size=3) conv.weight.data *= init_scale if bias: conv.bias.data *= init_scale return conv def ncsn_conv1x1(in_planes, out_planes, stride=1, bias=True, dilation=1, init_scale=1.0, padding=0): """1x1 convolution. Same as NCSNv1/v2.""" conv = nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=bias, dilation=dilation, padding=padding) init_scale = 1e-10 if init_scale == 0 else init_scale conv.weight.data *= init_scale conv.bias.data *= init_scale return conv class ConvMeanPool(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True, adjust_padding=False): super().__init__() if not adjust_padding: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = conv else: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = nn.Sequential(nn.ZeroPad2d((1, 0, 1, 0)), conv) def forward(self, inputs): output = self.conv(inputs) output = sum([output[:, :, ::2, ::2], output[:, :, 1::2, ::2], output[:, :, ::2, 1::2], output[:, :, 1::2, 1::2]]) / 4.0 return output class ResidualBlock(nn.Module): def __init__(self, input_dim, output_dim, resample=None, act=nn.ELU(), normalization=nn.InstanceNorm2d, adjust_padding=False, dilation=1): super().__init__() self.non_linearity = act self.input_dim = input_dim self.output_dim = output_dim self.resample = resample self.normalization = normalization if resample == 'down': if dilation > 1: self.conv1 = ncsn_conv3x3(input_dim, input_dim, dilation= dilation) self.normalize2 = normalization(input_dim) self.conv2 = ncsn_conv3x3(input_dim, output_dim, dilation= dilation) conv_shortcut = partial(ncsn_conv3x3, dilation=dilation) else: self.conv1 = ncsn_conv3x3(input_dim, input_dim) self.normalize2 = normalization(input_dim) self.conv2 = ConvMeanPool(input_dim, output_dim, 3, adjust_padding=adjust_padding) conv_shortcut = partial(ConvMeanPool, kernel_size=1, adjust_padding=adjust_padding) elif resample is None: if dilation > 1: conv_shortcut = partial(ncsn_conv3x3, dilation=dilation) self.conv1 = ncsn_conv3x3(input_dim, output_dim, dilation= dilation) self.normalize2 = normalization(output_dim) self.conv2 = ncsn_conv3x3(output_dim, output_dim, dilation= dilation) else: conv_shortcut = partial(ncsn_conv1x1) self.conv1 = ncsn_conv3x3(input_dim, output_dim) self.normalize2 = normalization(output_dim) self.conv2 = ncsn_conv3x3(output_dim, output_dim) else: raise Exception('invalid resample value') if output_dim != input_dim or resample is not None: self.shortcut = conv_shortcut(input_dim, output_dim) self.normalize1 = normalization(input_dim) def forward(self, x): output = self.normalize1(x) output = self.non_linearity(output) output = self.conv1(output) output = self.normalize2(output) output = self.non_linearity(output) output = self.conv2(output) if self.output_dim == self.input_dim and self.resample is None: shortcut = x else: shortcut = self.shortcut(x) return shortcut + output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from functools import partial assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__native_batch_norm_legit_elu_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = tmp0 - tmp10 tmp18 = 16.0 tmp19 = tmp16 / tmp18 tmp20 = 1e-05 tmp21 = tmp19 + tmp20 tmp22 = libdevice.rsqrt(tmp21) tmp23 = tmp17 * tmp22 tmp24 = 0.0 tmp25 = tmp23 > tmp24 tmp26 = 1.0 tmp27 = tmp23 * tmp26 tmp28 = libdevice.expm1(tmp27) tmp29 = tmp28 * tmp26 tmp30 = tl.where(tmp25, tmp27, tmp29) tl.store(out_ptr2 + (r1 + 16 * x0), tmp30, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_convolution_elu_1(in_out_ptr0, in_out_ptr1, in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl. constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp2 - tmp12 tmp25 = tmp24 * tmp23 tmp26 = 0.0 tmp27 = tmp25 > tmp26 tmp28 = 1.0 tmp29 = tmp25 * tmp28 tmp30 = libdevice.expm1(tmp29) tmp31 = tmp30 * tmp28 tmp32 = tl.where(tmp27, tmp29, tmp31) tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp23, xmask) tl.store(out_ptr1 + (r2 + 16 * x3), tmp32, xmask) tl.store(out_ptr0 + x3, tmp12, 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_ptr0 + x3, xmask) tmp1 = tl.load(in_out_ptr0 + x3, xmask) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x3, 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, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_elu_0[grid(16)](primals_1, buf3, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32) buf7 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf9 = reinterpret_tensor(buf7, (1, 16, 1, 1), (16, 1, 1, 1), 0) del buf7 buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_per_fused__native_batch_norm_legit_convolution_elu_1[grid(16)]( buf5, buf9, primals_3, buf6, buf10, 16, 16, XBLOCK=1, num_warps =2, num_stages=1) del primals_3 buf11 = extern_kernels.convolution(buf10, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 4, 4, 4), (64, 16, 4, 1)) buf12 = buf11 del buf11 triton_poi_fused_add_convolution_2[grid(256)](buf12, primals_1, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf12, primals_2, primals_4, buf3, buf5, buf6, buf9, buf10 def ncsn_conv3x3(in_planes, out_planes, stride=1, bias=True, dilation=1, init_scale=1.0, padding=1): """3x3 convolution with PyTorch initialization. Same as NCSNv1/NCSNv2.""" init_scale = 1e-10 if init_scale == 0 else init_scale conv = nn.Conv2d(in_planes, out_planes, stride=stride, bias=bias, dilation=dilation, padding=padding, kernel_size=3) conv.weight.data *= init_scale if bias: conv.bias.data *= init_scale return conv def ncsn_conv1x1(in_planes, out_planes, stride=1, bias=True, dilation=1, init_scale=1.0, padding=0): """1x1 convolution. Same as NCSNv1/v2.""" conv = nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, bias=bias, dilation=dilation, padding=padding) init_scale = 1e-10 if init_scale == 0 else init_scale conv.weight.data *= init_scale conv.bias.data *= init_scale return conv class ConvMeanPool(nn.Module): def __init__(self, input_dim, output_dim, kernel_size=3, biases=True, adjust_padding=False): super().__init__() if not adjust_padding: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = conv else: conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=kernel_size // 2, bias=biases) self.conv = nn.Sequential(nn.ZeroPad2d((1, 0, 1, 0)), conv) def forward(self, inputs): output = self.conv(inputs) output = sum([output[:, :, ::2, ::2], output[:, :, 1::2, ::2], output[:, :, ::2, 1::2], output[:, :, 1::2, 1::2]]) / 4.0 return output class ResidualBlockNew(nn.Module): def __init__(self, input_dim, output_dim, resample=None, act=nn.ELU(), normalization=nn.InstanceNorm2d, adjust_padding=False, dilation=1): super().__init__() self.non_linearity = act self.input_dim = input_dim self.output_dim = output_dim self.resample = resample self.normalization = normalization if resample == 'down': if dilation > 1: self.conv1 = ncsn_conv3x3(input_dim, input_dim, dilation= dilation) self.normalize2 = normalization(input_dim) self.conv2 = ncsn_conv3x3(input_dim, output_dim, dilation= dilation) conv_shortcut = partial(ncsn_conv3x3, dilation=dilation) else: self.conv1 = ncsn_conv3x3(input_dim, input_dim) self.normalize2 = normalization(input_dim) self.conv2 = ConvMeanPool(input_dim, output_dim, 3, adjust_padding=adjust_padding) conv_shortcut = partial(ConvMeanPool, kernel_size=1, adjust_padding=adjust_padding) elif resample is None: if dilation > 1: conv_shortcut = partial(ncsn_conv3x3, dilation=dilation) self.conv1 = ncsn_conv3x3(input_dim, output_dim, dilation= dilation) self.normalize2 = normalization(output_dim) self.conv2 = ncsn_conv3x3(output_dim, output_dim, dilation= dilation) else: conv_shortcut = partial(ncsn_conv1x1) self.conv1 = ncsn_conv3x3(input_dim, output_dim) self.normalize2 = normalization(output_dim) self.conv2 = ncsn_conv3x3(output_dim, output_dim) else: raise Exception('invalid resample value') if output_dim != input_dim or resample is not None: self.shortcut = conv_shortcut(input_dim, output_dim) self.normalize1 = normalization(input_dim) 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]
samsartor/score_sde
ResidualBlock
false
7,607
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
LinActorCritic
import torch class LinActorCritic(torch.nn.Module): def __init__(self, actor_lr, epsilon, in_dim, h_dim, out_dim): super(LinActorCritic, self).__init__() self.in_dim = in_dim self.out_dim = out_dim self.h_dim = h_dim self.epsilon = epsilon self.define_network() self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self def normalize(self, tensor): return (tensor - tensor.mean()) / (torch.std(tensor) + 1e-05) def define_network(self): self.relu = torch.nn.LeakyReLU() self.leaky_relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.softmax = torch.nn.Softmax(dim=-1) size = self.h_dim self.p1 = torch.nn.Linear(self.in_dim, size) self.p2 = torch.nn.Linear(size, size) self.v1 = torch.nn.Linear(self.in_dim, size) self.v2 = torch.nn.Linear(size, size) self.pi = torch.nn.Linear(size, self.out_dim) self.value = torch.nn.Linear(size, 1) self.critic_loss = torch.nn.MSELoss() def forward(self, x): out = torch.Tensor(x).float() p = self.p1(out) p = self.tanh(p) p = self.p2(p) p = self.tanh(p) p = self.pi(p) pi = self.softmax(p) v = self.v1(out) v = self.tanh(v) v = self.v2(v) v = self.tanh(v) v = self.value(v) return pi, v def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'actor_lr': 4, 'epsilon': 4, 'in_dim': 4, 'h_dim': 4, 'out_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused__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 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 = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4, 4), (4, 1)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (1, 4), (4, 1)) assert_size_stride(primals_13, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_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=128, 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) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_tanh_0[grid(256)](buf3, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf7 = reinterpret_tensor(buf5, (64, 4), (4, 1), 0) del buf5 extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf7) del primals_8 buf8 = reinterpret_tensor(buf7, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf7 triton_poi_fused_tanh_0[grid(256)](buf8, primals_9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf9 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf8, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf9) buf10 = reinterpret_tensor(buf9, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf9 triton_poi_fused_tanh_0[grid(256)](buf10, primals_11, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_11 buf12 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_13, reinterpret_tensor(buf10, (64, 4), (4, 1), 0), reinterpret_tensor(primals_12, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_13 return (buf6, reinterpret_tensor(buf12, (4, 4, 4, 1), (16, 4, 1, 1), 0), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), buf1, buf3, buf6, buf8, buf10, primals_12, primals_10, primals_6, primals_4) class LinActorCriticNew(torch.nn.Module): def __init__(self, actor_lr, epsilon, in_dim, h_dim, out_dim): super(LinActorCriticNew, self).__init__() self.in_dim = in_dim self.out_dim = out_dim self.h_dim = h_dim self.epsilon = epsilon self.define_network() self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self def normalize(self, tensor): return (tensor - tensor.mean()) / (torch.std(tensor) + 1e-05) def define_network(self): self.relu = torch.nn.LeakyReLU() self.leaky_relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.softmax = torch.nn.Softmax(dim=-1) size = self.h_dim self.p1 = torch.nn.Linear(self.in_dim, size) self.p2 = torch.nn.Linear(size, size) self.v1 = torch.nn.Linear(self.in_dim, size) self.v2 = torch.nn.Linear(size, size) self.pi = torch.nn.Linear(size, self.out_dim) self.value = torch.nn.Linear(size, 1) self.critic_loss = torch.nn.MSELoss() def forward(self, input_0): primals_2 = self.p1.weight primals_3 = self.p1.bias primals_4 = self.p2.weight primals_5 = self.p2.bias primals_6 = self.v1.weight primals_7 = self.v1.bias primals_8 = self.v2.weight primals_9 = self.v2.bias primals_10 = self.pi.weight primals_11 = self.pi.bias primals_12 = self.value.weight primals_13 = self.value.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0], output[1]
Gregory-Eales/mban
LinActorCritic
false
7,608
[ "Apache-2.0" ]
1
d8b35db51c7e601b1db777d9a80343600374250b
https://github.com/Gregory-Eales/mban/tree/d8b35db51c7e601b1db777d9a80343600374250b
Net
import torch import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.conv1 = nn.Conv2d(1, 32, 5) self.pool1 = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(32, 64, 5) self.pool2 = nn.MaxPool2d(2, 2) self.fc5 = nn.Linear(64 * 21 * 21, 1000) self.fc6 = nn.Linear(1000, 500) self.fc7 = nn.Linear(500, 136) self.fc6_drop = nn.Dropout(p=0.4) def forward(self, x): x = self.pool1(F.relu(self.conv1(x))) x = self.pool2(F.relu(self.conv2(x))) x = x.view(-1, 64 * 21 * 21) x = F.relu(self.fc5(x)) x = F.relu(self.fc6(x)) x = self.fc7(x) return x def get_inputs(): return [torch.rand([4, 1, 96, 96])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 8464 % 32 x0 = xindex % 8464 x4 = xindex // 8464 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 8480 * x4), tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 270848 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 46 x1 = xindex // 46 % 46 x2 = xindex // 2116 x3 = xindex % 2116 tmp0 = tl.load(in_ptr0 + (2 * x0 + 184 * x1 + 8480 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 184 * x1 + 8480 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (92 + 2 * x0 + 184 * x1 + 8480 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (93 + 2 * x0 + 184 * x1 + 8480 * x2), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x3 + 2144 * x2), tmp6, xmask) tl.store(out_ptr1 + (x3 + 2176 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 451584 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 1764 % 64 x0 = xindex % 1764 x4 = xindex // 1764 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 1792 * x4), tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 112896 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 21 x1 = xindex // 21 % 21 x4 = xindex // 441 x3 = xindex // 28224 x5 = xindex % 28224 x6 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 84 * x1 + 1792 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 84 * x1 + 1792 * x4), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (42 + 2 * x0 + 84 * x1 + 1792 * x4), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (43 + 2 * x0 + 84 * x1 + 1792 * x4), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + (x5 + 28288 * x3), tmp15, xmask) tl.store(out_ptr1 + x6, tmp16, xmask) @triton.jit def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 4000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 1000 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 2000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 500 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (32, 1, 5, 5), (25, 25, 5, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 1, 96, 96), (9216, 9216, 96, 1)) assert_size_stride(primals_4, (64, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (1000, 28224), (28224, 1)) assert_size_stride(primals_7, (1000,), (1,)) assert_size_stride(primals_8, (500, 1000), (1000, 1)) assert_size_stride(primals_9, (500,), (1,)) assert_size_stride(primals_10, (136, 500), (500, 1)) assert_size_stride(primals_11, (136,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 92, 92), (270848, 8464, 92, 1)) buf1 = empty_strided_cuda((4, 32, 92, 92), (271360, 8480, 92, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1083392)](buf0, primals_2, buf1, 1083392, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del primals_2 buf2 = empty_strided_cuda((4, 32, 46, 46), (68608, 2144, 46, 1), torch.float32) buf3 = empty_strided_cuda((4, 32, 46, 46), (69632, 2176, 46, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(270848)](buf1, buf2, buf3, 270848, XBLOCK=512, num_warps=8, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 42, 42), (112896, 1764, 42, 1)) buf5 = empty_strided_cuda((4, 64, 42, 42), (114688, 1792, 42, 1), torch.float32) triton_poi_fused_convolution_relu_2[grid(451584)](buf4, primals_5, buf5, 451584, XBLOCK=512, num_warps=8, num_stages=1) del buf4 del primals_5 buf6 = empty_strided_cuda((4, 64, 21, 21), (28288, 441, 21, 1), torch.int8) buf7 = empty_strided_cuda((4, 64, 21, 21), (28224, 441, 21, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_3[grid(112896)](buf5, buf6, buf7, 112896, XBLOCK=512, num_warps=8, num_stages=1) buf8 = empty_strided_cuda((4, 1000), (1000, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (4, 28224), (28224, 1), 0), reinterpret_tensor(primals_6, (28224, 1000), (1, 28224), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_4[grid(4000)](buf9, primals_7, 4000, XBLOCK= 256, num_warps=4, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 500), (500, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_8, (1000, 500), (1, 1000), 0), out=buf10) buf11 = buf10 del buf10 triton_poi_fused_relu_5[grid(2000)](buf11, primals_9, 2000, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 buf12 = empty_strided_cuda((4, 136), (136, 1), torch.float32) extern_kernels.addmm(primals_11, buf11, reinterpret_tensor( primals_10, (500, 136), (1, 500), 0), alpha=1, beta=1, out=buf12) del primals_11 return (buf12, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 28224), (28224, 1), 0), buf9, buf11, primals_10, primals_8, primals_6) class NetNew(nn.Module): def __init__(self): super(NetNew, self).__init__() self.conv1 = nn.Conv2d(1, 32, 5) self.pool1 = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(32, 64, 5) self.pool2 = nn.MaxPool2d(2, 2) self.fc5 = nn.Linear(64 * 21 * 21, 1000) self.fc6 = nn.Linear(1000, 500) self.fc7 = nn.Linear(500, 136) self.fc6_drop = nn.Dropout(p=0.4) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.fc5.weight primals_7 = self.fc5.bias primals_8 = self.fc6.weight primals_9 = self.fc6.bias primals_10 = self.fc7.weight primals_11 = 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]) return output[0]
piyushpathak03/Facial-key-point-detection
Net
false
7,609
[ "Apache-2.0" ]
1
863eeeac50c46befb17ecf7610cd341ea0e65291
https://github.com/piyushpathak03/Facial-key-point-detection/tree/863eeeac50c46befb17ecf7610cd341ea0e65291
BertImagePooler
from _paritybench_helpers import _mock_config import torch import torch.optim import torch.utils.data from torch import nn import torch class BertImagePooler(nn.Module): def __init__(self, config): super(BertImagePooler, self).__init__() self.dense = nn.Linear(config.v_hidden_size, config.bi_hidden_size) self.activation = nn.ReLU() def forward(self, hidden_states): first_token_tensor = hidden_states[:, 0] pooled_output = self.dense(first_token_tensor) pooled_output = self.activation(pooled_output) return pooled_output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(v_hidden_size=4, bi_hidden_size=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.optim import torch.utils.data from torch import nn import torch assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_add_relu_threshold_backward_1[grid(64)](buf2, primals_3, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf2, reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf3 class BertImagePoolerNew(nn.Module): def __init__(self, config): super(BertImagePoolerNew, self).__init__() self.dense = nn.Linear(config.v_hidden_size, config.bi_hidden_size) self.activation = nn.ReLU() def forward(self, input_0): primals_2 = self.dense.weight primals_3 = self.dense.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ChoiIseungil/vilbert-multi-task
BertImagePooler
false
7,610
[ "MIT" ]
1
37d14b9aed9c48117a820e05157c7ccd3dd20d5b
https://github.com/ChoiIseungil/vilbert-multi-task/tree/37d14b9aed9c48117a820e05157c7ccd3dd20d5b
Net2
import torch import torch.nn as nn from torch.testing._internal.common_utils import * class MyRelu2(torch.autograd.Function): @staticmethod def forward(ctx, input): ctx.save_for_backward(input) return input.clamp(min=0) class Net2(nn.Module): def __init__(self): super().__init__() def forward(self, x): return MyRelu2.apply(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 from torch.testing._internal.common_utils import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clamp_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class MyRelu2(torch.autograd.Function): @staticmethod def forward(ctx, input): ctx.save_for_backward(input) return input.clamp(min=0) class Net2New(nn.Module): def __init__(self): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
LexcaliburR/notebook
Net2
false
7,611
[ "MIT" ]
1
84a8f3801dff20d07caa0ed2584e722656fb5726
https://github.com/LexcaliburR/notebook/tree/84a8f3801dff20d07caa0ed2584e722656fb5726
Conv2d
from torch.autograd import Function import torch import numpy as np import torch.nn as nn import torch.nn.functional as F def _setup_kernel(k): k = np.asarray(k, dtype=np.float32) if k.ndim == 1: k = np.outer(k, k) k /= np.sum(k) assert k.ndim == 2 assert k.shape[0] == k.shape[1] return k def upfirdn2d_native(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1): _, channel, in_h, in_w = input.shape input = input.reshape(-1, in_h, in_w, 1) _, in_h, in_w, minor = input.shape kernel_h, kernel_w = kernel.shape out = input.view(-1, in_h, 1, in_w, 1, minor) out = F.pad(out, [0, 0, 0, up_x - 1, 0, 0, 0, up_y - 1]) out = out.view(-1, in_h * up_y, in_w * up_x, minor) out = F.pad(out, [0, 0, max(pad_x0, 0), max(pad_x1, 0), max(pad_y0, 0), max(pad_y1, 0)]) out = out[:, max(-pad_y0, 0):out.shape[1] - max(-pad_y1, 0), max(- pad_x0, 0):out.shape[2] - max(-pad_x1, 0), :] out = out.permute(0, 3, 1, 2) out = out.reshape([-1, 1, in_h * up_y + pad_y0 + pad_y1, in_w * up_x + pad_x0 + pad_x1]) w = torch.flip(kernel, [0, 1]).view(1, 1, kernel_h, kernel_w) out = F.conv2d(out, w) out = out.reshape(-1, minor, in_h * up_y + pad_y0 + pad_y1 - kernel_h + 1, in_w * up_x + pad_x0 + pad_x1 - kernel_w + 1) out = out.permute(0, 2, 3, 1) out = out[:, ::down_y, ::down_x, :] out_h = (in_h * up_y + pad_y0 + pad_y1 - kernel_h) // down_y + 1 out_w = (in_w * up_x + pad_x0 + pad_x1 - kernel_w) // down_x + 1 return out.view(-1, channel, out_h, out_w) def upfirdn2d(input, kernel, up=1, down=1, pad=(0, 0)): if input.device.type == 'cpu': out = upfirdn2d_native(input, kernel, up, up, down, down, pad[0], pad[1], pad[0], pad[1]) else: out = UpFirDn2d.apply(input, kernel, (up, up), (down, down), (pad[0 ], pad[1], pad[0], pad[1])) return out def conv_downsample_2d(x, w, k=None, factor=2, gain=1): """Fused `tf.nn.conv2d()` followed by `downsample_2d()`. Padding is performed only once at the beginning, not between the operations. The fused op is considerably more efficient than performing the same calculation using standard TensorFlow ops. It supports gradients of arbitrary order. Args: x: Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`. w: Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`. Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`. k: FIR filter of the shape `[firH, firW]` or `[firN]` (separable). The default is `[1] * factor`, which corresponds to average pooling. factor: Integer downsampling factor (default: 2). gain: Scaling factor for signal magnitude (default: 1.0). Returns: Tensor of the shape `[N, C, H // factor, W // factor]` or `[N, H // factor, W // factor, C]`, and same datatype as `x`. """ assert isinstance(factor, int) and factor >= 1 _outC, _inC, convH, convW = w.shape assert convW == convH if k is None: k = [1] * factor k = _setup_kernel(k) * gain p = k.shape[0] - factor + (convW - 1) s = [factor, factor] x = upfirdn2d(x, torch.tensor(k, device=x.device), pad=((p + 1) // 2, p // 2)) return F.conv2d(x, w, stride=s, padding=0) def _shape(x, dim): return x.shape[dim] def upsample_conv_2d(x, w, k=None, factor=2, gain=1): """Fused `upsample_2d()` followed by `tf.nn.conv2d()`. Padding is performed only once at the beginning, not between the operations. The fused op is considerably more efficient than performing the same calculation using standard TensorFlow ops. It supports gradients of arbitrary order. Args: x: Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`. w: Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`. Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`. k: FIR filter of the shape `[firH, firW]` or `[firN]` (separable). The default is `[1] * factor`, which corresponds to nearest-neighbor upsampling. factor: Integer upsampling factor (default: 2). gain: Scaling factor for signal magnitude (default: 1.0). Returns: Tensor of the shape `[N, C, H * factor, W * factor]` or `[N, H * factor, W * factor, C]`, and same datatype as `x`. """ assert isinstance(factor, int) and factor >= 1 assert len(w.shape) == 4 convH = w.shape[2] convW = w.shape[3] inC = w.shape[1] w.shape[0] assert convW == convH if k is None: k = [1] * factor k = _setup_kernel(k) * (gain * factor ** 2) p = k.shape[0] - factor - (convW - 1) stride = factor, factor stride = [1, 1, factor, factor] output_shape = (_shape(x, 2) - 1) * factor + convH, (_shape(x, 3) - 1 ) * factor + convW output_padding = output_shape[0] - (_shape(x, 2) - 1) * stride[0 ] - convH, output_shape[1] - (_shape(x, 3) - 1) * stride[1] - convW assert output_padding[0] >= 0 and output_padding[1] >= 0 num_groups = _shape(x, 1) // inC w = torch.reshape(w, (num_groups, -1, inC, convH, convW)) w = w[..., ::-1, ::-1].permute(0, 2, 1, 3, 4) w = torch.reshape(w, (num_groups * inC, -1, convH, convW)) x = F.conv_transpose2d(x, w, stride=stride, output_padding= output_padding, padding=0) return upfirdn2d(x, torch.tensor(k, device=x.device), pad=((p + 1) // 2 + factor - 1, p // 2 + 1)) class UpFirDn2dBackward(Function): @staticmethod def forward(ctx, grad_output, kernel, grad_kernel, up, down, pad, g_pad, in_size, out_size): up_x, up_y = up down_x, down_y = down g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1 = g_pad grad_output = grad_output.reshape(-1, out_size[0], out_size[1], 1) grad_input = upfirdn2d_op.upfirdn2d(grad_output, grad_kernel, down_x, down_y, up_x, up_y, g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1) grad_input = grad_input.view(in_size[0], in_size[1], in_size[2], in_size[3]) ctx.save_for_backward(kernel) pad_x0, pad_x1, pad_y0, pad_y1 = pad ctx.up_x = up_x ctx.up_y = up_y ctx.down_x = down_x ctx.down_y = down_y ctx.pad_x0 = pad_x0 ctx.pad_x1 = pad_x1 ctx.pad_y0 = pad_y0 ctx.pad_y1 = pad_y1 ctx.in_size = in_size ctx.out_size = out_size return grad_input @staticmethod def backward(ctx, gradgrad_input): kernel, = ctx.saved_tensors gradgrad_input = gradgrad_input.reshape(-1, ctx.in_size[2], ctx. in_size[3], 1) gradgrad_out = upfirdn2d_op.upfirdn2d(gradgrad_input, kernel, ctx. up_x, ctx.up_y, ctx.down_x, ctx.down_y, ctx.pad_x0, ctx.pad_x1, ctx.pad_y0, ctx.pad_y1) gradgrad_out = gradgrad_out.view(ctx.in_size[0], ctx.in_size[1], ctx.out_size[0], ctx.out_size[1]) return gradgrad_out, None, None, None, None, None, None, None, None class UpFirDn2d(Function): @staticmethod def forward(ctx, input, kernel, up, down, pad): up_x, up_y = up down_x, down_y = down pad_x0, pad_x1, pad_y0, pad_y1 = pad kernel_h, kernel_w = kernel.shape _batch, channel, in_h, in_w = input.shape ctx.in_size = input.shape input = input.reshape(-1, in_h, in_w, 1) ctx.save_for_backward(kernel, torch.flip(kernel, [0, 1])) out_h = (in_h * up_y + pad_y0 + pad_y1 - kernel_h) // down_y + 1 out_w = (in_w * up_x + pad_x0 + pad_x1 - kernel_w) // down_x + 1 ctx.out_size = out_h, out_w ctx.up = up_x, up_y ctx.down = down_x, down_y ctx.pad = pad_x0, pad_x1, pad_y0, pad_y1 g_pad_x0 = kernel_w - pad_x0 - 1 g_pad_y0 = kernel_h - pad_y0 - 1 g_pad_x1 = in_w * up_x - out_w * down_x + pad_x0 - up_x + 1 g_pad_y1 = in_h * up_y - out_h * down_y + pad_y0 - up_y + 1 ctx.g_pad = g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1 out = upfirdn2d_op.upfirdn2d(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1) out = out.view(-1, channel, out_h, out_w) return out @staticmethod def backward(ctx, grad_output): kernel, grad_kernel = ctx.saved_tensors grad_input = UpFirDn2dBackward.apply(grad_output, kernel, grad_kernel, ctx.up, ctx.down, ctx.pad, ctx.g_pad, ctx.in_size, ctx.out_size) return grad_input, None, None, None, None class Conv2d(nn.Module): """Conv2d layer with optimal upsampling and downsampling (StyleGAN2).""" def __init__(self, in_ch, out_ch, kernel, up=False, down=False, resample_kernel=(1, 3, 3, 1), use_bias=True, kernel_init=None): super().__init__() assert not (up and down) assert kernel >= 1 and kernel % 2 == 1 self.weight = nn.Parameter(torch.zeros(out_ch, in_ch, kernel, kernel)) if kernel_init is not None: self.weight.data = kernel_init(self.weight.data.shape) if use_bias: self.bias = nn.Parameter(torch.zeros(out_ch)) self.up = up self.down = down self.resample_kernel = resample_kernel self.kernel = kernel self.use_bias = use_bias def forward(self, x): if self.up: x = upsample_conv_2d(x, self.weight, k=self.resample_kernel) elif self.down: x = conv_downsample_2d(x, self.weight, k=self.resample_kernel) else: x = F.conv2d(x, self.weight, stride=1, padding=self.kernel // 2) if self.use_bias: x = x + self.bias.reshape(1, -1, 1, 1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'out_ch': 4, 'kernel': 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.autograd import Function import numpy as np import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf1, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf1, primals_1, primals_2 def _setup_kernel(k): k = np.asarray(k, dtype=np.float32) if k.ndim == 1: k = np.outer(k, k) k /= np.sum(k) assert k.ndim == 2 assert k.shape[0] == k.shape[1] return k def upfirdn2d_native(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1): _, channel, in_h, in_w = input.shape input = input.reshape(-1, in_h, in_w, 1) _, in_h, in_w, minor = input.shape kernel_h, kernel_w = kernel.shape out = input.view(-1, in_h, 1, in_w, 1, minor) out = F.pad(out, [0, 0, 0, up_x - 1, 0, 0, 0, up_y - 1]) out = out.view(-1, in_h * up_y, in_w * up_x, minor) out = F.pad(out, [0, 0, max(pad_x0, 0), max(pad_x1, 0), max(pad_y0, 0), max(pad_y1, 0)]) out = out[:, max(-pad_y0, 0):out.shape[1] - max(-pad_y1, 0), max(- pad_x0, 0):out.shape[2] - max(-pad_x1, 0), :] out = out.permute(0, 3, 1, 2) out = out.reshape([-1, 1, in_h * up_y + pad_y0 + pad_y1, in_w * up_x + pad_x0 + pad_x1]) w = torch.flip(kernel, [0, 1]).view(1, 1, kernel_h, kernel_w) out = F.conv2d(out, w) out = out.reshape(-1, minor, in_h * up_y + pad_y0 + pad_y1 - kernel_h + 1, in_w * up_x + pad_x0 + pad_x1 - kernel_w + 1) out = out.permute(0, 2, 3, 1) out = out[:, ::down_y, ::down_x, :] out_h = (in_h * up_y + pad_y0 + pad_y1 - kernel_h) // down_y + 1 out_w = (in_w * up_x + pad_x0 + pad_x1 - kernel_w) // down_x + 1 return out.view(-1, channel, out_h, out_w) def upfirdn2d(input, kernel, up=1, down=1, pad=(0, 0)): if input.device.type == 'cpu': out = upfirdn2d_native(input, kernel, up, up, down, down, pad[0], pad[1], pad[0], pad[1]) else: out = UpFirDn2d.apply(input, kernel, (up, up), (down, down), (pad[0 ], pad[1], pad[0], pad[1])) return out def conv_downsample_2d(x, w, k=None, factor=2, gain=1): """Fused `tf.nn.conv2d()` followed by `downsample_2d()`. Padding is performed only once at the beginning, not between the operations. The fused op is considerably more efficient than performing the same calculation using standard TensorFlow ops. It supports gradients of arbitrary order. Args: x: Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`. w: Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`. Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`. k: FIR filter of the shape `[firH, firW]` or `[firN]` (separable). The default is `[1] * factor`, which corresponds to average pooling. factor: Integer downsampling factor (default: 2). gain: Scaling factor for signal magnitude (default: 1.0). Returns: Tensor of the shape `[N, C, H // factor, W // factor]` or `[N, H // factor, W // factor, C]`, and same datatype as `x`. """ assert isinstance(factor, int) and factor >= 1 _outC, _inC, convH, convW = w.shape assert convW == convH if k is None: k = [1] * factor k = _setup_kernel(k) * gain p = k.shape[0] - factor + (convW - 1) s = [factor, factor] x = upfirdn2d(x, torch.tensor(k, device=x.device), pad=((p + 1) // 2, p // 2)) return F.conv2d(x, w, stride=s, padding=0) def _shape(x, dim): return x.shape[dim] def upsample_conv_2d(x, w, k=None, factor=2, gain=1): """Fused `upsample_2d()` followed by `tf.nn.conv2d()`. Padding is performed only once at the beginning, not between the operations. The fused op is considerably more efficient than performing the same calculation using standard TensorFlow ops. It supports gradients of arbitrary order. Args: x: Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`. w: Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`. Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`. k: FIR filter of the shape `[firH, firW]` or `[firN]` (separable). The default is `[1] * factor`, which corresponds to nearest-neighbor upsampling. factor: Integer upsampling factor (default: 2). gain: Scaling factor for signal magnitude (default: 1.0). Returns: Tensor of the shape `[N, C, H * factor, W * factor]` or `[N, H * factor, W * factor, C]`, and same datatype as `x`. """ assert isinstance(factor, int) and factor >= 1 assert len(w.shape) == 4 convH = w.shape[2] convW = w.shape[3] inC = w.shape[1] w.shape[0] assert convW == convH if k is None: k = [1] * factor k = _setup_kernel(k) * (gain * factor ** 2) p = k.shape[0] - factor - (convW - 1) stride = factor, factor stride = [1, 1, factor, factor] output_shape = (_shape(x, 2) - 1) * factor + convH, (_shape(x, 3) - 1 ) * factor + convW output_padding = output_shape[0] - (_shape(x, 2) - 1) * stride[0 ] - convH, output_shape[1] - (_shape(x, 3) - 1) * stride[1] - convW assert output_padding[0] >= 0 and output_padding[1] >= 0 num_groups = _shape(x, 1) // inC w = torch.reshape(w, (num_groups, -1, inC, convH, convW)) w = w[..., ::-1, ::-1].permute(0, 2, 1, 3, 4) w = torch.reshape(w, (num_groups * inC, -1, convH, convW)) x = F.conv_transpose2d(x, w, stride=stride, output_padding= output_padding, padding=0) return upfirdn2d(x, torch.tensor(k, device=x.device), pad=((p + 1) // 2 + factor - 1, p // 2 + 1)) class UpFirDn2dBackward(Function): @staticmethod def forward(ctx, grad_output, kernel, grad_kernel, up, down, pad, g_pad, in_size, out_size): up_x, up_y = up down_x, down_y = down g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1 = g_pad grad_output = grad_output.reshape(-1, out_size[0], out_size[1], 1) grad_input = upfirdn2d_op.upfirdn2d(grad_output, grad_kernel, down_x, down_y, up_x, up_y, g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1) grad_input = grad_input.view(in_size[0], in_size[1], in_size[2], in_size[3]) ctx.save_for_backward(kernel) pad_x0, pad_x1, pad_y0, pad_y1 = pad ctx.up_x = up_x ctx.up_y = up_y ctx.down_x = down_x ctx.down_y = down_y ctx.pad_x0 = pad_x0 ctx.pad_x1 = pad_x1 ctx.pad_y0 = pad_y0 ctx.pad_y1 = pad_y1 ctx.in_size = in_size ctx.out_size = out_size return grad_input @staticmethod def backward(ctx, gradgrad_input): kernel, = ctx.saved_tensors gradgrad_input = gradgrad_input.reshape(-1, ctx.in_size[2], ctx. in_size[3], 1) gradgrad_out = upfirdn2d_op.upfirdn2d(gradgrad_input, kernel, ctx. up_x, ctx.up_y, ctx.down_x, ctx.down_y, ctx.pad_x0, ctx.pad_x1, ctx.pad_y0, ctx.pad_y1) gradgrad_out = gradgrad_out.view(ctx.in_size[0], ctx.in_size[1], ctx.out_size[0], ctx.out_size[1]) return gradgrad_out, None, None, None, None, None, None, None, None class UpFirDn2d(Function): @staticmethod def forward(ctx, input, kernel, up, down, pad): up_x, up_y = up down_x, down_y = down pad_x0, pad_x1, pad_y0, pad_y1 = pad kernel_h, kernel_w = kernel.shape _batch, channel, in_h, in_w = input.shape ctx.in_size = input.shape input = input.reshape(-1, in_h, in_w, 1) ctx.save_for_backward(kernel, torch.flip(kernel, [0, 1])) out_h = (in_h * up_y + pad_y0 + pad_y1 - kernel_h) // down_y + 1 out_w = (in_w * up_x + pad_x0 + pad_x1 - kernel_w) // down_x + 1 ctx.out_size = out_h, out_w ctx.up = up_x, up_y ctx.down = down_x, down_y ctx.pad = pad_x0, pad_x1, pad_y0, pad_y1 g_pad_x0 = kernel_w - pad_x0 - 1 g_pad_y0 = kernel_h - pad_y0 - 1 g_pad_x1 = in_w * up_x - out_w * down_x + pad_x0 - up_x + 1 g_pad_y1 = in_h * up_y - out_h * down_y + pad_y0 - up_y + 1 ctx.g_pad = g_pad_x0, g_pad_x1, g_pad_y0, g_pad_y1 out = upfirdn2d_op.upfirdn2d(input, kernel, up_x, up_y, down_x, down_y, pad_x0, pad_x1, pad_y0, pad_y1) out = out.view(-1, channel, out_h, out_w) return out @staticmethod def backward(ctx, grad_output): kernel, grad_kernel = ctx.saved_tensors grad_input = UpFirDn2dBackward.apply(grad_output, kernel, grad_kernel, ctx.up, ctx.down, ctx.pad, ctx.g_pad, ctx.in_size, ctx.out_size) return grad_input, None, None, None, None class Conv2dNew(nn.Module): """Conv2d layer with optimal upsampling and downsampling (StyleGAN2).""" def __init__(self, in_ch, out_ch, kernel, up=False, down=False, resample_kernel=(1, 3, 3, 1), use_bias=True, kernel_init=None): super().__init__() assert not (up and down) assert kernel >= 1 and kernel % 2 == 1 self.weight = nn.Parameter(torch.zeros(out_ch, in_ch, kernel, kernel)) if kernel_init is not None: self.weight.data = kernel_init(self.weight.data.shape) if use_bias: self.bias = nn.Parameter(torch.zeros(out_ch)) self.up = up self.down = down self.resample_kernel = resample_kernel self.kernel = kernel self.use_bias = use_bias def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
samsartor/score_sde
Conv2d
false
7,612
[ "Apache-2.0" ]
1
d25c8d092a68d643c796d771c55f80075aa041d1
https://github.com/samsartor/score_sde/tree/d25c8d092a68d643c796d771c55f80075aa041d1
BertOutput
from _paritybench_helpers import _mock_config import torch import torch.nn import torch.nn as nn class BertOutput(nn.Module): """BERT output layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super(BertOutput, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = torch.nn.LayerNorm(config.hidden_size, eps=1e-12) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, hidden_dropout_prob= 0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_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-12 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_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf1, primals_2, primals_4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 del primals_4 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](buf1, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_2[grid(256)](buf1, buf2, buf3, primals_5, primals_6, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf2 del buf3 del primals_6 return buf4, primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1 class BertOutputNew(nn.Module): """BERT output layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super(BertOutputNew, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = torch.nn.LayerNorm(config.hidden_size, eps=1e-12) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, input_0, input_1): primals_1 = self.dense.weight primals_2 = self.dense.bias primals_5 = self.LayerNorm.weight primals_6 = self.LayerNorm.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
Erotemic/MONAI
BertOutput
false
7,613
[ "Apache-2.0" ]
1
a9cd2d88168107281a2abcc2f63efaed80580e79
https://github.com/Erotemic/MONAI/tree/a9cd2d88168107281a2abcc2f63efaed80580e79
BERTLowRank
from _paritybench_helpers import _mock_config 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)))) """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class BERTLowRank(nn.Module): def __init__(self, config, extra_dim=None): super(BERTLowRank, self).__init__() if config.extra_dim: self.aug_dense = nn.Linear(config.hidden_size, config.extra_dim) self.aug_dense2 = nn.Linear(config.extra_dim, config.hidden_size) else: self.aug_dense = nn.Linear(config.hidden_size, config. hidden_size_aug) self.aug_dense2 = nn.Linear(config.hidden_size_aug, config. hidden_size) self.config = config self.hidden_act_fn = gelu def forward(self, hidden_states, attention_mask=None): hidden_states_aug = self.aug_dense(hidden_states) hidden_states_aug = self.hidden_act_fn(hidden_states_aug) hidden_states = self.aug_dense2(hidden_states_aug) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(extra_dim=4, hidden_size=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865475 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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_add_div_erf_mul_0[grid(256)](buf0, buf1, 256, 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, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_4 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)))) """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class BERTLowRankNew(nn.Module): def __init__(self, config, extra_dim=None): super(BERTLowRankNew, self).__init__() if config.extra_dim: self.aug_dense = nn.Linear(config.hidden_size, config.extra_dim) self.aug_dense2 = nn.Linear(config.extra_dim, config.hidden_size) else: self.aug_dense = nn.Linear(config.hidden_size, config. hidden_size_aug) self.aug_dense2 = nn.Linear(config.hidden_size_aug, config. hidden_size) self.config = config self.hidden_act_fn = gelu def forward(self, input_0): primals_1 = self.aug_dense.weight primals_2 = self.aug_dense.bias primals_4 = self.aug_dense2.weight primals_5 = self.aug_dense2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
DAQuestionAnswering/Bert-n-Pals
BERTLowRank
false
7,614
[ "MIT" ]
1
d5a288b9ac62259e70c249635108ba3906e19f00
https://github.com/DAQuestionAnswering/Bert-n-Pals/tree/d5a288b9ac62259e70c249635108ba3906e19f00
Decoder
import torch import torch.nn as nn class INConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, dilation=1, groups=1, relu=True, ins_n=True, bias=False): super(INConv, self).__init__() self.out_channels = out_planes self.conv = nn.Conv2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, x): x = self.conv(x) if self.ins_n is not None: x = self.ins_n(x) if self.relu is not None: x = self.relu(x) return x class INDeConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, out_padding=0, dilation=1, groups=1, relu=True, ins_n= True, bias=False): super(INDeConv, self).__init__() self.out_channels = out_planes self.conv = nn.ConvTranspose2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, output_padding= out_padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, x): x = self.conv(x) if self.ins_n is not None: x = self.ins_n(x) if self.relu is not None: x = self.relu(x) return x class Decoder(nn.Module): def __init__(self, img_channel): super(Decoder, self).__init__() self.deconv1 = INDeConv(in_planes=32, out_planes=64, kernel_size=3, stride=1, padding=1, relu=False) self.activation1 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv2 = INDeConv(in_planes=64, out_planes=128, kernel_size=3, stride=1, padding=1, relu=False) self.activation2 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv3 = INDeConv(in_planes=128, out_planes=64, kernel_size=4, stride=2, padding=1, relu=False) self.activation3 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv4 = INDeConv(in_planes=64, out_planes=64, kernel_size=3, stride=1, padding=1, relu=False) self.activation4 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv5 = INDeConv(in_planes=64, out_planes=32, kernel_size=4, stride=2, padding=1, relu=False) self.activation5 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv6 = INDeConv(in_planes=32, out_planes=32, kernel_size=3, stride=1, padding=1, relu=False) self.activation6 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv7 = INDeConv(in_planes=32, out_planes=32, kernel_size=4, stride=2, padding=1, relu=False) self.activation7 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv8 = INDeConv(in_planes=32, out_planes=16, kernel_size=4, stride=2, padding=1, relu=False) self.activation8 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.output = INConv(in_planes=16, out_planes=img_channel, kernel_size=1, stride=1, padding=0, ins_n=False, relu=False) self.activation9 = nn.Sigmoid() def forward(self, x): x = self.activation1(self.deconv1(x)) x = self.activation2(self.deconv2(x)) x = self.activation3(self.deconv3(x)) x = self.activation4(self.deconv4(x)) x = self.activation5(self.deconv5(x)) x = self.activation6(self.deconv6(x)) x = self.activation7(self.deconv7(x)) x = self.activation8(self.deconv8(x)) x = self.activation9(self.output(x)) return x def get_inputs(): return [torch.rand([4, 32, 4, 4])] def get_init_inputs(): return [[], {'img_channel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_batch_norm_legit_leaky_relu_repeat_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, 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) x0 = xindex r1 = rindex tmp0 = tl.load(in_ptr0 + x0 % 64, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr2 + x0 % 64, xmask, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tl.where(xmask, tmp2, 0) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(xmask, tmp5, 0) tmp8 = tl.sum(tmp7, 1)[:, None] tmp9 = tl.full([XBLOCK, 1], 16, tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 / tmp10 tmp12 = tmp2 - tmp11 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp18 = tmp1 - tmp11 tmp19 = 16.0 tmp20 = tmp17 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp18 * tmp23 tmp25 = tmp24 * tmp0 tmp27 = tmp25 + tmp26 tmp28 = 0.0 tmp29 = tmp27 > tmp28 tmp30 = 0.2 tmp31 = tmp27 * tmp30 tmp32 = tl.where(tmp29, tmp27, tmp31) tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + (r1 + 16 * x0), tmp32, xmask) tl.store(out_ptr3 + x0, tmp23, xmask) tl.store(out_ptr1 + x0, tmp11, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 512 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) x0 = xindex r1 = rindex tmp0 = tl.load(in_ptr0 + x0 % 128, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr2 + x0 % 128, xmask, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tl.where(xmask, tmp2, 0) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(xmask, tmp5, 0) tmp8 = tl.sum(tmp7, 1)[:, None] tmp9 = tl.full([XBLOCK, 1], 16, tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 / tmp10 tmp12 = tmp2 - tmp11 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp18 = tmp1 - tmp11 tmp19 = 16.0 tmp20 = tmp17 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp18 * tmp23 tmp25 = tmp24 * tmp0 tmp27 = tmp25 + tmp26 tmp28 = 0.0 tmp29 = tmp27 > tmp28 tmp30 = 0.2 tmp31 = tmp27 * tmp30 tmp32 = tl.where(tmp29, tmp27, tmp31) tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + (r1 + 16 * x0), tmp32, xmask) tl.store(out_ptr3 + x0, tmp23, xmask) tl.store(out_ptr1 + x0, tmp11, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) x0 = xindex r1 = rindex tmp0 = tl.load(in_ptr0 + x0 % 64, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr2 + x0 % 64, xmask, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tl.where(xmask, tmp2, 0) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(xmask, tmp5, 0) tmp8 = tl.sum(tmp7, 1)[:, None] tmp9 = tl.full([XBLOCK, 1], 64, tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 / tmp10 tmp12 = tmp2 - tmp11 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp18 = tmp1 - tmp11 tmp19 = 64.0 tmp20 = tmp17 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp18 * tmp23 tmp25 = tmp24 * tmp0 tmp27 = tmp25 + tmp26 tmp28 = 0.0 tmp29 = tmp27 > tmp28 tmp30 = 0.2 tmp31 = tmp27 * tmp30 tmp32 = tl.where(tmp29, tmp27, tmp31) tl.store(out_ptr0 + x0, tmp0, xmask) tl.store(in_out_ptr0 + (r1 + 64 * x0), tmp32, xmask) tl.store(out_ptr3 + x0, tmp23, xmask) tl.store(out_ptr1 + x0, tmp11, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) x0 = xindex r1 = rindex tmp0 = tl.load(in_ptr0 + x0 % 32, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 256 * x0), None) tmp23 = tl.load(in_ptr2 + x0 % 32, None, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = tl.broadcast_to(tmp2, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tl.full([1], 256, tl.int32) tmp8 = tmp7.to(tl.float32) tmp9 = tmp6 / tmp8 tmp10 = tmp2 - tmp9 tmp11 = tmp10 * tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = tmp1 - tmp9 tmp16 = 256.0 tmp17 = tmp14 / tmp16 tmp18 = 1e-05 tmp19 = tmp17 + tmp18 tmp20 = libdevice.rsqrt(tmp19) tmp21 = tmp15 * tmp20 tmp22 = tmp21 * tmp0 tmp24 = tmp22 + tmp23 tmp25 = 0.0 tmp26 = tmp24 > tmp25 tmp27 = 0.2 tmp28 = tmp24 * tmp27 tmp29 = tl.where(tmp26, tmp24, tmp28) tl.store(out_ptr0 + x0, tmp0, None) tl.store(in_out_ptr0 + (r1 + 256 * x0), tmp29, None) tl.store(out_ptr3 + x0, tmp20, None) tl.store(out_ptr1 + x0, tmp9, None) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) x0 = xindex r1 = rindex tmp0 = tl.load(in_ptr0 + x0 % 32, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (r1 + 1024 * x0), None) tmp23 = tl.load(in_ptr2 + x0 % 32, None, eviction_policy='evict_last') tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = tl.broadcast_to(tmp2, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tl.full([1], 1024, tl.int32) tmp8 = tmp7.to(tl.float32) tmp9 = tmp6 / tmp8 tmp10 = tmp2 - tmp9 tmp11 = tmp10 * tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = tmp1 - tmp9 tmp16 = 1024.0 tmp17 = tmp14 / tmp16 tmp18 = 1e-05 tmp19 = tmp17 + tmp18 tmp20 = libdevice.rsqrt(tmp19) tmp21 = tmp15 * tmp20 tmp22 = tmp21 * tmp0 tmp24 = tmp22 + tmp23 tmp25 = 0.0 tmp26 = tmp24 > tmp25 tmp27 = 0.2 tmp28 = tmp24 * tmp27 tmp29 = tl.where(tmp26, tmp24, tmp28) tl.store(out_ptr0 + x0, tmp0, None) tl.store(in_out_ptr0 + (r1 + 1024 * x0), tmp29, None) tl.store(out_ptr3 + x0, tmp20, None) tl.store(out_ptr1 + x0, tmp9, None) @triton.jit def triton_red_fused__native_batch_norm_legit_leaky_relu_repeat_5(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 64 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp0 = tl.load(in_ptr0 + x0 % 16, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) tmp3_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp3_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp3_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp1 = tl.load(in_ptr1 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp3_mean_next, tmp3_m2_next, tmp3_weight_next = (triton_helpers. welford_reduce(tmp2, tmp3_mean, tmp3_m2, tmp3_weight, roffset == 0) ) tmp3_mean = tl.where(rmask & xmask, tmp3_mean_next, tmp3_mean) tmp3_m2 = tl.where(rmask & xmask, tmp3_m2_next, tmp3_m2) tmp3_weight = tl.where(rmask & xmask, tmp3_weight_next, tmp3_weight) tmp3_tmp, tmp4_tmp, tmp5_tmp = triton_helpers.welford(tmp3_mean, tmp3_m2, tmp3_weight, 1) tmp3 = tmp3_tmp[:, None] tmp4 = tmp4_tmp[:, None] tmp5_tmp[:, None] tl.store(out_ptr1 + x0, tmp3, xmask) tmp15 = tl.load(in_ptr2 + x0 % 16, xmask, eviction_policy='evict_last') for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp6 = tl.load(in_ptr1 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp7 = tmp6 - tmp3 tmp8 = 4096.0 tmp9 = tmp4 / tmp8 tmp10 = 1e-05 tmp11 = tmp9 + tmp10 tmp12 = libdevice.rsqrt(tmp11) tmp13 = tmp7 * tmp12 tmp14 = tmp13 * tmp0 tmp16 = tmp14 + tmp15 tmp17 = 0.0 tmp18 = tmp16 > tmp17 tmp19 = 0.2 tmp20 = tmp16 * tmp19 tmp21 = tl.where(tmp18, tmp16, tmp20) tl.store(in_out_ptr0 + (r1 + 4096 * x0), tmp21, rmask & xmask) tmp22 = 4096.0 tmp23 = tmp4 / tmp22 tmp24 = 1e-05 tmp25 = tmp23 + tmp24 tmp26 = libdevice.rsqrt(tmp25) tl.store(out_ptr3 + x0, tmp26, xmask) @triton.jit def triton_poi_fused_sigmoid_6(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.sigmoid(tmp0) tl.store(in_out_ptr0 + x0, tmp1, None) def call(args): (primals_1, primals_2, 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) = args args.clear() assert_size_stride(primals_1, (32, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_2, (4, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64,), (1,)) assert_size_stride(primals_5, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_6, (128,), (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,), (1,)) assert_size_stride(primals_11, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_12, (64,), (1,)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_15, (32,), (1,)) assert_size_stride(primals_16, (32,), (1,)) assert_size_stride(primals_17, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_18, (32,), (1,)) assert_size_stride(primals_19, (32,), (1,)) assert_size_stride(primals_20, (32, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_21, (32,), (1,)) assert_size_stride(primals_22, (32,), (1,)) assert_size_stride(primals_23, (32, 16, 4, 4), (256, 16, 4, 1)) assert_size_stride(primals_24, (16,), (1,)) assert_size_stride(primals_25, (16,), (1,)) assert_size_stride(primals_26, (4, 16, 1, 1), (16, 1, 1, 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=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 4, 4), (1024, 16, 4, 1)) buf1 = empty_strided_cuda((256,), (1,), torch.float32) buf2 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch .float32) buf6 = empty_strided_cuda((1, 256, 4, 4), (4096, 16, 4, 1), torch. float32) buf7 = reinterpret_tensor(buf6, (4, 64, 4, 4), (1024, 16, 4, 1), 0) del buf6 buf5 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch .float32) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_0[grid(256) ](buf7, primals_3, buf0, primals_4, buf1, buf2, buf5, 256, 16, XBLOCK=32, num_warps=4, num_stages=1) del primals_3 del primals_4 buf8 = extern_kernels.convolution(buf7, primals_5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 128, 4, 4), (2048, 16, 4, 1)) buf9 = empty_strided_cuda((512,), (1,), torch.float32) buf10 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 512, 512), torch.float32) buf14 = empty_strided_cuda((1, 512, 4, 4), (8192, 16, 4, 1), torch. float32) buf15 = reinterpret_tensor(buf14, (4, 128, 4, 4), (2048, 16, 4, 1), 0) del buf14 buf13 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 512, 512), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_1[grid(512) ](buf15, primals_6, buf8, primals_7, buf9, buf10, buf13, 512, 16, XBLOCK=32, num_warps=4, num_stages=1) del primals_6 del primals_7 buf16 = extern_kernels.convolution(buf15, primals_8, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 64, 8, 8), (4096, 64, 8, 1)) buf17 = empty_strided_cuda((256,), (1,), torch.float32) buf18 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf22 = empty_strided_cuda((1, 256, 8, 8), (16384, 64, 8, 1), torch .float32) buf23 = reinterpret_tensor(buf22, (4, 64, 8, 8), (4096, 64, 8, 1), 0) del buf22 buf21 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_2[grid(256) ](buf23, primals_9, buf16, primals_10, buf17, buf18, buf21, 256, 64, XBLOCK=8, num_warps=4, num_stages=1) del primals_10 del primals_9 buf24 = extern_kernels.convolution(buf23, primals_11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 64, 8, 8), (4096, 64, 8, 1)) buf25 = empty_strided_cuda((256,), (1,), torch.float32) buf26 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) buf30 = empty_strided_cuda((1, 256, 8, 8), (16384, 64, 8, 1), torch .float32) buf31 = reinterpret_tensor(buf30, (4, 64, 8, 8), (4096, 64, 8, 1), 0) del buf30 buf29 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_2[grid(256) ](buf31, primals_12, buf24, primals_13, buf25, buf26, buf29, 256, 64, XBLOCK=8, num_warps=4, num_stages=1) del primals_12 del primals_13 buf32 = extern_kernels.convolution(buf31, primals_14, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 32, 16, 16), (8192, 256, 16, 1)) buf33 = empty_strided_cuda((128,), (1,), torch.float32) buf34 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf38 = empty_strided_cuda((1, 128, 16, 16), (32768, 256, 16, 1), torch.float32) buf39 = reinterpret_tensor(buf38, (4, 32, 16, 16), (8192, 256, 16, 1), 0) del buf38 buf37 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_3[grid(128) ](buf39, primals_15, buf32, primals_16, buf33, buf34, buf37, 128, 256, num_warps=2, num_stages=1) del primals_15 del primals_16 buf40 = extern_kernels.convolution(buf39, primals_17, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf40, (4, 32, 16, 16), (8192, 256, 16, 1)) buf41 = empty_strided_cuda((128,), (1,), torch.float32) buf42 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf46 = empty_strided_cuda((1, 128, 16, 16), (32768, 256, 16, 1), torch.float32) buf47 = reinterpret_tensor(buf46, (4, 32, 16, 16), (8192, 256, 16, 1), 0) del buf46 buf45 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_3[grid(128) ](buf47, primals_18, buf40, primals_19, buf41, buf42, buf45, 128, 256, num_warps=2, num_stages=1) del primals_18 del primals_19 buf48 = extern_kernels.convolution(buf47, primals_20, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 32, 32, 32), (32768, 1024, 32, 1)) buf49 = empty_strided_cuda((128,), (1,), torch.float32) buf50 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) buf54 = empty_strided_cuda((1, 128, 32, 32), (131072, 1024, 32, 1), torch.float32) buf55 = reinterpret_tensor(buf54, (4, 32, 32, 32), (32768, 1024, 32, 1), 0) del buf54 buf53 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_repeat_4[grid(128) ](buf55, primals_21, buf48, primals_22, buf49, buf50, buf53, 128, 1024, num_warps=8, num_stages=1) del primals_21 del primals_22 buf56 = extern_kernels.convolution(buf55, primals_23, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf57 = empty_strided_cuda((64,), (1,), torch.float32) buf58 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) buf62 = empty_strided_cuda((1, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) buf63 = reinterpret_tensor(buf62, (4, 16, 64, 64), (65536, 4096, 64, 1), 0) del buf62 buf61 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch. float32) triton_red_fused__native_batch_norm_legit_leaky_relu_repeat_5[grid(64) ](buf63, primals_24, buf56, primals_25, buf57, buf58, buf61, 64, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) del primals_24 del primals_25 buf64 = extern_kernels.convolution(buf63, primals_26, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 4, 64, 64), (16384, 4096, 64, 1)) buf65 = buf64 del buf64 triton_poi_fused_sigmoid_6[grid(65536)](buf65, 65536, XBLOCK=512, num_warps=4, num_stages=1) return (buf65, primals_1, primals_2, primals_5, primals_8, primals_11, primals_14, primals_17, primals_20, primals_23, primals_26, buf0, buf1, reinterpret_tensor(buf5, (256,), (1,), 0), buf7, buf8, buf9, reinterpret_tensor(buf13, (512,), (1,), 0), buf15, buf16, buf17, reinterpret_tensor(buf21, (256,), (1,), 0), buf23, buf24, buf25, reinterpret_tensor(buf29, (256,), (1,), 0), buf31, buf32, buf33, reinterpret_tensor(buf37, (128,), (1,), 0), buf39, buf40, buf41, reinterpret_tensor(buf45, (128,), (1,), 0), buf47, buf48, buf49, reinterpret_tensor(buf53, (128,), (1,), 0), buf55, buf56, buf57, reinterpret_tensor(buf61, (64,), (1,), 0), buf63, buf65, reinterpret_tensor(buf58, (1, 64, 1, 1), (64, 1, 1, 1), 0), reinterpret_tensor(buf50, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf42, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf34, (1, 128, 1, 1), (128, 1, 1, 1), 0), reinterpret_tensor(buf26, (1, 256, 1, 1), (256, 1, 1, 1), 0), reinterpret_tensor(buf18, (1, 256, 1, 1), (256, 1, 1, 1), 0), reinterpret_tensor(buf10, (1, 512, 1, 1), (512, 1, 1, 1), 0), reinterpret_tensor(buf2, (1, 256, 1, 1), (256, 1, 1, 1), 0)) class INConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, dilation=1, groups=1, relu=True, ins_n=True, bias=False): super(INConv, self).__init__() self.out_channels = out_planes self.conv = nn.Conv2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, x): x = self.conv(x) if self.ins_n is not None: x = self.ins_n(x) if self.relu is not None: x = self.relu(x) return x class INDeConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, out_padding=0, dilation=1, groups=1, relu=True, ins_n= True, bias=False): super(INDeConv, self).__init__() self.out_channels = out_planes self.conv = nn.ConvTranspose2d(in_planes, out_planes, kernel_size= kernel_size, stride=stride, padding=padding, output_padding= out_padding, dilation=dilation, groups=groups, bias=bias) self.ins_n = nn.InstanceNorm2d(out_planes, affine=True ) if ins_n else None self.relu = nn.ReLU(inplace=True) if relu else None def forward(self, x): x = self.conv(x) if self.ins_n is not None: x = self.ins_n(x) if self.relu is not None: x = self.relu(x) return x class DecoderNew(nn.Module): def __init__(self, img_channel): super(DecoderNew, self).__init__() self.deconv1 = INDeConv(in_planes=32, out_planes=64, kernel_size=3, stride=1, padding=1, relu=False) self.activation1 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv2 = INDeConv(in_planes=64, out_planes=128, kernel_size=3, stride=1, padding=1, relu=False) self.activation2 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv3 = INDeConv(in_planes=128, out_planes=64, kernel_size=4, stride=2, padding=1, relu=False) self.activation3 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv4 = INDeConv(in_planes=64, out_planes=64, kernel_size=3, stride=1, padding=1, relu=False) self.activation4 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv5 = INDeConv(in_planes=64, out_planes=32, kernel_size=4, stride=2, padding=1, relu=False) self.activation5 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv6 = INDeConv(in_planes=32, out_planes=32, kernel_size=3, stride=1, padding=1, relu=False) self.activation6 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv7 = INDeConv(in_planes=32, out_planes=32, kernel_size=4, stride=2, padding=1, relu=False) self.activation7 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.deconv8 = INDeConv(in_planes=32, out_planes=16, kernel_size=4, stride=2, padding=1, relu=False) self.activation8 = nn.LeakyReLU(inplace=True, negative_slope=0.2) self.output = INConv(in_planes=16, out_planes=img_channel, kernel_size=1, stride=1, padding=0, ins_n=False, relu=False) self.activation9 = nn.Sigmoid() def forward(self, input_0): primals_1 = self.deconv1.conv.weight primals_3 = self.deconv1.ins_n.weight primals_4 = self.deconv1.ins_n.bias primals_5 = self.deconv2.conv.weight primals_6 = self.deconv2.ins_n.weight primals_7 = self.deconv2.ins_n.bias primals_8 = self.deconv3.conv.weight primals_9 = self.deconv3.ins_n.weight primals_10 = self.deconv3.ins_n.bias primals_11 = self.deconv4.conv.weight primals_12 = self.deconv4.ins_n.weight primals_13 = self.deconv4.ins_n.bias primals_14 = self.deconv5.conv.weight primals_15 = self.deconv5.ins_n.weight primals_16 = self.deconv5.ins_n.bias primals_17 = self.deconv6.conv.weight primals_18 = self.deconv6.ins_n.weight primals_19 = self.deconv6.ins_n.bias primals_20 = self.deconv7.conv.weight primals_21 = self.deconv7.ins_n.weight primals_22 = self.deconv7.ins_n.bias primals_23 = self.deconv8.conv.weight primals_24 = self.deconv8.ins_n.weight primals_25 = self.deconv8.ins_n.bias primals_26 = self.output.conv.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26]) return output[0]
samsgood0310/Unsupervised-Defect-Segmentation
Decoder
false
7,615
[ "Apache-2.0" ]
1
66af32506cd6e60c356890616e28d679622fd8e6
https://github.com/samsgood0310/Unsupervised-Defect-Segmentation/tree/66af32506cd6e60c356890616e28d679622fd8e6
FrameAvgPool
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class FrameAvgPool(nn.Module): def __init__(self, cfg): super(FrameAvgPool, self).__init__() input_size = cfg.INPUT_SIZE hidden_size = cfg.HIDDEN_SIZE kernel_size = cfg.KERNEL_SIZE stride = cfg.STRIDE self.vis_conv = nn.Conv1d(input_size, hidden_size, 1, 1) self.avg_pool = nn.AvgPool1d(kernel_size, stride) def forward(self, visual_input): vis_h = torch.relu(self.vis_conv(visual_input)) vis_h = self.avg_pool(vis_h) return vis_h def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'cfg': _mock_config(INPUT_SIZE=4, HIDDEN_SIZE=4, KERNEL_SIZE=4, STRIDE=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_avg_pool2d_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp7 = 0.25 tmp8 = tmp6 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_1, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 4), (16, 4, 1)) buf1 = reinterpret_tensor(buf0, (4, 4), (4, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16)](buf1, primals_2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32) triton_poi_fused_avg_pool2d_1[grid(4)](buf1, buf2, 4, XBLOCK=4, num_warps=1, num_stages=1) return reinterpret_tensor(buf2, (4, 1), (1, 1), 0 ), primals_1, reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf1, (4, 1, 4), (4, 4, 1), 0), buf3 class FrameAvgPoolNew(nn.Module): def __init__(self, cfg): super(FrameAvgPoolNew, self).__init__() input_size = cfg.INPUT_SIZE hidden_size = cfg.HIDDEN_SIZE kernel_size = cfg.KERNEL_SIZE stride = cfg.STRIDE self.vis_conv = nn.Conv1d(input_size, hidden_size, 1, 1) self.avg_pool = nn.AvgPool1d(kernel_size, stride) def forward(self, input_0): primals_1 = self.vis_conv.weight primals_2 = self.vis_conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
CFM-MSG/Code_LEORN
FrameAvgPool
false
7,616
[ "MIT" ]
1
fabea1e1ded973a4db692e51e2df442bde55f626
https://github.com/CFM-MSG/Code_LEORN/tree/fabea1e1ded973a4db692e51e2df442bde55f626
BertOutput
from _paritybench_helpers import _mock_config import torch import torch.nn as nn import torch.utils.checkpoint class BertLayerNorm(nn.Module): """LayerNorm层, 见Transformer(一), 讲编码器(encoder)的第3部分""" def __init__(self, hidden_size, eps=1e-12, conditional=False): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps self.conditional = conditional if conditional is True: self.weight_dense = nn.Linear(2 * hidden_size, hidden_size, bias=False) self.weight_dense.weight.data.uniform_(0, 0) self.bias_dense = nn.Linear(2 * hidden_size, hidden_size, bias= False) self.bias_dense.weight.data.uniform_(0, 0) def forward(self, x): if self.conditional is False: 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 else: inputs = x[0] cond = x[1] for _ in range(len(inputs.shape) - len(cond.shape)): cond = cond.unsqueeze(dim=1) weight = self.weight + self.weight_dense(cond) bias = self.bias + self.bias_dense(cond) u = inputs.mean(-1, keepdim=True) s = (inputs - u).pow(2).mean(-1, keepdim=True) x = (inputs - u) / torch.sqrt(s + self.variance_epsilon) return weight * x + bias class BertOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(intermediate_size=4, hidden_size=4, layer_norm_eps=1, hidden_dropout_prob=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.checkpoint 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_mean_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp10 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + 2) tmp15 = tl.broadcast_to(tmp14, [XBLOCK]) tmp17 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp21 = tl.load(in_ptr1 + 3) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp24 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tmp0 + tmp2 tmp5 = tmp3 + tmp4 tmp9 = tmp6 + tmp8 tmp11 = tmp9 + tmp10 tmp12 = tmp5 + tmp11 tmp16 = tmp13 + tmp15 tmp18 = tmp16 + tmp17 tmp19 = tmp12 + tmp18 tmp23 = tmp20 + tmp22 tmp25 = tmp23 + tmp24 tmp26 = tmp19 + tmp25 tmp27 = 4.0 tmp28 = tmp26 / tmp27 tl.store(out_ptr0 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_sub_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = 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) tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 - tmp5 tl.store(in_out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_pow_sqrt_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp2 * tmp2 tmp5 = tmp4 * tmp4 tmp6 = tmp3 + tmp5 tmp8 = tmp7 * tmp7 tmp9 = tmp6 + tmp8 tmp11 = tmp10 * tmp10 tmp12 = tmp9 + tmp11 tmp13 = 4.0 tmp14 = tmp12 / tmp13 tmp15 = 1.0 tmp16 = tmp14 + tmp15 tmp17 = libdevice.sqrt(tmp16) tmp18 = tmp1 / tmp17 tmp19 = tmp0 * tmp18 tmp21 = tmp19 + tmp20 tl.store(out_ptr0 + x2, tmp21, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_mean_0[grid(64)](buf0, primals_2, primals_4, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_add_sub_1[grid(256)](buf2, primals_2, primals_4, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_2 del primals_4 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_pow_sqrt_2[grid(256)](primals_5, buf2, primals_6, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_6 return buf3, primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2 class BertLayerNorm(nn.Module): """LayerNorm层, 见Transformer(一), 讲编码器(encoder)的第3部分""" def __init__(self, hidden_size, eps=1e-12, conditional=False): """Construct a layernorm module in the TF style (epsilon inside the square root). """ super(BertLayerNorm, self).__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.bias = nn.Parameter(torch.zeros(hidden_size)) self.variance_epsilon = eps self.conditional = conditional if conditional is True: self.weight_dense = nn.Linear(2 * hidden_size, hidden_size, bias=False) self.weight_dense.weight.data.uniform_(0, 0) self.bias_dense = nn.Linear(2 * hidden_size, hidden_size, bias= False) self.bias_dense.weight.data.uniform_(0, 0) def forward(self, x): if self.conditional is False: 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 else: inputs = x[0] cond = x[1] for _ in range(len(inputs.shape) - len(cond.shape)): cond = cond.unsqueeze(dim=1) weight = self.weight + self.weight_dense(cond) bias = self.bias + self.bias_dense(cond) u = inputs.mean(-1, keepdim=True) s = (inputs - u).pow(2).mean(-1, keepdim=True) x = (inputs - u) / torch.sqrt(s + self.variance_epsilon) return weight * x + bias class BertOutputNew(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = BertLayerNorm(config.hidden_size, eps=config. layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, input_0, input_1): primals_1 = self.dense.weight primals_2 = self.dense.bias primals_5 = self.LayerNorm.weight primals_6 = self.LayerNorm.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
Elvisambition/bert_seq2seq
BertOutput
false
7,617
[ "Apache-2.0" ]
1
643ac537c16872f0d13200de06001d8201a54fbb
https://github.com/Elvisambition/bert_seq2seq/tree/643ac537c16872f0d13200de06001d8201a54fbb
EncoderLayer
import math import torch import torch.nn as nn class MultiHeadAttentionLayer(nn.Module): def __init__(self, d_model, n_heads, dropout): super().__init__() assert d_model % n_heads == 0 self.d_model = d_model self.n_heads = n_heads self.head_dim = d_model // n_heads self.fc_q = nn.Linear(d_model, d_model) self.fc_k = nn.Linear(d_model, d_model) self.fc_v = nn.Linear(d_model, d_model) self.fc_o = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.scale = math.sqrt(d_model) def forward(self, query, key, value, mask=None): batch_size = query.shape[0] Q = self.fc_q(query) K = self.fc_k(key) V = self.fc_v(value) Q = Q.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K = K.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) V = V.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K_t = K.permute(0, 1, 3, 2) energy = torch.matmul(Q, K_t) / self.scale if mask is not None: energy = energy.masked_fill(mask == 0, -1e+18) attention = torch.softmax(energy, dim=-1) x = torch.matmul(self.dropout(attention), V) x = x.permute(0, 2, 1, 3).contiguous() x = x.view(batch_size, -1, self.d_model) x = self.fc_o(x) return x, attention class PositionwiseFeedforwardLayer(nn.Module): def __init__(self, d_model, pf_dim, dropout): super().__init__() self.fc_1 = nn.Linear(d_model, pf_dim) self.fc_2 = nn.Linear(pf_dim, d_model) self.dropout = nn.Dropout(dropout) def forward(self, x): x = self.dropout(torch.relu(self.fc_1(x))) x = self.fc_2(x) return x class EncoderLayer(nn.Module): def __init__(self, d_model, n_heads, dff, dropout): super().__init__() self.self_attn_layer_norm = nn.LayerNorm(d_model) self.ff_layer_norm = nn.LayerNorm(d_model) self.self_attention = MultiHeadAttentionLayer(d_model, n_heads, dropout ) self.positionwise_feedforward = PositionwiseFeedforwardLayer(d_model, dff, dropout) self.dropout = nn.Dropout(dropout) def forward(self, src, src_mask): _src, _ = self.self_attention(src, src, src, src_mask) src = self.self_attn_layer_norm(src + self.dropout(_src)) _src = self.positionwise_feedforward(src) src = self.ff_layer_norm(src + self.dropout(_src)) return src def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'n_heads': 4, 'dff': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_eq_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 == tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused__softmax_div_masked_fill_2(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 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last').to(tl .int1) tmp1 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp7 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp12 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = -9.999999843067494e+17 tmp5 = tl.where(tmp0, tmp4, tmp3) tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp6, tmp4, tmp8) tmp10 = triton_helpers.maximum(tmp5, tmp9) tmp13 = tmp12 * tmp2 tmp14 = tl.where(tmp11, tmp4, tmp13) tmp15 = triton_helpers.maximum(tmp10, tmp14) tmp18 = tmp17 * tmp2 tmp19 = tl.where(tmp16, tmp4, tmp18) tmp20 = triton_helpers.maximum(tmp15, tmp19) tmp21 = tmp5 - tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = tmp9 - tmp20 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = tmp14 - tmp20 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tmp19 - tmp20 tmp30 = tl_math.exp(tmp29) tmp31 = tmp28 + tmp30 tl.store(out_ptr0 + x2, tmp20, xmask) tl.store(out_ptr1 + x2, tmp31, xmask) @triton.jit def triton_poi_fused__softmax_div_masked_fill_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex % 64 x4 = xindex x5 = xindex // 4 tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last').to(tl .int1) tmp1 = tl.load(in_out_ptr0 + x4, xmask) tmp6 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = -9.999999843067494e+17 tmp5 = tl.where(tmp0, tmp4, tmp3) tmp7 = tmp5 - tmp6 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 / tmp9 tl.store(in_out_ptr0 + x4, tmp10, xmask) @triton.jit def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_5(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_6(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-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_7(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_8(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_out_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_native_layer_norm_9(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_10(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) 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 ) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4,), (1,)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 4), (4, 1)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (4, 4), (4, 1)) assert_size_stride(primals_16, (4,), (1,)) assert_size_stride(primals_17, (4,), (1,)) assert_size_stride(primals_18, (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, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_3, buf3, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf0 triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5) buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_eq_1[grid(64)](primals_8, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_8 buf7 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf1 buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_div_masked_fill_2[grid(64)](buf6, buf5, buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 triton_poi_fused__softmax_div_masked_fill_3[grid(256)](buf9, buf6, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) buf10 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf8 triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_7, buf10, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_7 buf11 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11) buf12 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf7 triton_poi_fused_clone_4[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf13 = reinterpret_tensor(buf11, (16, 4), (4, 1), 0) del buf11 extern_kernels.addmm(primals_10, reinterpret_tensor(buf12, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf13) del primals_10 buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf15 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_add_native_layer_norm_5[grid(16)](primals_1, buf13, buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_6[grid(64)](primals_1, buf13, buf14, buf15, primals_11, primals_12, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_12 buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf17) buf18 = reinterpret_tensor(buf17, (4, 4, 4), (16, 4, 1), 0) del buf17 buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_7[grid(64)](buf18, primals_14, buf24, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_14 buf19 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf18, (16, 4), (4, 1), 0), reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf19) buf20 = reinterpret_tensor(buf19, (4, 4, 4), (16, 4, 1), 0) del buf19 triton_poi_fused_add_8[grid(64)](buf20, buf16, primals_16, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_16 buf21 = buf15 del buf15 buf22 = buf14 del buf14 triton_poi_fused_native_layer_norm_9[grid(16)](buf20, buf21, buf22, 16, XBLOCK=16, num_warps=1, num_stages=1) buf23 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_10[grid(64)](buf20, buf21, buf22, primals_17, primals_18, buf23, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf21 del buf22 del primals_18 return (buf23, primals_1, primals_11, primals_17, buf6, buf9, reinterpret_tensor(buf12, (16, 4), (4, 1), 0), buf13, reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor( buf18, (16, 4), (4, 1), 0), buf20, primals_15, buf24, primals_13, primals_9, reinterpret_tensor(buf10, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0)) class MultiHeadAttentionLayer(nn.Module): def __init__(self, d_model, n_heads, dropout): super().__init__() assert d_model % n_heads == 0 self.d_model = d_model self.n_heads = n_heads self.head_dim = d_model // n_heads self.fc_q = nn.Linear(d_model, d_model) self.fc_k = nn.Linear(d_model, d_model) self.fc_v = nn.Linear(d_model, d_model) self.fc_o = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.scale = math.sqrt(d_model) def forward(self, query, key, value, mask=None): batch_size = query.shape[0] Q = self.fc_q(query) K = self.fc_k(key) V = self.fc_v(value) Q = Q.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K = K.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) V = V.view(batch_size, -1, self.n_heads, self.head_dim).permute(0, 2, 1, 3) K_t = K.permute(0, 1, 3, 2) energy = torch.matmul(Q, K_t) / self.scale if mask is not None: energy = energy.masked_fill(mask == 0, -1e+18) attention = torch.softmax(energy, dim=-1) x = torch.matmul(self.dropout(attention), V) x = x.permute(0, 2, 1, 3).contiguous() x = x.view(batch_size, -1, self.d_model) x = self.fc_o(x) return x, attention class PositionwiseFeedforwardLayer(nn.Module): def __init__(self, d_model, pf_dim, dropout): super().__init__() self.fc_1 = nn.Linear(d_model, pf_dim) self.fc_2 = nn.Linear(pf_dim, d_model) self.dropout = nn.Dropout(dropout) def forward(self, x): x = self.dropout(torch.relu(self.fc_1(x))) x = self.fc_2(x) return x class EncoderLayerNew(nn.Module): def __init__(self, d_model, n_heads, dff, dropout): super().__init__() self.self_attn_layer_norm = nn.LayerNorm(d_model) self.ff_layer_norm = nn.LayerNorm(d_model) self.self_attention = MultiHeadAttentionLayer(d_model, n_heads, dropout ) self.positionwise_feedforward = PositionwiseFeedforwardLayer(d_model, dff, dropout) self.dropout = nn.Dropout(dropout) def forward(self, input_0, input_1): primals_3 = self.self_attn_layer_norm.weight primals_5 = self.self_attn_layer_norm.bias primals_7 = self.ff_layer_norm.weight primals_10 = self.ff_layer_norm.bias primals_2 = self.self_attention.fc_q.weight primals_11 = self.self_attention.fc_q.bias primals_4 = self.self_attention.fc_k.weight primals_12 = self.self_attention.fc_k.bias primals_6 = self.self_attention.fc_v.weight primals_14 = self.self_attention.fc_v.bias primals_9 = self.self_attention.fc_o.weight primals_16 = self.self_attention.fc_o.bias primals_13 = self.positionwise_feedforward.fc_1.weight primals_17 = self.positionwise_feedforward.fc_1.bias primals_15 = self.positionwise_feedforward.fc_2.weight primals_18 = self.positionwise_feedforward.fc_2.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]) return output[0]
salvacarrion/nmt-continual-learning
EncoderLayer
false
7,618
[ "MIT" ]
1
302147ac9c270f3341a68a72c803c457f05ff37b
https://github.com/salvacarrion/nmt-continual-learning/tree/302147ac9c270f3341a68a72c803c457f05ff37b
T5DenseReluDense
from _paritybench_helpers import _mock_config import torch import torch.nn.functional as F import torch.nn as nn import torch.utils.checkpoint class T5DenseReluDense(nn.Module): def __init__(self, config): super().__init__() self.wi = nn.Linear(config.d_model, config.d_ff, bias=False) self.wo = nn.Linear(config.d_ff, config.d_model, bias=False) self.dropout = nn.Dropout(config.dropout_rate) def forward(self, hidden_states): hidden_states = self.wi(hidden_states) hidden_states = F.relu(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.wo(hidden_states) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(d_model=4, d_ff=4, dropout_rate=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.checkpoint assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(in_out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = 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)) 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 buf3 = 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, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf2) return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_3, buf3 class T5DenseReluDenseNew(nn.Module): def __init__(self, config): super().__init__() self.wi = nn.Linear(config.d_model, config.d_ff, bias=False) self.wo = nn.Linear(config.d_ff, config.d_model, bias=False) self.dropout = nn.Dropout(config.dropout_rate) def forward(self, input_0): primals_1 = self.wi.weight primals_3 = self.wo.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Elvisambition/bert_seq2seq
T5DenseReluDense
false
7,619
[ "Apache-2.0" ]
1
643ac537c16872f0d13200de06001d8201a54fbb
https://github.com/Elvisambition/bert_seq2seq/tree/643ac537c16872f0d13200de06001d8201a54fbb
AdapterLayer
from _paritybench_helpers import _mock_config 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)))) """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class AdapterLayer(nn.Module): def __init__(self, config): super().__init__() self.adapter_linear1 = nn.Linear(config.hidden_size, config. adapter_size) self.gelu = gelu self.adapter_linear2 = nn.Linear(config.adapter_size, config. hidden_size) def forward(self, input_tensor): net = self.adapter_linear1(input_tensor) net = self.gelu(net) net = self.adapter_linear2(net) return net + input_tensor def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, adapter_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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865475 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 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 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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_add_div_erf_mul_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_add_1[grid(256)](buf3, primals_5, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_4 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)))) """ return x * 0.5 * (1.0 + torch.erf(x / math.sqrt(2.0))) class AdapterLayerNew(nn.Module): def __init__(self, config): super().__init__() self.adapter_linear1 = nn.Linear(config.hidden_size, config. adapter_size) self.gelu = gelu self.adapter_linear2 = nn.Linear(config.adapter_size, config. hidden_size) def forward(self, input_0): primals_1 = self.adapter_linear1.weight primals_2 = self.adapter_linear1.bias primals_4 = self.adapter_linear2.weight primals_5 = self.adapter_linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
DAQuestionAnswering/Bert-n-Pals
AdapterLayer
false
7,620
[ "MIT" ]
1
d5a288b9ac62259e70c249635108ba3906e19f00
https://github.com/DAQuestionAnswering/Bert-n-Pals/tree/d5a288b9ac62259e70c249635108ba3906e19f00
BertSelfAttention
from _paritybench_helpers import _mock_config import math import torch import torch.nn as nn class BertSelfAttention(nn.Module): def __init__(self, config): super(BertSelfAttention, self).__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, attention_mask): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(hidden_states) mixed_value_layer = self.value(hidden_states) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_scores = attention_scores + attention_mask attention_probs = nn.Softmax(dim=-1)(attention_scores) attention_probs = self.dropout(attention_probs) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) return context_layer def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, num_attention_heads= 4, attention_probs_dropout_prob=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from 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_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + (x2 + 4 * y3), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + 4 * x2, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x2), 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 * x2), 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 * x2), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = triton_helpers.maximum(tmp2, tmp5) tmp9 = tmp7 + tmp8 tmp10 = triton_helpers.maximum(tmp6, tmp9) tmp13 = tmp11 + tmp12 tmp14 = triton_helpers.maximum(tmp10, tmp13) tmp15 = tmp2 - tmp14 tmp16 = tl_math.exp(tmp15) tmp17 = tmp5 - tmp14 tmp18 = tl_math.exp(tmp17) tmp19 = tmp16 + tmp18 tmp20 = tmp9 - tmp14 tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp23 = tmp13 - tmp14 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = float('-inf') tmp27 = tmp2 == tmp26 tmp28 = tmp27 == 0 tmp29 = tmp28.to(tl.int64) tmp30 = tmp29 != 0 tmp31 = tmp5 == tmp26 tmp32 = tmp31 == 0 tmp33 = tmp32.to(tl.int64) tmp34 = tmp33 != 0 tmp35 = tmp30 | tmp34 tmp36 = tmp9 == tmp26 tmp37 = tmp36 == 0 tmp38 = tmp37.to(tl.int64) tmp39 = tmp38 != 0 tmp40 = tmp35 | tmp39 tmp41 = tmp13 == tmp26 tmp42 = tmp41 == 0 tmp43 = tmp42.to(tl.int64) tmp44 = tmp43 != 0 tmp45 = tmp40 | tmp44 tl.store(out_ptr0 + x2, tmp14, xmask) tl.store(out_ptr1 + x2, tmp25, xmask) tl.store(out_ptr2 + x2, tmp45, xmask) @triton.jit def triton_poi_fused_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 x3 = xindex // 4 x4 = xindex x5 = xindex % 64 tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last').to(tl .int1) tmp2 = tl.load(in_out_ptr0 + x4, xmask) tmp3 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr3 + x3, xmask, eviction_policy='evict_last') tmp1 = tmp0 == 0 tmp4 = tmp2 + tmp3 tmp6 = tmp4 - tmp5 tmp7 = tl_math.exp(tmp6) tmp9 = tmp7 / tmp8 tmp10 = 0.0 tmp11 = tl.where(tmp1, tmp10, tmp9) tl.store(in_out_ptr0 + x4, tmp11, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_2 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf0 triton_poi_fused_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5) buf6 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf1 buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.bool) triton_poi_fused_1[grid(64)](buf5, primals_8, buf6, buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 triton_poi_fused_2[grid(256)](buf9, buf8, primals_8, buf6, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf8 del primals_8 buf10 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf7 triton_poi_fused_3[grid(16, 4)](buf2, primals_7, buf10, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del primals_7 buf11 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11) buf12 = reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf6 triton_poi_fused_clone_4[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del buf11 return reinterpret_tensor(buf12, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_3, (16, 4), (4, 1), 0 ), buf9, reinterpret_tensor(buf10, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0) class BertSelfAttentionNew(nn.Module): def __init__(self, config): super(BertSelfAttentionNew, self).__init__() if config.hidden_size % config.num_attention_heads != 0: raise ValueError( 'The hidden size (%d) is not a multiple of the number of attention heads (%d)' % (config.hidden_size, config.num_attention_heads)) self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, input_0, input_1): primals_1 = self.query.weight primals_2 = self.query.bias primals_4 = self.key.weight primals_5 = self.key.bias primals_6 = self.value.weight primals_7 = self.value.bias primals_3 = input_0 primals_8 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
AlanFokCo/bert-chinese-horovod-elastic
BertSelfAttention
false
7,621
[ "Apache-2.0" ]
1
02317d0857e0e8e313dd63ead61ca9996b25548e
https://github.com/AlanFokCo/bert-chinese-horovod-elastic/tree/02317d0857e0e8e313dd63ead61ca9996b25548e
RobertaClassificationHead
from _paritybench_helpers import _mock_config import torch import torch.nn as nn import torch.utils.data import torch.nn class RobertaClassificationHead(nn.Module): """Head for sentence-level classification tasks.""" def __init__(self, config): super(RobertaClassificationHead, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.dropout = nn.Dropout(config.hidden_dropout_prob) self.out_proj = nn.Linear(config.hidden_size, config.num_labels) def forward(self, features, **kwargs): x = features[:, 0, :] x = self.dropout(x) x = self.dense(x) x = torch.tanh(x) x = self.dropout(x) x = self.out_proj(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, hidden_dropout_prob= 0.5, num_labels=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.data import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_tanh_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 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_tanh_1[grid(64)](buf2, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf2, primals_4 class RobertaClassificationHeadNew(nn.Module): """Head for sentence-level classification tasks.""" def __init__(self, config): super(RobertaClassificationHeadNew, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.dropout = nn.Dropout(config.hidden_dropout_prob) self.out_proj = nn.Linear(config.hidden_size, config.num_labels) def forward(self, input_0): primals_2 = self.dense.weight primals_3 = self.dense.bias primals_4 = self.out_proj.weight primals_5 = self.out_proj.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
GavinGuan95/Generative-VQA
RobertaClassificationHead
false
7,622
[ "MIT" ]
1
0912e3a2426809ef4d4eb40bae667b31c2269161
https://github.com/GavinGuan95/Generative-VQA/tree/0912e3a2426809ef4d4eb40bae667b31c2269161
Actor
import torch class Actor(torch.nn.Module): def __init__(self, actor_lr, epsilon): super(Actor, self).__init__() self.epsilon = epsilon self.define_network() self.optimizer = torch.optim.Adam(params=self.parameters(), lr=actor_lr ) self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self self.prev_params = self.parameters() def define_network(self): self.relu = torch.nn.ReLU() self.leaky_relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.softmax = torch.nn.Softmax(dim=0) self.l1 = torch.nn.Linear(1024, 512) self.l2 = torch.nn.Linear(512, 64) self.l3 = torch.nn.Linear(64, 15) self.conv1 = torch.nn.Conv2d(3, 32, kernel_size=4, stride=2) self.conv2 = torch.nn.Conv2d(32, 64, kernel_size=4, stride=2) self.conv3 = torch.nn.Conv2d(64, 128, kernel_size=4, stride=2) self.conv4 = torch.nn.Conv2d(128, 256, kernel_size=4, stride=2) def loss(self, log_probs, k_log_probs, advantages): r_theta = torch.exp(log_probs - k_log_probs) clipped_r = torch.clamp(r_theta, 1.0 - self.epsilon, 1.0 + self.epsilon ) return torch.mean(torch.min(r_theta * advantages, clipped_r * advantages)) def forward(self, x): out = torch.Tensor(x).float() out = self.conv1(out) out = self.leaky_relu(out) out = self.conv2(out) out = self.leaky_relu(out) out = self.conv3(out) out = self.leaky_relu(out) out = self.conv4(out) out = self.leaky_relu(out) out = out.reshape(-1, 2 * 2 * 256) out = self.l1(out) out = self.leaky_relu(out) out = self.l2(out) out = self.leaky_relu(out) out = self.l3(out) out = self.relu(out) out = self.softmax(out) return out def optimize(self, log_probs, k_log_probs, advantages, batch_sz=32): loss = self.loss(log_probs, k_log_probs, advantages) self.optimizer.zero_grad() loss.backward() self.optimizer.step() def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {'actor_lr': 4, 'epsilon': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 96 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 48 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 512 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 64 * x2 + 1024 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 128 * x2 + 2048 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 123008 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 50176 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_7(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_8(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 256 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex y2 = yindex % 4 y3 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x1 + 256 * y0), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + (x1 + 256 * y0), tmp4, xmask & ymask) tl.store(out_ptr1 + (y2 + 4 * x1 + 1024 * y3), tmp7, xmask & ymask) @triton.jit def triton_poi_fused_leaky_relu_9(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_leaky_relu_10(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused__softmax_relu_11(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 15 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) tmp5 = tl.load(in_ptr0 + (15 + x0), xmask) tmp9 = tl.load(in_ptr0 + (30 + x0), xmask) tmp13 = tl.load(in_ptr0 + (45 + x0), xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp5 + tmp1 tmp7 = triton_helpers.maximum(tmp3, tmp6) tmp8 = triton_helpers.maximum(tmp4, tmp7) tmp10 = tmp9 + tmp1 tmp11 = triton_helpers.maximum(tmp3, tmp10) tmp12 = triton_helpers.maximum(tmp8, tmp11) tmp14 = tmp13 + tmp1 tmp15 = triton_helpers.maximum(tmp3, tmp14) tmp16 = triton_helpers.maximum(tmp12, tmp15) tmp17 = tmp4 - tmp16 tmp18 = tl_math.exp(tmp17) tmp19 = tmp7 - tmp16 tmp20 = tl_math.exp(tmp19) tmp21 = tmp18 + tmp20 tmp22 = tmp11 - tmp16 tmp23 = tl_math.exp(tmp22) tmp24 = tmp21 + tmp23 tmp25 = tmp15 - tmp16 tmp26 = tl_math.exp(tmp25) tmp27 = tmp24 + tmp26 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp27, xmask) @triton.jit def triton_poi_fused__softmax_relu_threshold_backward_12(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 60 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 15 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp4 - tmp5 tmp7 = tl_math.exp(tmp6) tmp9 = tmp7 / tmp8 tmp10 = 0.0 tmp11 = tmp4 <= tmp10 tl.store(out_ptr0 + x2, tmp9, xmask) tl.store(out_ptr1 + x2, tmp11, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15) = args args.clear() assert_size_stride(primals_1, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_2, (32, 3, 4, 4), (48, 16, 4, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (256, 128, 4, 4), (2048, 16, 4, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (512, 1024), (1024, 1)) assert_size_stride(primals_11, (512,), (1,)) assert_size_stride(primals_12, (64, 512), (512, 1)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (15, 64), (64, 1)) assert_size_stride(primals_15, (15,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) get_raw_stream(0) triton_poi_fused_0[grid(12, 4096)](primals_1, buf0, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((32, 3, 4, 4), (48, 1, 12, 3), torch.float32) triton_poi_fused_1[grid(96, 16)](primals_2, buf1, 96, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 32, 4, 4), (512, 1, 128, 32), torch. float32) triton_poi_fused_2[grid(2048, 16)](primals_4, buf2, 2048, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((128, 64, 4, 4), (1024, 1, 256, 64), torch.float32) triton_poi_fused_3[grid(8192, 16)](primals_6, buf3, 8192, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = empty_strided_cuda((256, 128, 4, 4), (2048, 1, 512, 128), torch.float32) triton_poi_fused_4[grid(32768, 16)](primals_8, buf4, 32768, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf5 = extern_kernels.convolution(buf0, buf1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 32, 31, 31), (30752, 1, 992, 32)) buf6 = empty_strided_cuda((4, 32, 31, 31), (30752, 1, 992, 32), torch.bool) buf7 = empty_strided_cuda((4, 32, 31, 31), (30752, 1, 992, 32), torch.float32) triton_poi_fused_convolution_leaky_relu_5[grid(123008)](buf5, primals_3, buf6, buf7, 123008, XBLOCK=1024, num_warps=4, num_stages=1) del buf5 del primals_3 buf8 = extern_kernels.convolution(buf7, buf2, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 14, 14), (12544, 1, 896, 64)) buf9 = empty_strided_cuda((4, 64, 14, 14), (12544, 1, 896, 64), torch.bool) buf10 = empty_strided_cuda((4, 64, 14, 14), (12544, 1, 896, 64), torch.float32) triton_poi_fused_convolution_leaky_relu_6[grid(50176)](buf8, primals_5, buf9, buf10, 50176, XBLOCK=512, num_warps=4, num_stages=1) del buf8 del primals_5 buf11 = extern_kernels.convolution(buf10, buf3, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 128, 6, 6), (4608, 1, 768, 128)) buf12 = empty_strided_cuda((4, 128, 6, 6), (4608, 1, 768, 128), torch.bool) buf13 = empty_strided_cuda((4, 128, 6, 6), (4608, 1, 768, 128), torch.float32) triton_poi_fused_convolution_leaky_relu_7[grid(18432)](buf11, primals_7, buf12, buf13, 18432, XBLOCK=256, num_warps=4, num_stages=1) del buf11 del primals_7 buf14 = extern_kernels.convolution(buf13, buf4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 2, 2), (1024, 1, 512, 256)) buf15 = empty_strided_cuda((4, 256, 2, 2), (1024, 1, 512, 256), torch.bool) buf16 = empty_strided_cuda((4, 256, 2, 2), (1024, 4, 2, 1), torch. float32) triton_poi_fused_convolution_leaky_relu_8[grid(16, 256)](buf14, primals_9, buf15, buf16, 16, 256, XBLOCK=256, YBLOCK=1, num_warps=4, num_stages=1) del buf14 del primals_9 buf17 = empty_strided_cuda((4, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf16, (4, 1024), (1024, 1), 0 ), reinterpret_tensor(primals_10, (1024, 512), (1, 1024), 0), out=buf17) buf18 = empty_strided_cuda((4, 512), (512, 1), torch.bool) buf19 = empty_strided_cuda((4, 512), (512, 1), torch.float32) triton_poi_fused_leaky_relu_9[grid(2048)](buf17, primals_11, buf18, buf19, 2048, XBLOCK=256, num_warps=4, num_stages=1) del buf17 del primals_11 buf20 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf19, reinterpret_tensor(primals_12, (512, 64), (1, 512), 0), out=buf20) buf21 = empty_strided_cuda((4, 64), (64, 1), torch.bool) buf22 = empty_strided_cuda((4, 64), (64, 1), torch.float32) triton_poi_fused_leaky_relu_10[grid(256)](buf20, primals_13, buf21, buf22, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf20 del primals_13 buf23 = empty_strided_cuda((4, 15), (15, 1), torch.float32) extern_kernels.mm(buf22, reinterpret_tensor(primals_14, (64, 15), ( 1, 64), 0), out=buf23) buf24 = empty_strided_cuda((1, 15), (15, 1), torch.float32) buf25 = empty_strided_cuda((1, 15), (15, 1), torch.float32) triton_poi_fused__softmax_relu_11[grid(15)](buf23, primals_15, buf24, buf25, 15, XBLOCK=16, num_warps=1, num_stages=1) buf26 = empty_strided_cuda((4, 15), (15, 1), torch.float32) buf27 = empty_strided_cuda((4, 15), (15, 1), torch.bool) triton_poi_fused__softmax_relu_threshold_backward_12[grid(60)](buf23, primals_15, buf24, buf25, buf26, buf27, 60, XBLOCK=64, num_warps=1, num_stages=1) del buf23 del buf24 del buf25 del primals_15 return (buf26, buf0, buf1, buf2, buf3, buf4, buf6, buf7, buf9, buf10, buf12, buf13, buf15, reinterpret_tensor(buf16, (4, 1024), (1024, 1), 0), buf18, buf19, buf21, buf22, buf26, buf27, primals_14, primals_12, primals_10) class ActorNew(torch.nn.Module): def __init__(self, actor_lr, epsilon): super(ActorNew, self).__init__() self.epsilon = epsilon self.define_network() self.optimizer = torch.optim.Adam(params=self.parameters(), lr=actor_lr ) self.device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu:0') self self.prev_params = self.parameters() def define_network(self): self.relu = torch.nn.ReLU() self.leaky_relu = torch.nn.LeakyReLU() self.sigmoid = torch.nn.Sigmoid() self.tanh = torch.nn.Tanh() self.softmax = torch.nn.Softmax(dim=0) self.l1 = torch.nn.Linear(1024, 512) self.l2 = torch.nn.Linear(512, 64) self.l3 = torch.nn.Linear(64, 15) self.conv1 = torch.nn.Conv2d(3, 32, kernel_size=4, stride=2) self.conv2 = torch.nn.Conv2d(32, 64, kernel_size=4, stride=2) self.conv3 = torch.nn.Conv2d(64, 128, kernel_size=4, stride=2) self.conv4 = torch.nn.Conv2d(128, 256, kernel_size=4, stride=2) def loss(self, log_probs, k_log_probs, advantages): r_theta = torch.exp(log_probs - k_log_probs) clipped_r = torch.clamp(r_theta, 1.0 - self.epsilon, 1.0 + self.epsilon ) return torch.mean(torch.min(r_theta * advantages, clipped_r * advantages)) def optimize(self, log_probs, k_log_probs, advantages, batch_sz=32): loss = self.loss(log_probs, k_log_probs, advantages) self.optimizer.zero_grad() loss.backward() self.optimizer.step() def forward(self, input_0): primals_10 = self.l1.weight primals_11 = self.l1.bias primals_12 = self.l2.weight primals_5 = self.l2.bias primals_14 = self.l3.weight primals_15 = self.l3.bias primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_13 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15]) return output[0]
Gregory-Eales/Proximal-Policy-Optimization
Actor
false
7,623
[ "Apache-2.0" ]
1
134f930bd1436c34e79af9344fe70f75e11c8a30
https://github.com/Gregory-Eales/Proximal-Policy-Optimization/tree/134f930bd1436c34e79af9344fe70f75e11c8a30
Normalization
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class Normalization(nn.Module): def __init__(self, cfg): super(Normalization, self).__init__() self.normalizer = nn.LayerNorm(cfg.embedding_dim, elementwise_affine=True) def forward(self, input): return self.normalizer(input.view(-1, input.size(-1))).view(*input. size()) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'cfg': _mock_config(embedding_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 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_native_layer_norm_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') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = 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((64, 1), (1, 64), torch.float32) buf1 = empty_strided_cuda((64, 1), (1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(64)](primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(256)](primals_1, buf0, buf1, primals_2, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf1 del primals_2 del primals_3 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0), primals_1 class NormalizationNew(nn.Module): def __init__(self, cfg): super(NormalizationNew, self).__init__() self.normalizer = nn.LayerNorm(cfg.embedding_dim, elementwise_affine=True) def forward(self, input_0): primals_2 = self.normalizer.weight primals_3 = self.normalizer.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JustinLiam/DAN
Normalization
false
7,624
[ "MIT" ]
1
eb29cddad6c93e591854b115ef524643b1cd471c
https://github.com/JustinLiam/DAN/tree/eb29cddad6c93e591854b115ef524643b1cd471c
SingleHeadAttention
from _paritybench_helpers import _mock_config import math import torch import torch.nn as nn class SingleHeadAttention(nn.Module): def __init__(self, cfg): super(SingleHeadAttention, self).__init__() self.input_dim = cfg.embedding_dim self.embedding_dim = cfg.embedding_dim self.value_dim = self.embedding_dim self.key_dim = self.value_dim self.tanh_clipping = cfg.tanh_clipping self.norm_factor = 1 / math.sqrt(self.key_dim) self.w_query = nn.Parameter(torch.Tensor(self.input_dim, self.key_dim)) self.w_key = nn.Parameter(torch.Tensor(self.input_dim, self.key_dim)) self.init_parameters() def init_parameters(self): for param in self.parameters(): stdv = 1.0 / math.sqrt(param.size(-1)) param.data.uniform_(-stdv, stdv) def forward(self, q, h=None, mask=None): """ :param q: queries (batch_size, n_query, input_dim) :param h: data (batch_size, graph_size, input_dim) :param mask: mask (batch_size, n_query, graph_size) or viewable as that (i.e. can be 2 dim if n_query == 1) Mask should contain 1 if attention is not possible (i.e. mask is negative adjacency) :return: """ if h is None: h = q batch_size, target_size, input_dim = h.size() n_query = q.size(1) assert q.size(0) == batch_size assert q.size(2) == input_dim assert input_dim == self.input_dim h_flat = h.reshape(-1, input_dim) q_flat = q.reshape(-1, input_dim) shape_k = batch_size, target_size, -1 shape_q = batch_size, n_query, -1 Q = torch.matmul(q_flat, self.w_query).view(shape_q) K = torch.matmul(h_flat, self.w_key).view(shape_k) U = self.norm_factor * torch.matmul(Q, K.transpose(1, 2)) U = self.tanh_clipping * torch.tanh(U) if mask is not None: mask = mask.view(batch_size, 1, target_size).expand_as(U) U[mask.bool()] = -100000000.0 attention = torch.log_softmax(U, dim=-1) out = attention return out def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'cfg': _mock_config(embedding_dim=4, tanh_clipping=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math import torch.nn as nn 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_tanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = libdevice.tanh(tmp2) tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp7 = tmp6 * tmp1 tmp8 = libdevice.tanh(tmp7) tmp9 = tmp8 * tmp4 tmp11 = tmp10 * tmp1 tmp12 = libdevice.tanh(tmp11) tmp13 = tmp12 * tmp4 tmp14 = triton_helpers.maximum(tmp9, tmp13) tmp16 = tmp15 * tmp1 tmp17 = libdevice.tanh(tmp16) tmp18 = tmp17 * tmp4 tmp19 = triton_helpers.maximum(tmp14, tmp18) tmp21 = tmp20 * tmp1 tmp22 = libdevice.tanh(tmp21) tmp23 = tmp22 * tmp4 tmp24 = triton_helpers.maximum(tmp19, tmp23) tmp25 = tmp5 - tmp24 tmp26 = 4.0 tmp27 = tmp25 * tmp26 tl.store(out_ptr0 + x2, tmp27, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): 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), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_3, out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0), out=buf2) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_tanh_0[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(64)](buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 return buf4, buf2, buf4, reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0) class SingleHeadAttentionNew(nn.Module): def __init__(self, cfg): super(SingleHeadAttentionNew, self).__init__() self.input_dim = cfg.embedding_dim self.embedding_dim = cfg.embedding_dim self.value_dim = self.embedding_dim self.key_dim = self.value_dim self.tanh_clipping = cfg.tanh_clipping self.norm_factor = 1 / math.sqrt(self.key_dim) self.w_query = nn.Parameter(torch.Tensor(self.input_dim, self.key_dim)) self.w_key = nn.Parameter(torch.Tensor(self.input_dim, self.key_dim)) self.init_parameters() def init_parameters(self): for param in self.parameters(): stdv = 1.0 / math.sqrt(param.size(-1)) param.data.uniform_(-stdv, stdv) def forward(self, input_0): primals_2 = self.w_query primals_3 = self.w_key primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
JustinLiam/DAN
SingleHeadAttention
false
7,625
[ "MIT" ]
1
eb29cddad6c93e591854b115ef524643b1cd471c
https://github.com/JustinLiam/DAN/tree/eb29cddad6c93e591854b115ef524643b1cd471c
SparsemaxBisect
from torch.autograd import Function import torch import torch.nn as nn def sparsemax_bisect(X, dim=-1, n_iter=50, ensure_sum_one=True): """sparsemax: normalizing sparse transform (a la softmax), via bisection. Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. ensure_sum_one : bool, Whether to divide the result by its sum. If false, the result might sum to close but not exactly 1, which might cause downstream problems. Note: This function does not yet support normalizing along anything except the last dimension. Please use transposing and views to achieve more general behavior. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxBisectFunction.apply(X, dim, n_iter, ensure_sum_one) class EntmaxBisectFunction(Function): @classmethod def _gp(cls, x, alpha): return x ** (alpha - 1) @classmethod def _gp_inv(cls, y, alpha): return y ** (1 / (alpha - 1)) @classmethod def _p(cls, X, alpha): return cls._gp_inv(torch.clamp(X, min=0), alpha) @classmethod def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True ): if not isinstance(alpha, torch.Tensor): alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device) alpha_shape = list(X.shape) alpha_shape[dim] = 1 alpha = alpha.expand(*alpha_shape) ctx.alpha = alpha ctx.dim = dim d = X.shape[dim] X = X * (alpha - 1) max_val, _ = X.max(dim=dim, keepdim=True) tau_lo = max_val - cls._gp(1, alpha) tau_hi = max_val - cls._gp(1 / d, alpha) f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1 dm = tau_hi - tau_lo for it in range(n_iter): dm /= 2 tau_m = tau_lo + dm p_m = cls._p(X - tau_m, alpha) f_m = p_m.sum(dim) - 1 mask = (f_m * f_lo >= 0).unsqueeze(dim) tau_lo = torch.where(mask, tau_m, tau_lo) if ensure_sum_one: p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim) ctx.save_for_backward(p_m) return p_m @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1)) dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr d_alpha = None if ctx.needs_input_grad[1]: S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1)) ent = S.sum(ctx.dim).unsqueeze(ctx.dim) Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim) d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2 d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1) d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim) return dX, d_alpha, None, None, None class SparsemaxBisectFunction(EntmaxBisectFunction): @classmethod def _gp(cls, x, alpha): return x @classmethod def _gp_inv(cls, y, alpha): return y @classmethod def _p(cls, x, alpha): return torch.clamp(x, min=0) @classmethod def forward(cls, ctx, X, dim=-1, n_iter=50, ensure_sum_one=True): return super().forward(ctx, X, alpha=2, dim=dim, n_iter=50, ensure_sum_one=True) @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y > 0 dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None, None class SparsemaxBisect(nn.Module): def __init__(self, dim=-1, n_iter=None): """sparsemax: normalizing sparse transform (a la softmax) via bisection Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. """ self.dim = dim self.n_iter = n_iter super().__init__() def forward(self, X): return sparsemax_bisect(X, dim=self.dim, n_iter=self.n_iter) 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.autograd import Function import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_0(in_out_ptr8, 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_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) tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp9 = 0.25 tmp10 = tmp6 - tmp9 tmp11 = tmp10 - tmp8 tmp12 = 0.5 tmp13 = tmp11 * tmp12 tmp14 = tmp8 + tmp13 tmp15 = tmp0 - tmp14 tmp16 = 0.0 tmp17 = triton_helpers.maximum(tmp15, tmp16) tmp18 = tmp1 - tmp14 tmp19 = triton_helpers.maximum(tmp18, tmp16) tmp20 = tmp17 + tmp19 tmp21 = tmp3 - tmp14 tmp22 = triton_helpers.maximum(tmp21, tmp16) tmp23 = tmp20 + tmp22 tmp24 = tmp5 - tmp14 tmp25 = triton_helpers.maximum(tmp24, tmp16) tmp26 = tmp23 + tmp25 tmp27 = tmp26 - tmp7 tmp28 = tmp0 - tmp8 tmp29 = triton_helpers.maximum(tmp28, tmp16) tmp30 = tmp1 - tmp8 tmp31 = triton_helpers.maximum(tmp30, tmp16) tmp32 = tmp29 + tmp31 tmp33 = tmp3 - tmp8 tmp34 = triton_helpers.maximum(tmp33, tmp16) tmp35 = tmp32 + tmp34 tmp36 = tmp5 - tmp8 tmp37 = triton_helpers.maximum(tmp36, tmp16) tmp38 = tmp35 + tmp37 tmp39 = tmp38 - tmp7 tmp40 = tmp27 * tmp39 tmp41 = tmp40 >= tmp16 tmp42 = tl.where(tmp41, tmp14, tmp8) tmp43 = tmp13 * tmp12 tmp44 = tmp42 + tmp43 tmp45 = tmp0 - tmp44 tmp46 = triton_helpers.maximum(tmp45, tmp16) tmp47 = tmp1 - tmp44 tmp48 = triton_helpers.maximum(tmp47, tmp16) tmp49 = tmp46 + tmp48 tmp50 = tmp3 - tmp44 tmp51 = triton_helpers.maximum(tmp50, tmp16) tmp52 = tmp49 + tmp51 tmp53 = tmp5 - tmp44 tmp54 = triton_helpers.maximum(tmp53, tmp16) tmp55 = tmp52 + tmp54 tmp56 = tmp55 - tmp7 tmp57 = tmp56 * tmp39 tmp58 = tmp57 >= tmp16 tmp59 = tl.where(tmp58, tmp44, tmp42) tmp60 = tmp43 * tmp12 tmp61 = tmp59 + tmp60 tmp62 = tmp0 - tmp61 tmp63 = triton_helpers.maximum(tmp62, tmp16) tmp64 = tmp1 - tmp61 tmp65 = triton_helpers.maximum(tmp64, tmp16) tmp66 = tmp63 + tmp65 tmp67 = tmp3 - tmp61 tmp68 = triton_helpers.maximum(tmp67, tmp16) tmp69 = tmp66 + tmp68 tmp70 = tmp5 - tmp61 tmp71 = triton_helpers.maximum(tmp70, tmp16) tmp72 = tmp69 + tmp71 tmp73 = tmp72 - tmp7 tmp74 = tmp73 * tmp39 tmp75 = tmp74 >= tmp16 tmp76 = tl.where(tmp75, tmp61, tmp59) tmp77 = tmp60 * tmp12 tmp78 = tmp76 + tmp77 tmp79 = tmp0 - tmp78 tmp80 = triton_helpers.maximum(tmp79, tmp16) tmp81 = tmp1 - tmp78 tmp82 = triton_helpers.maximum(tmp81, tmp16) tmp83 = tmp80 + tmp82 tmp84 = tmp3 - tmp78 tmp85 = triton_helpers.maximum(tmp84, tmp16) tmp86 = tmp83 + tmp85 tmp87 = tmp5 - tmp78 tmp88 = triton_helpers.maximum(tmp87, tmp16) tmp89 = tmp86 + tmp88 tmp90 = tmp89 - tmp7 tmp91 = tmp90 * tmp39 tmp92 = tmp91 >= tmp16 tmp93 = tl.where(tmp92, tmp78, tmp76) tmp94 = tmp77 * tmp12 tmp95 = tmp93 + tmp94 tmp96 = tmp0 - tmp95 tmp97 = triton_helpers.maximum(tmp96, tmp16) tmp98 = tmp1 - tmp95 tmp99 = triton_helpers.maximum(tmp98, tmp16) tmp100 = tmp97 + tmp99 tmp101 = tmp3 - tmp95 tmp102 = triton_helpers.maximum(tmp101, tmp16) tmp103 = tmp100 + tmp102 tmp104 = tmp5 - tmp95 tmp105 = triton_helpers.maximum(tmp104, tmp16) tmp106 = tmp103 + tmp105 tmp107 = tmp106 - tmp7 tmp108 = tmp107 * tmp39 tmp109 = tmp108 >= tmp16 tmp110 = tl.where(tmp109, tmp95, tmp93) tmp111 = tmp94 * tmp12 tmp112 = tmp110 + tmp111 tmp113 = tmp0 - tmp112 tmp114 = triton_helpers.maximum(tmp113, tmp16) tmp115 = tmp1 - tmp112 tmp116 = triton_helpers.maximum(tmp115, tmp16) tmp117 = tmp114 + tmp116 tmp118 = tmp3 - tmp112 tmp119 = triton_helpers.maximum(tmp118, tmp16) tmp120 = tmp117 + tmp119 tmp121 = tmp5 - tmp112 tmp122 = triton_helpers.maximum(tmp121, tmp16) tmp123 = tmp120 + tmp122 tmp124 = tmp123 - tmp7 tmp125 = tmp124 * tmp39 tmp126 = tmp125 >= tmp16 tmp127 = tl.where(tmp126, tmp112, tmp110) tmp128 = tmp111 * tmp12 tmp129 = tmp127 + tmp128 tmp130 = tmp0 - tmp129 tmp131 = triton_helpers.maximum(tmp130, tmp16) tmp132 = tmp1 - tmp129 tmp133 = triton_helpers.maximum(tmp132, tmp16) tmp134 = tmp131 + tmp133 tmp135 = tmp3 - tmp129 tmp136 = triton_helpers.maximum(tmp135, tmp16) tmp137 = tmp134 + tmp136 tmp138 = tmp5 - tmp129 tmp139 = triton_helpers.maximum(tmp138, tmp16) tmp140 = tmp137 + tmp139 tmp141 = tmp140 - tmp7 tmp142 = tmp141 * tmp39 tmp143 = tmp142 >= tmp16 tmp144 = tl.where(tmp143, tmp129, tmp127) tmp145 = tmp128 * tmp12 tmp146 = tmp144 + tmp145 tmp147 = tmp0 - tmp146 tmp148 = triton_helpers.maximum(tmp147, tmp16) tmp149 = tmp1 - tmp146 tmp150 = triton_helpers.maximum(tmp149, tmp16) tmp151 = tmp148 + tmp150 tmp152 = tmp3 - tmp146 tmp153 = triton_helpers.maximum(tmp152, tmp16) tmp154 = tmp151 + tmp153 tmp155 = tmp5 - tmp146 tmp156 = triton_helpers.maximum(tmp155, tmp16) tmp157 = tmp154 + tmp156 tmp158 = tmp157 - tmp7 tmp159 = tmp158 * tmp39 tmp160 = tmp159 >= tmp16 tmp161 = tl.where(tmp160, tmp146, tmp144) tmp162 = tmp145 * tmp12 tmp163 = tmp161 + tmp162 tmp164 = tmp0 - tmp163 tmp165 = triton_helpers.maximum(tmp164, tmp16) tmp166 = tmp1 - tmp163 tmp167 = triton_helpers.maximum(tmp166, tmp16) tmp168 = tmp165 + tmp167 tmp169 = tmp3 - tmp163 tmp170 = triton_helpers.maximum(tmp169, tmp16) tmp171 = tmp168 + tmp170 tmp172 = tmp5 - tmp163 tmp173 = triton_helpers.maximum(tmp172, tmp16) tmp174 = tmp171 + tmp173 tmp175 = tmp174 - tmp7 tmp176 = tmp175 * tmp39 tmp177 = tmp176 >= tmp16 tmp178 = tl.where(tmp177, tmp163, tmp161) tmp179 = tmp162 * tmp12 tmp180 = tmp178 + tmp179 tmp181 = tmp0 - tmp180 tmp182 = triton_helpers.maximum(tmp181, tmp16) tmp183 = tmp1 - tmp180 tmp184 = triton_helpers.maximum(tmp183, tmp16) tmp185 = tmp182 + tmp184 tmp186 = tmp3 - tmp180 tmp187 = triton_helpers.maximum(tmp186, tmp16) tmp188 = tmp185 + tmp187 tmp189 = tmp5 - tmp180 tmp190 = triton_helpers.maximum(tmp189, tmp16) tmp191 = tmp188 + tmp190 tmp192 = tmp191 - tmp7 tmp193 = tmp192 * tmp39 tmp194 = tmp193 >= tmp16 tmp195 = tl.where(tmp194, tmp180, tmp178) tmp196 = tmp179 * tmp12 tmp197 = tmp195 + tmp196 tmp198 = tmp0 - tmp197 tmp199 = triton_helpers.maximum(tmp198, tmp16) tmp200 = tmp1 - tmp197 tmp201 = triton_helpers.maximum(tmp200, tmp16) tmp202 = tmp199 + tmp201 tmp203 = tmp3 - tmp197 tmp204 = triton_helpers.maximum(tmp203, tmp16) tmp205 = tmp202 + tmp204 tmp206 = tmp5 - tmp197 tmp207 = triton_helpers.maximum(tmp206, tmp16) tmp208 = tmp205 + tmp207 tmp209 = tmp208 - tmp7 tmp210 = tmp209 * tmp39 tmp211 = tmp210 >= tmp16 tmp212 = tl.where(tmp211, tmp197, tmp195) tmp213 = tmp196 * tmp12 tmp214 = tmp212 + tmp213 tmp215 = tmp0 - tmp214 tmp216 = triton_helpers.maximum(tmp215, tmp16) tmp217 = tmp1 - tmp214 tmp218 = triton_helpers.maximum(tmp217, tmp16) tmp219 = tmp216 + tmp218 tmp220 = tmp3 - tmp214 tmp221 = triton_helpers.maximum(tmp220, tmp16) tmp222 = tmp219 + tmp221 tmp223 = tmp5 - tmp214 tmp224 = triton_helpers.maximum(tmp223, tmp16) tmp225 = tmp222 + tmp224 tmp226 = tmp225 - tmp7 tmp227 = tmp226 * tmp39 tmp228 = tmp227 >= tmp16 tmp229 = tl.where(tmp228, tmp214, tmp212) tmp230 = tmp213 * tmp12 tmp231 = tmp229 + tmp230 tmp232 = tmp0 - tmp231 tmp233 = triton_helpers.maximum(tmp232, tmp16) tmp234 = tmp1 - tmp231 tmp235 = triton_helpers.maximum(tmp234, tmp16) tmp236 = tmp233 + tmp235 tmp237 = tmp3 - tmp231 tmp238 = triton_helpers.maximum(tmp237, tmp16) tmp239 = tmp236 + tmp238 tmp240 = tmp5 - tmp231 tmp241 = triton_helpers.maximum(tmp240, tmp16) tmp242 = tmp239 + tmp241 tmp243 = tmp242 - tmp7 tmp244 = tmp243 * tmp39 tmp245 = tmp244 >= tmp16 tmp246 = tl.where(tmp245, tmp231, tmp229) tmp247 = tmp230 * tmp12 tmp248 = tmp246 + tmp247 tmp249 = tmp0 - tmp248 tmp250 = triton_helpers.maximum(tmp249, tmp16) tmp251 = tmp1 - tmp248 tmp252 = triton_helpers.maximum(tmp251, tmp16) tmp253 = tmp250 + tmp252 tmp254 = tmp3 - tmp248 tmp255 = triton_helpers.maximum(tmp254, tmp16) tmp256 = tmp253 + tmp255 tmp257 = tmp5 - tmp248 tmp258 = triton_helpers.maximum(tmp257, tmp16) tmp259 = tmp256 + tmp258 tmp260 = tmp259 - tmp7 tmp261 = tmp260 * tmp39 tmp262 = tmp261 >= tmp16 tmp263 = tl.where(tmp262, tmp248, tmp246) tmp264 = tmp247 * tmp12 tmp265 = tmp263 + tmp264 tmp266 = tmp0 - tmp265 tmp267 = triton_helpers.maximum(tmp266, tmp16) tmp268 = tmp1 - tmp265 tmp269 = triton_helpers.maximum(tmp268, tmp16) tmp270 = tmp267 + tmp269 tmp271 = tmp3 - tmp265 tmp272 = triton_helpers.maximum(tmp271, tmp16) tmp273 = tmp270 + tmp272 tmp274 = tmp5 - tmp265 tmp275 = triton_helpers.maximum(tmp274, tmp16) tmp276 = tmp273 + tmp275 tmp277 = tmp276 - tmp7 tmp278 = tmp277 * tmp39 tmp279 = tmp278 >= tmp16 tmp280 = tl.where(tmp279, tmp265, tmp263) tmp281 = tmp264 * tmp12 tmp282 = tmp280 + tmp281 tmp283 = tmp0 - tmp282 tmp284 = triton_helpers.maximum(tmp283, tmp16) tmp285 = tmp1 - tmp282 tmp286 = triton_helpers.maximum(tmp285, tmp16) tmp287 = tmp284 + tmp286 tmp288 = tmp3 - tmp282 tmp289 = triton_helpers.maximum(tmp288, tmp16) tmp290 = tmp287 + tmp289 tmp291 = tmp5 - tmp282 tmp292 = triton_helpers.maximum(tmp291, tmp16) tmp293 = tmp290 + tmp292 tmp294 = tmp293 - tmp7 tmp295 = tmp294 * tmp39 tmp296 = tmp295 >= tmp16 tmp297 = tl.where(tmp296, tmp282, tmp280) tmp298 = tmp281 * tmp12 tmp299 = tmp297 + tmp298 tmp300 = tmp0 - tmp299 tmp301 = triton_helpers.maximum(tmp300, tmp16) tmp302 = tmp1 - tmp299 tmp303 = triton_helpers.maximum(tmp302, tmp16) tmp304 = tmp301 + tmp303 tmp305 = tmp3 - tmp299 tmp306 = triton_helpers.maximum(tmp305, tmp16) tmp307 = tmp304 + tmp306 tmp308 = tmp5 - tmp299 tmp309 = triton_helpers.maximum(tmp308, tmp16) tmp310 = tmp307 + tmp309 tmp311 = tmp310 - tmp7 tmp312 = tmp311 * tmp39 tmp313 = tmp312 >= tmp16 tmp314 = tl.where(tmp313, tmp299, tmp297) tl.store(in_out_ptr8 + x0, tmp314, xmask) @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_1(in_out_ptr16, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp31 = tl.load(in_ptr1 + x0, xmask) tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = 0.25 tmp8 = tmp6 - tmp7 tmp9 = 1.0 tmp10 = tmp6 - tmp9 tmp11 = tmp8 - tmp10 tmp12 = 0.5 tmp13 = tmp11 * tmp12 tmp14 = tmp13 * tmp12 tmp15 = tmp14 * tmp12 tmp16 = tmp15 * tmp12 tmp17 = tmp16 * tmp12 tmp18 = tmp17 * tmp12 tmp19 = tmp18 * tmp12 tmp20 = tmp19 * tmp12 tmp21 = tmp20 * tmp12 tmp22 = tmp21 * tmp12 tmp23 = tmp22 * tmp12 tmp24 = tmp23 * tmp12 tmp25 = tmp24 * tmp12 tmp26 = tmp25 * tmp12 tmp27 = tmp26 * tmp12 tmp28 = tmp27 * tmp12 tmp29 = tmp28 * tmp12 tmp30 = tmp29 * tmp12 tmp32 = tmp31 + tmp30 tmp33 = tmp0 - tmp32 tmp34 = 0.0 tmp35 = triton_helpers.maximum(tmp33, tmp34) tmp36 = tmp1 - tmp32 tmp37 = triton_helpers.maximum(tmp36, tmp34) tmp38 = tmp35 + tmp37 tmp39 = tmp3 - tmp32 tmp40 = triton_helpers.maximum(tmp39, tmp34) tmp41 = tmp38 + tmp40 tmp42 = tmp5 - tmp32 tmp43 = triton_helpers.maximum(tmp42, tmp34) tmp44 = tmp41 + tmp43 tmp45 = tmp44 - tmp9 tmp46 = tmp0 - tmp10 tmp47 = triton_helpers.maximum(tmp46, tmp34) tmp48 = tmp1 - tmp10 tmp49 = triton_helpers.maximum(tmp48, tmp34) tmp50 = tmp47 + tmp49 tmp51 = tmp3 - tmp10 tmp52 = triton_helpers.maximum(tmp51, tmp34) tmp53 = tmp50 + tmp52 tmp54 = tmp5 - tmp10 tmp55 = triton_helpers.maximum(tmp54, tmp34) tmp56 = tmp53 + tmp55 tmp57 = tmp56 - tmp9 tmp58 = tmp45 * tmp57 tmp59 = tmp58 >= tmp34 tmp60 = tl.where(tmp59, tmp32, tmp31) tmp61 = tmp30 * tmp12 tmp62 = tmp60 + tmp61 tmp63 = tmp0 - tmp62 tmp64 = triton_helpers.maximum(tmp63, tmp34) tmp65 = tmp1 - tmp62 tmp66 = triton_helpers.maximum(tmp65, tmp34) tmp67 = tmp64 + tmp66 tmp68 = tmp3 - tmp62 tmp69 = triton_helpers.maximum(tmp68, tmp34) tmp70 = tmp67 + tmp69 tmp71 = tmp5 - tmp62 tmp72 = triton_helpers.maximum(tmp71, tmp34) tmp73 = tmp70 + tmp72 tmp74 = tmp73 - tmp9 tmp75 = tmp74 * tmp57 tmp76 = tmp75 >= tmp34 tmp77 = tl.where(tmp76, tmp62, tmp60) tmp78 = tmp61 * tmp12 tmp79 = tmp77 + tmp78 tmp80 = tmp0 - tmp79 tmp81 = triton_helpers.maximum(tmp80, tmp34) tmp82 = tmp1 - tmp79 tmp83 = triton_helpers.maximum(tmp82, tmp34) tmp84 = tmp81 + tmp83 tmp85 = tmp3 - tmp79 tmp86 = triton_helpers.maximum(tmp85, tmp34) tmp87 = tmp84 + tmp86 tmp88 = tmp5 - tmp79 tmp89 = triton_helpers.maximum(tmp88, tmp34) tmp90 = tmp87 + tmp89 tmp91 = tmp90 - tmp9 tmp92 = tmp91 * tmp57 tmp93 = tmp92 >= tmp34 tmp94 = tl.where(tmp93, tmp79, tmp77) tmp95 = tmp78 * tmp12 tmp96 = tmp94 + tmp95 tmp97 = tmp0 - tmp96 tmp98 = triton_helpers.maximum(tmp97, tmp34) tmp99 = tmp1 - tmp96 tmp100 = triton_helpers.maximum(tmp99, tmp34) tmp101 = tmp98 + tmp100 tmp102 = tmp3 - tmp96 tmp103 = triton_helpers.maximum(tmp102, tmp34) tmp104 = tmp101 + tmp103 tmp105 = tmp5 - tmp96 tmp106 = triton_helpers.maximum(tmp105, tmp34) tmp107 = tmp104 + tmp106 tmp108 = tmp107 - tmp9 tmp109 = tmp108 * tmp57 tmp110 = tmp109 >= tmp34 tmp111 = tl.where(tmp110, tmp96, tmp94) tmp112 = tmp95 * tmp12 tmp113 = tmp111 + tmp112 tmp114 = tmp0 - tmp113 tmp115 = triton_helpers.maximum(tmp114, tmp34) tmp116 = tmp1 - tmp113 tmp117 = triton_helpers.maximum(tmp116, tmp34) tmp118 = tmp115 + tmp117 tmp119 = tmp3 - tmp113 tmp120 = triton_helpers.maximum(tmp119, tmp34) tmp121 = tmp118 + tmp120 tmp122 = tmp5 - tmp113 tmp123 = triton_helpers.maximum(tmp122, tmp34) tmp124 = tmp121 + tmp123 tmp125 = tmp124 - tmp9 tmp126 = tmp125 * tmp57 tmp127 = tmp126 >= tmp34 tmp128 = tl.where(tmp127, tmp113, tmp111) tmp129 = tmp112 * tmp12 tmp130 = tmp128 + tmp129 tmp131 = tmp0 - tmp130 tmp132 = triton_helpers.maximum(tmp131, tmp34) tmp133 = tmp1 - tmp130 tmp134 = triton_helpers.maximum(tmp133, tmp34) tmp135 = tmp132 + tmp134 tmp136 = tmp3 - tmp130 tmp137 = triton_helpers.maximum(tmp136, tmp34) tmp138 = tmp135 + tmp137 tmp139 = tmp5 - tmp130 tmp140 = triton_helpers.maximum(tmp139, tmp34) tmp141 = tmp138 + tmp140 tmp142 = tmp141 - tmp9 tmp143 = tmp142 * tmp57 tmp144 = tmp143 >= tmp34 tmp145 = tl.where(tmp144, tmp130, tmp128) tmp146 = tmp129 * tmp12 tmp147 = tmp145 + tmp146 tmp148 = tmp0 - tmp147 tmp149 = triton_helpers.maximum(tmp148, tmp34) tmp150 = tmp1 - tmp147 tmp151 = triton_helpers.maximum(tmp150, tmp34) tmp152 = tmp149 + tmp151 tmp153 = tmp3 - tmp147 tmp154 = triton_helpers.maximum(tmp153, tmp34) tmp155 = tmp152 + tmp154 tmp156 = tmp5 - tmp147 tmp157 = triton_helpers.maximum(tmp156, tmp34) tmp158 = tmp155 + tmp157 tmp159 = tmp158 - tmp9 tmp160 = tmp159 * tmp57 tmp161 = tmp160 >= tmp34 tmp162 = tl.where(tmp161, tmp147, tmp145) tmp163 = tmp146 * tmp12 tmp164 = tmp162 + tmp163 tmp165 = tmp0 - tmp164 tmp166 = triton_helpers.maximum(tmp165, tmp34) tmp167 = tmp1 - tmp164 tmp168 = triton_helpers.maximum(tmp167, tmp34) tmp169 = tmp166 + tmp168 tmp170 = tmp3 - tmp164 tmp171 = triton_helpers.maximum(tmp170, tmp34) tmp172 = tmp169 + tmp171 tmp173 = tmp5 - tmp164 tmp174 = triton_helpers.maximum(tmp173, tmp34) tmp175 = tmp172 + tmp174 tmp176 = tmp175 - tmp9 tmp177 = tmp176 * tmp57 tmp178 = tmp177 >= tmp34 tmp179 = tl.where(tmp178, tmp164, tmp162) tmp180 = tmp163 * tmp12 tmp181 = tmp179 + tmp180 tmp182 = tmp0 - tmp181 tmp183 = triton_helpers.maximum(tmp182, tmp34) tmp184 = tmp1 - tmp181 tmp185 = triton_helpers.maximum(tmp184, tmp34) tmp186 = tmp183 + tmp185 tmp187 = tmp3 - tmp181 tmp188 = triton_helpers.maximum(tmp187, tmp34) tmp189 = tmp186 + tmp188 tmp190 = tmp5 - tmp181 tmp191 = triton_helpers.maximum(tmp190, tmp34) tmp192 = tmp189 + tmp191 tmp193 = tmp192 - tmp9 tmp194 = tmp193 * tmp57 tmp195 = tmp194 >= tmp34 tmp196 = tl.where(tmp195, tmp181, tmp179) tmp197 = tmp180 * tmp12 tmp198 = tmp196 + tmp197 tmp199 = tmp0 - tmp198 tmp200 = triton_helpers.maximum(tmp199, tmp34) tmp201 = tmp1 - tmp198 tmp202 = triton_helpers.maximum(tmp201, tmp34) tmp203 = tmp200 + tmp202 tmp204 = tmp3 - tmp198 tmp205 = triton_helpers.maximum(tmp204, tmp34) tmp206 = tmp203 + tmp205 tmp207 = tmp5 - tmp198 tmp208 = triton_helpers.maximum(tmp207, tmp34) tmp209 = tmp206 + tmp208 tmp210 = tmp209 - tmp9 tmp211 = tmp210 * tmp57 tmp212 = tmp211 >= tmp34 tmp213 = tl.where(tmp212, tmp198, tmp196) tmp214 = tmp197 * tmp12 tmp215 = tmp213 + tmp214 tmp216 = tmp0 - tmp215 tmp217 = triton_helpers.maximum(tmp216, tmp34) tmp218 = tmp1 - tmp215 tmp219 = triton_helpers.maximum(tmp218, tmp34) tmp220 = tmp217 + tmp219 tmp221 = tmp3 - tmp215 tmp222 = triton_helpers.maximum(tmp221, tmp34) tmp223 = tmp220 + tmp222 tmp224 = tmp5 - tmp215 tmp225 = triton_helpers.maximum(tmp224, tmp34) tmp226 = tmp223 + tmp225 tmp227 = tmp226 - tmp9 tmp228 = tmp227 * tmp57 tmp229 = tmp228 >= tmp34 tmp230 = tl.where(tmp229, tmp215, tmp213) tmp231 = tmp214 * tmp12 tmp232 = tmp230 + tmp231 tmp233 = tmp0 - tmp232 tmp234 = triton_helpers.maximum(tmp233, tmp34) tmp235 = tmp1 - tmp232 tmp236 = triton_helpers.maximum(tmp235, tmp34) tmp237 = tmp234 + tmp236 tmp238 = tmp3 - tmp232 tmp239 = triton_helpers.maximum(tmp238, tmp34) tmp240 = tmp237 + tmp239 tmp241 = tmp5 - tmp232 tmp242 = triton_helpers.maximum(tmp241, tmp34) tmp243 = tmp240 + tmp242 tmp244 = tmp243 - tmp9 tmp245 = tmp244 * tmp57 tmp246 = tmp245 >= tmp34 tmp247 = tl.where(tmp246, tmp232, tmp230) tmp248 = tmp231 * tmp12 tmp249 = tmp247 + tmp248 tmp250 = tmp0 - tmp249 tmp251 = triton_helpers.maximum(tmp250, tmp34) tmp252 = tmp1 - tmp249 tmp253 = triton_helpers.maximum(tmp252, tmp34) tmp254 = tmp251 + tmp253 tmp255 = tmp3 - tmp249 tmp256 = triton_helpers.maximum(tmp255, tmp34) tmp257 = tmp254 + tmp256 tmp258 = tmp5 - tmp249 tmp259 = triton_helpers.maximum(tmp258, tmp34) tmp260 = tmp257 + tmp259 tmp261 = tmp260 - tmp9 tmp262 = tmp261 * tmp57 tmp263 = tmp262 >= tmp34 tmp264 = tl.where(tmp263, tmp249, tmp247) tmp265 = tmp248 * tmp12 tmp266 = tmp264 + tmp265 tmp267 = tmp0 - tmp266 tmp268 = triton_helpers.maximum(tmp267, tmp34) tmp269 = tmp1 - tmp266 tmp270 = triton_helpers.maximum(tmp269, tmp34) tmp271 = tmp268 + tmp270 tmp272 = tmp3 - tmp266 tmp273 = triton_helpers.maximum(tmp272, tmp34) tmp274 = tmp271 + tmp273 tmp275 = tmp5 - tmp266 tmp276 = triton_helpers.maximum(tmp275, tmp34) tmp277 = tmp274 + tmp276 tmp278 = tmp277 - tmp9 tmp279 = tmp278 * tmp57 tmp280 = tmp279 >= tmp34 tmp281 = tl.where(tmp280, tmp266, tmp264) tmp282 = tmp265 * tmp12 tmp283 = tmp281 + tmp282 tmp284 = tmp0 - tmp283 tmp285 = triton_helpers.maximum(tmp284, tmp34) tmp286 = tmp1 - tmp283 tmp287 = triton_helpers.maximum(tmp286, tmp34) tmp288 = tmp285 + tmp287 tmp289 = tmp3 - tmp283 tmp290 = triton_helpers.maximum(tmp289, tmp34) tmp291 = tmp288 + tmp290 tmp292 = tmp5 - tmp283 tmp293 = triton_helpers.maximum(tmp292, tmp34) tmp294 = tmp291 + tmp293 tmp295 = tmp294 - tmp9 tmp296 = tmp295 * tmp57 tmp297 = tmp296 >= tmp34 tmp298 = tl.where(tmp297, tmp283, tmp281) tmp299 = tmp282 * tmp12 tmp300 = tmp298 + tmp299 tmp301 = tmp0 - tmp300 tmp302 = triton_helpers.maximum(tmp301, tmp34) tmp303 = tmp1 - tmp300 tmp304 = triton_helpers.maximum(tmp303, tmp34) tmp305 = tmp302 + tmp304 tmp306 = tmp3 - tmp300 tmp307 = triton_helpers.maximum(tmp306, tmp34) tmp308 = tmp305 + tmp307 tmp309 = tmp5 - tmp300 tmp310 = triton_helpers.maximum(tmp309, tmp34) tmp311 = tmp308 + tmp310 tmp312 = tmp311 - tmp9 tmp313 = tmp312 * tmp57 tmp314 = tmp313 >= tmp34 tmp315 = tl.where(tmp314, tmp300, tmp298) tmp316 = tmp299 * tmp12 tmp317 = tmp315 + tmp316 tmp318 = tmp0 - tmp317 tmp319 = triton_helpers.maximum(tmp318, tmp34) tmp320 = tmp1 - tmp317 tmp321 = triton_helpers.maximum(tmp320, tmp34) tmp322 = tmp319 + tmp321 tmp323 = tmp3 - tmp317 tmp324 = triton_helpers.maximum(tmp323, tmp34) tmp325 = tmp322 + tmp324 tmp326 = tmp5 - tmp317 tmp327 = triton_helpers.maximum(tmp326, tmp34) tmp328 = tmp325 + tmp327 tmp329 = tmp328 - tmp9 tmp330 = tmp329 * tmp57 tmp331 = tmp330 >= tmp34 tmp332 = tl.where(tmp331, tmp317, tmp315) tmp333 = tmp316 * tmp12 tmp334 = tmp332 + tmp333 tmp335 = tmp0 - tmp334 tmp336 = triton_helpers.maximum(tmp335, tmp34) tmp337 = tmp1 - tmp334 tmp338 = triton_helpers.maximum(tmp337, tmp34) tmp339 = tmp336 + tmp338 tmp340 = tmp3 - tmp334 tmp341 = triton_helpers.maximum(tmp340, tmp34) tmp342 = tmp339 + tmp341 tmp343 = tmp5 - tmp334 tmp344 = triton_helpers.maximum(tmp343, tmp34) tmp345 = tmp342 + tmp344 tmp346 = tmp345 - tmp9 tmp347 = tmp346 * tmp57 tmp348 = tmp347 >= tmp34 tmp349 = tl.where(tmp348, tmp334, tmp332) tmp350 = tmp333 * tmp12 tmp351 = tmp349 + tmp350 tmp352 = tmp0 - tmp351 tmp353 = triton_helpers.maximum(tmp352, tmp34) tmp354 = tmp1 - tmp351 tmp355 = triton_helpers.maximum(tmp354, tmp34) tmp356 = tmp353 + tmp355 tmp357 = tmp3 - tmp351 tmp358 = triton_helpers.maximum(tmp357, tmp34) tmp359 = tmp356 + tmp358 tmp360 = tmp5 - tmp351 tmp361 = triton_helpers.maximum(tmp360, tmp34) tmp362 = tmp359 + tmp361 tmp363 = tmp362 - tmp9 tmp364 = tmp363 * tmp57 tmp365 = tmp364 >= tmp34 tmp366 = tl.where(tmp365, tmp351, tmp349) tmp367 = tmp350 * tmp12 tmp368 = tmp366 + tmp367 tmp369 = tmp0 - tmp368 tmp370 = triton_helpers.maximum(tmp369, tmp34) tmp371 = tmp1 - tmp368 tmp372 = triton_helpers.maximum(tmp371, tmp34) tmp373 = tmp370 + tmp372 tmp374 = tmp3 - tmp368 tmp375 = triton_helpers.maximum(tmp374, tmp34) tmp376 = tmp373 + tmp375 tmp377 = tmp5 - tmp368 tmp378 = triton_helpers.maximum(tmp377, tmp34) tmp379 = tmp376 + tmp378 tmp380 = tmp379 - tmp9 tmp381 = tmp380 * tmp57 tmp382 = tmp381 >= tmp34 tmp383 = tl.where(tmp382, tmp368, tmp366) tmp384 = tmp367 * tmp12 tmp385 = tmp383 + tmp384 tmp386 = tmp0 - tmp385 tmp387 = triton_helpers.maximum(tmp386, tmp34) tmp388 = tmp1 - tmp385 tmp389 = triton_helpers.maximum(tmp388, tmp34) tmp390 = tmp387 + tmp389 tmp391 = tmp3 - tmp385 tmp392 = triton_helpers.maximum(tmp391, tmp34) tmp393 = tmp390 + tmp392 tmp394 = tmp5 - tmp385 tmp395 = triton_helpers.maximum(tmp394, tmp34) tmp396 = tmp393 + tmp395 tmp397 = tmp396 - tmp9 tmp398 = tmp397 * tmp57 tmp399 = tmp398 >= tmp34 tmp400 = tl.where(tmp399, tmp385, tmp383) tmp401 = tmp384 * tmp12 tmp402 = tmp400 + tmp401 tmp403 = tmp0 - tmp402 tmp404 = triton_helpers.maximum(tmp403, tmp34) tmp405 = tmp1 - tmp402 tmp406 = triton_helpers.maximum(tmp405, tmp34) tmp407 = tmp404 + tmp406 tmp408 = tmp3 - tmp402 tmp409 = triton_helpers.maximum(tmp408, tmp34) tmp410 = tmp407 + tmp409 tmp411 = tmp5 - tmp402 tmp412 = triton_helpers.maximum(tmp411, tmp34) tmp413 = tmp410 + tmp412 tmp414 = tmp413 - tmp9 tmp415 = tmp414 * tmp57 tmp416 = tmp415 >= tmp34 tmp417 = tl.where(tmp416, tmp402, tmp400) tmp418 = tmp401 * tmp12 tmp419 = tmp417 + tmp418 tmp420 = tmp0 - tmp419 tmp421 = triton_helpers.maximum(tmp420, tmp34) tmp422 = tmp1 - tmp419 tmp423 = triton_helpers.maximum(tmp422, tmp34) tmp424 = tmp421 + tmp423 tmp425 = tmp3 - tmp419 tmp426 = triton_helpers.maximum(tmp425, tmp34) tmp427 = tmp424 + tmp426 tmp428 = tmp5 - tmp419 tmp429 = triton_helpers.maximum(tmp428, tmp34) tmp430 = tmp427 + tmp429 tmp431 = tmp430 - tmp9 tmp432 = tmp431 * tmp57 tmp433 = tmp432 >= tmp34 tmp434 = tl.where(tmp433, tmp419, tmp417) tl.store(out_ptr0 + x0, tmp30, xmask) tl.store(in_out_ptr16 + x0, tmp434, xmask) @triton.jit def triton_poi_fused_add_clamp_div_sub_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) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tmp4 * tmp3 tmp6 = tmp5 * tmp3 tmp7 = tmp6 * tmp3 tmp8 = tmp7 * tmp3 tmp9 = tmp8 * tmp3 tmp10 = tmp9 * tmp3 tmp11 = tmp10 * tmp3 tmp12 = tmp11 * tmp3 tmp13 = tmp12 * tmp3 tmp14 = tmp13 * tmp3 tmp15 = tmp14 * tmp3 tmp16 = tmp15 * tmp3 tmp17 = tmp16 * tmp3 tmp18 = tmp17 * tmp3 tmp19 = tmp18 * tmp3 tmp20 = tmp19 * tmp3 tmp21 = tmp20 * tmp3 tmp22 = tmp21 * tmp3 tmp23 = tmp22 * tmp3 tmp24 = tmp23 * tmp3 tmp25 = tmp24 * tmp3 tmp26 = tmp25 * tmp3 tmp27 = tmp1 + tmp26 tmp28 = tmp0 - tmp27 tmp29 = 0.0 tmp30 = triton_helpers.maximum(tmp28, tmp29) tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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') tmp9 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_out_ptr0 + x0, xmask) tmp33 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp13 = triton_helpers.maximum(tmp11, tmp12) tmp15 = triton_helpers.maximum(tmp13, tmp14) tmp16 = tmp15 - tmp7 tmp17 = tmp9 - tmp16 tmp18 = 0.0 tmp19 = triton_helpers.maximum(tmp17, tmp18) tmp20 = tmp10 - tmp16 tmp21 = triton_helpers.maximum(tmp20, tmp18) tmp22 = tmp19 + tmp21 tmp23 = tmp12 - tmp16 tmp24 = triton_helpers.maximum(tmp23, tmp18) tmp25 = tmp22 + tmp24 tmp26 = tmp14 - tmp16 tmp27 = triton_helpers.maximum(tmp26, tmp18) tmp28 = tmp25 + tmp27 tmp29 = tmp28 - tmp7 tmp30 = tmp8 * tmp29 tmp31 = tmp30 >= tmp18 tmp34 = 0.5 tmp35 = tmp33 * tmp34 tmp36 = tmp35 * tmp34 tmp37 = tmp36 * tmp34 tmp38 = tmp37 * tmp34 tmp39 = tmp38 * tmp34 tmp40 = tmp39 * tmp34 tmp41 = tmp40 * tmp34 tmp42 = tmp41 * tmp34 tmp43 = tmp42 * tmp34 tmp44 = tmp43 * tmp34 tmp45 = tmp44 * tmp34 tmp46 = tmp45 * tmp34 tmp47 = tmp46 * tmp34 tmp48 = tmp47 * tmp34 tmp49 = tmp48 * tmp34 tmp50 = tmp49 * tmp34 tmp51 = tmp50 * tmp34 tmp52 = tmp51 * tmp34 tmp53 = tmp52 * tmp34 tmp54 = tmp53 * tmp34 tmp55 = tmp54 * tmp34 tmp56 = tmp55 * tmp34 tmp57 = tmp56 * tmp34 tmp58 = tmp32 + tmp57 tmp59 = tl.where(tmp31, tmp58, tmp32) tl.store(in_out_ptr0 + x0, tmp59, xmask) @triton.jit def triton_poi_fused_add_clamp_div_sub_4(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) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tmp4 * tmp3 tmp6 = tmp5 * tmp3 tmp7 = tmp6 * tmp3 tmp8 = tmp7 * tmp3 tmp9 = tmp8 * tmp3 tmp10 = tmp9 * tmp3 tmp11 = tmp10 * tmp3 tmp12 = tmp11 * tmp3 tmp13 = tmp12 * tmp3 tmp14 = tmp13 * tmp3 tmp15 = tmp14 * tmp3 tmp16 = tmp15 * tmp3 tmp17 = tmp16 * tmp3 tmp18 = tmp17 * tmp3 tmp19 = tmp18 * tmp3 tmp20 = tmp19 * tmp3 tmp21 = tmp20 * tmp3 tmp22 = tmp21 * tmp3 tmp23 = tmp22 * tmp3 tmp24 = tmp23 * tmp3 tmp25 = tmp24 * tmp3 tmp26 = tmp25 * tmp3 tmp27 = tmp26 * tmp3 tmp28 = tmp1 + tmp27 tmp29 = tmp0 - tmp28 tmp30 = 0.0 tmp31 = triton_helpers.maximum(tmp29, tmp30) tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_5(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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') tmp9 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_out_ptr0 + x0, xmask) tmp33 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp13 = triton_helpers.maximum(tmp11, tmp12) tmp15 = triton_helpers.maximum(tmp13, tmp14) tmp16 = tmp15 - tmp7 tmp17 = tmp9 - tmp16 tmp18 = 0.0 tmp19 = triton_helpers.maximum(tmp17, tmp18) tmp20 = tmp10 - tmp16 tmp21 = triton_helpers.maximum(tmp20, tmp18) tmp22 = tmp19 + tmp21 tmp23 = tmp12 - tmp16 tmp24 = triton_helpers.maximum(tmp23, tmp18) tmp25 = tmp22 + tmp24 tmp26 = tmp14 - tmp16 tmp27 = triton_helpers.maximum(tmp26, tmp18) tmp28 = tmp25 + tmp27 tmp29 = tmp28 - tmp7 tmp30 = tmp8 * tmp29 tmp31 = tmp30 >= tmp18 tmp34 = 0.5 tmp35 = tmp33 * tmp34 tmp36 = tmp35 * tmp34 tmp37 = tmp36 * tmp34 tmp38 = tmp37 * tmp34 tmp39 = tmp38 * tmp34 tmp40 = tmp39 * tmp34 tmp41 = tmp40 * tmp34 tmp42 = tmp41 * tmp34 tmp43 = tmp42 * tmp34 tmp44 = tmp43 * tmp34 tmp45 = tmp44 * tmp34 tmp46 = tmp45 * tmp34 tmp47 = tmp46 * tmp34 tmp48 = tmp47 * tmp34 tmp49 = tmp48 * tmp34 tmp50 = tmp49 * tmp34 tmp51 = tmp50 * tmp34 tmp52 = tmp51 * tmp34 tmp53 = tmp52 * tmp34 tmp54 = tmp53 * tmp34 tmp55 = tmp54 * tmp34 tmp56 = tmp55 * tmp34 tmp57 = tmp56 * tmp34 tmp58 = tmp57 * tmp34 tmp59 = tmp32 + tmp58 tmp60 = tl.where(tmp31, tmp59, tmp32) tl.store(in_out_ptr0 + x0, tmp60, xmask) @triton.jit def triton_poi_fused_add_div_sub_6(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) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tmp4 * tmp3 tmp6 = tmp5 * tmp3 tmp7 = tmp6 * tmp3 tmp8 = tmp7 * tmp3 tmp9 = tmp8 * tmp3 tmp10 = tmp9 * tmp3 tmp11 = tmp10 * tmp3 tmp12 = tmp11 * tmp3 tmp13 = tmp12 * tmp3 tmp14 = tmp13 * tmp3 tmp15 = tmp14 * tmp3 tmp16 = tmp15 * tmp3 tmp17 = tmp16 * tmp3 tmp18 = tmp17 * tmp3 tmp19 = tmp18 * tmp3 tmp20 = tmp19 * tmp3 tmp21 = tmp20 * tmp3 tmp22 = tmp21 * tmp3 tmp23 = tmp22 * tmp3 tmp24 = tmp23 * tmp3 tmp25 = tmp24 * tmp3 tmp26 = tmp25 * tmp3 tmp27 = tmp26 * tmp3 tmp28 = tmp27 * tmp3 tmp29 = tmp1 + tmp28 tmp30 = tmp0 - tmp29 tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_7(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp36 = tl.load(in_out_ptr0 + x0, xmask) tmp37 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp3, tmp1) tmp5 = tmp2 + tmp4 tmp7 = triton_helpers.maximum(tmp6, tmp1) tmp8 = tmp5 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 - tmp12 tmp16 = triton_helpers.maximum(tmp14, tmp15) tmp18 = triton_helpers.maximum(tmp16, tmp17) tmp20 = triton_helpers.maximum(tmp18, tmp19) tmp21 = tmp20 - tmp12 tmp22 = tmp14 - tmp21 tmp23 = triton_helpers.maximum(tmp22, tmp1) tmp24 = tmp15 - tmp21 tmp25 = triton_helpers.maximum(tmp24, tmp1) tmp26 = tmp23 + tmp25 tmp27 = tmp17 - tmp21 tmp28 = triton_helpers.maximum(tmp27, tmp1) tmp29 = tmp26 + tmp28 tmp30 = tmp19 - tmp21 tmp31 = triton_helpers.maximum(tmp30, tmp1) tmp32 = tmp29 + tmp31 tmp33 = tmp32 - tmp12 tmp34 = tmp13 * tmp33 tmp35 = tmp34 >= tmp1 tmp38 = 0.5 tmp39 = tmp37 * tmp38 tmp40 = tmp39 * tmp38 tmp41 = tmp40 * tmp38 tmp42 = tmp41 * tmp38 tmp43 = tmp42 * tmp38 tmp44 = tmp43 * tmp38 tmp45 = tmp44 * tmp38 tmp46 = tmp45 * tmp38 tmp47 = tmp46 * tmp38 tmp48 = tmp47 * tmp38 tmp49 = tmp48 * tmp38 tmp50 = tmp49 * tmp38 tmp51 = tmp50 * tmp38 tmp52 = tmp51 * tmp38 tmp53 = tmp52 * tmp38 tmp54 = tmp53 * tmp38 tmp55 = tmp54 * tmp38 tmp56 = tmp55 * tmp38 tmp57 = tmp56 * tmp38 tmp58 = tmp57 * tmp38 tmp59 = tmp58 * tmp38 tmp60 = tmp59 * tmp38 tmp61 = tmp60 * tmp38 tmp62 = tmp61 * tmp38 tmp63 = tmp62 * tmp38 tmp64 = tmp36 + tmp63 tmp65 = tl.where(tmp35, tmp64, tmp36) tl.store(in_out_ptr0 + x0, tmp65, xmask) @triton.jit def triton_poi_fused_add_div_sub_8(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) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tmp4 * tmp3 tmp6 = tmp5 * tmp3 tmp7 = tmp6 * tmp3 tmp8 = tmp7 * tmp3 tmp9 = tmp8 * tmp3 tmp10 = tmp9 * tmp3 tmp11 = tmp10 * tmp3 tmp12 = tmp11 * tmp3 tmp13 = tmp12 * tmp3 tmp14 = tmp13 * tmp3 tmp15 = tmp14 * tmp3 tmp16 = tmp15 * tmp3 tmp17 = tmp16 * tmp3 tmp18 = tmp17 * tmp3 tmp19 = tmp18 * tmp3 tmp20 = tmp19 * tmp3 tmp21 = tmp20 * tmp3 tmp22 = tmp21 * tmp3 tmp23 = tmp22 * tmp3 tmp24 = tmp23 * tmp3 tmp25 = tmp24 * tmp3 tmp26 = tmp25 * tmp3 tmp27 = tmp26 * tmp3 tmp28 = tmp27 * tmp3 tmp29 = tmp28 * tmp3 tmp30 = tmp1 + tmp29 tmp31 = tmp0 - tmp30 tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_9(in_out_ptr0, in_out_ptr2, in_ptr0, in_ptr1, in_ptr2, out_ptr4, out_ptr7, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp36 = tl.load(in_out_ptr0 + x0, xmask) tmp37 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp3, tmp1) tmp5 = tmp2 + tmp4 tmp7 = triton_helpers.maximum(tmp6, tmp1) tmp8 = tmp5 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 - tmp12 tmp16 = triton_helpers.maximum(tmp14, tmp15) tmp18 = triton_helpers.maximum(tmp16, tmp17) tmp20 = triton_helpers.maximum(tmp18, tmp19) tmp21 = tmp20 - tmp12 tmp22 = tmp14 - tmp21 tmp23 = triton_helpers.maximum(tmp22, tmp1) tmp24 = tmp15 - tmp21 tmp25 = triton_helpers.maximum(tmp24, tmp1) tmp26 = tmp23 + tmp25 tmp27 = tmp17 - tmp21 tmp28 = triton_helpers.maximum(tmp27, tmp1) tmp29 = tmp26 + tmp28 tmp30 = tmp19 - tmp21 tmp31 = triton_helpers.maximum(tmp30, tmp1) tmp32 = tmp29 + tmp31 tmp33 = tmp32 - tmp12 tmp34 = tmp13 * tmp33 tmp35 = tmp34 >= tmp1 tmp38 = 0.5 tmp39 = tmp37 * tmp38 tmp40 = tmp39 * tmp38 tmp41 = tmp40 * tmp38 tmp42 = tmp41 * tmp38 tmp43 = tmp42 * tmp38 tmp44 = tmp43 * tmp38 tmp45 = tmp44 * tmp38 tmp46 = tmp45 * tmp38 tmp47 = tmp46 * tmp38 tmp48 = tmp47 * tmp38 tmp49 = tmp48 * tmp38 tmp50 = tmp49 * tmp38 tmp51 = tmp50 * tmp38 tmp52 = tmp51 * tmp38 tmp53 = tmp52 * tmp38 tmp54 = tmp53 * tmp38 tmp55 = tmp54 * tmp38 tmp56 = tmp55 * tmp38 tmp57 = tmp56 * tmp38 tmp58 = tmp57 * tmp38 tmp59 = tmp58 * tmp38 tmp60 = tmp59 * tmp38 tmp61 = tmp60 * tmp38 tmp62 = tmp61 * tmp38 tmp63 = tmp62 * tmp38 tmp64 = tmp63 * tmp38 tmp65 = tmp36 + tmp64 tmp66 = tl.where(tmp35, tmp65, tmp36) tmp67 = tmp64 * tmp38 tmp68 = tmp66 + tmp67 tmp69 = tmp14 - tmp68 tmp70 = triton_helpers.maximum(tmp69, tmp1) tmp71 = tmp15 - tmp68 tmp72 = triton_helpers.maximum(tmp71, tmp1) tmp73 = tmp70 + tmp72 tmp74 = tmp17 - tmp68 tmp75 = triton_helpers.maximum(tmp74, tmp1) tmp76 = tmp73 + tmp75 tmp77 = tmp19 - tmp68 tmp78 = triton_helpers.maximum(tmp77, tmp1) tmp79 = tmp76 + tmp78 tmp80 = tmp79 - tmp12 tmp81 = tmp80 * tmp33 tmp82 = tmp81 >= tmp1 tmp83 = tl.where(tmp82, tmp68, tmp66) tmp84 = tmp67 * tmp38 tmp85 = tmp83 + tmp84 tmp86 = tmp14 - tmp85 tmp87 = triton_helpers.maximum(tmp86, tmp1) tmp88 = tmp15 - tmp85 tmp89 = triton_helpers.maximum(tmp88, tmp1) tmp90 = tmp87 + tmp89 tmp91 = tmp17 - tmp85 tmp92 = triton_helpers.maximum(tmp91, tmp1) tmp93 = tmp90 + tmp92 tmp94 = tmp19 - tmp85 tmp95 = triton_helpers.maximum(tmp94, tmp1) tmp96 = tmp93 + tmp95 tmp97 = tmp96 - tmp12 tmp98 = tmp97 * tmp33 tmp99 = tmp98 >= tmp1 tmp100 = tl.where(tmp99, tmp85, tmp83) tmp101 = tmp84 * tmp38 tmp102 = tmp100 + tmp101 tmp103 = tmp14 - tmp102 tmp104 = triton_helpers.maximum(tmp103, tmp1) tmp105 = tmp15 - tmp102 tmp106 = triton_helpers.maximum(tmp105, tmp1) tmp107 = tmp104 + tmp106 tmp108 = tmp17 - tmp102 tmp109 = triton_helpers.maximum(tmp108, tmp1) tmp110 = tmp107 + tmp109 tmp111 = tmp19 - tmp102 tmp112 = triton_helpers.maximum(tmp111, tmp1) tmp113 = tmp110 + tmp112 tmp114 = tmp113 - tmp12 tmp115 = tmp114 * tmp33 tmp116 = tmp115 >= tmp1 tmp117 = tl.where(tmp116, tmp102, tmp100) tmp118 = tmp101 * tmp38 tmp119 = tmp117 + tmp118 tmp120 = tmp14 - tmp119 tmp121 = triton_helpers.maximum(tmp120, tmp1) tmp122 = tmp15 - tmp119 tmp123 = triton_helpers.maximum(tmp122, tmp1) tmp124 = tmp121 + tmp123 tmp125 = tmp17 - tmp119 tmp126 = triton_helpers.maximum(tmp125, tmp1) tmp127 = tmp124 + tmp126 tmp128 = tmp19 - tmp119 tmp129 = triton_helpers.maximum(tmp128, tmp1) tmp130 = tmp127 + tmp129 tmp131 = tmp130 - tmp12 tmp132 = tmp131 * tmp33 tmp133 = tmp132 >= tmp1 tmp134 = tl.where(tmp133, tmp119, tmp117) tmp135 = tmp118 * tmp38 tmp136 = tmp134 + tmp135 tmp137 = tmp14 - tmp136 tmp138 = triton_helpers.maximum(tmp137, tmp1) tmp139 = tmp15 - tmp136 tmp140 = triton_helpers.maximum(tmp139, tmp1) tmp141 = tmp138 + tmp140 tmp142 = tmp17 - tmp136 tmp143 = triton_helpers.maximum(tmp142, tmp1) tmp144 = tmp141 + tmp143 tmp145 = tmp19 - tmp136 tmp146 = triton_helpers.maximum(tmp145, tmp1) tmp147 = tmp144 + tmp146 tmp148 = tmp147 - tmp12 tmp149 = tmp148 * tmp33 tmp150 = tmp149 >= tmp1 tmp151 = tl.where(tmp150, tmp136, tmp134) tmp152 = tmp135 * tmp38 tmp153 = tmp151 + tmp152 tmp154 = tmp14 - tmp153 tmp155 = triton_helpers.maximum(tmp154, tmp1) tmp156 = tmp15 - tmp153 tmp157 = triton_helpers.maximum(tmp156, tmp1) tmp158 = tmp155 + tmp157 tmp159 = tmp17 - tmp153 tmp160 = triton_helpers.maximum(tmp159, tmp1) tmp161 = tmp158 + tmp160 tmp162 = tmp19 - tmp153 tmp163 = triton_helpers.maximum(tmp162, tmp1) tmp164 = tmp161 + tmp163 tl.store(out_ptr4 + x0, tmp101, xmask) tl.store(in_out_ptr2 + x0, tmp151, xmask) tl.store(out_ptr7 + x0, tmp164, xmask) @triton.jit def triton_poi_fused_add_clamp_div_sub_10(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = tmp4 * tmp3 tmp6 = tmp5 * tmp3 tmp7 = tmp1 + tmp6 tmp8 = tmp0 - tmp7 tmp9 = 0.0 tmp10 = triton_helpers.maximum(tmp8, tmp9) tmp12 = tmp10 / tmp11 tl.store(out_ptr0 + x2, tmp12, 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) buf40 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf41 = reinterpret_tensor(buf40, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf40 get_raw_stream(0) triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_0[grid(64)](buf41, arg0_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf42 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf81 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf82 = reinterpret_tensor(buf81, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf81 triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_1[grid(64)](buf82, arg0_1, buf41, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1) buf83 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_clamp_div_sub_2[grid(256)](arg0_1, buf82, buf42, buf83, 256, XBLOCK=128, num_warps=4, num_stages=1) buf85 = buf82 del buf82 triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_3[grid(64)](buf85, buf83, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1) buf86 = buf83 del buf83 triton_poi_fused_add_clamp_div_sub_4[grid(256)](arg0_1, buf85, buf42, buf86, 256, XBLOCK=128, num_warps=4, num_stages=1) buf88 = buf85 del buf85 triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_5[grid(64)](buf88, buf86, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1) buf89 = buf86 del buf86 triton_poi_fused_add_div_sub_6[grid(256)](arg0_1, buf88, buf42, buf89, 256, XBLOCK=256, num_warps=4, num_stages=1) buf91 = buf88 del buf88 triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_7[grid(64)](buf91, buf89, arg0_1, buf42, 64, XBLOCK=64, num_warps=1, num_stages=1) buf92 = buf89 del buf89 triton_poi_fused_add_div_sub_8[grid(256)](arg0_1, buf91, buf42, buf92, 256, XBLOCK=256, num_warps=4, num_stages=1) buf94 = buf91 del buf91 buf100 = buf41 del buf41 buf103 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf104 = reinterpret_tensor(buf103, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf103 buf105 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_clamp_div_max_mul_sub_sum_where_9[grid(64)](buf94, buf104, buf92, arg0_1, buf42, buf100, buf105, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf42 del buf94 buf106 = buf92 del buf92 triton_poi_fused_add_clamp_div_sub_10[grid(256)](arg0_1, buf104, buf100, buf105, buf106, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del buf100 del buf104 del buf105 return buf106, def sparsemax_bisect(X, dim=-1, n_iter=50, ensure_sum_one=True): """sparsemax: normalizing sparse transform (a la softmax), via bisection. Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. ensure_sum_one : bool, Whether to divide the result by its sum. If false, the result might sum to close but not exactly 1, which might cause downstream problems. Note: This function does not yet support normalizing along anything except the last dimension. Please use transposing and views to achieve more general behavior. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxBisectFunction.apply(X, dim, n_iter, ensure_sum_one) class EntmaxBisectFunction(Function): @classmethod def _gp(cls, x, alpha): return x ** (alpha - 1) @classmethod def _gp_inv(cls, y, alpha): return y ** (1 / (alpha - 1)) @classmethod def _p(cls, X, alpha): return cls._gp_inv(torch.clamp(X, min=0), alpha) @classmethod def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True ): if not isinstance(alpha, torch.Tensor): alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device) alpha_shape = list(X.shape) alpha_shape[dim] = 1 alpha = alpha.expand(*alpha_shape) ctx.alpha = alpha ctx.dim = dim d = X.shape[dim] X = X * (alpha - 1) max_val, _ = X.max(dim=dim, keepdim=True) tau_lo = max_val - cls._gp(1, alpha) tau_hi = max_val - cls._gp(1 / d, alpha) f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1 dm = tau_hi - tau_lo for it in range(n_iter): dm /= 2 tau_m = tau_lo + dm p_m = cls._p(X - tau_m, alpha) f_m = p_m.sum(dim) - 1 mask = (f_m * f_lo >= 0).unsqueeze(dim) tau_lo = torch.where(mask, tau_m, tau_lo) if ensure_sum_one: p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim) ctx.save_for_backward(p_m) return p_m @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1)) dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr d_alpha = None if ctx.needs_input_grad[1]: S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1)) ent = S.sum(ctx.dim).unsqueeze(ctx.dim) Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim) d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2 d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1) d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim) return dX, d_alpha, None, None, None class SparsemaxBisectFunction(EntmaxBisectFunction): @classmethod def _gp(cls, x, alpha): return x @classmethod def _gp_inv(cls, y, alpha): return y @classmethod def _p(cls, x, alpha): return torch.clamp(x, min=0) @classmethod def forward(cls, ctx, X, dim=-1, n_iter=50, ensure_sum_one=True): return super().forward(ctx, X, alpha=2, dim=dim, n_iter=50, ensure_sum_one=True) @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y > 0 dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None, None class SparsemaxBisectNew(nn.Module): def __init__(self, dim=-1, n_iter=None): """sparsemax: normalizing sparse transform (a la softmax) via bisection Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. """ self.dim = dim self.n_iter = n_iter super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
roholazandie/entmax
SparsemaxBisect
false
7,626
[ "MIT" ]
1
657374e6a792ec6840b6f78bc759cc1f51570aad
https://github.com/roholazandie/entmax/tree/657374e6a792ec6840b6f78bc759cc1f51570aad
GPT2Layer
from _paritybench_helpers import _mock_config import torch import torch.nn as nn import torch.nn.functional as F class MultiHeadSelfAttention(nn.Module): def __init__(self, d_ipt: 'int', n_head: 'int', dropout_p: 'float'=0.1): super(MultiHeadSelfAttention, self).__init__() self.qkv_linear = nn.Linear(d_ipt, d_ipt * 3, True) self.n_head = n_head self.output_linear = nn.Linear(d_ipt, d_ipt, True) self.dropout = nn.Dropout(dropout_p) def forward(self, src: 'torch.FloatTensor', attn_mask: 'torch.FloatTensor' ) ->torch.FloatTensor: if attn_mask.dim() == 2: attn_mask = attn_mask.unsqueeze(0) if attn_mask.dim() == 3: attn_mask = attn_mask.unsqueeze(1) q, k, v = self.qkv_linear(src).chunk(3, dim=-1) q = q.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 1, 3) k = k.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 3, 1) v = v.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 1, 3) attn_weights = torch.matmul(q, k) attn_weights = attn_weights * float(src.shape[2] // self.n_head ) ** -0.5 attn_weights = attn_weights * attn_mask + (attn_mask - 1) * 10000.0 attn_weights = F.softmax(attn_weights, dim=-1) attn_weights = self.dropout(attn_weights) attn_output = torch.matmul(attn_weights, v) attn_output = attn_output.permute(0, 2, 1, 3).contiguous().view(src .shape) attn_output = self.output_linear(attn_output) return attn_output class GPT2Layer(nn.Module): def __init__(self, config: 'GPT2Config'): super(GPT2Layer, self).__init__() self.layer_norm1 = nn.LayerNorm(config.hidden_size) self.self_attn = MultiHeadSelfAttention(d_ipt=config.hidden_size, n_head=config.n_head, dropout_p=config.drop_out) self.layer_norm2 = nn.LayerNorm(config.hidden_size) self.intermediate_linear1 = nn.Linear(config.hidden_size, config. d_intermediate, True) self.intermediate_linear2 = nn.Linear(config.d_intermediate, config .hidden_size, True) self.dropout = nn.Dropout(config.drop_out) self.dropout1 = nn.Dropout(config.drop_out) self.dropout2 = nn.Dropout(config.drop_out) def forward(self, src: 'torch.FloatTensor', src_mask: 'torch.FloatTensor' ) ->torch.FloatTensor: src1 = self.layer_norm1(src) src1 = self.self_attn(src1, src_mask) src = src + self.dropout1(src1) src1 = self.layer_norm2(src) src1 = F.gelu(self.intermediate_linear1(src1)) src1 = self.intermediate_linear2(src1) src1 = self.dropout(src1) src = src + src1 return src def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4, n_head=4, drop_out= 0.5, d_intermediate=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-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (4 + y0), ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused__softmax_add_mul_sub_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp25 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last' ) tmp27 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 * tmp3 tmp5 = tmp3 - tmp1 tmp6 = 10000.0 tmp7 = tmp5 * tmp6 tmp8 = tmp4 + tmp7 tmp10 = tmp9 * tmp1 tmp12 = tmp10 * tmp11 tmp13 = tmp11 - tmp1 tmp14 = tmp13 * tmp6 tmp15 = tmp12 + tmp14 tmp16 = triton_helpers.maximum(tmp8, tmp15) tmp18 = tmp17 * tmp1 tmp20 = tmp18 * tmp19 tmp21 = tmp19 - tmp1 tmp22 = tmp21 * tmp6 tmp23 = tmp20 + tmp22 tmp24 = triton_helpers.maximum(tmp16, tmp23) tmp26 = tmp25 * tmp1 tmp28 = tmp26 * tmp27 tmp29 = tmp27 - tmp1 tmp30 = tmp29 * tmp6 tmp31 = tmp28 + tmp30 tmp32 = triton_helpers.maximum(tmp24, tmp31) tmp33 = tmp8 - tmp32 tmp34 = tl_math.exp(tmp33) tmp35 = tmp15 - tmp32 tmp36 = tl_math.exp(tmp35) tmp37 = tmp34 + tmp36 tmp38 = tmp23 - tmp32 tmp39 = tl_math.exp(tmp38) tmp40 = tmp37 + tmp39 tmp41 = tmp31 - tmp32 tmp42 = tl_math.exp(tmp41) tmp43 = tmp40 + tmp42 tl.store(out_ptr0 + x3, tmp32, xmask) tl.store(out_ptr1 + x3, tmp43, xmask) @triton.jit def triton_poi_fused__softmax_add_mul_sub_5(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 x4 = xindex x3 = xindex // 64 x5 = xindex % 16 x6 = xindex // 4 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp3 = tl.load(in_ptr0 + (x5 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr1 + x6, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr2 + x6, xmask, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 * tmp3 tmp5 = tmp3 - tmp1 tmp6 = 10000.0 tmp7 = tmp5 * tmp6 tmp8 = tmp4 + tmp7 tmp10 = tmp8 - tmp9 tmp11 = tl_math.exp(tmp10) tmp13 = tmp11 / tmp12 tl.store(in_out_ptr0 + x4, tmp13, xmask) @triton.jit def triton_poi_fused_clone_6(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (8 + y0), ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_7(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_8(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_9(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-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_gelu_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865476 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_11(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_out_ptr0 + x2, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tl.store(in_out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14) = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (12, 4), (4, 1)) assert_size_stride(primals_6, (12,), (1,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 4), (4, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 4), (4, 1)) assert_size_stride(primals_14, (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_3, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](primals_3, buf0, buf1, primals_1, primals_2, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 del primals_2 buf3 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 12), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_2[grid(16, 4)](buf3, primals_6, buf4, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32) triton_poi_fused_clone_3[grid(16, 4)](buf3, primals_6, buf5, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_add_mul_sub_4[grid(64)](buf6, primals_4, buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused__softmax_add_mul_sub_5[grid(256)](buf9, primals_4, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) buf10 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf8 triton_poi_fused_clone_6[grid(16, 4)](buf3, primals_6, buf10, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del buf3 del primals_6 buf11 = reinterpret_tensor(buf7, (16, 4, 1), (4, 1, 1), 0) del buf7 extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11) buf12 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_7[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf13 = reinterpret_tensor(buf11, (16, 4), (4, 1), 0) del buf11 extern_kernels.addmm(primals_8, reinterpret_tensor(buf12, (16, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf13) del primals_8 buf14 = buf1 del buf1 buf15 = buf0 del buf0 triton_poi_fused_add_native_layer_norm_8[grid(16)](primals_3, buf13, buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_9[grid(64)](primals_3, buf13, buf14, buf15, primals_9, primals_10, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf14 del buf15 del primals_10 buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_12, reinterpret_tensor(buf16, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf17) del primals_12 buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_gelu_10[grid(64)](buf17, buf18, 64, XBLOCK=64, num_warps=1, num_stages=1) buf19 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf18, (16, 4), (4, 1), 0), reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf19) buf20 = reinterpret_tensor(buf19, (4, 4, 4), (16, 4, 1), 0) del buf19 triton_poi_fused_add_11[grid(64)](buf20, primals_3, buf13, primals_14, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_14 return buf20, primals_3, primals_4, primals_9, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), buf9, reinterpret_tensor(buf12, (16, 4), (4, 1), 0 ), buf13, reinterpret_tensor(buf16, (16, 4), (4, 1), 0 ), buf17, reinterpret_tensor(buf18, (16, 4), (4, 1), 0 ), primals_13, primals_11, primals_7, reinterpret_tensor(buf10, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0), primals_5 class MultiHeadSelfAttention(nn.Module): def __init__(self, d_ipt: 'int', n_head: 'int', dropout_p: 'float'=0.1): super(MultiHeadSelfAttention, self).__init__() self.qkv_linear = nn.Linear(d_ipt, d_ipt * 3, True) self.n_head = n_head self.output_linear = nn.Linear(d_ipt, d_ipt, True) self.dropout = nn.Dropout(dropout_p) def forward(self, src: 'torch.FloatTensor', attn_mask: 'torch.FloatTensor' ) ->torch.FloatTensor: if attn_mask.dim() == 2: attn_mask = attn_mask.unsqueeze(0) if attn_mask.dim() == 3: attn_mask = attn_mask.unsqueeze(1) q, k, v = self.qkv_linear(src).chunk(3, dim=-1) q = q.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 1, 3) k = k.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 3, 1) v = v.contiguous().view(src.shape[0], src.shape[1], self.n_head, src.shape[2] // self.n_head).permute(0, 2, 1, 3) attn_weights = torch.matmul(q, k) attn_weights = attn_weights * float(src.shape[2] // self.n_head ) ** -0.5 attn_weights = attn_weights * attn_mask + (attn_mask - 1) * 10000.0 attn_weights = F.softmax(attn_weights, dim=-1) attn_weights = self.dropout(attn_weights) attn_output = torch.matmul(attn_weights, v) attn_output = attn_output.permute(0, 2, 1, 3).contiguous().view(src .shape) attn_output = self.output_linear(attn_output) return attn_output class GPT2LayerNew(nn.Module): def __init__(self, config: 'GPT2Config'): super(GPT2LayerNew, self).__init__() self.layer_norm1 = nn.LayerNorm(config.hidden_size) self.self_attn = MultiHeadSelfAttention(d_ipt=config.hidden_size, n_head=config.n_head, dropout_p=config.drop_out) self.layer_norm2 = nn.LayerNorm(config.hidden_size) self.intermediate_linear1 = nn.Linear(config.hidden_size, config. d_intermediate, True) self.intermediate_linear2 = nn.Linear(config.d_intermediate, config .hidden_size, True) self.dropout = nn.Dropout(config.drop_out) self.dropout1 = nn.Dropout(config.drop_out) self.dropout2 = nn.Dropout(config.drop_out) def forward(self, input_0, input_1): primals_1 = self.layer_norm1.weight primals_2 = self.layer_norm1.bias primals_5 = self.self_attn.qkv_linear.weight primals_6 = self.self_attn.qkv_linear.bias primals_7 = self.self_attn.output_linear.weight primals_8 = self.self_attn.output_linear.bias primals_9 = self.layer_norm2.weight primals_10 = self.layer_norm2.bias primals_11 = self.intermediate_linear1.weight primals_12 = self.intermediate_linear1.bias primals_13 = self.intermediate_linear2.weight primals_14 = self.intermediate_linear2.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14]) return output[0]
DunZhang/GPT2SourceCode
GPT2Layer
false
7,627
[ "MIT" ]
1
d598dbae278c93f88469d45ec025da4cfa7d69ee
https://github.com/DunZhang/GPT2SourceCode/tree/d598dbae278c93f88469d45ec025da4cfa7d69ee
Gaussian
import torch from torch import Tensor import torch.utils.tensorboard import torch.utils.data class Gaussian(torch.nn.Module): """Gaussian activation""" def forward(self, x: 'Tensor') ->Tensor: return torch.exp(-x * x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.utils.tensorboard 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_exp_mul_neg_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = -tmp0 tmp2 = tmp1 * tmp0 tmp3 = tl_math.exp(tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_exp_mul_neg_0[grid(256)](arg0_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) del arg0_1 return buf0, class GaussianNew(torch.nn.Module): """Gaussian activation""" def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
raimis/torchani
Gaussian
false
7,628
[ "MIT" ]
1
19882c6e18174e08423706a536366f89029a740a
https://github.com/raimis/torchani/tree/19882c6e18174e08423706a536366f89029a740a
EntmaxBisect
from torch.autograd import Function import torch import torch.nn as nn def entmax_bisect(X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True): """alpha-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_a(p) s.t. p >= 0, sum(p) == 1. where H_a(p) is the Tsallis alpha-entropy with custom alpha >= 1, using a bisection (root finding, binary search) algorithm. This function is differentiable with respect to both X and alpha. Parameters ---------- X : torch.Tensor The input tensor. alpha : float or torch.Tensor Tensor of alpha parameters (> 1) to use. If scalar or python float, the same value is used for all rows, otherwise, it must have shape (or be expandable to) alpha.shape[j] == (X.shape[j] if j != dim else 1) A value of alpha=2 corresponds to sparsemax, and alpha=1 corresponds to softmax (but computing it this way is likely unstable). dim : int The dimension along which to apply alpha-entmax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. ensure_sum_one : bool, Whether to divide the result by its sum. If false, the result might sum to close but not exactly 1, which might cause downstream problems. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return EntmaxBisectFunction.apply(X, alpha, dim, n_iter, ensure_sum_one) class EntmaxBisectFunction(Function): @classmethod def _gp(cls, x, alpha): return x ** (alpha - 1) @classmethod def _gp_inv(cls, y, alpha): return y ** (1 / (alpha - 1)) @classmethod def _p(cls, X, alpha): return cls._gp_inv(torch.clamp(X, min=0), alpha) @classmethod def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True ): if not isinstance(alpha, torch.Tensor): alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device) alpha_shape = list(X.shape) alpha_shape[dim] = 1 alpha = alpha.expand(*alpha_shape) ctx.alpha = alpha ctx.dim = dim d = X.shape[dim] X = X * (alpha - 1) max_val, _ = X.max(dim=dim, keepdim=True) tau_lo = max_val - cls._gp(1, alpha) tau_hi = max_val - cls._gp(1 / d, alpha) f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1 dm = tau_hi - tau_lo for it in range(n_iter): dm /= 2 tau_m = tau_lo + dm p_m = cls._p(X - tau_m, alpha) f_m = p_m.sum(dim) - 1 mask = (f_m * f_lo >= 0).unsqueeze(dim) tau_lo = torch.where(mask, tau_m, tau_lo) if ensure_sum_one: p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim) ctx.save_for_backward(p_m) return p_m @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1)) dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr d_alpha = None if ctx.needs_input_grad[1]: S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1)) ent = S.sum(ctx.dim).unsqueeze(ctx.dim) Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim) d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2 d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1) d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim) return dX, d_alpha, None, None, None class EntmaxBisect(nn.Module): def __init__(self, alpha=1.5, dim=-1, n_iter=50): """alpha-entmax: normalizing sparse map (a la softmax) via bisection. Solves the optimization problem: max_p <x, p> - H_a(p) s.t. p >= 0, sum(p) == 1. where H_a(p) is the Tsallis alpha-entropy with custom alpha >= 1, using a bisection (root finding, binary search) algorithm. Parameters ---------- alpha : float or torch.Tensor Tensor of alpha parameters (> 1) to use. If scalar or python float, the same value is used for all rows, otherwise, it must have shape (or be expandable to) alpha.shape[j] == (X.shape[j] if j != dim else 1) A value of alpha=2 corresponds to sparsemax; alpha=1 corresponds to softmax (but computing it this way is likely unstable). dim : int The dimension along which to apply alpha-entmax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. """ self.dim = dim self.n_iter = n_iter self.alpha = alpha super().__init__() def forward(self, X): return entmax_bisect(X, alpha=self.alpha, dim=self.dim, n_iter=self .n_iter) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch.autograd import Function import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_clamp_div_max_mul_pow_sub_sum_where_0(in_out_ptr12, in_ptr0, out_ptr0, out_ptr19, out_ptr27, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp5 = triton_helpers.maximum(tmp2, tmp4) tmp7 = tmp6 * tmp1 tmp8 = triton_helpers.maximum(tmp5, tmp7) tmp10 = tmp9 * tmp1 tmp11 = triton_helpers.maximum(tmp8, tmp10) tmp12 = 1.0 tmp13 = tmp11 - tmp12 tmp14 = tmp11 - tmp1 tmp15 = tmp14 - tmp13 tmp16 = tmp15 * tmp1 tmp17 = tmp13 + tmp16 tmp18 = tmp2 - tmp17 tmp19 = 0.0 tmp20 = triton_helpers.maximum(tmp18, tmp19) tmp21 = 2.0 tmp22 = libdevice.pow(tmp20, tmp21) tmp23 = tmp4 - tmp17 tmp24 = triton_helpers.maximum(tmp23, tmp19) tmp25 = libdevice.pow(tmp24, tmp21) tmp26 = tmp22 + tmp25 tmp27 = tmp7 - tmp17 tmp28 = triton_helpers.maximum(tmp27, tmp19) tmp29 = libdevice.pow(tmp28, tmp21) tmp30 = tmp26 + tmp29 tmp31 = tmp10 - tmp17 tmp32 = triton_helpers.maximum(tmp31, tmp19) tmp33 = libdevice.pow(tmp32, tmp21) tmp34 = tmp30 + tmp33 tmp35 = tmp2 - tmp13 tmp36 = triton_helpers.maximum(tmp35, tmp19) tmp37 = libdevice.pow(tmp36, tmp21) tmp38 = tmp4 - tmp13 tmp39 = triton_helpers.maximum(tmp38, tmp19) tmp40 = libdevice.pow(tmp39, tmp21) tmp41 = tmp37 + tmp40 tmp42 = tmp7 - tmp13 tmp43 = triton_helpers.maximum(tmp42, tmp19) tmp44 = libdevice.pow(tmp43, tmp21) tmp45 = tmp41 + tmp44 tmp46 = tmp10 - tmp13 tmp47 = triton_helpers.maximum(tmp46, tmp19) tmp48 = libdevice.pow(tmp47, tmp21) tmp49 = tmp45 + tmp48 tmp50 = tmp34 - tmp12 tmp51 = tmp49 - tmp12 tmp52 = tmp50 * tmp51 tmp53 = tmp52 >= tmp19 tmp54 = tl.where(tmp53, tmp17, tmp13) tmp55 = tmp16 * tmp1 tmp56 = tmp54 + tmp55 tmp57 = tmp2 - tmp56 tmp58 = triton_helpers.maximum(tmp57, tmp19) tmp59 = libdevice.pow(tmp58, tmp21) tmp60 = tmp4 - tmp56 tmp61 = triton_helpers.maximum(tmp60, tmp19) tmp62 = libdevice.pow(tmp61, tmp21) tmp63 = tmp59 + tmp62 tmp64 = tmp7 - tmp56 tmp65 = triton_helpers.maximum(tmp64, tmp19) tmp66 = libdevice.pow(tmp65, tmp21) tmp67 = tmp63 + tmp66 tmp68 = tmp10 - tmp56 tmp69 = triton_helpers.maximum(tmp68, tmp19) tmp70 = libdevice.pow(tmp69, tmp21) tmp71 = tmp67 + tmp70 tmp72 = tmp71 - tmp12 tmp73 = tmp72 * tmp51 tmp74 = tmp73 >= tmp19 tmp75 = tl.where(tmp74, tmp56, tmp54) tmp76 = tmp55 * tmp1 tmp77 = tmp75 + tmp76 tmp78 = tmp2 - tmp77 tmp79 = triton_helpers.maximum(tmp78, tmp19) tmp80 = libdevice.pow(tmp79, tmp21) tmp81 = tmp4 - tmp77 tmp82 = triton_helpers.maximum(tmp81, tmp19) tmp83 = libdevice.pow(tmp82, tmp21) tmp84 = tmp80 + tmp83 tmp85 = tmp7 - tmp77 tmp86 = triton_helpers.maximum(tmp85, tmp19) tmp87 = libdevice.pow(tmp86, tmp21) tmp88 = tmp84 + tmp87 tmp89 = tmp10 - tmp77 tmp90 = triton_helpers.maximum(tmp89, tmp19) tmp91 = libdevice.pow(tmp90, tmp21) tmp92 = tmp88 + tmp91 tmp93 = tmp92 - tmp12 tmp94 = tmp93 * tmp51 tmp95 = tmp94 >= tmp19 tmp96 = tl.where(tmp95, tmp77, tmp75) tmp97 = tmp76 * tmp1 tmp98 = tmp96 + tmp97 tmp99 = tmp2 - tmp98 tmp100 = triton_helpers.maximum(tmp99, tmp19) tmp101 = libdevice.pow(tmp100, tmp21) tmp102 = tmp4 - tmp98 tmp103 = triton_helpers.maximum(tmp102, tmp19) tmp104 = libdevice.pow(tmp103, tmp21) tmp105 = tmp101 + tmp104 tmp106 = tmp7 - tmp98 tmp107 = triton_helpers.maximum(tmp106, tmp19) tmp108 = libdevice.pow(tmp107, tmp21) tmp109 = tmp105 + tmp108 tmp110 = tmp10 - tmp98 tmp111 = triton_helpers.maximum(tmp110, tmp19) tmp112 = libdevice.pow(tmp111, tmp21) tmp113 = tmp109 + tmp112 tmp114 = tmp113 - tmp12 tmp115 = tmp114 * tmp51 tmp116 = tmp115 >= tmp19 tmp117 = tl.where(tmp116, tmp98, tmp96) tmp118 = tmp97 * tmp1 tmp119 = tmp117 + tmp118 tmp120 = tmp2 - tmp119 tmp121 = triton_helpers.maximum(tmp120, tmp19) tmp122 = libdevice.pow(tmp121, tmp21) tmp123 = tmp4 - tmp119 tmp124 = triton_helpers.maximum(tmp123, tmp19) tmp125 = libdevice.pow(tmp124, tmp21) tmp126 = tmp122 + tmp125 tmp127 = tmp7 - tmp119 tmp128 = triton_helpers.maximum(tmp127, tmp19) tmp129 = libdevice.pow(tmp128, tmp21) tmp130 = tmp126 + tmp129 tmp131 = tmp10 - tmp119 tmp132 = triton_helpers.maximum(tmp131, tmp19) tmp133 = libdevice.pow(tmp132, tmp21) tmp134 = tmp130 + tmp133 tmp135 = tmp134 - tmp12 tmp136 = tmp135 * tmp51 tmp137 = tmp136 >= tmp19 tmp138 = tl.where(tmp137, tmp119, tmp117) tmp139 = tmp118 * tmp1 tmp140 = tmp138 + tmp139 tmp141 = tmp2 - tmp140 tmp142 = triton_helpers.maximum(tmp141, tmp19) tmp143 = libdevice.pow(tmp142, tmp21) tmp144 = tmp4 - tmp140 tmp145 = triton_helpers.maximum(tmp144, tmp19) tmp146 = libdevice.pow(tmp145, tmp21) tmp147 = tmp143 + tmp146 tmp148 = tmp7 - tmp140 tmp149 = triton_helpers.maximum(tmp148, tmp19) tmp150 = libdevice.pow(tmp149, tmp21) tmp151 = tmp147 + tmp150 tmp152 = tmp10 - tmp140 tmp153 = triton_helpers.maximum(tmp152, tmp19) tmp154 = libdevice.pow(tmp153, tmp21) tmp155 = tmp151 + tmp154 tmp156 = tmp155 - tmp12 tmp157 = tmp156 * tmp51 tmp158 = tmp157 >= tmp19 tmp159 = tl.where(tmp158, tmp140, tmp138) tmp160 = tmp139 * tmp1 tmp161 = tmp159 + tmp160 tmp162 = tmp2 - tmp161 tmp163 = triton_helpers.maximum(tmp162, tmp19) tmp164 = libdevice.pow(tmp163, tmp21) tmp165 = tmp4 - tmp161 tmp166 = triton_helpers.maximum(tmp165, tmp19) tmp167 = libdevice.pow(tmp166, tmp21) tmp168 = tmp164 + tmp167 tmp169 = tmp7 - tmp161 tmp170 = triton_helpers.maximum(tmp169, tmp19) tmp171 = libdevice.pow(tmp170, tmp21) tmp172 = tmp168 + tmp171 tmp173 = tmp10 - tmp161 tmp174 = triton_helpers.maximum(tmp173, tmp19) tmp175 = libdevice.pow(tmp174, tmp21) tmp176 = tmp172 + tmp175 tmp177 = tmp176 - tmp12 tmp178 = tmp177 * tmp51 tmp179 = tmp178 >= tmp19 tmp180 = tl.where(tmp179, tmp161, tmp159) tmp181 = tmp160 * tmp1 tmp182 = tmp180 + tmp181 tmp183 = tmp2 - tmp182 tmp184 = triton_helpers.maximum(tmp183, tmp19) tmp185 = libdevice.pow(tmp184, tmp21) tmp186 = tmp4 - tmp182 tmp187 = triton_helpers.maximum(tmp186, tmp19) tmp188 = libdevice.pow(tmp187, tmp21) tmp189 = tmp185 + tmp188 tmp190 = tmp7 - tmp182 tmp191 = triton_helpers.maximum(tmp190, tmp19) tmp192 = libdevice.pow(tmp191, tmp21) tmp193 = tmp189 + tmp192 tmp194 = tmp10 - tmp182 tmp195 = triton_helpers.maximum(tmp194, tmp19) tmp196 = libdevice.pow(tmp195, tmp21) tmp197 = tmp193 + tmp196 tmp198 = tmp197 - tmp12 tmp199 = tmp198 * tmp51 tmp200 = tmp199 >= tmp19 tmp201 = tl.where(tmp200, tmp182, tmp180) tmp202 = tmp181 * tmp1 tmp203 = tmp201 + tmp202 tmp204 = tmp2 - tmp203 tmp205 = triton_helpers.maximum(tmp204, tmp19) tmp206 = libdevice.pow(tmp205, tmp21) tmp207 = tmp4 - tmp203 tmp208 = triton_helpers.maximum(tmp207, tmp19) tmp209 = libdevice.pow(tmp208, tmp21) tmp210 = tmp206 + tmp209 tmp211 = tmp7 - tmp203 tmp212 = triton_helpers.maximum(tmp211, tmp19) tmp213 = libdevice.pow(tmp212, tmp21) tmp214 = tmp210 + tmp213 tmp215 = tmp10 - tmp203 tmp216 = triton_helpers.maximum(tmp215, tmp19) tmp217 = libdevice.pow(tmp216, tmp21) tmp218 = tmp214 + tmp217 tmp219 = tmp218 - tmp12 tmp220 = tmp219 * tmp51 tmp221 = tmp220 >= tmp19 tmp222 = tl.where(tmp221, tmp203, tmp201) tmp223 = tmp202 * tmp1 tmp224 = tmp222 + tmp223 tmp225 = tmp2 - tmp224 tmp226 = triton_helpers.maximum(tmp225, tmp19) tmp227 = libdevice.pow(tmp226, tmp21) tmp228 = tmp4 - tmp224 tmp229 = triton_helpers.maximum(tmp228, tmp19) tmp230 = libdevice.pow(tmp229, tmp21) tmp231 = tmp227 + tmp230 tmp232 = tmp7 - tmp224 tmp233 = triton_helpers.maximum(tmp232, tmp19) tmp234 = libdevice.pow(tmp233, tmp21) tmp235 = tmp231 + tmp234 tmp236 = tmp10 - tmp224 tmp237 = triton_helpers.maximum(tmp236, tmp19) tmp238 = libdevice.pow(tmp237, tmp21) tmp239 = tmp235 + tmp238 tmp240 = tmp239 - tmp12 tmp241 = tmp240 * tmp51 tmp242 = tmp241 >= tmp19 tmp243 = tl.where(tmp242, tmp224, tmp222) tmp244 = tmp223 * tmp1 tmp245 = tmp243 + tmp244 tmp246 = tmp2 - tmp245 tmp247 = triton_helpers.maximum(tmp246, tmp19) tmp248 = libdevice.pow(tmp247, tmp21) tmp249 = tmp4 - tmp245 tmp250 = triton_helpers.maximum(tmp249, tmp19) tmp251 = libdevice.pow(tmp250, tmp21) tmp252 = tmp248 + tmp251 tmp253 = tmp7 - tmp245 tmp254 = triton_helpers.maximum(tmp253, tmp19) tmp255 = libdevice.pow(tmp254, tmp21) tmp256 = tmp252 + tmp255 tmp257 = tmp10 - tmp245 tmp258 = triton_helpers.maximum(tmp257, tmp19) tmp259 = libdevice.pow(tmp258, tmp21) tmp260 = tmp256 + tmp259 tmp261 = tmp260 - tmp12 tmp262 = tmp261 * tmp51 tmp263 = tmp262 >= tmp19 tmp264 = tl.where(tmp263, tmp245, tmp243) tmp265 = tmp244 * tmp1 tmp266 = tmp264 + tmp265 tmp267 = tmp2 - tmp266 tmp268 = triton_helpers.maximum(tmp267, tmp19) tmp269 = libdevice.pow(tmp268, tmp21) tmp270 = tmp4 - tmp266 tmp271 = triton_helpers.maximum(tmp270, tmp19) tmp272 = libdevice.pow(tmp271, tmp21) tmp273 = tmp269 + tmp272 tmp274 = tmp7 - tmp266 tmp275 = triton_helpers.maximum(tmp274, tmp19) tmp276 = libdevice.pow(tmp275, tmp21) tmp277 = tmp273 + tmp276 tmp278 = tmp10 - tmp266 tmp279 = triton_helpers.maximum(tmp278, tmp19) tmp280 = libdevice.pow(tmp279, tmp21) tmp281 = tmp277 + tmp280 tmp282 = tmp281 - tmp12 tmp283 = tmp282 * tmp51 tmp284 = tmp283 >= tmp19 tmp285 = tl.where(tmp284, tmp266, tmp264) tmp286 = tmp265 * tmp1 tmp287 = tmp285 + tmp286 tmp288 = tmp2 - tmp287 tmp289 = triton_helpers.maximum(tmp288, tmp19) tmp290 = libdevice.pow(tmp289, tmp21) tmp291 = tmp4 - tmp287 tmp292 = triton_helpers.maximum(tmp291, tmp19) tmp293 = libdevice.pow(tmp292, tmp21) tmp294 = tmp290 + tmp293 tmp295 = tmp7 - tmp287 tmp296 = triton_helpers.maximum(tmp295, tmp19) tmp297 = libdevice.pow(tmp296, tmp21) tmp298 = tmp294 + tmp297 tmp299 = tmp10 - tmp287 tmp300 = triton_helpers.maximum(tmp299, tmp19) tmp301 = libdevice.pow(tmp300, tmp21) tmp302 = tmp298 + tmp301 tmp303 = tmp302 - tmp12 tmp304 = tmp303 * tmp51 tmp305 = tmp304 >= tmp19 tmp306 = tl.where(tmp305, tmp287, tmp285) tmp307 = tmp286 * tmp1 tmp308 = tmp307 * tmp1 tmp309 = tmp306 + tmp307 tmp310 = tmp2 - tmp309 tmp311 = triton_helpers.maximum(tmp310, tmp19) tmp312 = libdevice.pow(tmp311, tmp21) tmp313 = tmp4 - tmp309 tmp314 = triton_helpers.maximum(tmp313, tmp19) tmp315 = libdevice.pow(tmp314, tmp21) tmp316 = tmp312 + tmp315 tmp317 = tmp7 - tmp309 tmp318 = triton_helpers.maximum(tmp317, tmp19) tmp319 = libdevice.pow(tmp318, tmp21) tmp320 = tmp316 + tmp319 tmp321 = tmp10 - tmp309 tmp322 = triton_helpers.maximum(tmp321, tmp19) tmp323 = libdevice.pow(tmp322, tmp21) tmp324 = tmp320 + tmp323 tmp325 = tmp324 - tmp12 tmp326 = tmp325 * tmp51 tmp327 = tmp326 >= tmp19 tmp328 = tl.where(tmp327, tmp309, tmp306) tmp329 = tmp328 + tmp308 tmp330 = tmp2 - tmp329 tmp331 = triton_helpers.maximum(tmp330, tmp19) tmp332 = libdevice.pow(tmp331, tmp21) tmp333 = tmp4 - tmp329 tmp334 = triton_helpers.maximum(tmp333, tmp19) tmp335 = libdevice.pow(tmp334, tmp21) tmp336 = tmp332 + tmp335 tmp337 = tmp7 - tmp329 tmp338 = triton_helpers.maximum(tmp337, tmp19) tmp339 = libdevice.pow(tmp338, tmp21) tmp340 = tmp336 + tmp339 tmp341 = tmp10 - tmp329 tmp342 = triton_helpers.maximum(tmp341, tmp19) tmp343 = libdevice.pow(tmp342, tmp21) tmp344 = tmp340 + tmp343 tmp345 = tmp344 - tmp12 tmp346 = tmp345 * tmp51 tmp347 = tmp346 >= tmp19 tmp348 = tl.where(tmp347, tmp329, tmp328) tmp349 = tmp308 * tmp1 tmp350 = tmp348 + tmp349 tmp351 = tmp2 - tmp350 tmp352 = triton_helpers.maximum(tmp351, tmp19) tmp353 = libdevice.pow(tmp352, tmp21) tmp354 = tmp4 - tmp350 tmp355 = triton_helpers.maximum(tmp354, tmp19) tmp356 = libdevice.pow(tmp355, tmp21) tmp357 = tmp353 + tmp356 tmp358 = tmp7 - tmp350 tmp359 = triton_helpers.maximum(tmp358, tmp19) tmp360 = libdevice.pow(tmp359, tmp21) tmp361 = tmp357 + tmp360 tmp362 = tmp10 - tmp350 tmp363 = triton_helpers.maximum(tmp362, tmp19) tmp364 = libdevice.pow(tmp363, tmp21) tmp365 = tmp361 + tmp364 tmp366 = tmp365 - tmp12 tmp367 = tmp366 * tmp51 tmp368 = tmp367 >= tmp19 tmp369 = tl.where(tmp368, tmp350, tmp348) tmp370 = tmp349 * tmp1 tmp371 = tmp369 + tmp370 tmp372 = tmp2 - tmp371 tmp373 = triton_helpers.maximum(tmp372, tmp19) tmp374 = libdevice.pow(tmp373, tmp21) tmp375 = tmp4 - tmp371 tmp376 = triton_helpers.maximum(tmp375, tmp19) tmp377 = libdevice.pow(tmp376, tmp21) tmp378 = tmp374 + tmp377 tmp379 = tmp7 - tmp371 tmp380 = triton_helpers.maximum(tmp379, tmp19) tmp381 = libdevice.pow(tmp380, tmp21) tmp382 = tmp378 + tmp381 tmp383 = tmp10 - tmp371 tmp384 = triton_helpers.maximum(tmp383, tmp19) tmp385 = libdevice.pow(tmp384, tmp21) tmp386 = tmp382 + tmp385 tmp387 = tmp386 - tmp12 tmp388 = tmp387 * tmp51 tmp389 = tmp388 >= tmp19 tmp390 = tl.where(tmp389, tmp371, tmp369) tmp391 = tmp370 * tmp1 tmp392 = tmp390 + tmp391 tmp393 = tmp2 - tmp392 tmp394 = triton_helpers.maximum(tmp393, tmp19) tmp395 = libdevice.pow(tmp394, tmp21) tmp396 = tmp4 - tmp392 tmp397 = triton_helpers.maximum(tmp396, tmp19) tmp398 = libdevice.pow(tmp397, tmp21) tmp399 = tmp395 + tmp398 tmp400 = tmp7 - tmp392 tmp401 = triton_helpers.maximum(tmp400, tmp19) tmp402 = libdevice.pow(tmp401, tmp21) tmp403 = tmp399 + tmp402 tmp404 = tmp10 - tmp392 tmp405 = triton_helpers.maximum(tmp404, tmp19) tmp406 = libdevice.pow(tmp405, tmp21) tmp407 = tmp403 + tmp406 tmp408 = tmp407 - tmp12 tmp409 = tmp408 * tmp51 tmp410 = tmp409 >= tmp19 tmp411 = tl.where(tmp410, tmp392, tmp390) tmp412 = tmp391 * tmp1 tmp413 = tmp411 + tmp412 tmp414 = tmp2 - tmp413 tmp415 = triton_helpers.maximum(tmp414, tmp19) tmp416 = libdevice.pow(tmp415, tmp21) tmp417 = tmp4 - tmp413 tmp418 = triton_helpers.maximum(tmp417, tmp19) tmp419 = libdevice.pow(tmp418, tmp21) tmp420 = tmp416 + tmp419 tmp421 = tmp7 - tmp413 tmp422 = triton_helpers.maximum(tmp421, tmp19) tmp423 = libdevice.pow(tmp422, tmp21) tmp424 = tmp420 + tmp423 tmp425 = tmp10 - tmp413 tmp426 = triton_helpers.maximum(tmp425, tmp19) tmp427 = libdevice.pow(tmp426, tmp21) tmp428 = tmp424 + tmp427 tmp429 = tmp428 - tmp12 tmp430 = tmp429 * tmp51 tmp431 = tmp430 >= tmp19 tmp432 = tl.where(tmp431, tmp413, tmp411) tmp433 = tmp412 * tmp1 tmp434 = tmp432 + tmp433 tmp435 = tmp2 - tmp434 tmp436 = triton_helpers.maximum(tmp435, tmp19) tmp437 = libdevice.pow(tmp436, tmp21) tmp438 = tmp4 - tmp434 tmp439 = triton_helpers.maximum(tmp438, tmp19) tmp440 = libdevice.pow(tmp439, tmp21) tmp441 = tmp437 + tmp440 tmp442 = tmp7 - tmp434 tmp443 = triton_helpers.maximum(tmp442, tmp19) tmp444 = libdevice.pow(tmp443, tmp21) tmp445 = tmp441 + tmp444 tmp446 = tmp10 - tmp434 tmp447 = triton_helpers.maximum(tmp446, tmp19) tmp448 = libdevice.pow(tmp447, tmp21) tmp449 = tmp445 + tmp448 tmp450 = tmp449 - tmp12 tmp451 = tmp450 * tmp51 tmp452 = tmp451 >= tmp19 tmp453 = tl.where(tmp452, tmp434, tmp432) tmp454 = tmp433 * tmp1 tmp455 = tmp453 + tmp454 tmp456 = tmp2 - tmp455 tmp457 = triton_helpers.maximum(tmp456, tmp19) tmp458 = libdevice.pow(tmp457, tmp21) tmp459 = tmp4 - tmp455 tmp460 = triton_helpers.maximum(tmp459, tmp19) tmp461 = libdevice.pow(tmp460, tmp21) tmp462 = tmp458 + tmp461 tmp463 = tmp7 - tmp455 tmp464 = triton_helpers.maximum(tmp463, tmp19) tmp465 = libdevice.pow(tmp464, tmp21) tmp466 = tmp462 + tmp465 tmp467 = tmp10 - tmp455 tmp468 = triton_helpers.maximum(tmp467, tmp19) tmp469 = libdevice.pow(tmp468, tmp21) tmp470 = tmp466 + tmp469 tmp471 = tmp470 - tmp12 tmp472 = tmp471 * tmp51 tmp473 = tmp472 >= tmp19 tmp474 = tl.where(tmp473, tmp455, tmp453) tmp475 = tmp454 * tmp1 tmp476 = tmp474 + tmp475 tmp477 = tmp2 - tmp476 tmp478 = triton_helpers.maximum(tmp477, tmp19) tmp479 = libdevice.pow(tmp478, tmp21) tmp480 = tmp4 - tmp476 tmp481 = triton_helpers.maximum(tmp480, tmp19) tmp482 = libdevice.pow(tmp481, tmp21) tmp483 = tmp479 + tmp482 tmp484 = tmp7 - tmp476 tmp485 = triton_helpers.maximum(tmp484, tmp19) tmp486 = libdevice.pow(tmp485, tmp21) tmp487 = tmp483 + tmp486 tmp488 = tmp10 - tmp476 tmp489 = triton_helpers.maximum(tmp488, tmp19) tmp490 = libdevice.pow(tmp489, tmp21) tmp491 = tmp487 + tmp490 tmp492 = tmp491 - tmp12 tmp493 = tmp492 * tmp51 tmp494 = tmp493 >= tmp19 tmp495 = tl.where(tmp494, tmp476, tmp474) tmp496 = tmp475 * tmp1 tmp497 = tmp495 + tmp496 tmp498 = tmp2 - tmp497 tmp499 = triton_helpers.maximum(tmp498, tmp19) tmp500 = libdevice.pow(tmp499, tmp21) tmp501 = tmp4 - tmp497 tmp502 = triton_helpers.maximum(tmp501, tmp19) tmp503 = libdevice.pow(tmp502, tmp21) tmp504 = tmp500 + tmp503 tmp505 = tmp7 - tmp497 tmp506 = triton_helpers.maximum(tmp505, tmp19) tmp507 = libdevice.pow(tmp506, tmp21) tmp508 = tmp504 + tmp507 tmp509 = tmp10 - tmp497 tmp510 = triton_helpers.maximum(tmp509, tmp19) tmp511 = libdevice.pow(tmp510, tmp21) tmp512 = tmp508 + tmp511 tmp513 = tmp512 - tmp12 tmp514 = tmp513 * tmp51 tmp515 = tmp514 >= tmp19 tmp516 = tl.where(tmp515, tmp497, tmp495) tmp517 = tmp496 * tmp1 tmp518 = tmp516 + tmp517 tmp519 = tmp2 - tmp518 tmp520 = triton_helpers.maximum(tmp519, tmp19) tmp521 = libdevice.pow(tmp520, tmp21) tmp522 = tmp4 - tmp518 tmp523 = triton_helpers.maximum(tmp522, tmp19) tmp524 = libdevice.pow(tmp523, tmp21) tmp525 = tmp521 + tmp524 tmp526 = tmp7 - tmp518 tmp527 = triton_helpers.maximum(tmp526, tmp19) tmp528 = libdevice.pow(tmp527, tmp21) tmp529 = tmp525 + tmp528 tmp530 = tmp10 - tmp518 tmp531 = triton_helpers.maximum(tmp530, tmp19) tmp532 = libdevice.pow(tmp531, tmp21) tmp533 = tmp529 + tmp532 tmp534 = tmp533 - tmp12 tmp535 = tmp534 * tmp51 tmp536 = tmp535 >= tmp19 tmp537 = tl.where(tmp536, tmp518, tmp516) tmp538 = tmp517 * tmp1 tmp539 = tmp537 + tmp538 tmp540 = tmp2 - tmp539 tmp541 = triton_helpers.maximum(tmp540, tmp19) tmp542 = libdevice.pow(tmp541, tmp21) tmp543 = tmp4 - tmp539 tmp544 = triton_helpers.maximum(tmp543, tmp19) tmp545 = libdevice.pow(tmp544, tmp21) tmp546 = tmp542 + tmp545 tmp547 = tmp7 - tmp539 tmp548 = triton_helpers.maximum(tmp547, tmp19) tmp549 = libdevice.pow(tmp548, tmp21) tmp550 = tmp546 + tmp549 tmp551 = tmp10 - tmp539 tmp552 = triton_helpers.maximum(tmp551, tmp19) tmp553 = libdevice.pow(tmp552, tmp21) tmp554 = tmp550 + tmp553 tmp555 = tmp554 - tmp12 tmp556 = tmp555 * tmp51 tmp557 = tmp556 >= tmp19 tmp558 = tl.where(tmp557, tmp539, tmp537) tmp559 = tmp538 * tmp1 tmp560 = tmp558 + tmp559 tmp561 = tmp2 - tmp560 tmp562 = triton_helpers.maximum(tmp561, tmp19) tmp563 = libdevice.pow(tmp562, tmp21) tmp564 = tmp4 - tmp560 tmp565 = triton_helpers.maximum(tmp564, tmp19) tmp566 = libdevice.pow(tmp565, tmp21) tmp567 = tmp563 + tmp566 tmp568 = tmp7 - tmp560 tmp569 = triton_helpers.maximum(tmp568, tmp19) tmp570 = libdevice.pow(tmp569, tmp21) tmp571 = tmp567 + tmp570 tmp572 = tmp10 - tmp560 tmp573 = triton_helpers.maximum(tmp572, tmp19) tmp574 = libdevice.pow(tmp573, tmp21) tmp575 = tmp571 + tmp574 tl.store(out_ptr0 + x0, tmp49, xmask) tl.store(out_ptr19 + x0, tmp308, xmask) tl.store(in_out_ptr12 + x0, tmp558, xmask) tl.store(out_ptr27 + x0, tmp575, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_where_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = 1.0 tmp5 = tmp3 - tmp4 tmp7 = tmp6 - tmp4 tmp8 = tmp5 * tmp7 tmp9 = 0.0 tmp10 = tmp8 >= tmp9 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp11 + tmp23 tmp25 = tl.where(tmp10, tmp24, tmp11) tmp26 = tmp23 * tmp1 tmp27 = tmp25 + tmp26 tmp28 = tmp2 - tmp27 tmp29 = triton_helpers.maximum(tmp28, tmp9) tmp30 = 2.0 tmp31 = libdevice.pow(tmp29, tmp30) tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_2(in_out_ptr0, 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 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') tmp9 = tl.load(in_ptr1 + x0, xmask) tmp14 = tl.load(in_ptr2 + x0, xmask) tmp18 = tl.load(in_out_ptr0 + x0, xmask) tmp19 = tl.load(in_ptr3 + x0, xmask) tmp37 = tl.load(in_ptr4 + 4 * x0, xmask, eviction_policy='evict_last') tmp45 = tl.load(in_ptr4 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp51 = tl.load(in_ptr4 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp57 = tl.load(in_ptr4 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp10 = tmp9 - tmp7 tmp11 = tmp8 * tmp10 tmp12 = 0.0 tmp13 = tmp11 >= tmp12 tmp15 = tmp14 - tmp7 tmp16 = tmp15 * tmp10 tmp17 = tmp16 >= tmp12 tmp20 = 0.5 tmp21 = tmp19 * tmp20 tmp22 = tmp21 * tmp20 tmp23 = tmp22 * tmp20 tmp24 = tmp23 * tmp20 tmp25 = tmp24 * tmp20 tmp26 = tmp25 * tmp20 tmp27 = tmp26 * tmp20 tmp28 = tmp27 * tmp20 tmp29 = tmp28 * tmp20 tmp30 = tmp29 * tmp20 tmp31 = tmp30 * tmp20 tmp32 = tmp18 + tmp31 tmp33 = tl.where(tmp17, tmp32, tmp18) tmp34 = tmp31 * tmp20 tmp35 = tmp33 + tmp34 tmp36 = tl.where(tmp13, tmp35, tmp33) tmp38 = tmp37 * tmp20 tmp39 = tmp34 * tmp20 tmp40 = tmp36 + tmp39 tmp41 = tmp38 - tmp40 tmp42 = triton_helpers.maximum(tmp41, tmp12) tmp43 = 2.0 tmp44 = libdevice.pow(tmp42, tmp43) tmp46 = tmp45 * tmp20 tmp47 = tmp46 - tmp40 tmp48 = triton_helpers.maximum(tmp47, tmp12) tmp49 = libdevice.pow(tmp48, tmp43) tmp50 = tmp44 + tmp49 tmp52 = tmp51 * tmp20 tmp53 = tmp52 - tmp40 tmp54 = triton_helpers.maximum(tmp53, tmp12) tmp55 = libdevice.pow(tmp54, tmp43) tmp56 = tmp50 + tmp55 tmp58 = tmp57 * tmp20 tmp59 = tmp58 - tmp40 tmp60 = triton_helpers.maximum(tmp59, tmp12) tmp61 = libdevice.pow(tmp60, tmp43) tmp62 = tmp56 + tmp61 tl.store(in_out_ptr0 + x0, tmp36, xmask) tl.store(out_ptr0 + x0, tmp62, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_where_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = 1.0 tmp5 = tmp3 - tmp4 tmp7 = tmp6 - tmp4 tmp8 = tmp5 * tmp7 tmp9 = 0.0 tmp10 = tmp8 >= tmp9 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp11 + tmp25 tmp27 = tl.where(tmp10, tmp26, tmp11) tmp28 = tmp25 * tmp1 tmp29 = tmp27 + tmp28 tmp30 = tmp2 - tmp29 tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_4(in_out_ptr0, 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 x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + x0, xmask) tmp23 = tl.load(in_ptr2 + x0, xmask) tmp27 = tl.load(in_out_ptr0 + x0, xmask) tmp28 = tl.load(in_ptr3 + x0, xmask) tmp48 = tl.load(in_ptr4 + 4 * x0, xmask, eviction_policy='evict_last') tmp55 = tl.load(in_ptr4 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp61 = tl.load(in_ptr4 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp67 = tl.load(in_ptr4 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 2.0 tmp4 = libdevice.pow(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = libdevice.pow(tmp6, tmp3) tmp8 = tmp4 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = libdevice.pow(tmp10, tmp3) tmp12 = tmp8 + tmp11 tmp14 = triton_helpers.maximum(tmp13, tmp1) tmp15 = libdevice.pow(tmp14, tmp3) tmp16 = tmp12 + tmp15 tmp17 = 1.0 tmp18 = tmp16 - tmp17 tmp20 = tmp19 - tmp17 tmp21 = tmp18 * tmp20 tmp22 = tmp21 >= tmp1 tmp24 = tmp23 - tmp17 tmp25 = tmp24 * tmp20 tmp26 = tmp25 >= tmp1 tmp29 = 0.5 tmp30 = tmp28 * tmp29 tmp31 = tmp30 * tmp29 tmp32 = tmp31 * tmp29 tmp33 = tmp32 * tmp29 tmp34 = tmp33 * tmp29 tmp35 = tmp34 * tmp29 tmp36 = tmp35 * tmp29 tmp37 = tmp36 * tmp29 tmp38 = tmp37 * tmp29 tmp39 = tmp38 * tmp29 tmp40 = tmp39 * tmp29 tmp41 = tmp40 * tmp29 tmp42 = tmp41 * tmp29 tmp43 = tmp27 + tmp42 tmp44 = tl.where(tmp26, tmp43, tmp27) tmp45 = tmp42 * tmp29 tmp46 = tmp44 + tmp45 tmp47 = tl.where(tmp22, tmp46, tmp44) tmp49 = tmp48 * tmp29 tmp50 = tmp45 * tmp29 tmp51 = tmp47 + tmp50 tmp52 = tmp49 - tmp51 tmp53 = triton_helpers.maximum(tmp52, tmp1) tmp54 = libdevice.pow(tmp53, tmp3) tmp56 = tmp55 * tmp29 tmp57 = tmp56 - tmp51 tmp58 = triton_helpers.maximum(tmp57, tmp1) tmp59 = libdevice.pow(tmp58, tmp3) tmp60 = tmp54 + tmp59 tmp62 = tmp61 * tmp29 tmp63 = tmp62 - tmp51 tmp64 = triton_helpers.maximum(tmp63, tmp1) tmp65 = libdevice.pow(tmp64, tmp3) tmp66 = tmp60 + tmp65 tmp68 = tmp67 * tmp29 tmp69 = tmp68 - tmp51 tmp70 = triton_helpers.maximum(tmp69, tmp1) tmp71 = libdevice.pow(tmp70, tmp3) tmp72 = tmp66 + tmp71 tl.store(in_out_ptr0 + x0, tmp47, xmask) tl.store(out_ptr0 + x0, tmp72, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_where_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = 1.0 tmp5 = tmp3 - tmp4 tmp7 = tmp6 - tmp4 tmp8 = tmp5 * tmp7 tmp9 = 0.0 tmp10 = tmp8 >= tmp9 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp26 * tmp1 tmp28 = tmp11 + tmp27 tmp29 = tl.where(tmp10, tmp28, tmp11) tmp30 = tmp27 * tmp1 tmp31 = tmp29 + tmp30 tmp32 = tmp2 - tmp31 tl.store(out_ptr0 + x2, tmp32, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_6(in_out_ptr0, in_out_ptr2, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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') tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + x0, xmask) tmp23 = tl.load(in_ptr2 + x0, xmask) tmp27 = tl.load(in_out_ptr0 + x0, xmask) tmp28 = tl.load(in_ptr3 + x0, xmask) tmp50 = tl.load(in_ptr4 + 4 * x0, xmask, eviction_policy='evict_last') tmp57 = tl.load(in_ptr4 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp63 = tl.load(in_ptr4 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp69 = tl.load(in_ptr4 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 2.0 tmp4 = libdevice.pow(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = libdevice.pow(tmp6, tmp3) tmp8 = tmp4 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = libdevice.pow(tmp10, tmp3) tmp12 = tmp8 + tmp11 tmp14 = triton_helpers.maximum(tmp13, tmp1) tmp15 = libdevice.pow(tmp14, tmp3) tmp16 = tmp12 + tmp15 tmp17 = 1.0 tmp18 = tmp16 - tmp17 tmp20 = tmp19 - tmp17 tmp21 = tmp18 * tmp20 tmp22 = tmp21 >= tmp1 tmp24 = tmp23 - tmp17 tmp25 = tmp24 * tmp20 tmp26 = tmp25 >= tmp1 tmp29 = 0.5 tmp30 = tmp28 * tmp29 tmp31 = tmp30 * tmp29 tmp32 = tmp31 * tmp29 tmp33 = tmp32 * tmp29 tmp34 = tmp33 * tmp29 tmp35 = tmp34 * tmp29 tmp36 = tmp35 * tmp29 tmp37 = tmp36 * tmp29 tmp38 = tmp37 * tmp29 tmp39 = tmp38 * tmp29 tmp40 = tmp39 * tmp29 tmp41 = tmp40 * tmp29 tmp42 = tmp41 * tmp29 tmp43 = tmp42 * tmp29 tmp44 = tmp43 * tmp29 tmp45 = tmp27 + tmp44 tmp46 = tl.where(tmp26, tmp45, tmp27) tmp47 = tmp44 * tmp29 tmp48 = tmp46 + tmp47 tmp49 = tl.where(tmp22, tmp48, tmp46) tmp51 = tmp50 * tmp29 tmp52 = tmp47 * tmp29 tmp53 = tmp49 + tmp52 tmp54 = tmp51 - tmp53 tmp55 = triton_helpers.maximum(tmp54, tmp1) tmp56 = libdevice.pow(tmp55, tmp3) tmp58 = tmp57 * tmp29 tmp59 = tmp58 - tmp53 tmp60 = triton_helpers.maximum(tmp59, tmp1) tmp61 = libdevice.pow(tmp60, tmp3) tmp62 = tmp56 + tmp61 tmp64 = tmp63 * tmp29 tmp65 = tmp64 - tmp53 tmp66 = triton_helpers.maximum(tmp65, tmp1) tmp67 = libdevice.pow(tmp66, tmp3) tmp68 = tmp62 + tmp67 tmp70 = tmp69 * tmp29 tmp71 = tmp70 - tmp53 tmp72 = triton_helpers.maximum(tmp71, tmp1) tmp73 = libdevice.pow(tmp72, tmp3) tmp74 = tmp68 + tmp73 tmp75 = tmp74 - tmp17 tmp76 = tmp75 * tmp20 tmp77 = tmp76 >= tmp1 tmp78 = tl.where(tmp77, tmp53, tmp49) tmp79 = tmp52 * tmp29 tmp80 = tmp78 + tmp79 tmp81 = tmp51 - tmp80 tmp82 = triton_helpers.maximum(tmp81, tmp1) tmp83 = libdevice.pow(tmp82, tmp3) tmp84 = tmp58 - tmp80 tmp85 = triton_helpers.maximum(tmp84, tmp1) tmp86 = libdevice.pow(tmp85, tmp3) tmp87 = tmp83 + tmp86 tmp88 = tmp64 - tmp80 tmp89 = triton_helpers.maximum(tmp88, tmp1) tmp90 = libdevice.pow(tmp89, tmp3) tmp91 = tmp87 + tmp90 tmp92 = tmp70 - tmp80 tmp93 = triton_helpers.maximum(tmp92, tmp1) tmp94 = libdevice.pow(tmp93, tmp3) tmp95 = tmp91 + tmp94 tmp96 = tmp95 - tmp17 tmp97 = tmp96 * tmp20 tmp98 = tmp97 >= tmp1 tmp99 = tl.where(tmp98, tmp80, tmp78) tmp100 = tmp79 * tmp29 tmp101 = tmp99 + tmp100 tmp102 = tmp51 - tmp101 tmp103 = triton_helpers.maximum(tmp102, tmp1) tmp104 = libdevice.pow(tmp103, tmp3) tmp105 = tmp58 - tmp101 tmp106 = triton_helpers.maximum(tmp105, tmp1) tmp107 = libdevice.pow(tmp106, tmp3) tmp108 = tmp104 + tmp107 tmp109 = tmp64 - tmp101 tmp110 = triton_helpers.maximum(tmp109, tmp1) tmp111 = libdevice.pow(tmp110, tmp3) tmp112 = tmp108 + tmp111 tmp113 = tmp70 - tmp101 tmp114 = triton_helpers.maximum(tmp113, tmp1) tmp115 = libdevice.pow(tmp114, tmp3) tmp116 = tmp112 + tmp115 tmp117 = tmp116 - tmp17 tmp118 = tmp117 * tmp20 tmp119 = tmp118 >= tmp1 tmp120 = tl.where(tmp119, tmp101, tmp99) tl.store(in_out_ptr2 + x0, tmp120, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_7(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp3 + tmp24 tmp26 = tmp2 - tmp25 tmp27 = 0.0 tmp28 = triton_helpers.maximum(tmp26, tmp27) tmp29 = 2.0 tmp30 = libdevice.pow(tmp28, tmp29) tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_div_where_8(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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') tmp9 = tl.load(in_ptr1 + x0, xmask) tmp14 = tl.load(in_out_ptr0 + x0, xmask) tmp15 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp10 = tmp9 - tmp7 tmp11 = tmp8 * tmp10 tmp12 = 0.0 tmp13 = tmp11 >= tmp12 tmp16 = 0.5 tmp17 = tmp15 * tmp16 tmp18 = tmp17 * tmp16 tmp19 = tmp18 * tmp16 tmp20 = tmp19 * tmp16 tmp21 = tmp20 * tmp16 tmp22 = tmp21 * tmp16 tmp23 = tmp22 * tmp16 tmp24 = tmp23 * tmp16 tmp25 = tmp24 * tmp16 tmp26 = tmp25 * tmp16 tmp27 = tmp26 * tmp16 tmp28 = tmp27 * tmp16 tmp29 = tmp28 * tmp16 tmp30 = tmp29 * tmp16 tmp31 = tmp30 * tmp16 tmp32 = tmp31 * tmp16 tmp33 = tmp32 * tmp16 tmp34 = tmp33 * tmp16 tmp35 = tmp34 * tmp16 tmp36 = tmp35 * tmp16 tmp37 = tmp14 + tmp36 tmp38 = tl.where(tmp13, tmp37, tmp14) tl.store(in_out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_9(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp3 + tmp25 tmp27 = tmp2 - tmp26 tmp28 = 0.0 tmp29 = triton_helpers.maximum(tmp27, tmp28) tmp30 = 2.0 tmp31 = libdevice.pow(tmp29, tmp30) tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_div_where_10(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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') tmp9 = tl.load(in_ptr1 + x0, xmask) tmp14 = tl.load(in_out_ptr0 + x0, xmask) tmp15 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 - tmp7 tmp10 = tmp9 - tmp7 tmp11 = tmp8 * tmp10 tmp12 = 0.0 tmp13 = tmp11 >= tmp12 tmp16 = 0.5 tmp17 = tmp15 * tmp16 tmp18 = tmp17 * tmp16 tmp19 = tmp18 * tmp16 tmp20 = tmp19 * tmp16 tmp21 = tmp20 * tmp16 tmp22 = tmp21 * tmp16 tmp23 = tmp22 * tmp16 tmp24 = tmp23 * tmp16 tmp25 = tmp24 * tmp16 tmp26 = tmp25 * tmp16 tmp27 = tmp26 * tmp16 tmp28 = tmp27 * tmp16 tmp29 = tmp28 * tmp16 tmp30 = tmp29 * tmp16 tmp31 = tmp30 * tmp16 tmp32 = tmp31 * tmp16 tmp33 = tmp32 * tmp16 tmp34 = tmp33 * tmp16 tmp35 = tmp34 * tmp16 tmp36 = tmp35 * tmp16 tmp37 = tmp36 * tmp16 tmp38 = tmp14 + tmp37 tmp39 = tl.where(tmp13, tmp38, tmp14) tl.store(in_out_ptr0 + x0, tmp39, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_sub_11(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp3 + tmp26 tmp28 = tmp2 - tmp27 tmp29 = 0.0 tmp30 = triton_helpers.maximum(tmp28, tmp29) tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_div_where_12(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + x0, xmask) tmp19 = tl.load(in_out_ptr0 + x0, xmask) tmp20 = tl.load(in_ptr2 + x0, xmask) tmp1 = 2.0 tmp2 = libdevice.pow(tmp0, tmp1) tmp4 = libdevice.pow(tmp3, tmp1) tmp5 = tmp2 + tmp4 tmp7 = libdevice.pow(tmp6, tmp1) tmp8 = tmp5 + tmp7 tmp10 = libdevice.pow(tmp9, tmp1) tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 - tmp12 tmp15 = tmp14 - tmp12 tmp16 = tmp13 * tmp15 tmp17 = 0.0 tmp18 = tmp16 >= tmp17 tmp21 = 0.5 tmp22 = tmp20 * tmp21 tmp23 = tmp22 * tmp21 tmp24 = tmp23 * tmp21 tmp25 = tmp24 * tmp21 tmp26 = tmp25 * tmp21 tmp27 = tmp26 * tmp21 tmp28 = tmp27 * tmp21 tmp29 = tmp28 * tmp21 tmp30 = tmp29 * tmp21 tmp31 = tmp30 * tmp21 tmp32 = tmp31 * tmp21 tmp33 = tmp32 * tmp21 tmp34 = tmp33 * tmp21 tmp35 = tmp34 * tmp21 tmp36 = tmp35 * tmp21 tmp37 = tmp36 * tmp21 tmp38 = tmp37 * tmp21 tmp39 = tmp38 * tmp21 tmp40 = tmp39 * tmp21 tmp41 = tmp40 * tmp21 tmp42 = tmp41 * tmp21 tmp43 = tmp42 * tmp21 tmp44 = tmp19 + tmp43 tmp45 = tl.where(tmp18, tmp44, tmp19) tl.store(in_out_ptr0 + x0, tmp45, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_sub_13(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp26 * tmp1 tmp28 = tmp3 + tmp27 tmp29 = tmp2 - tmp28 tmp30 = 0.0 tmp31 = triton_helpers.maximum(tmp29, tmp30) tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_div_where_14(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + x0, xmask) tmp19 = tl.load(in_out_ptr0 + x0, xmask) tmp20 = tl.load(in_ptr2 + x0, xmask) tmp1 = 2.0 tmp2 = libdevice.pow(tmp0, tmp1) tmp4 = libdevice.pow(tmp3, tmp1) tmp5 = tmp2 + tmp4 tmp7 = libdevice.pow(tmp6, tmp1) tmp8 = tmp5 + tmp7 tmp10 = libdevice.pow(tmp9, tmp1) tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 - tmp12 tmp15 = tmp14 - tmp12 tmp16 = tmp13 * tmp15 tmp17 = 0.0 tmp18 = tmp16 >= tmp17 tmp21 = 0.5 tmp22 = tmp20 * tmp21 tmp23 = tmp22 * tmp21 tmp24 = tmp23 * tmp21 tmp25 = tmp24 * tmp21 tmp26 = tmp25 * tmp21 tmp27 = tmp26 * tmp21 tmp28 = tmp27 * tmp21 tmp29 = tmp28 * tmp21 tmp30 = tmp29 * tmp21 tmp31 = tmp30 * tmp21 tmp32 = tmp31 * tmp21 tmp33 = tmp32 * tmp21 tmp34 = tmp33 * tmp21 tmp35 = tmp34 * tmp21 tmp36 = tmp35 * tmp21 tmp37 = tmp36 * tmp21 tmp38 = tmp37 * tmp21 tmp39 = tmp38 * tmp21 tmp40 = tmp39 * tmp21 tmp41 = tmp40 * tmp21 tmp42 = tmp41 * tmp21 tmp43 = tmp42 * tmp21 tmp44 = tmp43 * tmp21 tmp45 = tmp19 + tmp44 tmp46 = tl.where(tmp18, tmp45, tmp19) tl.store(in_out_ptr0 + x0, tmp46, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_15(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp26 * tmp1 tmp28 = tmp27 * tmp1 tmp29 = tmp3 + tmp28 tmp30 = tmp2 - tmp29 tl.store(out_ptr0 + x2, tmp30, xmask) @triton.jit def triton_poi_fused_add_div_where_16(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + x0, xmask) tmp23 = tl.load(in_out_ptr0 + x0, xmask) tmp24 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 2.0 tmp4 = libdevice.pow(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = libdevice.pow(tmp6, tmp3) tmp8 = tmp4 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = libdevice.pow(tmp10, tmp3) tmp12 = tmp8 + tmp11 tmp14 = triton_helpers.maximum(tmp13, tmp1) tmp15 = libdevice.pow(tmp14, tmp3) tmp16 = tmp12 + tmp15 tmp17 = 1.0 tmp18 = tmp16 - tmp17 tmp20 = tmp19 - tmp17 tmp21 = tmp18 * tmp20 tmp22 = tmp21 >= tmp1 tmp25 = 0.5 tmp26 = tmp24 * tmp25 tmp27 = tmp26 * tmp25 tmp28 = tmp27 * tmp25 tmp29 = tmp28 * tmp25 tmp30 = tmp29 * tmp25 tmp31 = tmp30 * tmp25 tmp32 = tmp31 * tmp25 tmp33 = tmp32 * tmp25 tmp34 = tmp33 * tmp25 tmp35 = tmp34 * tmp25 tmp36 = tmp35 * tmp25 tmp37 = tmp36 * tmp25 tmp38 = tmp37 * tmp25 tmp39 = tmp38 * tmp25 tmp40 = tmp39 * tmp25 tmp41 = tmp40 * tmp25 tmp42 = tmp41 * tmp25 tmp43 = tmp42 * tmp25 tmp44 = tmp43 * tmp25 tmp45 = tmp44 * tmp25 tmp46 = tmp45 * tmp25 tmp47 = tmp46 * tmp25 tmp48 = tmp47 * tmp25 tmp49 = tmp48 * tmp25 tmp50 = tmp23 + tmp49 tmp51 = tl.where(tmp22, tmp50, tmp23) tl.store(in_out_ptr0 + x0, tmp51, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_17(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp26 * tmp1 tmp28 = tmp27 * tmp1 tmp29 = tmp28 * tmp1 tmp30 = tmp3 + tmp29 tmp31 = tmp2 - tmp30 tl.store(out_ptr0 + x2, tmp31, xmask) @triton.jit def triton_poi_fused_add_div_where_18(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + x0, xmask) tmp23 = tl.load(in_out_ptr0 + x0, xmask) tmp24 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 2.0 tmp4 = libdevice.pow(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = libdevice.pow(tmp6, tmp3) tmp8 = tmp4 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = libdevice.pow(tmp10, tmp3) tmp12 = tmp8 + tmp11 tmp14 = triton_helpers.maximum(tmp13, tmp1) tmp15 = libdevice.pow(tmp14, tmp3) tmp16 = tmp12 + tmp15 tmp17 = 1.0 tmp18 = tmp16 - tmp17 tmp20 = tmp19 - tmp17 tmp21 = tmp18 * tmp20 tmp22 = tmp21 >= tmp1 tmp25 = 0.5 tmp26 = tmp24 * tmp25 tmp27 = tmp26 * tmp25 tmp28 = tmp27 * tmp25 tmp29 = tmp28 * tmp25 tmp30 = tmp29 * tmp25 tmp31 = tmp30 * tmp25 tmp32 = tmp31 * tmp25 tmp33 = tmp32 * tmp25 tmp34 = tmp33 * tmp25 tmp35 = tmp34 * tmp25 tmp36 = tmp35 * tmp25 tmp37 = tmp36 * tmp25 tmp38 = tmp37 * tmp25 tmp39 = tmp38 * tmp25 tmp40 = tmp39 * tmp25 tmp41 = tmp40 * tmp25 tmp42 = tmp41 * tmp25 tmp43 = tmp42 * tmp25 tmp44 = tmp43 * tmp25 tmp45 = tmp44 * tmp25 tmp46 = tmp45 * tmp25 tmp47 = tmp46 * tmp25 tmp48 = tmp47 * tmp25 tmp49 = tmp48 * tmp25 tmp50 = tmp49 * tmp25 tmp51 = tmp23 + tmp50 tmp52 = tl.where(tmp22, tmp51, tmp23) tl.store(in_out_ptr0 + x0, tmp52, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_19(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 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp5 = tmp4 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = tmp6 * tmp1 tmp8 = tmp7 * tmp1 tmp9 = tmp8 * tmp1 tmp10 = tmp9 * tmp1 tmp11 = tmp10 * tmp1 tmp12 = tmp11 * tmp1 tmp13 = tmp12 * tmp1 tmp14 = tmp13 * tmp1 tmp15 = tmp14 * tmp1 tmp16 = tmp15 * tmp1 tmp17 = tmp16 * tmp1 tmp18 = tmp17 * tmp1 tmp19 = tmp18 * tmp1 tmp20 = tmp19 * tmp1 tmp21 = tmp20 * tmp1 tmp22 = tmp21 * tmp1 tmp23 = tmp22 * tmp1 tmp24 = tmp23 * tmp1 tmp25 = tmp24 * tmp1 tmp26 = tmp25 * tmp1 tmp27 = tmp26 * tmp1 tmp28 = tmp27 * tmp1 tmp29 = tmp28 * tmp1 tmp30 = tmp29 * tmp1 tmp31 = tmp3 + tmp30 tmp32 = tmp2 - tmp31 tl.store(out_ptr0 + x2, tmp32, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_20(in_out_ptr0, in_out_ptr4, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr7, 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') tmp5 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + x0, xmask) tmp23 = tl.load(in_out_ptr0 + x0, xmask) tmp24 = tl.load(in_ptr2 + x0, xmask) tmp56 = tl.load(in_ptr3 + 4 * x0, xmask, eviction_policy='evict_last') tmp61 = tl.load(in_ptr3 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp67 = tl.load(in_ptr3 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp73 = tl.load(in_ptr3 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 2.0 tmp4 = libdevice.pow(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp5, tmp1) tmp7 = libdevice.pow(tmp6, tmp3) tmp8 = tmp4 + tmp7 tmp10 = triton_helpers.maximum(tmp9, tmp1) tmp11 = libdevice.pow(tmp10, tmp3) tmp12 = tmp8 + tmp11 tmp14 = triton_helpers.maximum(tmp13, tmp1) tmp15 = libdevice.pow(tmp14, tmp3) tmp16 = tmp12 + tmp15 tmp17 = 1.0 tmp18 = tmp16 - tmp17 tmp20 = tmp19 - tmp17 tmp21 = tmp18 * tmp20 tmp22 = tmp21 >= tmp1 tmp25 = 0.5 tmp26 = tmp24 * tmp25 tmp27 = tmp26 * tmp25 tmp28 = tmp27 * tmp25 tmp29 = tmp28 * tmp25 tmp30 = tmp29 * tmp25 tmp31 = tmp30 * tmp25 tmp32 = tmp31 * tmp25 tmp33 = tmp32 * tmp25 tmp34 = tmp33 * tmp25 tmp35 = tmp34 * tmp25 tmp36 = tmp35 * tmp25 tmp37 = tmp36 * tmp25 tmp38 = tmp37 * tmp25 tmp39 = tmp38 * tmp25 tmp40 = tmp39 * tmp25 tmp41 = tmp40 * tmp25 tmp42 = tmp41 * tmp25 tmp43 = tmp42 * tmp25 tmp44 = tmp43 * tmp25 tmp45 = tmp44 * tmp25 tmp46 = tmp45 * tmp25 tmp47 = tmp46 * tmp25 tmp48 = tmp47 * tmp25 tmp49 = tmp48 * tmp25 tmp50 = tmp49 * tmp25 tmp51 = tmp50 * tmp25 tmp52 = tmp23 + tmp51 tmp53 = tl.where(tmp22, tmp52, tmp23) tmp54 = tmp51 * tmp25 tmp55 = tmp53 + tmp54 tmp57 = tmp56 * tmp25 tmp58 = tmp57 - tmp55 tmp59 = triton_helpers.maximum(tmp58, tmp1) tmp60 = libdevice.pow(tmp59, tmp3) tmp62 = tmp61 * tmp25 tmp63 = tmp62 - tmp55 tmp64 = triton_helpers.maximum(tmp63, tmp1) tmp65 = libdevice.pow(tmp64, tmp3) tmp66 = tmp60 + tmp65 tmp68 = tmp67 * tmp25 tmp69 = tmp68 - tmp55 tmp70 = triton_helpers.maximum(tmp69, tmp1) tmp71 = libdevice.pow(tmp70, tmp3) tmp72 = tmp66 + tmp71 tmp74 = tmp73 * tmp25 tmp75 = tmp74 - tmp55 tmp76 = triton_helpers.maximum(tmp75, tmp1) tmp77 = libdevice.pow(tmp76, tmp3) tmp78 = tmp72 + tmp77 tmp79 = tmp78 - tmp17 tmp80 = tmp79 * tmp20 tmp81 = tmp80 >= tmp1 tmp82 = tl.where(tmp81, tmp55, tmp53) tmp83 = tmp54 * tmp25 tmp84 = tmp82 + tmp83 tmp85 = tmp57 - tmp84 tmp86 = triton_helpers.maximum(tmp85, tmp1) tmp87 = libdevice.pow(tmp86, tmp3) tmp88 = tmp62 - tmp84 tmp89 = triton_helpers.maximum(tmp88, tmp1) tmp90 = libdevice.pow(tmp89, tmp3) tmp91 = tmp87 + tmp90 tmp92 = tmp68 - tmp84 tmp93 = triton_helpers.maximum(tmp92, tmp1) tmp94 = libdevice.pow(tmp93, tmp3) tmp95 = tmp91 + tmp94 tmp96 = tmp74 - tmp84 tmp97 = triton_helpers.maximum(tmp96, tmp1) tmp98 = libdevice.pow(tmp97, tmp3) tmp99 = tmp95 + tmp98 tmp100 = tmp99 - tmp17 tmp101 = tmp100 * tmp20 tmp102 = tmp101 >= tmp1 tmp103 = tl.where(tmp102, tmp84, tmp82) tmp104 = tmp83 * tmp25 tmp105 = tmp103 + tmp104 tmp106 = tmp57 - tmp105 tmp107 = triton_helpers.maximum(tmp106, tmp1) tmp108 = libdevice.pow(tmp107, tmp3) tmp109 = tmp62 - tmp105 tmp110 = triton_helpers.maximum(tmp109, tmp1) tmp111 = libdevice.pow(tmp110, tmp3) tmp112 = tmp108 + tmp111 tmp113 = tmp68 - tmp105 tmp114 = triton_helpers.maximum(tmp113, tmp1) tmp115 = libdevice.pow(tmp114, tmp3) tmp116 = tmp112 + tmp115 tmp117 = tmp74 - tmp105 tmp118 = triton_helpers.maximum(tmp117, tmp1) tmp119 = libdevice.pow(tmp118, tmp3) tmp120 = tmp116 + tmp119 tmp121 = tmp120 - tmp17 tmp122 = tmp121 * tmp20 tmp123 = tmp122 >= tmp1 tmp124 = tl.where(tmp123, tmp105, tmp103) tmp125 = tmp104 * tmp25 tmp126 = tmp124 + tmp125 tmp127 = tmp57 - tmp126 tmp128 = triton_helpers.maximum(tmp127, tmp1) tmp129 = libdevice.pow(tmp128, tmp3) tmp130 = tmp62 - tmp126 tmp131 = triton_helpers.maximum(tmp130, tmp1) tmp132 = libdevice.pow(tmp131, tmp3) tmp133 = tmp129 + tmp132 tmp134 = tmp68 - tmp126 tmp135 = triton_helpers.maximum(tmp134, tmp1) tmp136 = libdevice.pow(tmp135, tmp3) tmp137 = tmp133 + tmp136 tmp138 = tmp74 - tmp126 tmp139 = triton_helpers.maximum(tmp138, tmp1) tmp140 = libdevice.pow(tmp139, tmp3) tmp141 = tmp137 + tmp140 tmp142 = tmp141 - tmp17 tmp143 = tmp142 * tmp20 tmp144 = tmp143 >= tmp1 tmp145 = tl.where(tmp144, tmp126, tmp124) tmp146 = tmp125 * tmp25 tmp147 = tmp145 + tmp146 tmp148 = tmp57 - tmp147 tmp149 = triton_helpers.maximum(tmp148, tmp1) tmp150 = libdevice.pow(tmp149, tmp3) tmp151 = tmp62 - tmp147 tmp152 = triton_helpers.maximum(tmp151, tmp1) tmp153 = libdevice.pow(tmp152, tmp3) tmp154 = tmp150 + tmp153 tmp155 = tmp68 - tmp147 tmp156 = triton_helpers.maximum(tmp155, tmp1) tmp157 = libdevice.pow(tmp156, tmp3) tmp158 = tmp154 + tmp157 tmp159 = tmp74 - tmp147 tmp160 = triton_helpers.maximum(tmp159, tmp1) tmp161 = libdevice.pow(tmp160, tmp3) tmp162 = tmp158 + tmp161 tmp163 = tmp162 - tmp17 tmp164 = tmp163 * tmp20 tmp165 = tmp164 >= tmp1 tmp166 = tl.where(tmp165, tmp147, tmp145) tmp167 = tmp146 * tmp25 tmp168 = tmp166 + tmp167 tmp169 = tmp57 - tmp168 tmp170 = triton_helpers.maximum(tmp169, tmp1) tmp171 = libdevice.pow(tmp170, tmp3) tmp172 = tmp62 - tmp168 tmp173 = triton_helpers.maximum(tmp172, tmp1) tmp174 = libdevice.pow(tmp173, tmp3) tmp175 = tmp171 + tmp174 tmp176 = tmp68 - tmp168 tmp177 = triton_helpers.maximum(tmp176, tmp1) tmp178 = libdevice.pow(tmp177, tmp3) tmp179 = tmp175 + tmp178 tmp180 = tmp74 - tmp168 tmp181 = triton_helpers.maximum(tmp180, tmp1) tmp182 = libdevice.pow(tmp181, tmp3) tmp183 = tmp179 + tmp182 tmp184 = tmp183 - tmp17 tmp185 = tmp184 * tmp20 tmp186 = tmp185 >= tmp1 tmp187 = tl.where(tmp186, tmp168, tmp166) tmp188 = tmp167 * tmp25 tmp189 = tmp187 + tmp188 tmp190 = tmp57 - tmp189 tmp191 = triton_helpers.maximum(tmp190, tmp1) tmp192 = libdevice.pow(tmp191, tmp3) tmp193 = tmp62 - tmp189 tmp194 = triton_helpers.maximum(tmp193, tmp1) tmp195 = libdevice.pow(tmp194, tmp3) tmp196 = tmp192 + tmp195 tmp197 = tmp68 - tmp189 tmp198 = triton_helpers.maximum(tmp197, tmp1) tmp199 = libdevice.pow(tmp198, tmp3) tmp200 = tmp196 + tmp199 tmp201 = tmp74 - tmp189 tmp202 = triton_helpers.maximum(tmp201, tmp1) tmp203 = libdevice.pow(tmp202, tmp3) tmp204 = tmp200 + tmp203 tmp205 = tmp204 - tmp17 tmp206 = tmp205 * tmp20 tmp207 = tmp206 >= tmp1 tmp208 = tl.where(tmp207, tmp189, tmp187) tmp209 = tmp188 * tmp25 tmp210 = tmp208 + tmp209 tmp211 = tmp57 - tmp210 tmp212 = triton_helpers.maximum(tmp211, tmp1) tmp213 = libdevice.pow(tmp212, tmp3) tmp214 = tmp62 - tmp210 tmp215 = triton_helpers.maximum(tmp214, tmp1) tmp216 = libdevice.pow(tmp215, tmp3) tmp217 = tmp213 + tmp216 tmp218 = tmp68 - tmp210 tmp219 = triton_helpers.maximum(tmp218, tmp1) tmp220 = libdevice.pow(tmp219, tmp3) tmp221 = tmp217 + tmp220 tmp222 = tmp74 - tmp210 tmp223 = triton_helpers.maximum(tmp222, tmp1) tmp224 = libdevice.pow(tmp223, tmp3) tmp225 = tmp221 + tmp224 tmp226 = tmp225 - tmp17 tmp227 = tmp226 * tmp20 tmp228 = tmp227 >= tmp1 tmp229 = tl.where(tmp228, tmp210, tmp208) tmp230 = tmp209 * tmp25 tmp231 = tmp229 + tmp230 tmp232 = tmp57 - tmp231 tmp233 = triton_helpers.maximum(tmp232, tmp1) tmp234 = libdevice.pow(tmp233, tmp3) tmp235 = tmp62 - tmp231 tmp236 = triton_helpers.maximum(tmp235, tmp1) tmp237 = libdevice.pow(tmp236, tmp3) tmp238 = tmp234 + tmp237 tmp239 = tmp68 - tmp231 tmp240 = triton_helpers.maximum(tmp239, tmp1) tmp241 = libdevice.pow(tmp240, tmp3) tmp242 = tmp238 + tmp241 tmp243 = tmp74 - tmp231 tmp244 = triton_helpers.maximum(tmp243, tmp1) tmp245 = libdevice.pow(tmp244, tmp3) tmp246 = tmp242 + tmp245 tl.store(in_out_ptr4 + x0, tmp231, xmask) tl.store(out_ptr7 + x0, tmp246, xmask) @triton.jit def triton_poi_fused_add_clamp_div_mul_pow_sub_where_21(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 + x1, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = tmp2 - tmp3 tmp5 = 0.0 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = 2.0 tmp8 = libdevice.pow(tmp6, tmp7) tmp10 = tmp8 / tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf35 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf51 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf52 = reinterpret_tensor(buf51, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf51 buf53 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_clamp_div_max_mul_pow_sub_sum_where_0[grid(64)]( buf52, arg0_1, buf1, buf35, buf53, 64, XBLOCK=64, num_warps=1, num_stages=1) buf54 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_clamp_div_mul_pow_sub_where_1[grid(256)](arg0_1, buf53, buf1, buf52, buf35, buf54, 256, XBLOCK=128, num_warps=4, num_stages=1) buf55 = buf52 del buf52 buf56 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_2[grid(64)](buf55, buf54, buf1, buf53, buf35, arg0_1, buf56, 64, XBLOCK=64, num_warps=1, num_stages=1) buf57 = buf54 del buf54 triton_poi_fused_add_div_mul_sub_where_3[grid(256)](arg0_1, buf56, buf1, buf55, buf35, buf57, 256, XBLOCK=256, num_warps=4, num_stages=1) buf58 = buf55 del buf55 buf59 = buf53 del buf53 triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_4[grid(64)](buf58, buf57, buf1, buf56, buf35, arg0_1, buf59, 64, XBLOCK=64, num_warps=1, num_stages=1) buf60 = buf57 del buf57 triton_poi_fused_add_div_mul_sub_where_5[grid(256)](arg0_1, buf59, buf1, buf58, buf35, buf60, 256, XBLOCK=128, num_warps=4, num_stages=1) buf61 = buf58 del buf58 buf66 = buf56 del buf56 buf67 = reinterpret_tensor(buf66, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf66 triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_6[grid(64)](buf61, buf67, buf60, buf1, buf59, buf35, arg0_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf68 = buf60 del buf60 triton_poi_fused_add_clamp_div_mul_pow_sub_7[grid(256)](arg0_1, buf67, buf35, buf68, 256, XBLOCK=128, num_warps=4, num_stages=1) buf69 = buf67 del buf67 triton_poi_fused_add_div_where_8[grid(64)](buf69, buf68, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf70 = buf68 del buf68 triton_poi_fused_add_clamp_div_mul_pow_sub_9[grid(256)](arg0_1, buf69, buf35, buf70, 256, XBLOCK=128, num_warps=4, num_stages=1) buf71 = buf69 del buf69 triton_poi_fused_add_div_where_10[grid(64)](buf71, buf70, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf72 = buf70 del buf70 triton_poi_fused_add_clamp_div_mul_sub_11[grid(256)](arg0_1, buf71, buf35, buf72, 256, XBLOCK=256, num_warps=4, num_stages=1) buf73 = buf71 del buf71 triton_poi_fused_add_div_where_12[grid(64)](buf73, buf72, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf74 = buf72 del buf72 triton_poi_fused_add_clamp_div_mul_sub_13[grid(256)](arg0_1, buf73, buf35, buf74, 256, XBLOCK=256, num_warps=4, num_stages=1) buf75 = buf73 del buf73 triton_poi_fused_add_div_where_14[grid(64)](buf75, buf74, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf76 = buf74 del buf74 triton_poi_fused_add_div_mul_sub_15[grid(256)](arg0_1, buf75, buf35, buf76, 256, XBLOCK=256, num_warps=4, num_stages=1) buf77 = buf75 del buf75 triton_poi_fused_add_div_where_16[grid(64)](buf77, buf76, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf78 = buf76 del buf76 triton_poi_fused_add_div_mul_sub_17[grid(256)](arg0_1, buf77, buf35, buf78, 256, XBLOCK=256, num_warps=4, num_stages=1) buf79 = buf77 del buf77 triton_poi_fused_add_div_where_18[grid(64)](buf79, buf78, buf1, buf35, 64, XBLOCK=64, num_warps=1, num_stages=1) buf80 = buf78 del buf78 triton_poi_fused_add_div_mul_sub_19[grid(256)](arg0_1, buf79, buf35, buf80, 256, XBLOCK=256, num_warps=4, num_stages=1) buf81 = buf79 del buf79 buf95 = reinterpret_tensor(buf61, (4, 4, 4), (16, 4, 1), 0) del buf61 buf96 = reinterpret_tensor(buf95, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf95 buf97 = buf59 del buf59 triton_poi_fused_add_clamp_div_mul_pow_sub_sum_where_20[grid(64)](buf81 , buf96, buf80, buf1, buf35, arg0_1, buf97, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 del buf35 del buf81 buf98 = buf80 del buf80 triton_poi_fused_add_clamp_div_mul_pow_sub_where_21[grid(256)](arg0_1, buf96, buf97, buf98, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del buf96 del buf97 return buf98, def entmax_bisect(X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True): """alpha-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_a(p) s.t. p >= 0, sum(p) == 1. where H_a(p) is the Tsallis alpha-entropy with custom alpha >= 1, using a bisection (root finding, binary search) algorithm. This function is differentiable with respect to both X and alpha. Parameters ---------- X : torch.Tensor The input tensor. alpha : float or torch.Tensor Tensor of alpha parameters (> 1) to use. If scalar or python float, the same value is used for all rows, otherwise, it must have shape (or be expandable to) alpha.shape[j] == (X.shape[j] if j != dim else 1) A value of alpha=2 corresponds to sparsemax, and alpha=1 corresponds to softmax (but computing it this way is likely unstable). dim : int The dimension along which to apply alpha-entmax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. ensure_sum_one : bool, Whether to divide the result by its sum. If false, the result might sum to close but not exactly 1, which might cause downstream problems. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return EntmaxBisectFunction.apply(X, alpha, dim, n_iter, ensure_sum_one) class EntmaxBisectFunction(Function): @classmethod def _gp(cls, x, alpha): return x ** (alpha - 1) @classmethod def _gp_inv(cls, y, alpha): return y ** (1 / (alpha - 1)) @classmethod def _p(cls, X, alpha): return cls._gp_inv(torch.clamp(X, min=0), alpha) @classmethod def forward(cls, ctx, X, alpha=1.5, dim=-1, n_iter=50, ensure_sum_one=True ): if not isinstance(alpha, torch.Tensor): alpha = torch.tensor(alpha, dtype=X.dtype, device=X.device) alpha_shape = list(X.shape) alpha_shape[dim] = 1 alpha = alpha.expand(*alpha_shape) ctx.alpha = alpha ctx.dim = dim d = X.shape[dim] X = X * (alpha - 1) max_val, _ = X.max(dim=dim, keepdim=True) tau_lo = max_val - cls._gp(1, alpha) tau_hi = max_val - cls._gp(1 / d, alpha) f_lo = cls._p(X - tau_lo, alpha).sum(dim) - 1 dm = tau_hi - tau_lo for it in range(n_iter): dm /= 2 tau_m = tau_lo + dm p_m = cls._p(X - tau_m, alpha) f_m = p_m.sum(dim) - 1 mask = (f_m * f_lo >= 0).unsqueeze(dim) tau_lo = torch.where(mask, tau_m, tau_lo) if ensure_sum_one: p_m /= p_m.sum(dim=dim).unsqueeze(dim=dim) ctx.save_for_backward(p_m) return p_m @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = torch.where(Y > 0, Y ** (2 - ctx.alpha), Y.new_zeros(1)) dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr d_alpha = None if ctx.needs_input_grad[1]: S = torch.where(Y > 0, Y * torch.log(Y), Y.new_zeros(1)) ent = S.sum(ctx.dim).unsqueeze(ctx.dim) Y_skewed = gppr / gppr.sum(ctx.dim).unsqueeze(ctx.dim) d_alpha = dY * (Y - Y_skewed) / (ctx.alpha - 1) ** 2 d_alpha -= dY * (S - Y_skewed * ent) / (ctx.alpha - 1) d_alpha = d_alpha.sum(ctx.dim).unsqueeze(ctx.dim) return dX, d_alpha, None, None, None class EntmaxBisectNew(nn.Module): def __init__(self, alpha=1.5, dim=-1, n_iter=50): """alpha-entmax: normalizing sparse map (a la softmax) via bisection. Solves the optimization problem: max_p <x, p> - H_a(p) s.t. p >= 0, sum(p) == 1. where H_a(p) is the Tsallis alpha-entropy with custom alpha >= 1, using a bisection (root finding, binary search) algorithm. Parameters ---------- alpha : float or torch.Tensor Tensor of alpha parameters (> 1) to use. If scalar or python float, the same value is used for all rows, otherwise, it must have shape (or be expandable to) alpha.shape[j] == (X.shape[j] if j != dim else 1) A value of alpha=2 corresponds to sparsemax; alpha=1 corresponds to softmax (but computing it this way is likely unstable). dim : int The dimension along which to apply alpha-entmax. n_iter : int Number of bisection iterations. For float32, 24 iterations should suffice for machine precision. """ self.dim = dim self.n_iter = n_iter self.alpha = alpha super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
roholazandie/entmax
EntmaxBisect
false
7,629
[ "MIT" ]
1
657374e6a792ec6840b6f78bc759cc1f51570aad
https://github.com/roholazandie/entmax/tree/657374e6a792ec6840b6f78bc759cc1f51570aad
ResNetV2
import torch import torch.nn as nn import torch.nn.functional as F from collections import OrderedDict import torch.utils.data def conv1x1(cin, cout, stride=1, bias=False): return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0, bias=bias) def conv3x3(in_planes, out_planes, stride=1): return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True) def tf2th(conv_weights): """Possibly convert HWIO to OIHW.""" if conv_weights.ndim == 4: conv_weights = conv_weights.transpose([3, 2, 0, 1]) return torch.from_numpy(conv_weights) class StdConv2d(nn.Conv2d): def forward(self, x): w = self.weight v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False) w = (w - m) / torch.sqrt(v + 1e-10) return F.conv2d(x, w, self.bias, self.stride, self.padding, self. dilation, self.groups) class PreActBottleneck(nn.Module): """Pre-activation (v2) bottleneck block. Follows the implementation of "Identity Mappings in Deep Residual Networks": https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua Except it puts the stride on 3x3 conv when available. """ def __init__(self, cin, cout=None, cmid=None, stride=1): super().__init__() cout = cout or cin cmid = cmid or cout // 4 self.gn1 = nn.GroupNorm(32, cin) self.conv1 = conv1x1(cin, cmid) self.gn2 = nn.GroupNorm(32, cmid) self.conv2 = conv3x3(cmid, cmid, stride) self.gn3 = nn.GroupNorm(32, cmid) self.conv3 = conv1x1(cmid, cout) self.relu = nn.ReLU(inplace=True) if stride != 1 or cin != cout: self.downsample = conv1x1(cin, cout, stride) def forward(self, x): out = self.relu(self.gn1(x)) residual = x if hasattr(self, 'downsample'): residual = self.downsample(out) out = self.conv1(out) out = self.conv2(self.relu(self.gn2(out))) out = self.conv3(self.relu(self.gn3(out))) return out + residual def load_from(self, weights, prefix=''): convname = 'standardized_conv2d' with torch.no_grad(): self.conv1.weight.copy_(tf2th(weights[ f'{prefix}a/{convname}/kernel'])) self.conv2.weight.copy_(tf2th(weights[ f'{prefix}b/{convname}/kernel'])) self.conv3.weight.copy_(tf2th(weights[ f'{prefix}c/{convname}/kernel'])) self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma']) ) self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma']) ) self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma']) ) self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta'])) self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta'])) self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta'])) if hasattr(self, 'downsample'): w = weights[f'{prefix}a/proj/{convname}/kernel'] self.downsample.weight.copy_(tf2th(w)) class ResNetV2(nn.Module): """Implementation of Pre-activation (v2) ResNet mode.""" def __init__(self, block_units, width_factor, head_size=21843, zero_head=False): super().__init__() wf = width_factor self.wf = wf self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 * wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad', nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3, stride=2, padding=0))])) self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential( OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 * wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin= 256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2, block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid= 128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin= 512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2, block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid= 256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin= 1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2, block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid =512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin =2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2, block_units[3] + 1)])))])) self.zero_head = zero_head self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 * wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn. AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf, head_size, kernel_size=1, bias=True))])) def forward(self, x): x = self.head(self.body(self.root(x))) return x def load_from(self, weights, prefix='resnet/'): with torch.no_grad(): self.root.conv.weight.copy_(tf2th(weights[ f'{prefix}root_block/standardized_conv2d/kernel'])) self.head.gn.weight.copy_(tf2th(weights[ f'{prefix}group_norm/gamma'])) self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta'])) if self.zero_head: nn.init.zeros_(self.head.conv.weight) nn.init.zeros_(self.head.conv.bias) else: self.head.conv.weight.copy_(tf2th(weights[ f'{prefix}head/conv2d/kernel'])) self.head.conv.bias.copy_(tf2th(weights[ f'{prefix}head/conv2d/bias'])) for bname, block in self.body.named_children(): for uname, unit in block.named_children(): unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/') def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {'block_units': [4, 4, 4, 4], 'width_factor': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F from collections import OrderedDict import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 768 xnumel = 49 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 49 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 147 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 1024 y1 = yindex // 1024 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 1024 * x2 + 9216 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 2048 y1 = yindex // 2048 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 2048 * x2 + 18432 * y1), tmp0, xmask) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_6(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 rnumel = 147 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 147 * x0), rmask & xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(rmask & xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(rmask & xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 147, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(rmask & xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 147.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-10 tmp20 = tmp18 + tmp19 tmp21 = libdevice.sqrt(tmp20) tmp22 = tmp0 - tmp10 tmp23 = tmp22 / tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(out_ptr1 + (r1 + 147 * x0), tmp23, rmask & xmask) @triton.jit def triton_poi_fused_constant_pad_nd_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 8704 % 34 x1 = xindex // 256 % 34 x3 = xindex // 295936 x4 = xindex % 8704 x6 = xindex tmp0 = -1 + x2 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x1 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-8448 + x4 + 8192 * x2 + 262144 * x3), tmp10, other=0.0) tl.store(out_ptr0 + x6, tmp11, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 256 x1 = xindex // 256 % 16 x2 = xindex // 4096 % 16 x3 = xindex // 65536 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp3 = tl.load(in_ptr0 + (512 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp5 = tl.load(in_ptr0 + (8704 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp7 = tl.load(in_ptr0 + (8960 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp9 = tl.load(in_ptr0 + (9216 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp11 = tl.load(in_ptr0 + (17408 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp13 = tl.load(in_ptr0 + (17664 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp15 = tl.load(in_ptr0 + (17920 + x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp8 = triton_helpers.maximum(tmp7, tmp6) tmp10 = triton_helpers.maximum(tmp9, tmp8) tmp12 = triton_helpers.maximum(tmp11, tmp10) tmp14 = triton_helpers.maximum(tmp13, tmp12) tmp16 = triton_helpers.maximum(tmp15, tmp14) tmp17 = tmp1 > tmp0 tmp18 = tl.full([1], 1, tl.int8) tmp19 = tl.full([1], 0, tl.int8) tmp20 = tl.where(tmp17, tmp18, tmp19) tmp21 = tmp3 > tmp2 tmp22 = tl.full([1], 2, tl.int8) tmp23 = tl.where(tmp21, tmp22, tmp20) tmp24 = tmp5 > tmp4 tmp25 = tl.full([1], 3, tl.int8) tmp26 = tl.where(tmp24, tmp25, tmp23) tmp27 = tmp7 > tmp6 tmp28 = tl.full([1], 4, tl.int8) tmp29 = tl.where(tmp27, tmp28, tmp26) tmp30 = tmp9 > tmp8 tmp31 = tl.full([1], 5, tl.int8) tmp32 = tl.where(tmp30, tmp31, tmp29) tmp33 = tmp11 > tmp10 tmp34 = tl.full([1], 6, tl.int8) tmp35 = tl.where(tmp33, tmp34, tmp32) tmp36 = tmp13 > tmp12 tmp37 = tl.full([1], 7, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tmp15 > tmp14 tmp40 = tl.full([1], 8, tl.int8) tmp41 = tl.where(tmp39, tmp40, tmp38) tl.store(out_ptr0 + x4, tmp16, None) tl.store(out_ptr1 + x4, tmp41, None) @triton.jit def triton_red_fused_native_group_norm_9(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 2048 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 8 r3 = rindex // 8 tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 256 * r3 + 65536 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_10(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 256 x2 = xindex // 65536 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 8), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 8), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 2048.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_11(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 256, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 256 * x0), tmp20, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_12(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 256, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 256 * x0), tmp20, None) @triton.jit def triton_poi_fused_convolution_13(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_poi_fused_add_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = tl.load(in_out_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_red_fused_native_group_norm_15(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 8192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 32 r3 = rindex // 32 tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 262144 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 8192.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_16(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 1024 x2 = xindex // 262144 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 8192.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_17(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None) @triton.jit def triton_poi_fused_add_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) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_19(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_20(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None) @triton.jit def triton_red_fused_native_group_norm_21(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 16 r3 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 131072 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_22(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 512 x2 = xindex // 131072 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 4096.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_convolution_23(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_24(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 16 r3 = rindex // 16 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 32768 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) tl.store(out_ptr1 + x4, tmp13, None) @triton.jit def triton_poi_fused_native_group_norm_relu_25(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 512 x2 = xindex // 32768 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1024.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_26(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 512 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 512 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 512, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 512.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 512 * x0), tmp20, None) @triton.jit def triton_poi_fused_add_27(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = tl.load(in_out_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_red_fused_native_group_norm_28(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 64 r3 = rindex // 64 tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 131072 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_29(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 2048 x2 = xindex // 131072 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 4096.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_30(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 512 rnumel = 2048 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) 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 + 2048 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask & xmask) @triton.jit def triton_poi_fused_add_31(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_32(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 2048 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, None) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy= 'evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_33(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 1024 rnumel = 2048 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) 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 + 2048 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask & xmask) @triton.jit def triton_red_fused_native_group_norm_34(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 2048 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 32 r3 = rindex // 32 tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 65536 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_35(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 1024 x2 = xindex // 65536 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 2048.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_convolution_36(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_37(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 512 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 32 r3 = rindex // 32 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 16384 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 512, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 512.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) tl.store(out_ptr1 + x4, tmp13, None) @triton.jit def triton_poi_fused_native_group_norm_relu_38(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 1024 x2 = xindex // 16384 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 512.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_per_fused_add_div_sqrt_sub_var_mean_39(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 1024 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-10 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp0 - tmp8 tmp20 = tmp19 / tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp18, None) tl.store(out_ptr1 + (r1 + 1024 * x0), tmp20, None) @triton.jit def triton_poi_fused_add_40(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = tl.load(in_out_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_red_fused_native_group_norm_41(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 2048 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 32 x1 = xindex // 32 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) x4 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex % 128 r3 = rindex // 128 tmp0 = tl.load(in_ptr0 + (r2 + 128 * x0 + 4096 * r3 + 65536 * x1), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x4, tmp2, xmask) tl.store(out_ptr1 + x4, tmp3, xmask) tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-05 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tl.store(out_ptr2 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_native_group_norm_relu_42(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 4096 x2 = xindex // 65536 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 128), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 128), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 2048.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_43(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 1024 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) 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 + 4096 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask & xmask) @triton.jit def triton_poi_fused_add_44(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_45(in_out_ptr0, in_ptr0, out_ptr1, 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, None) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask, eviction_policy= 'evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_46(in_out_ptr0, in_ptr0, out_ptr1, 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 4096.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, None) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask, eviction_policy= 'evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 4096 * x0), tmp12, rmask) @triton.jit def triton_per_fused_native_group_norm_47(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 64 r3 = rindex // 64 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 32768 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) tl.store(out_ptr1 + x4, tmp13, None) @triton.jit def triton_poi_fused_native_group_norm_relu_48(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 2048 x2 = xindex // 32768 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1024.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_convolution_49(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 2048 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_50(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 64 r3 = rindex // 64 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 8192 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 256, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) tl.store(out_ptr1 + x4, tmp13, None) @triton.jit def triton_poi_fused_native_group_norm_relu_51(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 2048 x2 = xindex // 8192 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 256.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_52(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 2048 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 2048.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, None) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 2048 * x0), rmask, eviction_policy= 'evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 2048 * x0), tmp12, rmask) @triton.jit def triton_poi_fused_add_53(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = tl.load(in_out_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_54(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 256 r3 = rindex // 256 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * r3 + 32768 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.store(out_ptr2 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) tl.store(out_ptr1 + x4, tmp13, None) @triton.jit def triton_poi_fused_native_group_norm_relu_55(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 8192 x2 = xindex // 32768 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 256), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 256), None, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1024.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tmp14 = tl.full([1], 0, tl.int32) tmp15 = triton_helpers.maximum(tmp14, tmp13) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_red_fused_add_div_sqrt_sub_var_mean_56(in_out_ptr0, in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 8192 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 tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tmp5 = 8192.0 tmp6 = tmp3 / tmp5 tmp7 = 1e-10 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, None) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp10 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask, eviction_policy= 'evict_first', other=0.0) tmp11 = tmp10 - tmp2 tmp12 = tmp11 / tmp9 tl.store(out_ptr1 + (r1 + 8192 * x0), tmp12, rmask) @triton.jit def triton_poi_fused_add_57(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.load(in_ptr0 + x0, None) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_58(in_out_ptr0, in_ptr0, out_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex % 256 r3 = rindex // 256 x0 = xindex % 32 x1 = xindex // 32 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * r3 + 32768 * x1), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 1024, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 1024.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-05 tmp17 = tmp15 + tmp16 tmp18 = libdevice.rsqrt(tmp17) tl.debug_barrier() tl.store(in_out_ptr0 + x4, tmp18, None) tl.store(out_ptr0 + x4, tmp8, None) @triton.jit def triton_poi_fused_mean_native_group_norm_relu_59(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 8192 x1 = xindex // 8192 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 32768 * x1), None) tmp1 = tl.load(in_ptr1 + x2 // 256, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2 // 256, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (8192 + x0 + 32768 * x1), None) tmp18 = tl.load(in_ptr0 + (16384 + x0 + 32768 * x1), None) tmp25 = tl.load(in_ptr0 + (24576 + x0 + 32768 * x1), None) tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 0, tl.int32) tmp10 = triton_helpers.maximum(tmp9, tmp8) tmp12 = tmp11 - tmp1 tmp13 = tmp12 * tmp3 tmp14 = tmp13 * tmp5 tmp15 = tmp14 + tmp7 tmp16 = triton_helpers.maximum(tmp9, tmp15) tmp17 = tmp10 + tmp16 tmp19 = tmp18 - tmp1 tmp20 = tmp19 * tmp3 tmp21 = tmp20 * tmp5 tmp22 = tmp21 + tmp7 tmp23 = triton_helpers.maximum(tmp9, tmp22) tmp24 = tmp17 + tmp23 tmp26 = tmp25 - tmp1 tmp27 = tmp26 * tmp3 tmp28 = tmp27 * tmp5 tmp29 = tmp28 + tmp7 tmp30 = triton_helpers.maximum(tmp9, tmp29) tmp31 = tmp24 + tmp30 tmp32 = 4.0 tmp33 = tmp31 / tmp32 tl.store(out_ptr0 + x2, tmp33, None) @triton.jit def triton_poi_fused_convolution_60(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 87372 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 21843 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72, primals_73, primals_74, primals_75, primals_76, primals_77, primals_78, primals_79, primals_80, primals_81, primals_82, primals_83, primals_84, primals_85, primals_86, primals_87, primals_88, primals_89, primals_90, primals_91, primals_92, primals_93, primals_94, primals_95, primals_96, primals_97, primals_98, primals_99, primals_100, primals_101, primals_102, primals_103, primals_104, primals_105, primals_106, primals_107, primals_108, primals_109, primals_110, primals_111, primals_112, primals_113, primals_114, primals_115, primals_116, primals_117, primals_118, primals_119, primals_120, primals_121, primals_122, primals_123, primals_124, primals_125, primals_126, primals_127, primals_128, primals_129, primals_130, primals_131, primals_132, primals_133, primals_134, primals_135, primals_136, primals_137, primals_138, primals_139, primals_140, primals_141, primals_142, primals_143, primals_144, primals_145, primals_146, primals_147, primals_148, primals_149, primals_150, primals_151, primals_152, primals_153, primals_154, primals_155, primals_156, primals_157, primals_158, primals_159, primals_160, primals_161, primals_162, primals_163, primals_164, primals_165, primals_166, primals_167, primals_168, primals_169, primals_170) = args args.clear() assert_size_stride(primals_1, (256, 3, 7, 7), (147, 49, 7, 1)) assert_size_stride(primals_2, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_3, (256,), (1,)) assert_size_stride(primals_4, (256,), (1,)) assert_size_stride(primals_5, (1024, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_6, (256, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (256,), (1,)) assert_size_stride(primals_9, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_10, (256,), (1,)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256,), (1,)) assert_size_stride(primals_13, (1024, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_14, (1024,), (1,)) assert_size_stride(primals_15, (1024,), (1,)) assert_size_stride(primals_16, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_17, (256,), (1,)) assert_size_stride(primals_18, (256,), (1,)) assert_size_stride(primals_19, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_20, (256,), (1,)) assert_size_stride(primals_21, (256,), (1,)) assert_size_stride(primals_22, (256,), (1,)) assert_size_stride(primals_23, (1024, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_24, (1024,), (1,)) assert_size_stride(primals_25, (1024,), (1,)) assert_size_stride(primals_26, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_27, (256,), (1,)) assert_size_stride(primals_28, (256,), (1,)) assert_size_stride(primals_29, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_30, (256,), (1,)) assert_size_stride(primals_31, (256,), (1,)) assert_size_stride(primals_32, (256,), (1,)) assert_size_stride(primals_33, (1024, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_34, (1024,), (1,)) assert_size_stride(primals_35, (1024,), (1,)) assert_size_stride(primals_36, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_37, (256,), (1,)) assert_size_stride(primals_38, (256,), (1,)) assert_size_stride(primals_39, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_40, (256,), (1,)) assert_size_stride(primals_41, (256,), (1,)) assert_size_stride(primals_42, (256,), (1,)) assert_size_stride(primals_43, (1024, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_44, (1024,), (1,)) assert_size_stride(primals_45, (1024,), (1,)) assert_size_stride(primals_46, (2048, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_47, (512, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_48, (512,), (1,)) assert_size_stride(primals_49, (512,), (1,)) assert_size_stride(primals_50, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_51, (512,), (1,)) assert_size_stride(primals_52, (512,), (1,)) assert_size_stride(primals_53, (512,), (1,)) assert_size_stride(primals_54, (2048, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_55, (2048,), (1,)) assert_size_stride(primals_56, (2048,), (1,)) assert_size_stride(primals_57, (512, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_58, (512,), (1,)) assert_size_stride(primals_59, (512,), (1,)) assert_size_stride(primals_60, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_61, (512,), (1,)) assert_size_stride(primals_62, (512,), (1,)) assert_size_stride(primals_63, (512,), (1,)) assert_size_stride(primals_64, (2048, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_65, (2048,), (1,)) assert_size_stride(primals_66, (2048,), (1,)) assert_size_stride(primals_67, (512, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_68, (512,), (1,)) assert_size_stride(primals_69, (512,), (1,)) assert_size_stride(primals_70, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_71, (512,), (1,)) assert_size_stride(primals_72, (512,), (1,)) assert_size_stride(primals_73, (512,), (1,)) assert_size_stride(primals_74, (2048, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_75, (2048,), (1,)) assert_size_stride(primals_76, (2048,), (1,)) assert_size_stride(primals_77, (512, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_78, (512,), (1,)) assert_size_stride(primals_79, (512,), (1,)) assert_size_stride(primals_80, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_81, (512,), (1,)) assert_size_stride(primals_82, (512,), (1,)) assert_size_stride(primals_83, (512,), (1,)) assert_size_stride(primals_84, (2048, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_85, (2048,), (1,)) assert_size_stride(primals_86, (2048,), (1,)) assert_size_stride(primals_87, (4096, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_88, (1024, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_89, (1024,), (1,)) assert_size_stride(primals_90, (1024,), (1,)) assert_size_stride(primals_91, (1024, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_92, (1024,), (1,)) assert_size_stride(primals_93, (1024,), (1,)) assert_size_stride(primals_94, (1024,), (1,)) assert_size_stride(primals_95, (4096, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_96, (4096,), (1,)) assert_size_stride(primals_97, (4096,), (1,)) assert_size_stride(primals_98, (1024, 4096, 1, 1), (4096, 1, 1, 1)) assert_size_stride(primals_99, (1024,), (1,)) assert_size_stride(primals_100, (1024,), (1,)) assert_size_stride(primals_101, (1024, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_102, (1024,), (1,)) assert_size_stride(primals_103, (1024,), (1,)) assert_size_stride(primals_104, (1024,), (1,)) assert_size_stride(primals_105, (4096, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_106, (4096,), (1,)) assert_size_stride(primals_107, (4096,), (1,)) assert_size_stride(primals_108, (1024, 4096, 1, 1), (4096, 1, 1, 1)) assert_size_stride(primals_109, (1024,), (1,)) assert_size_stride(primals_110, (1024,), (1,)) assert_size_stride(primals_111, (1024, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_112, (1024,), (1,)) assert_size_stride(primals_113, (1024,), (1,)) assert_size_stride(primals_114, (1024,), (1,)) assert_size_stride(primals_115, (4096, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_116, (4096,), (1,)) assert_size_stride(primals_117, (4096,), (1,)) assert_size_stride(primals_118, (1024, 4096, 1, 1), (4096, 1, 1, 1)) assert_size_stride(primals_119, (1024,), (1,)) assert_size_stride(primals_120, (1024,), (1,)) assert_size_stride(primals_121, (1024, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_122, (1024,), (1,)) assert_size_stride(primals_123, (1024,), (1,)) assert_size_stride(primals_124, (1024,), (1,)) assert_size_stride(primals_125, (4096, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_126, (4096,), (1,)) assert_size_stride(primals_127, (4096,), (1,)) assert_size_stride(primals_128, (8192, 4096, 1, 1), (4096, 1, 1, 1)) assert_size_stride(primals_129, (2048, 4096, 1, 1), (4096, 1, 1, 1)) assert_size_stride(primals_130, (2048,), (1,)) assert_size_stride(primals_131, (2048,), (1,)) assert_size_stride(primals_132, (2048, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_133, (2048,), (1,)) assert_size_stride(primals_134, (2048,), (1,)) assert_size_stride(primals_135, (2048,), (1,)) assert_size_stride(primals_136, (8192, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_137, (8192,), (1,)) assert_size_stride(primals_138, (8192,), (1,)) assert_size_stride(primals_139, (2048, 8192, 1, 1), (8192, 1, 1, 1)) assert_size_stride(primals_140, (2048,), (1,)) assert_size_stride(primals_141, (2048,), (1,)) assert_size_stride(primals_142, (2048, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_143, (2048,), (1,)) assert_size_stride(primals_144, (2048,), (1,)) assert_size_stride(primals_145, (2048,), (1,)) assert_size_stride(primals_146, (8192, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_147, (8192,), (1,)) assert_size_stride(primals_148, (8192,), (1,)) assert_size_stride(primals_149, (2048, 8192, 1, 1), (8192, 1, 1, 1)) assert_size_stride(primals_150, (2048,), (1,)) assert_size_stride(primals_151, (2048,), (1,)) assert_size_stride(primals_152, (2048, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_153, (2048,), (1,)) assert_size_stride(primals_154, (2048,), (1,)) assert_size_stride(primals_155, (2048,), (1,)) assert_size_stride(primals_156, (8192, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_157, (8192,), (1,)) assert_size_stride(primals_158, (8192,), (1,)) assert_size_stride(primals_159, (2048, 8192, 1, 1), (8192, 1, 1, 1)) assert_size_stride(primals_160, (2048,), (1,)) assert_size_stride(primals_161, (2048,), (1,)) assert_size_stride(primals_162, (2048, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_163, (2048,), (1,)) assert_size_stride(primals_164, (2048,), (1,)) assert_size_stride(primals_165, (2048,), (1,)) assert_size_stride(primals_166, (8192, 2048, 1, 1), (2048, 1, 1, 1)) assert_size_stride(primals_167, (8192,), (1,)) assert_size_stride(primals_168, (8192,), (1,)) assert_size_stride(primals_169, (21843, 8192, 1, 1), (8192, 1, 1, 1)) assert_size_stride(primals_170, (21843,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch. float32) get_raw_stream(0) triton_poi_fused_0[grid(768, 49)](primals_1, buf0, 768, 49, XBLOCK= 32, YBLOCK=32, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) triton_poi_fused_1[grid(12, 4096)](primals_2, buf1, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_2[grid(65536, 9)](primals_9, buf2, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_9 buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_2[grid(65536, 9)](primals_19, buf3, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_19 buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_2[grid(65536, 9)](primals_29, buf4, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_29 buf5 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_2[grid(65536, 9)](primals_39, buf5, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_39 buf6 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_3[grid(262144, 9)](primals_50, buf6, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_50 buf7 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_3[grid(262144, 9)](primals_60, buf7, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_60 buf8 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_3[grid(262144, 9)](primals_70, buf8, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_70 buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_3[grid(262144, 9)](primals_80, buf9, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_80 buf10 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024 ), torch.float32) triton_poi_fused_4[grid(1048576, 9)](primals_91, buf10, 1048576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_91 buf11 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024 ), torch.float32) triton_poi_fused_4[grid(1048576, 9)](primals_101, buf11, 1048576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_101 buf12 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024 ), torch.float32) triton_poi_fused_4[grid(1048576, 9)](primals_111, buf12, 1048576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_111 buf13 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024 ), torch.float32) triton_poi_fused_4[grid(1048576, 9)](primals_121, buf13, 1048576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_121 buf14 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144, 2048), torch.float32) triton_poi_fused_5[grid(4194304, 9)](primals_132, buf14, 4194304, 9, XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1) del primals_132 buf15 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144, 2048), torch.float32) triton_poi_fused_5[grid(4194304, 9)](primals_142, buf15, 4194304, 9, XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1) del primals_142 buf16 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144, 2048), torch.float32) triton_poi_fused_5[grid(4194304, 9)](primals_152, buf16, 4194304, 9, XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1) del primals_152 buf17 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144, 2048), torch.float32) triton_poi_fused_5[grid(4194304, 9)](primals_162, buf17, 4194304, 9, XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1) del primals_162 buf19 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256), torch.float32) buf21 = reinterpret_tensor(buf19, (256, 1, 1, 1), (1, 1, 1, 1), 0) del buf19 buf22 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch. float32) triton_per_fused_add_div_sqrt_sub_var_mean_6[grid(256)](buf21, buf0, buf22, 256, 147, XBLOCK=1, num_warps=2, num_stages=1) buf23 = extern_kernels.convolution(buf1, buf22, stride=(2, 2), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf23, (4, 256, 32, 32), (262144, 1, 8192, 256)) buf24 = empty_strided_cuda((4, 256, 34, 34), (295936, 1, 8704, 256), torch.float32) triton_poi_fused_constant_pad_nd_7[grid(1183744)](buf23, buf24, 1183744, XBLOCK=512, num_warps=8, num_stages=1) buf25 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) buf26 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.int8) triton_poi_fused_max_pool2d_with_indices_8[grid(262144)](buf24, buf25, buf26, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf27 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf28 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf30 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_9[grid(128)](buf25, buf27, buf28, buf30, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf31 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf25, buf27, buf28, primals_3, primals_4, buf31, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_4 buf33 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf35 = reinterpret_tensor(buf33, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf33 buf36 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf35, primals_5, buf36, 1024, 256, num_warps=2, num_stages=1) buf37 = extern_kernels.convolution(buf31, buf36, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf37, (4, 1024, 16, 16), (262144, 1, 16384, 1024)) buf39 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256), torch.float32) buf41 = reinterpret_tensor(buf39, (256, 1, 1, 1), (1, 1, 1, 1), 0) del buf39 buf42 = empty_strided_cuda((256, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_12[grid(256)](buf41, primals_6, buf42, 256, 256, num_warps=2, num_stages=1) buf43 = extern_kernels.convolution(buf31, buf42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf43, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf44 = buf28 del buf28 buf45 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf47 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_9[grid(128)](buf43, buf44, buf45, buf47, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf48 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf43, buf44, buf45, primals_7, primals_8, buf48, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_8 buf49 = extern_kernels.convolution(buf48, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf49, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf50 = buf49 del buf49 triton_poi_fused_convolution_13[grid(262144)](buf50, primals_10, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_10 buf51 = buf45 del buf45 buf52 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf54 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_9[grid(128)](buf50, buf51, buf52, buf54, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf55 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf50, buf51, buf52, primals_11, primals_12, buf55, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_12 buf57 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf59 = reinterpret_tensor(buf57, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf57 buf60 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf59, primals_13, buf60, 1024, 256, num_warps=2, num_stages=1) buf61 = extern_kernels.convolution(buf55, buf60, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 1024, 16, 16), (262144, 1, 16384, 1024)) buf62 = buf37 del buf37 triton_poi_fused_add_14[grid(1048576)](buf62, buf61, 1048576, XBLOCK=512, num_warps=8, num_stages=1) buf63 = buf52 del buf52 buf64 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf66 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_15[grid(128)](buf62, buf63, buf64, buf66, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf67 = buf61 del buf61 triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf62, buf63, buf64, primals_14, primals_15, buf67, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_15 buf69 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256), torch.float32) buf71 = reinterpret_tensor(buf69, (256, 1, 1, 1), (1, 1, 1, 1), 0) del buf69 buf72 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf71, primals_16, buf72, 256, 1024, num_warps=8, num_stages=1) buf73 = extern_kernels.convolution(buf67, buf72, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf73, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf74 = buf64 del buf64 buf75 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf77 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_9[grid(128)](buf73, buf74, buf75, buf77, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf78 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf73, buf74, buf75, primals_17, primals_18, buf78, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_18 buf79 = extern_kernels.convolution(buf78, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf79, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf80 = buf79 del buf79 triton_poi_fused_convolution_13[grid(262144)](buf80, primals_20, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_20 buf81 = buf75 del buf75 buf82 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf84 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_9[grid(128)](buf80, buf81, buf82, buf84, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1 ) buf85 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf80, buf81, buf82, primals_21, primals_22, buf85, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_22 buf87 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf89 = reinterpret_tensor(buf87, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf87 buf90 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf89, primals_23, buf90, 1024, 256, num_warps=2, num_stages=1) buf91 = extern_kernels.convolution(buf85, buf90, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf91, (4, 1024, 16, 16), (262144, 1, 16384, 1024)) buf92 = buf91 del buf91 triton_poi_fused_add_18[grid(1048576)](buf92, buf62, 1048576, XBLOCK=512, num_warps=8, num_stages=1) buf93 = buf82 del buf82 buf94 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf96 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) triton_red_fused_native_group_norm_15[grid(128)](buf92, buf93, buf94, buf96, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf97 = reinterpret_tensor(buf23, (4, 1024, 16, 16), (262144, 1, 16384, 1024), 0) del buf23 triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf92, buf93, buf94, primals_24, primals_25, buf97, 1048576, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_25 buf99 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256), torch.float32) buf101 = reinterpret_tensor(buf99, (256, 1, 1, 1), (1, 1, 1, 1), 0) del buf99 buf102 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024 ), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf101, primals_26, buf102, 256, 1024, num_warps=8, num_stages=1) buf103 = extern_kernels.convolution(buf97, buf102, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf103, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf104 = buf94 del buf94 buf105 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf107 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_9[grid(128)](buf103, buf104, buf105, buf107, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf108 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf103, buf104, buf105, primals_27, primals_28, buf108, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_28 buf109 = extern_kernels.convolution(buf108, buf4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf109, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf110 = buf109 del buf109 triton_poi_fused_convolution_13[grid(262144)](buf110, primals_30, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_30 buf111 = buf105 del buf105 buf112 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf114 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_9[grid(128)](buf110, buf111, buf112, buf114, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf115 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf110, buf111, buf112, primals_31, primals_32, buf115, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_32 buf117 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf119 = reinterpret_tensor(buf117, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf117 buf120 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf119, primals_33, buf120, 1024, 256, num_warps=2, num_stages=1) buf121 = extern_kernels.convolution(buf115, buf120, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf121, (4, 1024, 16, 16), (262144, 1, 16384, 1024)) buf122 = buf121 del buf121 triton_poi_fused_add_18[grid(1048576)](buf122, buf92, 1048576, XBLOCK=512, num_warps=8, num_stages=1) buf123 = buf112 del buf112 buf124 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf126 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_15[grid(128)](buf122, buf123, buf124, buf126, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf127 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf122, buf123, buf124, primals_34, primals_35, buf127, 1048576, XBLOCK =1024, num_warps=4, num_stages=1) del primals_35 buf129 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256), torch.float32) buf131 = reinterpret_tensor(buf129, (256, 1, 1, 1), (1, 1, 1, 1), 0) del buf129 buf132 = empty_strided_cuda((256, 1024, 1, 1), (1024, 1, 1024, 1024 ), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_17[grid(256)](buf131, primals_36, buf132, 256, 1024, num_warps=8, num_stages=1) buf133 = extern_kernels.convolution(buf127, buf132, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf133, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf134 = buf124 del buf124 buf135 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf137 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_9[grid(128)](buf133, buf134, buf135, buf137, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf138 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf133, buf134, buf135, primals_37, primals_38, buf138, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_38 buf139 = extern_kernels.convolution(buf138, buf5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf139, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf140 = buf139 del buf139 triton_poi_fused_convolution_13[grid(262144)](buf140, primals_40, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_40 buf141 = buf135 del buf135 buf142 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf144 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_9[grid(128)](buf140, buf141, buf142, buf144, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf145 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf140, buf141, buf142, primals_41, primals_42, buf145, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_42 buf147 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf149 = reinterpret_tensor(buf147, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf147 buf150 = empty_strided_cuda((1024, 256, 1, 1), (256, 1, 256, 256), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_11[grid(1024)](buf149, primals_43, buf150, 1024, 256, num_warps=2, num_stages=1) buf151 = extern_kernels.convolution(buf145, buf150, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf151, (4, 1024, 16, 16), (262144, 1, 16384, 1024)) buf152 = buf151 del buf151 triton_poi_fused_add_18[grid(1048576)](buf152, buf122, 1048576, XBLOCK=512, num_warps=8, num_stages=1) buf153 = buf142 del buf142 buf154 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf156 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_15[grid(128)](buf152, buf153, buf154, buf156, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf157 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_16[grid(1048576)](buf152, buf153, buf154, primals_44, primals_45, buf157, 1048576, XBLOCK =1024, num_warps=4, num_stages=1) del primals_45 buf159 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf161 = reinterpret_tensor(buf159, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf159 buf162 = empty_strided_cuda((2048, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_19[grid(2048)](buf161, primals_46, buf162, 2048, 1024, num_warps=8, num_stages=1) buf163 = extern_kernels.convolution(buf157, buf162, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf163, (4, 2048, 8, 8), (131072, 1, 16384, 2048)) buf165 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512), torch.float32) buf167 = reinterpret_tensor(buf165, (512, 1, 1, 1), (1, 1, 1, 1), 0) del buf165 buf168 = empty_strided_cuda((512, 1024, 1, 1), (1024, 1, 1024, 1024 ), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_20[grid(512)](buf167, primals_47, buf168, 512, 1024, num_warps=8, num_stages=1) buf169 = extern_kernels.convolution(buf157, buf168, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf169, (4, 512, 16, 16), (131072, 1, 8192, 512)) buf170 = buf154 del buf154 buf171 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf173 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_21[grid(128)](buf169, buf170, buf171, buf173, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf174 = empty_strided_cuda((4, 512, 16, 16), (131072, 1, 8192, 512 ), torch.float32) triton_poi_fused_native_group_norm_relu_22[grid(524288)](buf169, buf170, buf171, primals_48, primals_49, buf174, 524288, XBLOCK= 512, num_warps=8, num_stages=1) del primals_49 buf175 = extern_kernels.convolution(buf174, buf6, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf175, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf176 = buf175 del buf175 triton_poi_fused_convolution_23[grid(131072)](buf176, primals_51, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_51 buf177 = buf171 del buf171 buf178 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf180 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf176, buf177, buf178, buf180, 128, 1024, num_warps=8, num_stages=1) buf181 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf176, buf177, buf178, primals_52, primals_53, buf181, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_53 buf183 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf185 = reinterpret_tensor(buf183, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf183 buf186 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf185, primals_54, buf186, 2048, 512, num_warps=4, num_stages=1) buf187 = extern_kernels.convolution(buf181, buf186, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf187, (4, 2048, 8, 8), (131072, 1, 16384, 2048)) buf188 = buf163 del buf163 triton_poi_fused_add_27[grid(524288)](buf188, buf187, 524288, XBLOCK=1024, num_warps=4, num_stages=1) buf189 = buf178 del buf178 buf190 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf192 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_28[grid(128)](buf188, buf189, buf190, buf192, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf193 = buf187 del buf187 triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf188, buf189, buf190, primals_55, primals_56, buf193, 524288, XBLOCK= 512, num_warps=8, num_stages=1) del primals_56 buf195 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512), torch.float32) buf197 = reinterpret_tensor(buf195, (512, 1, 1, 1), (1, 1, 1, 1), 0) del buf195 buf198 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048 ), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf197, primals_57, buf198, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps =16, num_stages=1) buf199 = extern_kernels.convolution(buf193, buf198, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf199, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf200 = buf190 del buf190 buf201 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf203 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf199, buf200, buf201, buf203, 128, 1024, num_warps=8, num_stages=1) buf204 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf199, buf200, buf201, primals_58, primals_59, buf204, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_59 buf205 = extern_kernels.convolution(buf204, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf205, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf206 = buf205 del buf205 triton_poi_fused_convolution_23[grid(131072)](buf206, primals_61, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_61 buf207 = buf201 del buf201 buf208 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf210 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf206, buf207, buf208, buf210, 128, 1024, num_warps=8, num_stages=1) buf211 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf206, buf207, buf208, primals_62, primals_63, buf211, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_63 buf213 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf215 = reinterpret_tensor(buf213, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf213 buf216 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf215, primals_64, buf216, 2048, 512, num_warps=4, num_stages=1) buf217 = extern_kernels.convolution(buf211, buf216, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf217, (4, 2048, 8, 8), (131072, 1, 16384, 2048)) buf218 = buf217 del buf217 triton_poi_fused_add_31[grid(524288)](buf218, buf188, 524288, XBLOCK=1024, num_warps=4, num_stages=1) buf219 = buf208 del buf208 buf220 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf222 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_28[grid(128)](buf218, buf219, buf220, buf222, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf223 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf218, buf219, buf220, primals_65, primals_66, buf223, 524288, XBLOCK= 512, num_warps=8, num_stages=1) del primals_66 buf225 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512), torch.float32) buf227 = reinterpret_tensor(buf225, (512, 1, 1, 1), (1, 1, 1, 1), 0) del buf225 buf228 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048 ), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf227, primals_67, buf228, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps =16, num_stages=1) buf229 = extern_kernels.convolution(buf223, buf228, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf229, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf230 = buf220 del buf220 buf231 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf233 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf229, buf230, buf231, buf233, 128, 1024, num_warps=8, num_stages=1) buf234 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf229, buf230, buf231, primals_68, primals_69, buf234, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_69 buf235 = extern_kernels.convolution(buf234, buf8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf235, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf236 = buf235 del buf235 triton_poi_fused_convolution_23[grid(131072)](buf236, primals_71, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_71 buf237 = buf231 del buf231 buf238 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf240 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf236, buf237, buf238, buf240, 128, 1024, num_warps=8, num_stages=1) buf241 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf236, buf237, buf238, primals_72, primals_73, buf241, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_73 buf243 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf245 = reinterpret_tensor(buf243, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf243 buf246 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf245, primals_74, buf246, 2048, 512, num_warps=4, num_stages=1) buf247 = extern_kernels.convolution(buf241, buf246, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf247, (4, 2048, 8, 8), (131072, 1, 16384, 2048)) buf248 = buf247 del buf247 triton_poi_fused_add_31[grid(524288)](buf248, buf218, 524288, XBLOCK=1024, num_warps=4, num_stages=1) buf249 = buf238 del buf238 buf250 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf252 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_28[grid(128)](buf248, buf249, buf250, buf252, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf253 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf248, buf249, buf250, primals_75, primals_76, buf253, 524288, XBLOCK= 512, num_warps=8, num_stages=1) del primals_76 buf255 = empty_strided_cuda((512, 1, 1, 1), (1, 512, 512, 512), torch.float32) buf257 = reinterpret_tensor(buf255, (512, 1, 1, 1), (1, 1, 1, 1), 0) del buf255 buf258 = empty_strided_cuda((512, 2048, 1, 1), (2048, 1, 2048, 2048 ), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_30[grid(512)](buf257, primals_77, buf258, 512, 2048, XBLOCK=1, RBLOCK=2048, num_warps =16, num_stages=1) buf259 = extern_kernels.convolution(buf253, buf258, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf259, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf260 = buf250 del buf250 buf261 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf263 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf259, buf260, buf261, buf263, 128, 1024, num_warps=8, num_stages=1) buf264 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf259, buf260, buf261, primals_78, primals_79, buf264, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_79 buf265 = extern_kernels.convolution(buf264, buf9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf265, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf266 = buf265 del buf265 triton_poi_fused_convolution_23[grid(131072)](buf266, primals_81, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_81 buf267 = buf261 del buf261 buf268 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf270 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_24[grid(128)](buf266, buf267, buf268, buf270, 128, 1024, num_warps=8, num_stages=1) buf271 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_native_group_norm_relu_25[grid(131072)](buf266, buf267, buf268, primals_82, primals_83, buf271, 131072, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_83 buf273 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf275 = reinterpret_tensor(buf273, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf273 buf276 = empty_strided_cuda((2048, 512, 1, 1), (512, 1, 512, 512), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_26[grid(2048)](buf275, primals_84, buf276, 2048, 512, num_warps=4, num_stages=1) buf277 = extern_kernels.convolution(buf271, buf276, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf277, (4, 2048, 8, 8), (131072, 1, 16384, 2048)) buf278 = buf277 del buf277 triton_poi_fused_add_31[grid(524288)](buf278, buf248, 524288, XBLOCK=1024, num_warps=4, num_stages=1) buf279 = buf268 del buf268 buf280 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf282 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_28[grid(128)](buf278, buf279, buf280, buf282, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf283 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_29[grid(524288)](buf278, buf279, buf280, primals_85, primals_86, buf283, 524288, XBLOCK= 512, num_warps=8, num_stages=1) del primals_86 buf285 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096), torch.float32) buf287 = reinterpret_tensor(buf285, (4096, 1, 1, 1), (1, 1, 1, 1), 0) del buf285 buf288 = empty_strided_cuda((4096, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_32[grid(4096)](buf287, primals_87, buf288, 4096, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf289 = extern_kernels.convolution(buf283, buf288, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf289, (4, 4096, 4, 4), (65536, 1, 16384, 4096)) buf291 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf293 = reinterpret_tensor(buf291, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf291 buf294 = empty_strided_cuda((1024, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_33[grid(1024)](buf293, primals_88, buf294, 1024, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf295 = extern_kernels.convolution(buf283, buf294, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf295, (4, 1024, 8, 8), (65536, 1, 8192, 1024)) buf296 = buf280 del buf280 buf297 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf299 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_34[grid(128)](buf295, buf296, buf297, buf299, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf300 = empty_strided_cuda((4, 1024, 8, 8), (65536, 1, 8192, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_35[grid(262144)](buf295, buf296, buf297, primals_89, primals_90, buf300, 262144, XBLOCK= 1024, num_warps=4, num_stages=1) del primals_90 buf301 = extern_kernels.convolution(buf300, buf10, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf301, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf302 = buf301 del buf301 triton_poi_fused_convolution_36[grid(65536)](buf302, primals_92, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_92 buf303 = buf297 del buf297 buf304 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf306 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf302, buf303, buf304, buf306, 128, 512, num_warps=4, num_stages=1) buf307 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf302, buf303, buf304, primals_93, primals_94, buf307, 65536, XBLOCK= 512, num_warps=4, num_stages=1) del primals_94 buf309 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096), torch.float32) buf311 = reinterpret_tensor(buf309, (4096, 1, 1, 1), (1, 1, 1, 1), 0) del buf309 buf312 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf311, primals_95, buf312, 4096, 1024, num_warps=8, num_stages=1) buf313 = extern_kernels.convolution(buf307, buf312, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf313, (4, 4096, 4, 4), (65536, 1, 16384, 4096)) buf314 = buf289 del buf289 triton_poi_fused_add_40[grid(262144)](buf314, buf313, 262144, XBLOCK=1024, num_warps=4, num_stages=1) buf315 = buf304 del buf304 buf316 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf318 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_41[grid(128)](buf314, buf315, buf316, buf318, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf319 = buf313 del buf313 triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf314, buf315, buf316, primals_96, primals_97, buf319, 262144, XBLOCK= 512, num_warps=8, num_stages=1) del primals_97 buf321 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf323 = reinterpret_tensor(buf321, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf321 buf324 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096, 4096), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf323, primals_98, buf324, 1024, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf325 = extern_kernels.convolution(buf319, buf324, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf325, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf326 = buf316 del buf316 buf327 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf329 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf325, buf326, buf327, buf329, 128, 512, num_warps=4, num_stages=1) buf330 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf325, buf326, buf327, primals_99, primals_100, buf330, 65536, XBLOCK= 512, num_warps=4, num_stages=1) del primals_100 buf331 = extern_kernels.convolution(buf330, buf11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf331, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf332 = buf331 del buf331 triton_poi_fused_convolution_36[grid(65536)](buf332, primals_102, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_102 buf333 = buf327 del buf327 buf334 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf336 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf332, buf333, buf334, buf336, 128, 512, num_warps=4, num_stages=1) buf337 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf332, buf333, buf334, primals_103, primals_104, buf337, 65536, XBLOCK =512, num_warps=4, num_stages=1) del primals_104 buf339 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096), torch.float32) buf341 = reinterpret_tensor(buf339, (4096, 1, 1, 1), (1, 1, 1, 1), 0) del buf339 buf342 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf341, primals_105, buf342, 4096, 1024, num_warps=8, num_stages=1) buf343 = extern_kernels.convolution(buf337, buf342, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf343, (4, 4096, 4, 4), (65536, 1, 16384, 4096)) buf344 = buf343 del buf343 triton_poi_fused_add_44[grid(262144)](buf344, buf314, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf345 = buf334 del buf334 buf346 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf348 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_41[grid(128)](buf344, buf345, buf346, buf348, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf349 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096 ), torch.float32) triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf344, buf345, buf346, primals_106, primals_107, buf349, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_107 buf351 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf353 = reinterpret_tensor(buf351, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf351 buf354 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096, 4096), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf353, primals_108, buf354, 1024, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf355 = extern_kernels.convolution(buf349, buf354, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf355, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf356 = buf346 del buf346 buf357 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf359 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf355, buf356, buf357, buf359, 128, 512, num_warps=4, num_stages=1) buf360 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf355, buf356, buf357, primals_109, primals_110, buf360, 65536, XBLOCK =512, num_warps=4, num_stages=1) del primals_110 buf361 = extern_kernels.convolution(buf360, buf12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf361, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf362 = buf361 del buf361 triton_poi_fused_convolution_36[grid(65536)](buf362, primals_112, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_112 buf363 = buf357 del buf357 buf364 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf366 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf362, buf363, buf364, buf366, 128, 512, num_warps=4, num_stages=1) buf367 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf362, buf363, buf364, primals_113, primals_114, buf367, 65536, XBLOCK =512, num_warps=4, num_stages=1) del primals_114 buf369 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096), torch.float32) buf371 = reinterpret_tensor(buf369, (4096, 1, 1, 1), (1, 1, 1, 1), 0) del buf369 buf372 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf371, primals_115, buf372, 4096, 1024, num_warps=8, num_stages=1) buf373 = extern_kernels.convolution(buf367, buf372, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf373, (4, 4096, 4, 4), (65536, 1, 16384, 4096)) buf374 = buf373 del buf373 triton_poi_fused_add_44[grid(262144)](buf374, buf344, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf375 = buf364 del buf364 buf376 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf378 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_41[grid(128)](buf374, buf375, buf376, buf378, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf379 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096 ), torch.float32) triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf374, buf375, buf376, primals_116, primals_117, buf379, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_117 buf381 = empty_strided_cuda((1024, 1, 1, 1), (1, 1024, 1024, 1024), torch.float32) buf383 = reinterpret_tensor(buf381, (1024, 1, 1, 1), (1, 1, 1, 1), 0) del buf381 buf384 = empty_strided_cuda((1024, 4096, 1, 1), (4096, 1, 4096, 4096), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_43[grid(1024)](buf383, primals_118, buf384, 1024, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf385 = extern_kernels.convolution(buf379, buf384, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf385, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf386 = buf376 del buf376 buf387 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf389 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf385, buf386, buf387, buf389, 128, 512, num_warps=4, num_stages=1) buf390 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf385, buf386, buf387, primals_119, primals_120, buf390, 65536, XBLOCK =512, num_warps=4, num_stages=1) del primals_120 buf391 = extern_kernels.convolution(buf390, buf13, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf391, (4, 1024, 4, 4), (16384, 1, 4096, 1024)) buf392 = buf391 del buf391 triton_poi_fused_convolution_36[grid(65536)](buf392, primals_122, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_122 buf393 = buf387 del buf387 buf394 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf396 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_37[grid(128)](buf392, buf393, buf394, buf396, 128, 512, num_warps=4, num_stages=1) buf397 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024), torch.float32) triton_poi_fused_native_group_norm_relu_38[grid(65536)](buf392, buf393, buf394, primals_123, primals_124, buf397, 65536, XBLOCK =512, num_warps=4, num_stages=1) del primals_124 buf399 = empty_strided_cuda((4096, 1, 1, 1), (1, 4096, 4096, 4096), torch.float32) buf401 = reinterpret_tensor(buf399, (4096, 1, 1, 1), (1, 1, 1, 1), 0) del buf399 buf402 = empty_strided_cuda((4096, 1024, 1, 1), (1024, 1, 1024, 1024), torch.float32) triton_per_fused_add_div_sqrt_sub_var_mean_39[grid(4096)](buf401, primals_125, buf402, 4096, 1024, num_warps=8, num_stages=1) buf403 = extern_kernels.convolution(buf397, buf402, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf403, (4, 4096, 4, 4), (65536, 1, 16384, 4096)) buf404 = buf403 del buf403 triton_poi_fused_add_44[grid(262144)](buf404, buf374, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf405 = buf394 del buf394 buf406 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf408 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_red_fused_native_group_norm_41[grid(128)](buf404, buf405, buf406, buf408, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf409 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096 ), torch.float32) triton_poi_fused_native_group_norm_relu_42[grid(262144)](buf404, buf405, buf406, primals_126, primals_127, buf409, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_127 buf411 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192), torch.float32) buf413 = reinterpret_tensor(buf411, (8192, 1, 1, 1), (1, 1, 1, 1), 0) del buf411 buf414 = empty_strided_cuda((8192, 4096, 1, 1), (4096, 1, 4096, 4096), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_45[grid(8192)](buf413, primals_128, buf414, 8192, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf415 = extern_kernels.convolution(buf409, buf414, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf415, (4, 8192, 2, 2), (32768, 1, 16384, 8192)) buf417 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf419 = reinterpret_tensor(buf417, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf417 buf420 = empty_strided_cuda((2048, 4096, 1, 1), (4096, 1, 4096, 4096), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_46[grid(2048)](buf419, primals_129, buf420, 2048, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf421 = extern_kernels.convolution(buf409, buf420, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf421, (4, 2048, 4, 4), (32768, 1, 8192, 2048)) buf422 = buf406 del buf406 buf423 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf425 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_47[grid(128)](buf421, buf422, buf423, buf425, 128, 1024, num_warps=8, num_stages=1) buf426 = empty_strided_cuda((4, 2048, 4, 4), (32768, 1, 8192, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_48[grid(131072)](buf421, buf422, buf423, primals_130, primals_131, buf426, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_131 buf427 = extern_kernels.convolution(buf426, buf14, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf427, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf428 = buf427 del buf427 triton_poi_fused_convolution_49[grid(32768)](buf428, primals_133, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_133 buf429 = buf423 del buf423 buf430 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf432 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf428, buf429, buf430, buf432, 128, 256, num_warps=2, num_stages=1) buf433 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf428, buf429, buf430, primals_134, primals_135, buf433, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_135 buf435 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192), torch.float32) buf437 = reinterpret_tensor(buf435, (8192, 1, 1, 1), (1, 1, 1, 1), 0) del buf435 buf438 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf437, primals_136, buf438, 8192, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf439 = extern_kernels.convolution(buf433, buf438, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf439, (4, 8192, 2, 2), (32768, 1, 16384, 8192)) buf440 = buf415 del buf415 triton_poi_fused_add_53[grid(131072)](buf440, buf439, 131072, XBLOCK=1024, num_warps=4, num_stages=1) buf441 = buf430 del buf430 buf442 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf444 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_54[grid(128)](buf440, buf441, buf442, buf444, 128, 1024, num_warps=8, num_stages=1) buf445 = buf439 del buf439 triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf440, buf441, buf442, primals_137, primals_138, buf445, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_138 buf447 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf449 = reinterpret_tensor(buf447, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf447 buf450 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192, 8192), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf449, primals_139, buf450, 2048, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf451 = extern_kernels.convolution(buf445, buf450, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf451, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf452 = buf442 del buf442 buf453 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf455 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf451, buf452, buf453, buf455, 128, 256, num_warps=2, num_stages=1) buf456 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf451, buf452, buf453, primals_140, primals_141, buf456, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_141 buf457 = extern_kernels.convolution(buf456, buf15, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf457, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf458 = buf457 del buf457 triton_poi_fused_convolution_49[grid(32768)](buf458, primals_143, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_143 buf459 = buf453 del buf453 buf460 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf462 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf458, buf459, buf460, buf462, 128, 256, num_warps=2, num_stages=1) buf463 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf458, buf459, buf460, primals_144, primals_145, buf463, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_145 buf465 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192), torch.float32) buf467 = reinterpret_tensor(buf465, (8192, 1, 1, 1), (1, 1, 1, 1), 0) del buf465 buf468 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf467, primals_146, buf468, 8192, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf469 = extern_kernels.convolution(buf463, buf468, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf469, (4, 8192, 2, 2), (32768, 1, 16384, 8192)) buf470 = buf469 del buf469 triton_poi_fused_add_57[grid(131072)](buf470, buf440, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf471 = buf460 del buf460 buf472 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf474 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_54[grid(128)](buf470, buf471, buf472, buf474, 128, 1024, num_warps=8, num_stages=1) buf475 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192 ), torch.float32) triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf470, buf471, buf472, primals_147, primals_148, buf475, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_148 buf477 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf479 = reinterpret_tensor(buf477, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf477 buf480 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192, 8192), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf479, primals_149, buf480, 2048, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf481 = extern_kernels.convolution(buf475, buf480, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf481, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf482 = buf472 del buf472 buf483 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf485 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf481, buf482, buf483, buf485, 128, 256, num_warps=2, num_stages=1) buf486 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf481, buf482, buf483, primals_150, primals_151, buf486, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_151 buf487 = extern_kernels.convolution(buf486, buf16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf487, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf488 = buf487 del buf487 triton_poi_fused_convolution_49[grid(32768)](buf488, primals_153, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_153 buf489 = buf483 del buf483 buf490 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf492 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf488, buf489, buf490, buf492, 128, 256, num_warps=2, num_stages=1) buf493 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf488, buf489, buf490, primals_154, primals_155, buf493, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_155 buf495 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192), torch.float32) buf497 = reinterpret_tensor(buf495, (8192, 1, 1, 1), (1, 1, 1, 1), 0) del buf495 buf498 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf497, primals_156, buf498, 8192, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf499 = extern_kernels.convolution(buf493, buf498, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf499, (4, 8192, 2, 2), (32768, 1, 16384, 8192)) buf500 = buf499 del buf499 triton_poi_fused_add_57[grid(131072)](buf500, buf470, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf501 = buf490 del buf490 buf502 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf504 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_54[grid(128)](buf500, buf501, buf502, buf504, 128, 1024, num_warps=8, num_stages=1) buf505 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192 ), torch.float32) triton_poi_fused_native_group_norm_relu_55[grid(131072)](buf500, buf501, buf502, primals_157, primals_158, buf505, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_158 buf507 = empty_strided_cuda((2048, 1, 1, 1), (1, 2048, 2048, 2048), torch.float32) buf509 = reinterpret_tensor(buf507, (2048, 1, 1, 1), (1, 1, 1, 1), 0) del buf507 buf510 = empty_strided_cuda((2048, 8192, 1, 1), (8192, 1, 8192, 8192), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_56[grid(2048)](buf509, primals_159, buf510, 2048, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf511 = extern_kernels.convolution(buf505, buf510, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf511, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf512 = buf502 del buf502 buf513 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf515 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf511, buf512, buf513, buf515, 128, 256, num_warps=2, num_stages=1) buf516 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf511, buf512, buf513, primals_160, primals_161, buf516, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_161 buf517 = extern_kernels.convolution(buf516, buf17, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf517, (4, 2048, 2, 2), (8192, 1, 4096, 2048)) buf518 = buf517 del buf517 triton_poi_fused_convolution_49[grid(32768)](buf518, primals_163, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_163 buf519 = buf513 del buf513 buf520 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf522 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) triton_per_fused_native_group_norm_50[grid(128)](buf518, buf519, buf520, buf522, 128, 256, num_warps=2, num_stages=1) buf523 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048), torch.float32) triton_poi_fused_native_group_norm_relu_51[grid(32768)](buf518, buf519, buf520, primals_164, primals_165, buf523, 32768, XBLOCK =256, num_warps=4, num_stages=1) del primals_165 buf525 = empty_strided_cuda((8192, 1, 1, 1), (1, 8192, 8192, 8192), torch.float32) buf527 = reinterpret_tensor(buf525, (8192, 1, 1, 1), (1, 1, 1, 1), 0) del buf525 buf528 = empty_strided_cuda((8192, 2048, 1, 1), (2048, 1, 2048, 2048), torch.float32) triton_red_fused_add_div_sqrt_sub_var_mean_52[grid(8192)](buf527, primals_166, buf528, 8192, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf529 = extern_kernels.convolution(buf523, buf528, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf529, (4, 8192, 2, 2), (32768, 1, 16384, 8192)) buf530 = buf529 del buf529 triton_poi_fused_add_57[grid(131072)](buf530, buf500, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf531 = reinterpret_tensor(buf520, (4, 32, 1, 1), (32, 1, 32, 32), 0) del buf520 buf532 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch .float32) buf534 = reinterpret_tensor(buf532, (4, 32, 1, 1), (32, 1, 32, 32), 0) del buf532 triton_per_fused_native_group_norm_58[grid(128)](buf534, buf530, buf531, 128, 1024, num_warps=8, num_stages=1) buf535 = empty_strided_cuda((4, 8192, 1, 1), (8192, 1, 8192, 8192), torch.float32) triton_poi_fused_mean_native_group_norm_relu_59[grid(32768)](buf530, buf531, buf534, primals_167, primals_168, buf535, 32768, XBLOCK =128, num_warps=4, num_stages=1) buf536 = extern_kernels.convolution(buf535, primals_169, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf536, (4, 21843, 1, 1), (21843, 1, 21843, 21843)) buf537 = reinterpret_tensor(buf536, (4, 21843, 1, 1), (21843, 1, 1, 1), 0) del buf536 triton_poi_fused_convolution_60[grid(87372)](buf537, primals_170, 87372, XBLOCK=512, num_warps=8, num_stages=1) del primals_170 return (buf537, buf0, buf1, primals_3, primals_5, primals_6, primals_7, buf2, primals_11, primals_13, primals_14, primals_16, primals_17, buf3, primals_21, primals_23, primals_24, primals_26, primals_27, buf4, primals_31, primals_33, primals_34, primals_36, primals_37, buf5, primals_41, primals_43, primals_44, primals_46, primals_47, primals_48, buf6, primals_52, primals_54, primals_55, primals_57, primals_58, buf7, primals_62, primals_64, primals_65, primals_67, primals_68, buf8, primals_72, primals_74, primals_75, primals_77, primals_78, buf9, primals_82, primals_84, primals_85, primals_87, primals_88, primals_89, buf10, primals_93, primals_95, primals_96, primals_98, primals_99, buf11, primals_103, primals_105, primals_106, primals_108, primals_109, buf12, primals_113, primals_115, primals_116, primals_118, primals_119, buf13, primals_123, primals_125, primals_126, primals_128, primals_129, primals_130, buf14, primals_134, primals_136, primals_137, primals_139, primals_140, buf15, primals_144, primals_146, primals_147, primals_149, primals_150, buf16, primals_154, primals_156, primals_157, primals_159, primals_160, buf17, primals_164, primals_166, primals_167, primals_168, primals_169, buf21, buf22, buf24, buf25, buf26, reinterpret_tensor(buf27, (4, 32 ), (32, 1), 0), reinterpret_tensor(buf30, (4, 32), (32, 1), 0), buf31, buf35, buf36, buf41, buf42, buf43, reinterpret_tensor(buf44, (4, 32), (32, 1), 0), reinterpret_tensor(buf47, (4, 32), (32, 1), 0 ), buf48, buf50, reinterpret_tensor(buf51, (4, 32), (32, 1), 0), reinterpret_tensor(buf54, (4, 32), (32, 1), 0), buf55, buf59, buf60, buf62, reinterpret_tensor(buf63, (4, 32), (32, 1), 0), reinterpret_tensor(buf66, (4, 32), (32, 1), 0), buf67, buf71, buf72, buf73, reinterpret_tensor(buf74, (4, 32), (32, 1), 0), reinterpret_tensor(buf77, (4, 32), (32, 1), 0), buf78, buf80, reinterpret_tensor(buf81, (4, 32), (32, 1), 0), reinterpret_tensor( buf84, (4, 32), (32, 1), 0), buf85, buf89, buf90, buf92, reinterpret_tensor(buf93, (4, 32), (32, 1), 0), reinterpret_tensor( buf96, (4, 32), (32, 1), 0), buf97, buf101, buf102, buf103, reinterpret_tensor(buf104, (4, 32), (32, 1), 0), reinterpret_tensor (buf107, (4, 32), (32, 1), 0), buf108, buf110, reinterpret_tensor( buf111, (4, 32), (32, 1), 0), reinterpret_tensor(buf114, (4, 32), ( 32, 1), 0), buf115, buf119, buf120, buf122, reinterpret_tensor( buf123, (4, 32), (32, 1), 0), reinterpret_tensor(buf126, (4, 32), ( 32, 1), 0), buf127, buf131, buf132, buf133, reinterpret_tensor( buf134, (4, 32), (32, 1), 0), reinterpret_tensor(buf137, (4, 32), ( 32, 1), 0), buf138, buf140, reinterpret_tensor(buf141, (4, 32), (32, 1), 0), reinterpret_tensor(buf144, (4, 32), (32, 1), 0), buf145, buf149, buf150, buf152, reinterpret_tensor(buf153, (4, 32), (32, 1), 0), reinterpret_tensor(buf156, (4, 32), (32, 1), 0), buf157, buf161, buf162, buf167, buf168, buf169, reinterpret_tensor(buf170, (4, 32), (32, 1), 0), reinterpret_tensor(buf173, (4, 32), (32, 1), 0), buf174, buf176, reinterpret_tensor(buf177, (4, 32), (32, 1), 0), reinterpret_tensor(buf180, (4, 32), (32, 1), 0), buf181, buf185, buf186, buf188, reinterpret_tensor(buf189, (4, 32), (32, 1), 0), reinterpret_tensor(buf192, (4, 32), (32, 1), 0), buf193, buf197, buf198, buf199, reinterpret_tensor(buf200, (4, 32), (32, 1), 0), reinterpret_tensor(buf203, (4, 32), (32, 1), 0), buf204, buf206, reinterpret_tensor(buf207, (4, 32), (32, 1), 0), reinterpret_tensor (buf210, (4, 32), (32, 1), 0), buf211, buf215, buf216, buf218, reinterpret_tensor(buf219, (4, 32), (32, 1), 0), reinterpret_tensor (buf222, (4, 32), (32, 1), 0), buf223, buf227, buf228, buf229, reinterpret_tensor(buf230, (4, 32), (32, 1), 0), reinterpret_tensor (buf233, (4, 32), (32, 1), 0), buf234, buf236, reinterpret_tensor( buf237, (4, 32), (32, 1), 0), reinterpret_tensor(buf240, (4, 32), ( 32, 1), 0), buf241, buf245, buf246, buf248, reinterpret_tensor( buf249, (4, 32), (32, 1), 0), reinterpret_tensor(buf252, (4, 32), ( 32, 1), 0), buf253, buf257, buf258, buf259, reinterpret_tensor( buf260, (4, 32), (32, 1), 0), reinterpret_tensor(buf263, (4, 32), ( 32, 1), 0), buf264, buf266, reinterpret_tensor(buf267, (4, 32), (32, 1), 0), reinterpret_tensor(buf270, (4, 32), (32, 1), 0), buf271, buf275, buf276, buf278, reinterpret_tensor(buf279, (4, 32), (32, 1), 0), reinterpret_tensor(buf282, (4, 32), (32, 1), 0), buf283, buf287, buf288, buf293, buf294, buf295, reinterpret_tensor(buf296, (4, 32), (32, 1), 0), reinterpret_tensor(buf299, (4, 32), (32, 1), 0), buf300, buf302, reinterpret_tensor(buf303, (4, 32), (32, 1), 0), reinterpret_tensor(buf306, (4, 32), (32, 1), 0), buf307, buf311, buf312, buf314, reinterpret_tensor(buf315, (4, 32), (32, 1), 0), reinterpret_tensor(buf318, (4, 32), (32, 1), 0), buf319, buf323, buf324, buf325, reinterpret_tensor(buf326, (4, 32), (32, 1), 0), reinterpret_tensor(buf329, (4, 32), (32, 1), 0), buf330, buf332, reinterpret_tensor(buf333, (4, 32), (32, 1), 0), reinterpret_tensor (buf336, (4, 32), (32, 1), 0), buf337, buf341, buf342, buf344, reinterpret_tensor(buf345, (4, 32), (32, 1), 0), reinterpret_tensor (buf348, (4, 32), (32, 1), 0), buf349, buf353, buf354, buf355, reinterpret_tensor(buf356, (4, 32), (32, 1), 0), reinterpret_tensor (buf359, (4, 32), (32, 1), 0), buf360, buf362, reinterpret_tensor( buf363, (4, 32), (32, 1), 0), reinterpret_tensor(buf366, (4, 32), ( 32, 1), 0), buf367, buf371, buf372, buf374, reinterpret_tensor( buf375, (4, 32), (32, 1), 0), reinterpret_tensor(buf378, (4, 32), ( 32, 1), 0), buf379, buf383, buf384, buf385, reinterpret_tensor( buf386, (4, 32), (32, 1), 0), reinterpret_tensor(buf389, (4, 32), ( 32, 1), 0), buf390, buf392, reinterpret_tensor(buf393, (4, 32), (32, 1), 0), reinterpret_tensor(buf396, (4, 32), (32, 1), 0), buf397, buf401, buf402, buf404, reinterpret_tensor(buf405, (4, 32), (32, 1), 0), reinterpret_tensor(buf408, (4, 32), (32, 1), 0), buf409, buf413, buf414, buf419, buf420, buf421, reinterpret_tensor(buf422, (4, 32), (32, 1), 0), reinterpret_tensor(buf425, (4, 32), (32, 1), 0), buf426, buf428, reinterpret_tensor(buf429, (4, 32), (32, 1), 0), reinterpret_tensor(buf432, (4, 32), (32, 1), 0), buf433, buf437, buf438, buf440, reinterpret_tensor(buf441, (4, 32), (32, 1), 0), reinterpret_tensor(buf444, (4, 32), (32, 1), 0), buf445, buf449, buf450, buf451, reinterpret_tensor(buf452, (4, 32), (32, 1), 0), reinterpret_tensor(buf455, (4, 32), (32, 1), 0), buf456, buf458, reinterpret_tensor(buf459, (4, 32), (32, 1), 0), reinterpret_tensor (buf462, (4, 32), (32, 1), 0), buf463, buf467, buf468, buf470, reinterpret_tensor(buf471, (4, 32), (32, 1), 0), reinterpret_tensor (buf474, (4, 32), (32, 1), 0), buf475, buf479, buf480, buf481, reinterpret_tensor(buf482, (4, 32), (32, 1), 0), reinterpret_tensor (buf485, (4, 32), (32, 1), 0), buf486, buf488, reinterpret_tensor( buf489, (4, 32), (32, 1), 0), reinterpret_tensor(buf492, (4, 32), ( 32, 1), 0), buf493, buf497, buf498, buf500, reinterpret_tensor( buf501, (4, 32), (32, 1), 0), reinterpret_tensor(buf504, (4, 32), ( 32, 1), 0), buf505, buf509, buf510, buf511, reinterpret_tensor( buf512, (4, 32), (32, 1), 0), reinterpret_tensor(buf515, (4, 32), ( 32, 1), 0), buf516, buf518, reinterpret_tensor(buf519, (4, 32), (32, 1), 0), reinterpret_tensor(buf522, (4, 32), (32, 1), 0), buf523, buf527, buf528, buf530, buf531, buf534, buf535) def conv1x1(cin, cout, stride=1, bias=False): return StdConv2d(cin, cout, kernel_size=1, stride=stride, padding=0, bias=bias) def conv3x3(in_planes, out_planes, stride=1): return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True) def tf2th(conv_weights): """Possibly convert HWIO to OIHW.""" if conv_weights.ndim == 4: conv_weights = conv_weights.transpose([3, 2, 0, 1]) return torch.from_numpy(conv_weights) class StdConv2d(nn.Conv2d): def forward(self, x): w = self.weight v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False) w = (w - m) / torch.sqrt(v + 1e-10) return F.conv2d(x, w, self.bias, self.stride, self.padding, self. dilation, self.groups) class PreActBottleneck(nn.Module): """Pre-activation (v2) bottleneck block. Follows the implementation of "Identity Mappings in Deep Residual Networks": https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua Except it puts the stride on 3x3 conv when available. """ def __init__(self, cin, cout=None, cmid=None, stride=1): super().__init__() cout = cout or cin cmid = cmid or cout // 4 self.gn1 = nn.GroupNorm(32, cin) self.conv1 = conv1x1(cin, cmid) self.gn2 = nn.GroupNorm(32, cmid) self.conv2 = conv3x3(cmid, cmid, stride) self.gn3 = nn.GroupNorm(32, cmid) self.conv3 = conv1x1(cmid, cout) self.relu = nn.ReLU(inplace=True) if stride != 1 or cin != cout: self.downsample = conv1x1(cin, cout, stride) def forward(self, x): out = self.relu(self.gn1(x)) residual = x if hasattr(self, 'downsample'): residual = self.downsample(out) out = self.conv1(out) out = self.conv2(self.relu(self.gn2(out))) out = self.conv3(self.relu(self.gn3(out))) return out + residual def load_from(self, weights, prefix=''): convname = 'standardized_conv2d' with torch.no_grad(): self.conv1.weight.copy_(tf2th(weights[ f'{prefix}a/{convname}/kernel'])) self.conv2.weight.copy_(tf2th(weights[ f'{prefix}b/{convname}/kernel'])) self.conv3.weight.copy_(tf2th(weights[ f'{prefix}c/{convname}/kernel'])) self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma']) ) self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma']) ) self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma']) ) self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta'])) self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta'])) self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta'])) if hasattr(self, 'downsample'): w = weights[f'{prefix}a/proj/{convname}/kernel'] self.downsample.weight.copy_(tf2th(w)) class ResNetV2New(nn.Module): """Implementation of Pre-activation (v2) ResNet mode.""" def __init__(self, block_units, width_factor, head_size=21843, zero_head=False): super().__init__() wf = width_factor self.wf = wf self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 * wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad', nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3, stride=2, padding=0))])) self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential( OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 * wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin= 256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2, block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid= 128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin= 512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2, block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid= 256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin= 1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2, block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([ ('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid =512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin =2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2, block_units[3] + 1)])))])) self.zero_head = zero_head self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 * wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn. AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf, head_size, kernel_size=1, bias=True))])) def load_from(self, weights, prefix='resnet/'): with torch.no_grad(): self.root.conv.weight.copy_(tf2th(weights[ f'{prefix}root_block/standardized_conv2d/kernel'])) self.head.gn.weight.copy_(tf2th(weights[ f'{prefix}group_norm/gamma'])) self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta'])) if self.zero_head: nn.init.zeros_(self.head.conv.weight) nn.init.zeros_(self.head.conv.bias) else: self.head.conv.weight.copy_(tf2th(weights[ f'{prefix}head/conv2d/kernel'])) self.head.conv.bias.copy_(tf2th(weights[ f'{prefix}head/conv2d/bias'])) for bname, block in self.body.named_children(): for uname, unit in block.named_children(): unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/') def forward(self, input_0): primals_1 = self.root.conv.weight primals_3 = self.body.block1.unit01.gn1.weight primals_4 = self.body.block1.unit01.gn1.bias primals_6 = self.body.block1.unit01.conv1.weight primals_7 = self.body.block1.unit01.gn2.weight primals_8 = self.body.block1.unit01.gn2.bias primals_9 = self.body.block1.unit01.conv2.weight primals_10 = self.body.block1.unit01.conv2.bias primals_11 = self.body.block1.unit01.gn3.weight primals_12 = self.body.block1.unit01.gn3.bias primals_5 = self.body.block1.unit01.conv3.weight primals_13 = self.body.block1.unit01.downsample.weight primals_14 = self.body.block1.unit02.gn1.weight primals_15 = self.body.block1.unit02.gn1.bias primals_16 = self.body.block1.unit02.conv1.weight primals_17 = self.body.block1.unit02.gn2.weight primals_18 = self.body.block1.unit02.gn2.bias primals_19 = self.body.block1.unit02.conv2.weight primals_20 = self.body.block1.unit02.conv2.bias primals_21 = self.body.block1.unit02.gn3.weight primals_22 = self.body.block1.unit02.gn3.bias primals_23 = self.body.block1.unit02.conv3.weight primals_24 = self.body.block1.unit03.gn1.weight primals_25 = self.body.block1.unit03.gn1.bias primals_26 = self.body.block1.unit03.conv1.weight primals_27 = self.body.block1.unit03.gn2.weight primals_28 = self.body.block1.unit03.gn2.bias primals_29 = self.body.block1.unit03.conv2.weight primals_30 = self.body.block1.unit03.conv2.bias primals_31 = self.body.block1.unit03.gn3.weight primals_32 = self.body.block1.unit03.gn3.bias primals_33 = self.body.block1.unit03.conv3.weight primals_34 = self.body.block1.unit04.gn1.weight primals_35 = self.body.block1.unit04.gn1.bias primals_36 = self.body.block1.unit04.conv1.weight primals_37 = self.body.block1.unit04.gn2.weight primals_38 = self.body.block1.unit04.gn2.bias primals_39 = self.body.block1.unit04.conv2.weight primals_40 = self.body.block1.unit04.conv2.bias primals_41 = self.body.block1.unit04.gn3.weight primals_42 = self.body.block1.unit04.gn3.bias primals_43 = self.body.block1.unit04.conv3.weight primals_44 = self.body.block2.unit01.gn1.weight primals_45 = self.body.block2.unit01.gn1.bias primals_47 = self.body.block2.unit01.conv1.weight primals_48 = self.body.block2.unit01.gn2.weight primals_49 = self.body.block2.unit01.gn2.bias primals_50 = self.body.block2.unit01.conv2.weight primals_51 = self.body.block2.unit01.conv2.bias primals_52 = self.body.block2.unit01.gn3.weight primals_53 = self.body.block2.unit01.gn3.bias primals_54 = self.body.block2.unit01.conv3.weight primals_46 = self.body.block2.unit01.downsample.weight primals_55 = self.body.block2.unit02.gn1.weight primals_56 = self.body.block2.unit02.gn1.bias primals_57 = self.body.block2.unit02.conv1.weight primals_58 = self.body.block2.unit02.gn2.weight primals_59 = self.body.block2.unit02.gn2.bias primals_60 = self.body.block2.unit02.conv2.weight primals_61 = self.body.block2.unit02.conv2.bias primals_62 = self.body.block2.unit02.gn3.weight primals_63 = self.body.block2.unit02.gn3.bias primals_64 = self.body.block2.unit02.conv3.weight primals_65 = self.body.block2.unit03.gn1.weight primals_66 = self.body.block2.unit03.gn1.bias primals_67 = self.body.block2.unit03.conv1.weight primals_68 = self.body.block2.unit03.gn2.weight primals_69 = self.body.block2.unit03.gn2.bias primals_70 = self.body.block2.unit03.conv2.weight primals_71 = self.body.block2.unit03.conv2.bias primals_72 = self.body.block2.unit03.gn3.weight primals_73 = self.body.block2.unit03.gn3.bias primals_74 = self.body.block2.unit03.conv3.weight primals_75 = self.body.block2.unit04.gn1.weight primals_76 = self.body.block2.unit04.gn1.bias primals_77 = self.body.block2.unit04.conv1.weight primals_78 = self.body.block2.unit04.gn2.weight primals_79 = self.body.block2.unit04.gn2.bias primals_80 = self.body.block2.unit04.conv2.weight primals_81 = self.body.block2.unit04.conv2.bias primals_82 = self.body.block2.unit04.gn3.weight primals_83 = self.body.block2.unit04.gn3.bias primals_84 = self.body.block2.unit04.conv3.weight primals_85 = self.body.block3.unit01.gn1.weight primals_86 = self.body.block3.unit01.gn1.bias primals_88 = self.body.block3.unit01.conv1.weight primals_89 = self.body.block3.unit01.gn2.weight primals_90 = self.body.block3.unit01.gn2.bias primals_91 = self.body.block3.unit01.conv2.weight primals_92 = self.body.block3.unit01.conv2.bias primals_93 = self.body.block3.unit01.gn3.weight primals_94 = self.body.block3.unit01.gn3.bias primals_95 = self.body.block3.unit01.conv3.weight primals_87 = self.body.block3.unit01.downsample.weight primals_96 = self.body.block3.unit02.gn1.weight primals_97 = self.body.block3.unit02.gn1.bias primals_98 = self.body.block3.unit02.conv1.weight primals_99 = self.body.block3.unit02.gn2.weight primals_100 = self.body.block3.unit02.gn2.bias primals_101 = self.body.block3.unit02.conv2.weight primals_102 = self.body.block3.unit02.conv2.bias primals_103 = self.body.block3.unit02.gn3.weight primals_104 = self.body.block3.unit02.gn3.bias primals_105 = self.body.block3.unit02.conv3.weight primals_106 = self.body.block3.unit03.gn1.weight primals_107 = self.body.block3.unit03.gn1.bias primals_108 = self.body.block3.unit03.conv1.weight primals_109 = self.body.block3.unit03.gn2.weight primals_110 = self.body.block3.unit03.gn2.bias primals_111 = self.body.block3.unit03.conv2.weight primals_112 = self.body.block3.unit03.conv2.bias primals_113 = self.body.block3.unit03.gn3.weight primals_114 = self.body.block3.unit03.gn3.bias primals_115 = self.body.block3.unit03.conv3.weight primals_116 = self.body.block3.unit04.gn1.weight primals_117 = self.body.block3.unit04.gn1.bias primals_118 = self.body.block3.unit04.conv1.weight primals_119 = self.body.block3.unit04.gn2.weight primals_120 = self.body.block3.unit04.gn2.bias primals_121 = self.body.block3.unit04.conv2.weight primals_122 = self.body.block3.unit04.conv2.bias primals_123 = self.body.block3.unit04.gn3.weight primals_124 = self.body.block3.unit04.gn3.bias primals_125 = self.body.block3.unit04.conv3.weight primals_126 = self.body.block4.unit01.gn1.weight primals_127 = self.body.block4.unit01.gn1.bias primals_129 = self.body.block4.unit01.conv1.weight primals_130 = self.body.block4.unit01.gn2.weight primals_131 = self.body.block4.unit01.gn2.bias primals_132 = self.body.block4.unit01.conv2.weight primals_133 = self.body.block4.unit01.conv2.bias primals_134 = self.body.block4.unit01.gn3.weight primals_135 = self.body.block4.unit01.gn3.bias primals_136 = self.body.block4.unit01.conv3.weight primals_128 = self.body.block4.unit01.downsample.weight primals_137 = self.body.block4.unit02.gn1.weight primals_138 = self.body.block4.unit02.gn1.bias primals_139 = self.body.block4.unit02.conv1.weight primals_140 = self.body.block4.unit02.gn2.weight primals_141 = self.body.block4.unit02.gn2.bias primals_142 = self.body.block4.unit02.conv2.weight primals_143 = self.body.block4.unit02.conv2.bias primals_144 = self.body.block4.unit02.gn3.weight primals_145 = self.body.block4.unit02.gn3.bias primals_146 = self.body.block4.unit02.conv3.weight primals_147 = self.body.block4.unit03.gn1.weight primals_148 = self.body.block4.unit03.gn1.bias primals_149 = self.body.block4.unit03.conv1.weight primals_150 = self.body.block4.unit03.gn2.weight primals_151 = self.body.block4.unit03.gn2.bias primals_152 = self.body.block4.unit03.conv2.weight primals_153 = self.body.block4.unit03.conv2.bias primals_154 = self.body.block4.unit03.gn3.weight primals_155 = self.body.block4.unit03.gn3.bias primals_156 = self.body.block4.unit03.conv3.weight primals_157 = self.body.block4.unit04.gn1.weight primals_158 = self.body.block4.unit04.gn1.bias primals_159 = self.body.block4.unit04.conv1.weight primals_160 = self.body.block4.unit04.gn2.weight primals_161 = self.body.block4.unit04.gn2.bias primals_162 = self.body.block4.unit04.conv2.weight primals_163 = self.body.block4.unit04.conv2.bias primals_164 = self.body.block4.unit04.gn3.weight primals_165 = self.body.block4.unit04.gn3.bias primals_166 = self.body.block4.unit04.conv3.weight primals_167 = self.head.gn.weight primals_168 = self.head.gn.bias primals_169 = self.head.conv.weight primals_170 = self.head.conv.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72, primals_73, primals_74, primals_75, primals_76, primals_77, primals_78, primals_79, primals_80, primals_81, primals_82, primals_83, primals_84, primals_85, primals_86, primals_87, primals_88, primals_89, primals_90, primals_91, primals_92, primals_93, primals_94, primals_95, primals_96, primals_97, primals_98, primals_99, primals_100, primals_101, primals_102, primals_103, primals_104, primals_105, primals_106, primals_107, primals_108, primals_109, primals_110, primals_111, primals_112, primals_113, primals_114, primals_115, primals_116, primals_117, primals_118, primals_119, primals_120, primals_121, primals_122, primals_123, primals_124, primals_125, primals_126, primals_127, primals_128, primals_129, primals_130, primals_131, primals_132, primals_133, primals_134, primals_135, primals_136, primals_137, primals_138, primals_139, primals_140, primals_141, primals_142, primals_143, primals_144, primals_145, primals_146, primals_147, primals_148, primals_149, primals_150, primals_151, primals_152, primals_153, primals_154, primals_155, primals_156, primals_157, primals_158, primals_159, primals_160, primals_161, primals_162, primals_163, primals_164, primals_165, primals_166, primals_167, primals_168, primals_169, primals_170]) return output[0]
matsuolab/DomainBed
ResNetV2
false
7,630
[ "MIT" ]
1
00e0e3d183b36fd4d0c50442012149794a6504c2
https://github.com/matsuolab/DomainBed/tree/00e0e3d183b36fd4d0c50442012149794a6504c2
HSwish
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data.distributed class HSwish(nn.Module): def __init__(self, inplace=True): super(HSwish, self).__init__() self.inplace = inplace def forward(self, x): out = x * F.relu6(x + 3, inplace=self.inplace) / 6 return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data.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_div_hardtanh_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 3.0 tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 6.0 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = tmp0 * tmp6 tmp8 = 0.16666666666666666 tmp9 = tmp7 * tmp8 tl.store(out_ptr0 + x0, tmp9, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_hardtanh_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class HSwishNew(nn.Module): def __init__(self, inplace=True): super(HSwishNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
AberHu/ImageNet-training
HSwish
false
7,631
[ "MIT" ]
12
7201eb140176f4d7ec1ed0ff5c27deba2dfb60c2
https://github.com/AberHu/ImageNet-training/tree/7201eb140176f4d7ec1ed0ff5c27deba2dfb60c2
Normalize
import torch import torch.utils.data class Normalize(torch.nn.Module): def __init__(self): super(Normalize, self).__init__() self.normalize = torch.nn.functional.normalize def forward(self, x): x = self.normalize(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 from torch._inductor.runtime.triton_helpers import libdevice 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_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=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class NormalizeNew(torch.nn.Module): def __init__(self): super(NormalizeNew, self).__init__() self.normalize = torch.nn.functional.normalize def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alescontrela/AMP_for_hardware
Normalize
false
7,632
[ "BSD-3-Clause" ]
11
bfb0dbdcf32bdf83a916790bddf193fffc7e79b8
https://github.com/Alescontrela/AMP_for_hardware/tree/bfb0dbdcf32bdf83a916790bddf193fffc7e79b8
ResizeTransform
import torch import torch.nn as nn import torch.nn.functional as nnf import torch.utils class ResizeTransform(nn.Module): """ Resize a transform, which involves resizing the vector field *and* rescaling it. """ def __init__(self, vel_resize, ndims): super().__init__() self.factor = 1.0 / vel_resize self.mode = 'linear' if ndims == 2: self.mode = 'bi' + self.mode elif ndims == 3: self.mode = 'tri' + self.mode def forward(self, x): if self.factor < 1: x = nnf.interpolate(x, align_corners=True, scale_factor=self. factor, mode=self.mode) x = self.factor * x elif self.factor > 1: x = self.factor * x x = nnf.interpolate(x, align_corners=True, scale_factor=self. factor, mode=self.mode) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'vel_resize': 4, 'ndims': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(in_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 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp1 - tmp0 tmp3 = 0.0 tmp4 = tmp2 * tmp3 tmp5 = tmp0 + tmp4 tmp6 = 0.25 tmp7 = tmp5 * tmp6 tl.store(out_ptr0 + x0, tmp7, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid (16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf0, class ResizeTransformNew(nn.Module): """ Resize a transform, which involves resizing the vector field *and* rescaling it. """ def __init__(self, vel_resize, ndims): super().__init__() self.factor = 1.0 / vel_resize self.mode = 'linear' if ndims == 2: self.mode = 'bi' + self.mode elif ndims == 3: self.mode = 'tri' + self.mode def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alison-brie/MultiPropReg
ResizeTransform
false
7,633
[ "MIT" ]
14
526d843b161c0e2e53ec5c7c47de6964c6a44c60
https://github.com/Alison-brie/MultiPropReg/tree/526d843b161c0e2e53ec5c7c47de6964c6a44c60
LinearBlock
import torch from torch import nn class LinearBlock(nn.Module): def __init__(self, in_dim, out_dim, norm='none', activation='relu'): super(LinearBlock, self).__init__() use_bias = True self.fc = nn.Linear(in_dim, out_dim, bias=use_bias) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm1d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm1d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) def forward(self, x): out = self.fc(x) if self.norm: out = self.norm(out) if self.activation: out = self.activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_dim': 4, 'out_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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 buf2 = 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, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf2 class LinearBlockNew(nn.Module): def __init__(self, in_dim, out_dim, norm='none', activation='relu'): super(LinearBlockNew, self).__init__() use_bias = True self.fc = nn.Linear(in_dim, out_dim, bias=use_bias) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm1d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm1d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Alikfp/research-GANwriting
LinearBlock
false
7,634
[ "MIT" ]
41
2190954218a733deac52c929f51bb85bca5d7216
https://github.com/Alikfp/research-GANwriting/tree/2190954218a733deac52c929f51bb85bca5d7216
ResizeConv2d
import torch import torch.nn.functional as F import torch.nn as nn import torch.cuda import torch.optim import torch.utils.data class ResizeConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, scale_factor, mode='nearest'): super().__init__() self.scale_factor = scale_factor self.mode = mode self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=1) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode=self.mode) x = self.conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4, 'scale_factor': 1.0}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.cuda 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__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 144 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 9 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 3, 3), (36, 9, 3, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(144)](buf2, primals_3, 144, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class ResizeConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, scale_factor, mode='nearest'): super().__init__() self.scale_factor = scale_factor self.mode = mode self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=1) def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.conv.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AhmadQasim/MedAL
ResizeConv2d
false
7,635
[ "MIT" ]
13
0ad6064d0d07f23722034b866ba86d93b62517f4
https://github.com/AhmadQasim/MedAL/tree/0ad6064d0d07f23722034b866ba86d93b62517f4
BalancedL1Loss
import functools import torch import numpy as np import torch.nn as nn import torch.nn.functional as F def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Return: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() elif reduction_enum == 2: return loss.sum() def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. reduction (str): Same as built-in losses of PyTorch. avg_factor (float): Avarage factor when computing the mean of losses. Returns: Tensor: Processed loss values. """ if weight is not None: loss = loss * weight if avg_factor is None: loss = reduce_loss(loss, reduction) elif reduction == 'mean': loss = loss.sum() / avg_factor elif reduction != 'none': raise ValueError('avg_factor can not be used with reduction="sum"') return loss def weighted_loss(loss_func): """Create a weighted version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> @weighted_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, avg_factor=2) tensor(1.5000) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', avg_factor= None, **kwargs): loss = loss_func(pred, target, **kwargs) loss = weight_reduce_loss(loss, weight, reduction, avg_factor) return loss return wrapper @weighted_loss def balanced_l1_loss(pred, target, beta=1.0, alpha=0.5, gamma=1.5, reduction='mean'): assert beta > 0 assert pred.size() == target.size() and target.numel() > 0 diff = torch.abs(pred - target) b = np.e ** (gamma / alpha) - 1 loss = torch.where(diff < beta, alpha / b * (b * diff + 1) * torch.log( b * diff / beta + 1) - alpha * diff, gamma * diff + gamma / b - alpha * beta) return loss class BalancedL1Loss(nn.Module): """Balanced L1 Loss arXiv: https://arxiv.org/pdf/1904.02701.pdf (CVPR 2019) """ def __init__(self, alpha=0.5, gamma=1.5, beta=1.0, reduction='mean', loss_weight=1.0): super(BalancedL1Loss, self).__init__() self.alpha = alpha self.gamma = gamma self.beta = beta self.reduction = reduction self.loss_weight = loss_weight def forward(self, pred, target, weight=None, avg_factor=None, reduction_override=None, **kwargs): assert reduction_override in (None, 'none', 'mean', 'sum') reduction = (reduction_override if reduction_override else self. reduction) loss_bbox = self.loss_weight * balanced_l1_loss(pred, target, weight, alpha=self.alpha, gamma=self.gamma, beta=self.beta, reduction=reduction, avg_factor=avg_factor, **kwargs) return loss_bbox 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 functools import numpy as np import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_div_log_lt_mean_mul_sub_where_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 1.0 tmp5 = tmp3 < tmp4 tmp6 = 19.085536923187664 tmp7 = tmp3 * tmp6 tmp8 = tmp7 + tmp4 tmp9 = 0.02619784824562798 tmp10 = tmp8 * tmp9 tmp11 = tmp7 * tmp4 tmp12 = tmp11 + tmp4 tmp13 = tl_math.log(tmp12) tmp14 = tmp10 * tmp13 tmp15 = 0.5 tmp16 = tmp3 * tmp15 tmp17 = tmp14 - tmp16 tmp18 = 1.5 tmp19 = tmp3 * tmp18 tmp20 = 0.07859354473688394 tmp21 = tmp19 + tmp20 tmp22 = tmp21 - tmp15 tmp23 = tl.where(tmp5, tmp17, tmp22) tmp24 = tl.broadcast_to(tmp23, [RBLOCK]) tmp26 = triton_helpers.promote_to_tensor(tl.sum(tmp24, 0)) tmp27 = 256.0 tmp28 = tmp26 / tmp27 tmp29 = tmp28 * tmp4 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp29, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_div_log_lt_mean_mul_sub_where_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 reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Return: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() elif reduction_enum == 2: return loss.sum() def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. reduction (str): Same as built-in losses of PyTorch. avg_factor (float): Avarage factor when computing the mean of losses. Returns: Tensor: Processed loss values. """ if weight is not None: loss = loss * weight if avg_factor is None: loss = reduce_loss(loss, reduction) elif reduction == 'mean': loss = loss.sum() / avg_factor elif reduction != 'none': raise ValueError('avg_factor can not be used with reduction="sum"') return loss def weighted_loss(loss_func): """Create a weighted version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> @weighted_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, avg_factor=2) tensor(1.5000) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', avg_factor= None, **kwargs): loss = loss_func(pred, target, **kwargs) loss = weight_reduce_loss(loss, weight, reduction, avg_factor) return loss return wrapper @weighted_loss def balanced_l1_loss(pred, target, beta=1.0, alpha=0.5, gamma=1.5, reduction='mean'): assert beta > 0 assert pred.size() == target.size() and target.numel() > 0 diff = torch.abs(pred - target) b = np.e ** (gamma / alpha) - 1 loss = torch.where(diff < beta, alpha / b * (b * diff + 1) * torch.log( b * diff / beta + 1) - alpha * diff, gamma * diff + gamma / b - alpha * beta) return loss class BalancedL1LossNew(nn.Module): """Balanced L1 Loss arXiv: https://arxiv.org/pdf/1904.02701.pdf (CVPR 2019) """ def __init__(self, alpha=0.5, gamma=1.5, beta=1.0, reduction='mean', loss_weight=1.0): super(BalancedL1LossNew, self).__init__() self.alpha = alpha self.gamma = gamma self.beta = beta self.reduction = reduction self.loss_weight = loss_weight def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
AllenPeng0209/SaccadeNet
BalancedL1Loss
false
7,636
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
Conv2dBlock
import torch import torch.nn.functional as F from torch import nn class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_dim': 4, 'out_dim': 4, 'ks': 4, 'st': 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.functional as F from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(4, 4), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 1, 1), (4, 1, 1, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(16)](buf1, primals_3, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf2 class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlockNew(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlockNew, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.conv.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Alikfp/research-GANwriting
Conv2dBlock
false
7,637
[ "MIT" ]
41
2190954218a733deac52c929f51bb85bca5d7216
https://github.com/Alikfp/research-GANwriting/tree/2190954218a733deac52c929f51bb85bca5d7216
WeightedCrossEntropyLoss
import torch import torch.nn as nn import torch.nn.functional as F class WeightedCrossEntropyLoss(nn.Module): """ Transform input to fit the fomation of PyTorch offical cross entropy loss with anchor-wise weighting. """ def __init__(self): super(WeightedCrossEntropyLoss, self).__init__() def forward(self, input: 'torch.Tensor', target: 'torch.Tensor', weights: 'torch.Tensor'): """ Args: input: (B, #anchors, #classes) float tensor. Predited logits for each class. target: (B, #anchors, #classes) float tensor. One-hot classification targets. weights: (B, #anchors) float tensor. Anchor-wise weights. Returns: loss: (B, #anchors) float tensor. Weighted cross entropy loss without reduction """ input = input.permute(0, 2, 1) target = target.argmax(dim=-1) loss = F.cross_entropy(input, target, reduction='none') * weights return loss def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_argmax_nll_loss2d_forward_1(in_ptr0, in_ptr1, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp56 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp58 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp61 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp64 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tmp47 = tl.full([1], -100, tl.int64) tmp48 = tmp46 != tmp47 tmp49 = tl.where(tmp48, tmp46, tmp10) tmp50 = tl.full([XBLOCK], 4, tl.int32) tmp51 = tmp49 + tmp50 tmp52 = tmp49 < 0 tmp53 = tl.where(tmp52, tmp51, tmp49) tl.device_assert((0 <= tmp53) & (tmp53 < 4) | ~xmask, 'index out of bounds: 0 <= tmp53 < 4') tmp55 = tl.load(in_ptr1 + (tmp53 + 4 * x0), xmask, eviction_policy= 'evict_last') tmp57 = tl_math.exp(tmp56) tmp59 = tl_math.exp(tmp58) tmp60 = tmp57 + tmp59 tmp62 = tl_math.exp(tmp61) tmp63 = tmp60 + tmp62 tmp65 = tl_math.exp(tmp64) tmp66 = tmp63 + tmp65 tmp67 = tl_math.log(tmp66) tmp68 = tmp55 - tmp67 tmp69 = -tmp68 tmp70 = 0.0 tmp71 = tl.where(tmp48, tmp69, tmp70) tl.store(out_ptr1 + x0, tmp71, xmask) @triton.jit def triton_poi_fused_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(64)](arg0_1, buf1, 64, XBLOCK= 64, num_warps=1, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32) triton_poi_fused_argmax_nll_loss2d_forward_1[grid(16)](arg1_1, buf1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg1_1 buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_mul_2[grid(64)](buf2, arg2_1, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg2_1 del buf2 return buf3, class WeightedCrossEntropyLossNew(nn.Module): """ Transform input to fit the fomation of PyTorch offical cross entropy loss with anchor-wise weighting. """ def __init__(self): super(WeightedCrossEntropyLossNew, self).__init__() def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
AbangLZU/OpenPCDet
WeightedCrossEntropyLoss
false
7,638
[ "Apache-2.0" ]
29
eeea3f24d392f692228c1ad4e28c0dc9d0e25665
https://github.com/AbangLZU/OpenPCDet/tree/eeea3f24d392f692228c1ad4e28c0dc9d0e25665
GlobalAvgPool2d
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.parallel import torch.optim import torch.utils.data class GlobalAvgPool2d(nn.Module): def __init__(self): super(GlobalAvgPool2d, self).__init__() def forward(self, x): N = x.data.size(0) C = x.data.size(1) H = x.data.size(2) W = x.data.size(3) x = F.avg_pool2d(x, (H, W)) x = x.view(N, C) 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 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp8 = tmp7 + tmp6 tmp10 = tmp9 + tmp8 tmp12 = tmp11 + tmp10 tmp14 = tmp13 + tmp12 tmp16 = tmp15 + tmp14 tmp18 = tmp17 + tmp16 tmp20 = tmp19 + tmp18 tmp22 = tmp21 + tmp20 tmp24 = tmp23 + tmp22 tmp26 = tmp25 + tmp24 tmp28 = tmp27 + tmp26 tmp30 = tmp29 + tmp28 tmp31 = 0.0625 tmp32 = tmp30 * tmp31 tl.store(out_ptr0 + x0, tmp32, xmask) 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, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_avg_pool2d_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4), (4, 1), 0), class GlobalAvgPool2dNew(nn.Module): def __init__(self): super(GlobalAvgPool2dNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alin1102/Yolov3_Dartnet2Caffe
GlobalAvgPool2d
false
7,639
[ "MIT" ]
21
b4284b080f53c1ac73c1930b1b1c4e07dcd97559
https://github.com/Alin1102/Yolov3_Dartnet2Caffe/tree/b4284b080f53c1ac73c1930b1b1c4e07dcd97559
Eltwise
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data class Eltwise(nn.Module): def __init__(self, operation='+'): super(Eltwise, self).__init__() self.operation = operation def forward(self, x1, x2): if self.operation == '+' or self.operation == 'SUM': x = x1 + x2 if self.operation == '*' or self.operation == 'MUL': x = x1 * x2 if self.operation == '/' or self.operation == 'DIV': x = x1 / 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 import torch.nn.parallel import torch.optim import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) 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_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class EltwiseNew(nn.Module): def __init__(self, operation='+'): super(EltwiseNew, self).__init__() self.operation = operation def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Alin1102/Yolov3_Dartnet2Caffe
Eltwise
false
7,640
[ "MIT" ]
21
b4284b080f53c1ac73c1930b1b1c4e07dcd97559
https://github.com/Alin1102/Yolov3_Dartnet2Caffe/tree/b4284b080f53c1ac73c1930b1b1c4e07dcd97559
MaxPoolStride1
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.parallel import torch.optim import torch.utils.data class MaxPoolStride1(nn.Module): def __init__(self): super(MaxPoolStride1, self).__init__() def forward(self, x): x = F.max_pool2d(F.pad(x, (0, 1, 0, 1), mode='replicate'), 2, stride=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 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_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 + (4 * (3 * (3 <= x1) + x1 * (x1 < 3)) + 16 * x2 + (3 * (3 <= x0) + x0 * (x0 < 3))), xmask) tmp1 = tl.load(in_ptr0 + (4 * (3 * (3 <= x1) + x1 * (x1 < 3)) + 16 * x2 + (3 * (3 <= 1 + x0) + (1 + x0) * (1 + x0 < 3))), xmask) tmp3 = tl.load(in_ptr0 + (4 * (3 * (3 <= 1 + x1) + (1 + x1) * (1 + x1 < 3)) + 16 * x2 + (3 * (3 <= x0) + x0 * (x0 < 3))), xmask) tmp5 = tl.load(in_ptr0 + (4 * (3 * (3 <= 1 + x1) + (1 + x1) * (1 + x1 < 3)) + 16 * x2 + (3 * (3 <= 1 + x0) + (1 + x0) * (1 + x0 < 3))), xmask) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_pool2d_with_indices_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class MaxPoolStride1New(nn.Module): def __init__(self): super(MaxPoolStride1New, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alin1102/Yolov3_Dartnet2Caffe
MaxPoolStride1
false
7,641
[ "MIT" ]
21
b4284b080f53c1ac73c1930b1b1c4e07dcd97559
https://github.com/Alin1102/Yolov3_Dartnet2Caffe/tree/b4284b080f53c1ac73c1930b1b1c4e07dcd97559
SigmoidFocalClassificationLoss
import torch import torch.nn as nn class SigmoidFocalClassificationLoss(nn.Module): """ Sigmoid focal cross entropy loss. """ def __init__(self, gamma: 'float'=2.0, alpha: 'float'=0.25): """ Args: gamma: Weighting parameter to balance loss for hard and easy examples. alpha: Weighting parameter to balance loss for positive and negative examples. """ super(SigmoidFocalClassificationLoss, self).__init__() self.alpha = alpha self.gamma = gamma @staticmethod def sigmoid_cross_entropy_with_logits(input: 'torch.Tensor', target: 'torch.Tensor'): """ PyTorch Implementation for tf.nn.sigmoid_cross_entropy_with_logits: max(x, 0) - x * z + log(1 + exp(-abs(x))) in https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets Returns: loss: (B, #anchors, #classes) float tensor. Sigmoid cross entropy loss without reduction """ loss = torch.clamp(input, min=0) - input * target + torch.log1p(torch .exp(-torch.abs(input))) return loss def forward(self, input: 'torch.Tensor', target: 'torch.Tensor', weights: 'torch.Tensor'): """ Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets weights: (B, #anchors) float tensor. Anchor-wise weights. Returns: weighted_loss: (B, #anchors, #classes) float tensor after weighting. """ pred_sigmoid = torch.sigmoid(input) alpha_weight = target * self.alpha + (1 - target) * (1 - self.alpha) pt = target * (1.0 - pred_sigmoid) + (1.0 - target) * pred_sigmoid focal_weight = alpha_weight * torch.pow(pt, self.gamma) bce_loss = self.sigmoid_cross_entropy_with_logits(input, target) loss = focal_weight * bce_loss if weights.shape.__len__() == 2 or weights.shape.__len__( ) == 1 and target.shape.__len__() == 2: weights = weights.unsqueeze(-1) assert weights.shape.__len__() == loss.shape.__len__() return loss * weights def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_add_clamp_exp_log1p_mul_neg_pow_rsub_sigmoid_sub_0( in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp8 = tl.load(in_ptr1 + x0, xmask) tmp26 = tl.load(in_ptr2 + x0, xmask) tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp5 = 0.75 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp9 = tl.sigmoid(tmp8) tmp10 = tmp3 - tmp9 tmp11 = tmp0 * tmp10 tmp12 = tmp4 * tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp13 * tmp13 tmp15 = tmp7 * tmp14 tmp16 = 0.0 tmp17 = triton_helpers.maximum(tmp8, tmp16) tmp18 = tmp8 * tmp0 tmp19 = tmp17 - tmp18 tmp20 = tl_math.abs(tmp8) tmp21 = -tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = libdevice.log1p(tmp22) tmp24 = tmp19 + tmp23 tmp25 = tmp15 * tmp24 tmp27 = tmp25 * tmp26 tl.store(out_ptr0 + x0, tmp27, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_abs_add_clamp_exp_log1p_mul_neg_pow_rsub_sigmoid_sub_0[ grid(256)](arg1_1, arg0_1, arg2_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf0, class SigmoidFocalClassificationLossNew(nn.Module): """ Sigmoid focal cross entropy loss. """ def __init__(self, gamma: 'float'=2.0, alpha: 'float'=0.25): """ Args: gamma: Weighting parameter to balance loss for hard and easy examples. alpha: Weighting parameter to balance loss for positive and negative examples. """ super(SigmoidFocalClassificationLossNew, self).__init__() self.alpha = alpha self.gamma = gamma @staticmethod def sigmoid_cross_entropy_with_logits(input: 'torch.Tensor', target: 'torch.Tensor'): """ PyTorch Implementation for tf.nn.sigmoid_cross_entropy_with_logits: max(x, 0) - x * z + log(1 + exp(-abs(x))) in https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits Args: input: (B, #anchors, #classes) float tensor. Predicted logits for each class target: (B, #anchors, #classes) float tensor. One-hot encoded classification targets Returns: loss: (B, #anchors, #classes) float tensor. Sigmoid cross entropy loss without reduction """ loss = torch.clamp(input, min=0) - input * target + torch.log1p(torch .exp(-torch.abs(input))) return loss def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
AbangLZU/OpenPCDet
SigmoidFocalClassificationLoss
false
7,642
[ "Apache-2.0" ]
29
eeea3f24d392f692228c1ad4e28c0dc9d0e25665
https://github.com/AbangLZU/OpenPCDet/tree/eeea3f24d392f692228c1ad4e28c0dc9d0e25665
L2Norm
import torch import torch.nn as nn class L2Norm(nn.Module): def __init__(self, n_dims, scale=20.0, eps=1e-10): super(L2Norm, self).__init__() self.n_dims = n_dims self.weight = nn.Parameter(torch.Tensor(self.n_dims)) self.eps = eps self.scale = scale def forward(self, x): norm = x.pow(2).sum(1, keepdim=True).sqrt() + self.eps return self.weight[None, :, None, None].expand_as(x) * x / norm def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_dims': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_pow_sqrt_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 x1 = xindex // 16 % 4 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x3, xmask) tmp3 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = libdevice.sqrt(tmp13) tmp15 = 1e-10 tmp16 = tmp14 + tmp15 tmp17 = tmp2 / tmp16 tl.store(out_ptr0 + x3, tmp17, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mul_pow_sqrt_sum_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf0, primals_1 class L2NormNew(nn.Module): def __init__(self, n_dims, scale=20.0, eps=1e-10): super(L2NormNew, self).__init__() self.n_dims = n_dims self.weight = nn.Parameter(torch.Tensor(self.n_dims)) self.eps = eps self.scale = scale def forward(self, input_0): primals_2 = self.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
AllenPeng0209/SaccadeNet
L2Norm
false
7,643
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
Policy
import torch import torch.nn as nn class Policy(nn.Module): def __init__(self, num_inputs, num_outputs): super(Policy, self).__init__() self.affine1 = nn.Linear(num_inputs, 64) self.affine2 = nn.Linear(64, 64) self.action_mean = nn.Linear(64, num_outputs) self.action_mean.weight.data.mul_(0.1) self.action_mean.bias.data.mul_(0.0) self.action_log_std = nn.Parameter(torch.zeros(1, num_outputs)) def forward(self, x): x = torch.tanh(self.affine1(x)) x = torch.tanh(self.affine2(x)) action_mean = self.action_mean(x) action_log_std = self.action_log_std.expand_as(action_mean) action_std = torch.exp(action_log_std) return action_mean, action_log_std, action_std def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_inputs': 4, 'num_outputs': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, None) @triton.jit def triton_poi_fused_exp_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl_math.exp(tmp0) tl.store(out_ptr0 + x2, tmp1, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (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, (64, 64), (64, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (1, 4), (4, 1)) 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 get_raw_stream(0) triton_poi_fused_tanh_0[grid(4096)](buf1, primals_2, 4096, XBLOCK= 128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 64), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf2 triton_poi_fused_tanh_0[grid(4096)](buf3, primals_5, 4096, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_exp_1[grid(256)](primals_8, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_8, (4, 4, 4, 4), (0, 0, 0, 1), 0 ), buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf3, buf5, primals_6, primals_4 class PolicyNew(nn.Module): def __init__(self, num_inputs, num_outputs): super(PolicyNew, self).__init__() self.affine1 = nn.Linear(num_inputs, 64) self.affine2 = nn.Linear(64, 64) self.action_mean = nn.Linear(64, num_outputs) self.action_mean.weight.data.mul_(0.1) self.action_mean.bias.data.mul_(0.0) self.action_log_std = nn.Parameter(torch.zeros(1, num_outputs)) def forward(self, input_0): primals_8 = self.action_log_std primals_1 = self.affine1.weight primals_2 = self.affine1.bias primals_4 = self.affine2.weight primals_5 = self.affine2.bias primals_6 = self.action_mean.weight primals_7 = self.action_mean.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0], output[1], output[2]
Akella17/Deep-Bayesian-Quadrature-Policy-Optimization
Policy
false
7,644
[ "MIT" ]
16
e98fd68046486c002c33cf019db2ce66da18615b
https://github.com/Akella17/Deep-Bayesian-Quadrature-Policy-Optimization/tree/e98fd68046486c002c33cf019db2ce66da18615b
HSigmoid
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data.distributed class HSigmoid(nn.Module): def __init__(self, inplace=True): super(HSigmoid, self).__init__() self.inplace = inplace def forward(self, x): out = F.relu6(x + 3, inplace=self.inplace) / 6 return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data.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_div_hardtanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 3.0 tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 6.0 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = 0.16666666666666666 tmp8 = tmp6 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_hardtanh_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class HSigmoidNew(nn.Module): def __init__(self, inplace=True): super(HSigmoidNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
AberHu/ImageNet-training
HSigmoid
false
7,645
[ "MIT" ]
12
7201eb140176f4d7ec1ed0ff5c27deba2dfb60c2
https://github.com/AberHu/ImageNet-training/tree/7201eb140176f4d7ec1ed0ff5c27deba2dfb60c2
Scale
import torch import torch.nn as nn class Scale(nn.Module): def __init__(self, scale=1.0): super(Scale, self).__init__() self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float)) def forward(self, x): return x * self.scale 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_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (), ()) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 return buf0, primals_2 class ScaleNew(nn.Module): def __init__(self, scale=1.0): super(ScaleNew, self).__init__() self.scale = nn.Parameter(torch.tensor(scale, dtype=torch.float)) def forward(self, input_0): primals_1 = self.scale primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
AllenPeng0209/SaccadeNet
Scale
false
7,646
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
Abs
import torch import torch.nn as nn class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class Abs(ModuleWrapper): def __init__(self): super(Abs, self).__init__() def forward(self, x): return x.abs_() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_abs_0(in_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl_math.abs(tmp0) tl.store(out_ptr1 + x0, tmp1, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) get_raw_stream(0) triton_poi_fused_abs_0[grid(256)](arg0_1, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) return arg0_1, class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class AbsNew(ModuleWrapper): def __init__(self): super(AbsNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
AlliedToasters/elko_den
Abs
false
7,647
[ "Apache-2.0" ]
38
4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
https://github.com/AlliedToasters/elko_den/tree/4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
GHMC
import torch import torch.nn as nn import torch.nn.functional as F def _expand_binary_labels(labels, label_weights, label_channels): bin_labels = labels.new_full((labels.size(0), label_channels), 0) inds = torch.nonzero(labels >= 1).squeeze() if inds.numel() > 0: bin_labels[inds, labels[inds] - 1] = 1 bin_label_weights = label_weights.view(-1, 1).expand(label_weights.size (0), label_channels) return bin_labels, bin_label_weights class GHMC(nn.Module): """GHM Classification Loss. Details of the theorem can be viewed in the paper "Gradient Harmonized Single-stage Detector". https://arxiv.org/abs/1811.05181 Args: bins (int): Number of the unit regions for distribution calculation. momentum (float): The parameter for moving average. use_sigmoid (bool): Can only be true for BCE based loss now. loss_weight (float): The weight of the total GHM-C loss. """ def __init__(self, bins=10, momentum=0, use_sigmoid=True, loss_weight=1.0): super(GHMC, self).__init__() self.bins = bins self.momentum = momentum self.edges = torch.arange(bins + 1).float() / bins self.edges[-1] += 1e-06 if momentum > 0: self.acc_sum = torch.zeros(bins) self.use_sigmoid = use_sigmoid if not self.use_sigmoid: raise NotImplementedError self.loss_weight = loss_weight def forward(self, pred, target, label_weight, *args, **kwargs): """Calculate the GHM-C loss. Args: pred (float tensor of size [batch_num, class_num]): The direct prediction of classification fc layer. target (float tensor of size [batch_num, class_num]): Binary class target for each sample. label_weight (float tensor of size [batch_num, class_num]): the value is 1 if the sample is valid and 0 if ignored. Returns: The gradient harmonized loss. """ if pred.dim() != target.dim(): target, label_weight = _expand_binary_labels(target, label_weight, pred.size(-1)) target, label_weight = target.float(), label_weight.float() edges = self.edges mmt = self.momentum weights = torch.zeros_like(pred) g = torch.abs(pred.sigmoid().detach() - target) valid = label_weight > 0 tot = max(valid.float().sum().item(), 1.0) n = 0 for i in range(self.bins): inds = (g >= edges[i]) & (g < edges[i + 1]) & valid num_in_bin = inds.sum().item() if num_in_bin > 0: if mmt > 0: self.acc_sum[i] = mmt * self.acc_sum[i] + (1 - mmt ) * num_in_bin weights[inds] = tot / self.acc_sum[i] else: weights[inds] = tot / num_in_bin n += 1 if n > 0: weights = weights / n loss = F.binary_cross_entropy_with_logits(pred, target, weights, reduction='sum') / tot return loss * self.loss_weight 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused__to_copy_gt_sum_0(in_ptr0, out_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 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = tmp2.to(tl.float32) tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tl.store(out_ptr0 + tl.broadcast_to(r0, [RBLOCK]), tmp2, None) tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp6, None) @triton.jit def triton_poi_fused_zeros_like_1(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 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_abs_sigmoid_sub_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = tmp1 - tmp2 tmp4 = tl_math.abs(tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf1 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused__to_copy_gt_sum_0[grid(1)](arg2_1, buf0, buf1, 1, 256, num_warps=2, num_stages=1) del arg2_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_zeros_like_1[grid(256)](buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_abs_sigmoid_sub_2[grid(256)](arg0_1, arg1_1, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf1, arg1_1, buf2, buf3, buf0 def _expand_binary_labels(labels, label_weights, label_channels): bin_labels = labels.new_full((labels.size(0), label_channels), 0) inds = torch.nonzero(labels >= 1).squeeze() if inds.numel() > 0: bin_labels[inds, labels[inds] - 1] = 1 bin_label_weights = label_weights.view(-1, 1).expand(label_weights.size (0), label_channels) return bin_labels, bin_label_weights class GHMCNew(nn.Module): """GHM Classification Loss. Details of the theorem can be viewed in the paper "Gradient Harmonized Single-stage Detector". https://arxiv.org/abs/1811.05181 Args: bins (int): Number of the unit regions for distribution calculation. momentum (float): The parameter for moving average. use_sigmoid (bool): Can only be true for BCE based loss now. loss_weight (float): The weight of the total GHM-C loss. """ def __init__(self, bins=10, momentum=0, use_sigmoid=True, loss_weight=1.0): super(GHMCNew, self).__init__() self.bins = bins self.momentum = momentum self.edges = torch.arange(bins + 1).float() / bins self.edges[-1] += 1e-06 if momentum > 0: self.acc_sum = torch.zeros(bins) self.use_sigmoid = use_sigmoid if not self.use_sigmoid: raise NotImplementedError self.loss_weight = loss_weight 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]
AllenPeng0209/SaccadeNet
GHMC
false
7,648
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
ConvWS2d
import torch import torch.nn as nn import torch.nn.functional as F def conv_ws_2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1, eps=1e-05): c_in = weight.size(0) weight_flat = weight.view(c_in, -1) mean = weight_flat.mean(dim=1, keepdim=True).view(c_in, 1, 1, 1) std = weight_flat.std(dim=1, keepdim=True).view(c_in, 1, 1, 1) weight = (weight - mean) / (std + eps) return F.conv2d(input, weight, bias, stride, padding, dilation, groups) class ConvWS2d(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, eps=1e-05): super(ConvWS2d, self).__init__(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.eps = eps def forward(self, x): return conv_ws_2d(x, self.weight, self.bias, self.stride, self. padding, self.dilation, self.groups, self.eps) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.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_per_fused_add_div_mean_std_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp4 / tmp19 tmp21 = 63.0 tmp22 = tmp18 / tmp21 tmp23 = libdevice.sqrt(tmp22) tmp24 = tmp0 - tmp20 tmp25 = 1e-05 tmp26 = tmp23 + tmp25 tmp27 = tmp24 / tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp23, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp27, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1), (1, 1), 0) del buf0 buf5 = reinterpret_tensor(buf3, (4, 1), (1, 1), 0) del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_std_sub_0[grid(4)](buf1, buf5, primals_1, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf7 = extern_kernels.convolution(primals_3, buf6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 1, 1), (4, 1, 1, 1)) buf8 = buf7 del buf7 triton_poi_fused_convolution_1[grid(16)](buf8, primals_2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf8, primals_1, primals_3, buf1, buf5, buf6 def conv_ws_2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1, eps=1e-05): c_in = weight.size(0) weight_flat = weight.view(c_in, -1) mean = weight_flat.mean(dim=1, keepdim=True).view(c_in, 1, 1, 1) std = weight_flat.std(dim=1, keepdim=True).view(c_in, 1, 1, 1) weight = (weight - mean) / (std + eps) return F.conv2d(input, weight, bias, stride, padding, dilation, groups) class ConvWS2dNew(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, eps=1e-05): super(ConvWS2dNew, self).__init__(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.eps = eps 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]
AllenPeng0209/SaccadeNet
ConvWS2d
false
7,649
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
Attention
import math import torch import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): def __init__(self, embed_dim, hidden_dim=None, n_head=1, score_function ='scaled_dot_product'): super(Attention, self).__init__() if hidden_dim is None: hidden_dim = embed_dim self.embed_dim = embed_dim self.hidden_dim = hidden_dim self.n_head = n_head self.score_function = score_function self.w_kx = nn.Parameter(torch.FloatTensor(n_head, embed_dim, hidden_dim)) self.w_qx = nn.Parameter(torch.FloatTensor(n_head, embed_dim, hidden_dim)) if score_function == 'mlp': self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2, 1)) elif self.score_function == 'bi_linear': self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim)) elif self.score_function == 'mlp_sum': self.weight = nn.Parameter(torch.Tensor(hidden_dim, 1)) self.b1 = nn.Parameter(torch.Tensor(hidden_dim)) else: self.register_parameter('weight', None) """ TRY JONATAN WAY score = W_1 tanh ( W_m m_i + W_a + b ) (1) (dx1) (dxd) (d) (dxd) (d) """ def forward(self, k, q): if len(q.shape) == 2: q = torch.unsqueeze(q, dim=1) if len(k.shape) == 2: k = torch.unsqueeze(k, dim=1) mb_size = k.shape[0] k_len = k.shape[1] q_len = q.shape[1] kx = k.repeat(self.n_head, 1, 1).view(self.n_head, -1, self.embed_dim) qx = q.repeat(self.n_head, 1, 1).view(self.n_head, -1, self.embed_dim) kx = torch.bmm(kx, self.w_kx).view(-1, k_len, self.hidden_dim) qx = torch.bmm(qx, self.w_qx).view(-1, q_len, self.hidden_dim) if self.score_function == 'scaled_dot_product': kt = kx.permute(0, 2, 1) qkt = torch.bmm(qx, kt) score = torch.div(qkt, math.sqrt(self.hidden_dim)) elif self.score_function == 'mlp': kxx = torch.unsqueeze(kx, dim=1).expand(-1, q_len, -1, -1) qxx = torch.unsqueeze(qx, dim=2).expand(-1, -1, k_len, -1) kq = torch.cat((kxx, qxx), dim=-1) score = F.tanh(torch.matmul(kq, self.weight).squeeze(dim=-1)) elif self.score_function == 'bi_linear': qw = torch.matmul(q, self.weight) kt = k.permute(0, 2, 1) score = torch.bmm(qw, kt) elif self.score_function == 'mlp_sum': kxx = torch.unsqueeze(kx, dim=1).expand(-1, q_len, -1, -1) qxx = torch.unsqueeze(qx, dim=2).expand(-1, -1, k_len, -1) kq = kxx + qxx + self.b1 score = torch.matmul(F.tanh(kq), self.weight).squeeze(dim=-1) else: raise RuntimeError('invalid score_function') score = F.softmax(score, dim=-1) output = torch.bmm(score, kx) output = torch.cat(torch.split(output, mb_size, dim=0), dim=-1) return output def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'embed_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x2, tmp17, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = 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, (1, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (1, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 16, 4), (64, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_2, (1, 16, 4), (64, 4, 1), 0), primals_3, out=buf0) del primals_3 buf1 = empty_strided_cuda((1, 16, 4), (64, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_1, (1, 16, 4), (64, 4, 1), 0), primals_4, out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0), out=buf2) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = buf2 del buf2 triton_poi_fused__softmax_1[grid(64)](buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf3 del buf3 extern_kernels.bmm(buf4, reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), out=buf5) return buf5, reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0 ), buf4, reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(primals_1, (1, 4, 16), (64, 1, 4), 0 ), reinterpret_tensor(primals_2, (1, 4, 16), (64, 1, 4), 0) class AttentionNew(nn.Module): def __init__(self, embed_dim, hidden_dim=None, n_head=1, score_function ='scaled_dot_product'): super(AttentionNew, self).__init__() if hidden_dim is None: hidden_dim = embed_dim self.embed_dim = embed_dim self.hidden_dim = hidden_dim self.n_head = n_head self.score_function = score_function self.w_kx = nn.Parameter(torch.FloatTensor(n_head, embed_dim, hidden_dim)) self.w_qx = nn.Parameter(torch.FloatTensor(n_head, embed_dim, hidden_dim)) if score_function == 'mlp': self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2, 1)) elif self.score_function == 'bi_linear': self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim)) elif self.score_function == 'mlp_sum': self.weight = nn.Parameter(torch.Tensor(hidden_dim, 1)) self.b1 = nn.Parameter(torch.Tensor(hidden_dim)) else: self.register_parameter('weight', None) """ TRY JONATAN WAY score = W_1 tanh ( W_m m_i + W_a + b ) (1) (dx1) (dxd) (d) (dxd) (d) """ def forward(self, input_0, input_1): primals_3 = self.w_kx primals_4 = self.w_qx primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
AlbertoPaz/ABSA-PyTorch
Attention
false
7,650
[ "MIT" ]
20
070a4b6f20cde0e2021c72b84c534659d749f36e
https://github.com/AlbertoPaz/ABSA-PyTorch/tree/070a4b6f20cde0e2021c72b84c534659d749f36e
SmoothL1Loss
import functools import torch import torch.nn as nn import torch.nn.functional as F def reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Return: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() elif reduction_enum == 2: return loss.sum() def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. reduction (str): Same as built-in losses of PyTorch. avg_factor (float): Avarage factor when computing the mean of losses. Returns: Tensor: Processed loss values. """ if weight is not None: loss = loss * weight if avg_factor is None: loss = reduce_loss(loss, reduction) elif reduction == 'mean': loss = loss.sum() / avg_factor elif reduction != 'none': raise ValueError('avg_factor can not be used with reduction="sum"') return loss def weighted_loss(loss_func): """Create a weighted version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> @weighted_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, avg_factor=2) tensor(1.5000) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', avg_factor= None, **kwargs): loss = loss_func(pred, target, **kwargs) loss = weight_reduce_loss(loss, weight, reduction, avg_factor) return loss return wrapper @weighted_loss def smooth_l1_loss(pred, target, beta=1.0): assert beta > 0 assert pred.size() == target.size() and target.numel() > 0 diff = torch.abs(pred - target) loss = torch.where(diff < beta, 0.5 * diff * diff / beta, diff - 0.5 * beta ) return loss class SmoothL1Loss(nn.Module): def __init__(self, beta=1.0, reduction='mean', loss_weight=1.0): super(SmoothL1Loss, self).__init__() self.beta = beta self.reduction = reduction self.loss_weight = loss_weight def forward(self, pred, target, weight=None, avg_factor=None, reduction_override=None, **kwargs): assert reduction_override in (None, 'none', 'mean', 'sum') reduction = (reduction_override if reduction_override else self. reduction) loss_bbox = self.loss_weight * smooth_l1_loss(pred, target, weight, beta=self.beta, reduction=reduction, avg_factor=avg_factor, ** kwargs) return loss_bbox 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 functools import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_div_lt_mean_mul_sub_where_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 1.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) tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 256.0 tmp16 = tmp14 / tmp15 tmp17 = tmp16 * tmp4 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp17, 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_lt_mean_mul_sub_where_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 reduce_loss(loss, reduction): """Reduce loss as specified. Args: loss (Tensor): Elementwise loss tensor. reduction (str): Options are "none", "mean" and "sum". Return: Tensor: Reduced loss tensor. """ reduction_enum = F._Reduction.get_enum(reduction) if reduction_enum == 0: return loss elif reduction_enum == 1: return loss.mean() elif reduction_enum == 2: return loss.sum() def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None): """Apply element-wise weight and reduce loss. Args: loss (Tensor): Element-wise loss. weight (Tensor): Element-wise weights. reduction (str): Same as built-in losses of PyTorch. avg_factor (float): Avarage factor when computing the mean of losses. Returns: Tensor: Processed loss values. """ if weight is not None: loss = loss * weight if avg_factor is None: loss = reduce_loss(loss, reduction) elif reduction == 'mean': loss = loss.sum() / avg_factor elif reduction != 'none': raise ValueError('avg_factor can not be used with reduction="sum"') return loss def weighted_loss(loss_func): """Create a weighted version of a given loss function. To use this decorator, the loss function must have the signature like `loss_func(pred, target, **kwargs)`. The function only needs to compute element-wise loss without any reduction. This decorator will add weight and reduction arguments to the function. The decorated function will have the signature like `loss_func(pred, target, weight=None, reduction='mean', avg_factor=None, **kwargs)`. :Example: >>> @weighted_loss >>> def l1_loss(pred, target): >>> return (pred - target).abs() >>> pred = torch.Tensor([0, 2, 3]) >>> target = torch.Tensor([1, 1, 1]) >>> weight = torch.Tensor([1, 0, 1]) >>> l1_loss(pred, target) tensor(1.3333) >>> l1_loss(pred, target, weight) tensor(1.) >>> l1_loss(pred, target, reduction='none') tensor([1., 1., 2.]) >>> l1_loss(pred, target, weight, avg_factor=2) tensor(1.5000) """ @functools.wraps(loss_func) def wrapper(pred, target, weight=None, reduction='mean', avg_factor= None, **kwargs): loss = loss_func(pred, target, **kwargs) loss = weight_reduce_loss(loss, weight, reduction, avg_factor) return loss return wrapper @weighted_loss def smooth_l1_loss(pred, target, beta=1.0): assert beta > 0 assert pred.size() == target.size() and target.numel() > 0 diff = torch.abs(pred - target) loss = torch.where(diff < beta, 0.5 * diff * diff / beta, diff - 0.5 * beta ) return loss class SmoothL1LossNew(nn.Module): def __init__(self, beta=1.0, reduction='mean', loss_weight=1.0): super(SmoothL1LossNew, self).__init__() self.beta = beta self.reduction = reduction self.loss_weight = loss_weight def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
AllenPeng0209/SaccadeNet
SmoothL1Loss
false
7,651
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
KL_loss_softmax
import torch import torch.nn as nn import torch.nn.init class KL_loss_softmax(nn.Module): """ Compute KL_divergence between all prediction score (already sum=1, omit softmax function) """ def __init__(self): super(KL_loss_softmax, self).__init__() self.KL_loss = nn.KLDivLoss(reduce=False) def forward(self, im, s): img_prob = torch.log(im) s_prob = s KL_loss = self.KL_loss(img_prob, s_prob) loss = KL_loss.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 libdevice, math as tl_math import torch.nn as nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_log_mul_sub_sum_xlogy_0(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp9 = tl.load(in_ptr1 + r0, None) tmp1 = libdevice.isnan(tmp0).to(tl.int1) tmp2 = 0.0 tmp3 = tmp0 == tmp2 tmp4 = tl_math.log(tmp0) tmp5 = tmp0 * tmp4 tmp6 = tl.where(tmp3, tmp2, tmp5) tmp7 = float('nan') tmp8 = tl.where(tmp1, tmp7, tmp6) tmp10 = tl_math.log(tmp9) tmp11 = tmp0 * tmp10 tmp12 = tmp8 - tmp11 tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp15, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_log_mul_sub_sum_xlogy_0[grid(1)](arg1_1, arg0_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf0, class KL_loss_softmaxNew(nn.Module): """ Compute KL_divergence between all prediction score (already sum=1, omit softmax function) """ def __init__(self): super(KL_loss_softmaxNew, self).__init__() self.KL_loss = nn.KLDivLoss(reduce=False) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
AndresPMD/semantic_adaptive_margin
KL_loss_softmax
false
7,652
[ "Apache-2.0" ]
12
1e8bf2f1836498c48df030cb0a967b72b52e8460
https://github.com/AndresPMD/semantic_adaptive_margin/tree/1e8bf2f1836498c48df030cb0a967b72b52e8460
Centered_Grad
import torch import torch.nn as nn class Centered_Grad(nn.Module): def __init__(self): super(Centered_Grad, self).__init__() self.x_ker_init = torch.tensor([[[[-0.5, 0, 0.5]]]], dtype=torch. float, requires_grad=True) self.y_ker_init = torch.tensor([[[[-0.5], [0], [0.5]]]], dtype= torch.float, requires_grad=True) self.center_conv_x = nn.Conv2d(1, 1, (1, 3), padding=(0, 1), bias=False ) self.center_conv_x.weight.data = self.x_ker_init self.center_conv_y = nn.Conv2d(1, 1, (3, 1), padding=(1, 0), bias=False ) self.center_conv_y.weight.data = self.y_ker_init def forward(self, x): assert len(x.shape) == 4 diff_x = self.center_conv_x(x) diff_y = self.center_conv_y(x) first_col = 0.5 * (x[:, :, :, 1:2] - x[:, :, :, 0:1]) last_col = 0.5 * (x[:, :, :, -1:] - x[:, :, :, -2:-1]) diff_x_valid = diff_x[:, :, :, 1:-1] diff_x = torch.cat((first_col, diff_x_valid, last_col), 3) first_row = 0.5 * (x[:, :, 1:2, :] - x[:, :, 0:1, :]) last_row = 0.5 * (x[:, :, -1:, :] - x[:, :, -2:-1, :]) diff_y_valid = diff_y[:, :, 1:-1, :] diff_y = torch.cat((first_row, diff_y_valid, last_row), 2) return diff_x, diff_y def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_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) x0 = xindex % 64 x1 = xindex // 64 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 + (1 + 64 * x1), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + 64 * x1, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 - tmp6 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 63, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr1 + (1 + 64 * x1 + (-1 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp17 = tmp0 >= tmp13 tl.full([1], 64, tl.int64) tmp20 = tl.load(in_ptr0 + (63 + 64 * x1), tmp17, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.load(in_ptr0 + (62 + 64 * x1), tmp17, eviction_policy= 'evict_last', other=0.0) tmp22 = tmp20 - tmp21 tmp23 = tmp22 * tmp8 tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp17, tmp23, tmp24) tmp26 = tl.where(tmp15, tmp16, tmp25) tmp27 = tl.where(tmp4, tmp11, tmp26) tl.store(out_ptr0 + x2, tmp27, None) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 64 % 64 x0 = xindex % 64 x2 = xindex // 4096 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (64 + x0 + 4096 * x2), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (x0 + 4096 * x2), tmp4, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 - tmp6 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tmp13 = tl.full([1], 63, tl.int64) tmp14 = tmp0 < tmp13 tmp15 = tmp12 & tmp14 tmp16 = tl.load(in_ptr1 + (64 + x0 + 64 * (-1 + x1) + 4096 * x2), tmp15, other=0.0) tmp17 = tmp0 >= tmp13 tl.full([1], 64, tl.int64) tmp20 = tl.load(in_ptr0 + (4032 + x0 + 4096 * x2), tmp17, eviction_policy='evict_last', other=0.0) tmp21 = tl.load(in_ptr0 + (3968 + x0 + 4096 * x2), tmp17, eviction_policy='evict_last', other=0.0) tmp22 = tmp20 - tmp21 tmp23 = tmp22 * tmp8 tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp17, tmp23, tmp24) tmp26 = tl.where(tmp15, tmp16, tmp25) tmp27 = tl.where(tmp4, tmp11, tmp26) tl.store(out_ptr0 + x3, tmp27, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_2, (1, 1, 1, 3), (3, 3, 3, 1)) assert_size_stride(primals_3, (1, 1, 3, 1), (3, 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=(0, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 1, 64, 64), (4096, 4096, 64, 1)) buf1 = extern_kernels.convolution(primals_1, primals_3, stride=(1, 1), padding=(1, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 1, 64, 64), (4096, 4096, 64, 1)) buf2 = empty_strided_cuda((4, 1, 64, 64), (4096, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(16384)](primals_1, buf0, buf2, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf3 = buf0 del buf0 triton_poi_fused_cat_1[grid(16384)](primals_1, buf1, buf3, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf1 return buf2, buf3, primals_1, primals_2, primals_3 class Centered_GradNew(nn.Module): def __init__(self): super(Centered_GradNew, self).__init__() self.x_ker_init = torch.tensor([[[[-0.5, 0, 0.5]]]], dtype=torch. float, requires_grad=True) self.y_ker_init = torch.tensor([[[[-0.5], [0], [0.5]]]], dtype= torch.float, requires_grad=True) self.center_conv_x = nn.Conv2d(1, 1, (1, 3), padding=(0, 1), bias=False ) self.center_conv_x.weight.data = self.x_ker_init self.center_conv_y = nn.Conv2d(1, 1, (3, 1), padding=(1, 0), bias=False ) self.center_conv_y.weight.data = self.y_ker_init def forward(self, input_0): primals_2 = self.center_conv_x.weight primals_3 = self.center_conv_y.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
AmazingAng/pytorch-tvnet
Centered_Grad
false
7,653
[ "MIT" ]
12
e880d3ce15f55e5d9a11b423cfd1e0461de4fedb
https://github.com/AmazingAng/pytorch-tvnet/tree/e880d3ce15f55e5d9a11b423cfd1e0461de4fedb
ShuffleBlock
import torch from torch import nn class ShuffleBlock(nn.Module): def __init__(self, groups=2): super(ShuffleBlock, self).__init__() self.groups = groups def forward(self, x): """Channel shuffle: [N,C,H,W] -> [N,g,C/g,H,W] -> [N,C/g,g,H,w] -> [N,C,H,W]""" N, C, H, W = x.size() g = self.groups return x.view(N, g, C // g, H, W).permute(0, 2, 1, 3, 4).reshape(N, C, H, W) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 2 x2 = xindex // 32 % 2 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2 + 32 * x1 + 64 * x3), xmask) tl.store(out_ptr0 + x4, 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, 2, 2, 4, 4), (64, 32, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0), class ShuffleBlockNew(nn.Module): def __init__(self, groups=2): super(ShuffleBlockNew, self).__init__() self.groups = groups def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alibaba-MIIL/HeadSharingKD
ShuffleBlock
false
7,654
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
GLU
import torch import torch.nn as nn class GLU(nn.Module): def __init__(self, input_channel, output_channel): super(GLU, self).__init__() self.linear_left = nn.Linear(input_channel, output_channel) self.linear_right = nn.Linear(input_channel, output_channel) def forward(self, x): return torch.mul(self.linear_left(x), torch.sigmoid(self. linear_right(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channel': 4, 'output_channel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](buf0, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0, buf1 class GLUNew(nn.Module): def __init__(self, input_channel, output_channel): super(GLUNew, self).__init__() self.linear_left = nn.Linear(input_channel, output_channel) self.linear_right = nn.Linear(input_channel, output_channel) def forward(self, input_0): primals_1 = self.linear_left.weight primals_2 = self.linear_left.bias primals_4 = self.linear_right.weight primals_5 = self.linear_right.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
Abdulmajid-Murad/deep_probabilistic_forecast
GLU
false
7,655
[ "MIT" ]
11
399846381af4bb789021c9f63f121dd69fa0125d
https://github.com/Abdulmajid-Murad/deep_probabilistic_forecast/tree/399846381af4bb789021c9f63f121dd69fa0125d
ActFirstResBlock
import torch import torch.nn.functional as F from torch import nn class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class ActFirstResBlock(nn.Module): def __init__(self, fin, fout, fhid=None, activation='lrelu', norm='none'): super().__init__() self.learned_shortcut = fin != fout self.fin = fin self.fout = fout self.fhid = min(fin, fout) if fhid is None else fhid self.conv_0 = Conv2dBlock(self.fin, self.fhid, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) self.conv_1 = Conv2dBlock(self.fhid, self.fout, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) if self.learned_shortcut: self.conv_s = Conv2dBlock(self.fin, self.fout, 1, 1, activation ='none', use_bias=False) def forward(self, x): x_s = self.conv_s(x) if self.learned_shortcut else x dx = self.conv_0(x) dx = self.conv_1(dx) out = x_s + dx return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'fin': 4, 'fout': 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.functional as F 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_leaky_relu_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x2 = xindex // 36 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x3, tmp5, xmask) @triton.jit def triton_poi_fused_convolution_leaky_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 x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x4 = xindex // 36 x2 = xindex // 36 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4), xmask, eviction_policy='evict_last').to(tl.int1) tmp1 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4), xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = 0.2 tmp5 = tmp3 * tmp4 tmp6 = tl.where(tmp0, tmp3, tmp5) tl.store(out_ptr0 + x5, tmp6, xmask) @triton.jit def triton_poi_fused_add_convolution_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_out_ptr0 + x3, xmask) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x3, 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, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_reflection_pad2d_0[grid(576)](primals_1, buf0, 576, XBLOCK=128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf1, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2[grid(576)]( buf2, buf1, primals_3, buf3, 576, XBLOCK=256, num_warps=4, num_stages=1) del buf1 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, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_add_convolution_3[grid(256)](buf5, primals_1, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf5, primals_2, primals_4, buf0, buf2, buf3 class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class ActFirstResBlockNew(nn.Module): def __init__(self, fin, fout, fhid=None, activation='lrelu', norm='none'): super().__init__() self.learned_shortcut = fin != fout self.fin = fin self.fout = fout self.fhid = min(fin, fout) if fhid is None else fhid self.conv_0 = Conv2dBlock(self.fin, self.fhid, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) self.conv_1 = Conv2dBlock(self.fhid, self.fout, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) if self.learned_shortcut: self.conv_s = Conv2dBlock(self.fin, self.fout, 1, 1, activation ='none', use_bias=False) def forward(self, input_0): primals_2 = self.conv_0.conv.weight primals_3 = self.conv_0.conv.bias primals_4 = self.conv_1.conv.weight primals_5 = self.conv_1.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
Alikfp/research-GANwriting
ActFirstResBlock
false
7,656
[ "MIT" ]
41
2190954218a733deac52c929f51bb85bca5d7216
https://github.com/Alikfp/research-GANwriting/tree/2190954218a733deac52c929f51bb85bca5d7216
Multi_feature_fusing
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F import torch.nn.init def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class Multi_feature_fusing(nn.Module): """ Emb the features from both modalities to the joint attribute label space. """ def __init__(self, embed_dim, fuse_type='weight_sum'): """ param image_dim: dim of visual feature param embed_dim: dim of embedding space """ super(Multi_feature_fusing, self).__init__() self.fuse_type = fuse_type self.embed_dim = embed_dim if fuse_type == 'concat': input_dim = int(2 * embed_dim) self.joint_emb_v = nn.Linear(input_dim, embed_dim) self.joint_emb_t = nn.Linear(input_dim, embed_dim) self.init_weights_concat() if fuse_type == 'adap_sum': self.joint_emb_v = nn.Linear(embed_dim, 1) self.joint_emb_t = nn.Linear(embed_dim, 1) self.init_weights_adap_sum() def init_weights_concat(self): """Xavier initialization""" r = np.sqrt(6.0) / np.sqrt(self.embed_dim + 2 * self.embed_dim) self.joint_emb_v.weight.data.uniform_(-r, r) self.joint_emb_v.bias.data.fill_(0) self.joint_emb_t.weight.data.uniform_(-r, r) self.joint_emb_t.bias.data.fill_(0) def init_weights_adap_sum(self): """Xavier initialization""" r = np.sqrt(6.0) / np.sqrt(self.embed_dim + 1) self.joint_emb_v.weight.data.uniform_(-r, r) self.joint_emb_v.bias.data.fill_(0) self.joint_emb_t.weight.data.uniform_(-r, r) self.joint_emb_t.bias.data.fill_(0) def forward(self, v_emb_instance, t_emb_instance, v_emb_concept, t_emb_concept): """ Forward propagation. :param v_emb_instance, t_emb_instance: instance-level visual or textual features, shape: (batch_size, emb_dim) :param v_emb_concept, t_emb_concept: consensus-level concept features, shape: (batch_size, emb_dim) :return: joint embbeding features for both modalities """ if self.fuse_type == 'multiple': v_fused_emb = v_emb_instance.mul(v_emb_concept) v_fused_emb = l2norm(v_fused_emb) t_fused_emb = t_emb_instance.mul(t_emb_concept) t_fused_emb = l2norm(t_fused_emb) elif self.fuse_type == 'concat': v_fused_emb = torch.cat([v_emb_instance, v_emb_concept], dim=1) v_fused_emb = self.joint_emb_instance_v(v_fused_emb) v_fused_emb = l2norm(v_fused_emb) t_fused_emb = torch.cat([t_emb_instance, t_emb_concept], dim=1) t_fused_emb = self.joint_emb_instance_v(t_fused_emb) t_fused_emb = l2norm(t_fused_emb) elif self.fuse_type == 'adap_sum': v_mean = (v_emb_instance + v_emb_concept) / 2 v_emb_instance_mat = self.joint_emb_instance_v(v_mean) alpha_v = F.sigmoid(v_emb_instance_mat) v_fused_emb = alpha_v * v_emb_instance + (1 - alpha_v ) * v_emb_concept v_fused_emb = l2norm(v_fused_emb) t_mean = (t_emb_instance + t_emb_concept) / 2 t_emb_instance_mat = self.joint_emb_instance_t(t_mean) alpha_t = F.sigmoid(t_emb_instance_mat) t_fused_emb = alpha_t * t_emb_instance + (1 - alpha_t ) * t_emb_concept t_fused_emb = l2norm(t_fused_emb) elif self.fuse_type == 'weight_sum': alpha = 0.75 v_fused_emb = alpha * v_emb_instance + (1 - alpha) * v_emb_concept v_fused_emb = l2norm(v_fused_emb) t_fused_emb = alpha * t_emb_instance + (1 - alpha) * t_emb_concept t_fused_emb = l2norm(t_fused_emb) return v_fused_emb, t_fused_emb 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 [[], {'embed_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 import numpy as np import torch.nn as nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_pow_sqrt_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp17 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp24 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.75 tmp2 = tmp0 * tmp1 tmp4 = 0.25 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp7 = tmp6 * tmp6 tmp9 = tmp8 * tmp1 tmp11 = tmp10 * tmp4 tmp12 = tmp9 + tmp11 tmp13 = tmp12 * tmp12 tmp14 = tmp7 + tmp13 tmp16 = tmp15 * tmp1 tmp18 = tmp17 * tmp4 tmp19 = tmp16 + tmp18 tmp20 = tmp19 * tmp19 tmp21 = tmp14 + tmp20 tmp23 = tmp22 * tmp1 tmp25 = tmp24 * tmp4 tmp26 = tmp23 + tmp25 tmp27 = tmp26 * tmp26 tmp28 = tmp21 + tmp27 tmp29 = libdevice.sqrt(tmp28) tmp30 = 1e-12 tmp31 = tmp29 + tmp30 tl.store(out_ptr0 + x0, tmp31, xmask) @triton.jit def triton_poi_fused_add_div_mul_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr1 + x2, xmask) tmp7 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.75 tmp2 = tmp0 * tmp1 tmp4 = 0.25 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp8 = tmp6 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1, arg2_1, arg3_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_pow_sqrt_sum_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mul_1[grid(256)](arg0_1, arg1_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 buf2 = buf0 del buf0 triton_poi_fused_add_mul_pow_sqrt_sum_0[grid(64)](arg2_1, arg3_1, 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_mul_1[grid(256)](arg2_1, arg3_1, buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg2_1 del arg3_1 del buf2 return buf1, buf3 def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class Multi_feature_fusingNew(nn.Module): """ Emb the features from both modalities to the joint attribute label space. """ def __init__(self, embed_dim, fuse_type='weight_sum'): """ param image_dim: dim of visual feature param embed_dim: dim of embedding space """ super(Multi_feature_fusingNew, self).__init__() self.fuse_type = fuse_type self.embed_dim = embed_dim if fuse_type == 'concat': input_dim = int(2 * embed_dim) self.joint_emb_v = nn.Linear(input_dim, embed_dim) self.joint_emb_t = nn.Linear(input_dim, embed_dim) self.init_weights_concat() if fuse_type == 'adap_sum': self.joint_emb_v = nn.Linear(embed_dim, 1) self.joint_emb_t = nn.Linear(embed_dim, 1) self.init_weights_adap_sum() def init_weights_concat(self): """Xavier initialization""" r = np.sqrt(6.0) / np.sqrt(self.embed_dim + 2 * self.embed_dim) self.joint_emb_v.weight.data.uniform_(-r, r) self.joint_emb_v.bias.data.fill_(0) self.joint_emb_t.weight.data.uniform_(-r, r) self.joint_emb_t.bias.data.fill_(0) def init_weights_adap_sum(self): """Xavier initialization""" r = np.sqrt(6.0) / np.sqrt(self.embed_dim + 1) self.joint_emb_v.weight.data.uniform_(-r, r) self.joint_emb_v.bias.data.fill_(0) self.joint_emb_t.weight.data.uniform_(-r, r) self.joint_emb_t.bias.data.fill_(0) 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], output[1]
AndresPMD/semantic_adaptive_margin
Multi_feature_fusing
false
7,657
[ "Apache-2.0" ]
12
1e8bf2f1836498c48df030cb0a967b72b52e8460
https://github.com/AndresPMD/semantic_adaptive_margin/tree/1e8bf2f1836498c48df030cb0a967b72b52e8460
Permute
import torch from torch import nn class Permute(nn.Module): def __init__(self, permutation=[2, 1, 0]): super().__init__() self.permutation = permutation def forward(self, input): return input[:, self.permutation] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 3 x0 = xindex % 16 x2 = xindex // 48 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 1, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 0, tl.int64) tmp6 = tl.where(tmp4, tmp1, tmp5) tmp7 = tl.where(tmp2, tmp3, tmp6) tmp8 = tl.load(in_ptr0 + (x0 + 16 * tmp7 + 64 * x2), xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_index_0[grid(192)](arg0_1, buf0, 192, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class PermuteNew(nn.Module): def __init__(self, permutation=[2, 1, 0]): super().__init__() self.permutation = permutation def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alibaba-AAIG/Beyond-ImageNet-Attack
Permute
false
7,658
[ "MIT" ]
23
c14b4844b64a8035b8fe033a617c0567224a9fa4
https://github.com/Alibaba-AAIG/Beyond-ImageNet-Attack/tree/c14b4844b64a8035b8fe033a617c0567224a9fa4
FactorTransfer
import torch from torch import nn import torch.nn.functional as F class FactorTransfer(nn.Module): """Paraphrasing Complex Network: Network Compression via Factor Transfer, NeurIPS 2018""" def __init__(self, p1=2, p2=1): super(FactorTransfer, self).__init__() self.p1 = p1 self.p2 = p2 def forward(self, f_s, f_t): return self.factor_loss(f_s, f_t) def factor_loss(self, f_s, f_t): s_H, t_H = f_s.shape[2], f_t.shape[2] if s_H > t_H: f_s = F.adaptive_avg_pool2d(f_s, (t_H, t_H)) elif s_H < t_H: f_t = F.adaptive_avg_pool2d(f_t, (s_H, s_H)) else: pass if self.p2 == 1: return (self.factor(f_s) - self.factor(f_t)).abs().mean() else: return (self.factor(f_s) - self.factor(f_t)).pow(self.p2).mean() def factor(self, f): return F.normalize(f.pow(self.p1).mean(1).view(f.size(0), -1)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_div_linalg_vector_norm_sub_0(in_ptr0, in_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) tmp2 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp5 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp8 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp18 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp20 = tl.load(in_ptr1 + (16 + r1 + 64 * x0), xmask, other=0.0) tmp23 = tl.load(in_ptr1 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr1 + (48 + r1 + 64 * x0), xmask, other=0.0) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = 4.0 tmp12 = tmp10 / tmp11 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp19 = tmp18 * tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp27 = tmp26 * tmp26 tmp28 = tmp25 + tmp27 tmp29 = tmp28 / tmp11 tmp30 = tmp29 * tmp29 tmp31 = tl.broadcast_to(tmp30, [XBLOCK, RBLOCK]) tmp33 = tl.where(xmask, tmp31, 0) tmp34 = tl.sum(tmp33, 1)[:, None] tmp35 = libdevice.sqrt(tmp17) tmp36 = 1e-12 tmp37 = triton_helpers.maximum(tmp35, tmp36) tmp38 = tmp12 / tmp37 tmp39 = libdevice.sqrt(tmp34) tmp40 = triton_helpers.maximum(tmp39, tmp36) tmp41 = tmp29 / tmp40 tmp42 = tmp38 - tmp41 tl.store(out_ptr2 + (r1 + 16 * x0), tmp42, xmask) @triton.jit def triton_per_fused_abs_mean_1(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 + r0, None) tmp1 = tl_math.abs(tmp0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tmp5 = 64.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp6, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32) get_raw_stream(0) triton_per_fused_div_linalg_vector_norm_sub_0[grid(4)](arg0_1, arg1_1, buf2, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = buf3 del buf3 triton_per_fused_abs_mean_1[grid(1)](buf4, buf2, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf2 return buf4, class FactorTransferNew(nn.Module): """Paraphrasing Complex Network: Network Compression via Factor Transfer, NeurIPS 2018""" def __init__(self, p1=2, p2=1): super(FactorTransferNew, self).__init__() self.p1 = p1 self.p2 = p2 def factor_loss(self, f_s, f_t): s_H, t_H = f_s.shape[2], f_t.shape[2] if s_H > t_H: f_s = F.adaptive_avg_pool2d(f_s, (t_H, t_H)) elif s_H < t_H: f_t = F.adaptive_avg_pool2d(f_t, (s_H, s_H)) else: pass if self.p2 == 1: return (self.factor(f_s) - self.factor(f_t)).abs().mean() else: return (self.factor(f_s) - self.factor(f_t)).pow(self.p2).mean() def factor(self, f): return F.normalize(f.pow(self.p1).mean(1).view(f.size(0), -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]
Alibaba-MIIL/HeadSharingKD
FactorTransfer
false
7,659
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
GHMR
import torch import torch.nn as nn class GHMR(nn.Module): """GHM Regression Loss. Details of the theorem can be viewed in the paper "Gradient Harmonized Single-stage Detector" https://arxiv.org/abs/1811.05181 Args: mu (float): The parameter for the Authentic Smooth L1 loss. bins (int): Number of the unit regions for distribution calculation. momentum (float): The parameter for moving average. loss_weight (float): The weight of the total GHM-R loss. """ def __init__(self, mu=0.02, bins=10, momentum=0, loss_weight=1.0): super(GHMR, self).__init__() self.mu = mu self.bins = bins self.edges = torch.arange(bins + 1).float() / bins self.edges[-1] = 1000.0 self.momentum = momentum if momentum > 0: self.acc_sum = torch.zeros(bins) self.loss_weight = loss_weight def forward(self, pred, target, label_weight, avg_factor=None): """Calculate the GHM-R loss. Args: pred (float tensor of size [batch_num, 4 (* class_num)]): The prediction of box regression layer. Channel number can be 4 or 4 * class_num depending on whether it is class-agnostic. target (float tensor of size [batch_num, 4 (* class_num)]): The target regression values with the same size of pred. label_weight (float tensor of size [batch_num, 4 (* class_num)]): The weight of each sample, 0 if ignored. Returns: The gradient harmonized loss. """ mu = self.mu edges = self.edges mmt = self.momentum diff = pred - target loss = torch.sqrt(diff * diff + mu * mu) - mu g = torch.abs(diff / torch.sqrt(mu * mu + diff * diff)).detach() weights = torch.zeros_like(g) valid = label_weight > 0 tot = max(label_weight.float().sum().item(), 1.0) n = 0 for i in range(self.bins): inds = (g >= edges[i]) & (g < edges[i + 1]) & valid num_in_bin = inds.sum().item() if num_in_bin > 0: n += 1 if mmt > 0: self.acc_sum[i] = mmt * self.acc_sum[i] + (1 - mmt ) * num_in_bin weights[inds] = tot / self.acc_sum[i] else: weights[inds] = tot / num_in_bin if n > 0: weights /= n loss = loss * weights loss = loss.sum() / tot return loss * self.loss_weight def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_gt_sum_0(in_ptr0, out_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 = tmp0 > tmp4 tl.store(out_ptr1 + tl.broadcast_to(r0, [RBLOCK]), tmp5, None) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp3, None) @triton.jit def triton_poi_fused_abs_add_div_mul_sqrt_sub_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = 0.0004 tmp5 = tmp3 + tmp4 tmp6 = libdevice.sqrt(tmp5) tmp7 = 0.02 tmp8 = tmp6 - tmp7 tmp9 = tmp2 / tmp6 tmp10 = tl_math.abs(tmp9) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp10, xmask) @triton.jit def triton_poi_fused_zeros_like_2(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 = 0.0 tl.store(out_ptr0 + x0, tmp0, 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((), (), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_per_fused_gt_sum_0[grid(1)](arg2_1, buf0, buf4, 1, 256, num_warps=2, num_stages=1) del arg2_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_abs_add_div_mul_sqrt_sub_1[grid(256)](arg0_1, arg1_1, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_zeros_like_2[grid(256)](buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf0, buf1, buf2, buf3, buf4 class GHMRNew(nn.Module): """GHM Regression Loss. Details of the theorem can be viewed in the paper "Gradient Harmonized Single-stage Detector" https://arxiv.org/abs/1811.05181 Args: mu (float): The parameter for the Authentic Smooth L1 loss. bins (int): Number of the unit regions for distribution calculation. momentum (float): The parameter for moving average. loss_weight (float): The weight of the total GHM-R loss. """ def __init__(self, mu=0.02, bins=10, momentum=0, loss_weight=1.0): super(GHMRNew, self).__init__() self.mu = mu self.bins = bins self.edges = torch.arange(bins + 1).float() / bins self.edges[-1] = 1000.0 self.momentum = momentum if momentum > 0: self.acc_sum = torch.zeros(bins) self.loss_weight = loss_weight 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]
AllenPeng0209/SaccadeNet
GHMR
false
7,660
[ "Apache-2.0" ]
30
0fce4266cbffc9a2c5f70335efa636da849ce70c
https://github.com/AllenPeng0209/SaccadeNet/tree/0fce4266cbffc9a2c5f70335efa636da849ce70c
Forward_Grad
import torch import torch.nn as nn import torch.nn.functional as F class Forward_Grad(nn.Module): def __init__(self): super(Forward_Grad, self).__init__() self.x_ker_init = torch.tensor([[[[-1, 1]]]], dtype=torch.float, requires_grad=True) self.y_ker_init = torch.tensor([[[[-1], [1]]]], dtype=torch.float, requires_grad=True) self.forward_conv_x = nn.Conv2d(1, 1, (1, 2), bias=False) self.forward_conv_x.weight.data = self.x_ker_init self.forward_conv_y = nn.Conv2d(1, 1, (2, 1), bias=False) self.forward_conv_y.weight.data = self.y_ker_init def forward(self, x): assert len(x.shape) == 4 x.padright = F.pad(x, (0, 1, 0, 0)) x.padbottom = F.pad(x, (0, 0, 0, 1)) diff_x = self.forward_conv_x(x.padright) diff_y = self.forward_conv_y(x.padbottom) diff_x[:, :, :, x.shape[3] - 1] = 0 diff_y[:, :, x.shape[2] - 1, :] = 0 return diff_x, diff_y def get_inputs(): return [torch.rand([4, 1, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = x0 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp2 & xmask, other=0.0) tl.store(out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 5 x2 = xindex // 20 x3 = xindex % 20 x4 = xindex tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.load(in_ptr0 + (x3 + 16 * x2), tmp2 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp3, xmask) @triton.jit def triton_poi_fused_fill_lift_fresh_2(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 % 4 x2 = xindex tmp3 = tl.load(in_out_ptr0 + x2, xmask) tmp0 = x0 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tl.store(in_out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_fill_lift_fresh_3(in_out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 4 x3 = xindex tmp3 = tl.load(in_out_ptr0 + x3, xmask) tmp0 = x1 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tl.store(in_out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 1, 4, 4), (16, 16, 4, 1)) assert_size_stride(primals_2, (1, 1, 1, 2), (2, 2, 2, 1)) assert_size_stride(primals_3, (1, 1, 2, 1), (2, 2, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 4, 5), (20, 20, 5, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(80)](primals_1, buf0, 80, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 1, 5, 4), (20, 20, 4, 1), torch.float32) triton_poi_fused_constant_pad_nd_1[grid(80)](primals_1, buf1, 80, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf2 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 4, 4), (16, 16, 4, 1)) buf3 = extern_kernels.convolution(buf1, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 1, 4, 4), (16, 16, 4, 1)) buf4 = buf2 del buf2 triton_poi_fused_fill_lift_fresh_2[grid(64)](buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf3 del buf3 triton_poi_fused_fill_lift_fresh_3[grid(64)](buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf4, buf5, buf1, buf0, primals_2, primals_3, buf0, buf1 class Forward_GradNew(nn.Module): def __init__(self): super(Forward_GradNew, self).__init__() self.x_ker_init = torch.tensor([[[[-1, 1]]]], dtype=torch.float, requires_grad=True) self.y_ker_init = torch.tensor([[[[-1], [1]]]], dtype=torch.float, requires_grad=True) self.forward_conv_x = nn.Conv2d(1, 1, (1, 2), bias=False) self.forward_conv_x.weight.data = self.x_ker_init self.forward_conv_y = nn.Conv2d(1, 1, (2, 1), bias=False) self.forward_conv_y.weight.data = self.y_ker_init def forward(self, input_0): primals_2 = self.forward_conv_x.weight primals_3 = self.forward_conv_y.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
AmazingAng/pytorch-tvnet
Forward_Grad
false
7,661
[ "MIT" ]
12
e880d3ce15f55e5d9a11b423cfd1e0461de4fedb
https://github.com/AmazingAng/pytorch-tvnet/tree/e880d3ce15f55e5d9a11b423cfd1e0461de4fedb
EncoderImagePrecomp
import torch import numpy as np from collections import OrderedDict import torch.nn as nn import torch.nn.init def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class EncoderImagePrecomp(nn.Module): def __init__(self, img_dim, embed_size, no_imgnorm=False): super(EncoderImagePrecomp, self).__init__() self.embed_size = embed_size self.no_imgnorm = no_imgnorm self.fc = nn.Linear(img_dim, embed_size) self.init_weights() def init_weights(self): """Xavier initialization for the fully connected layer """ r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features) self.fc.weight.data.uniform_(-r, r) self.fc.bias.data.fill_(0) def forward(self, images): """Extract image feature vectors.""" features = self.fc(images) if not self.no_imgnorm: features = l2norm(features, dim=-1) """features_mean: visual initial memory""" features_mean = torch.mean(features, 1) """choose whether to l2norm""" return features, features_mean def load_state_dict(self, state_dict): """Copies parameters. overwritting the default one to accept state_dict from Full model """ own_state = self.state_dict() new_state = OrderedDict() for name, param in state_dict.items(): if name in own_state: new_state[name] = param super(EncoderImagePrecomp, self).load_state_dict(new_state) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'img_dim': 4, 'embed_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 numpy as np from collections import OrderedDict import torch.nn as nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_pow_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) 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 = tmp12 + tmp13 tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused_mean_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / 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, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_pow_sqrt_sum_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_mean_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf1, buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0 def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class EncoderImagePrecompNew(nn.Module): def __init__(self, img_dim, embed_size, no_imgnorm=False): super(EncoderImagePrecompNew, self).__init__() self.embed_size = embed_size self.no_imgnorm = no_imgnorm self.fc = nn.Linear(img_dim, embed_size) self.init_weights() def init_weights(self): """Xavier initialization for the fully connected layer """ r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features) self.fc.weight.data.uniform_(-r, r) self.fc.bias.data.fill_(0) def load_state_dict(self, state_dict): """Copies parameters. overwritting the default one to accept state_dict from Full model """ own_state = self.state_dict() new_state = OrderedDict() for name, param in state_dict.items(): if name in own_state: new_state[name] = param super(EncoderImagePrecompNew, self).load_state_dict(new_state) def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
AndresPMD/semantic_adaptive_margin
EncoderImagePrecomp
false
7,662
[ "Apache-2.0" ]
12
1e8bf2f1836498c48df030cb0a967b72b52e8460
https://github.com/AndresPMD/semantic_adaptive_margin/tree/1e8bf2f1836498c48df030cb0a967b72b52e8460
Normalize
import torch from torch import nn class Normalize(nn.Module): """normalization layer""" def __init__(self, power=2): super(Normalize, self).__init__() self.power = power def forward(self, x): norm = x.pow(self.power).sum(1, keepdim=True).pow(1.0 / self.power) out = x.div(norm) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice 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_div_pow_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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp0 / tmp12 tl.store(out_ptr0 + x3, tmp13, xmask) 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_pow_sum_0[grid(256)](arg0_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) del arg0_1 return buf0, class NormalizeNew(nn.Module): """normalization layer""" def __init__(self, power=2): super(NormalizeNew, self).__init__() self.power = power def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alibaba-MIIL/HeadSharingKD
Normalize
false
7,663
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
LinearBlock
import torch import torch.nn as nn import torch.utils.data def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): """ Based on the paper "Spectral Normalization for Generative Adversarial Networks" by Takeru Miyato, Toshiki Kataoka, Masanori Koyama, Yuichi Yoshida and the Pytorch implementation https://github.com/christiancosgrove/pytorch-spectral-normalization-gan """ def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = nn.Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = nn.Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = nn.Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class LinearBlock(nn.Module): def __init__(self, input_dim, output_dim, norm='none', activation='relu'): super(LinearBlock, self).__init__() use_bias = True if norm == 'sn': self.fc = SpectralNorm(nn.Linear(input_dim, output_dim, bias= use_bias)) else: self.fc = nn.Linear(input_dim, output_dim, bias=use_bias) norm_dim = output_dim if norm == 'bn': self.norm = nn.BatchNorm1d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm1d(norm_dim) elif norm == 'ln': self.norm = LayerNorm(norm_dim) elif norm == 'none' or norm == 'sn': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'prelu': self.activation = nn.PReLU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) def forward(self, x): out = self.fc(x) if self.norm: out = self.norm(out) if self.activation: out = self.activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_threshold_backward_view_0(in_out_ptr0, in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = 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 + x4, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_view_0[grid(256)](buf1, primals_2, buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_2 return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf3 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): """ Based on the paper "Spectral Normalization for Generative Adversarial Networks" by Takeru Miyato, Toshiki Kataoka, Masanori Koyama, Yuichi Yoshida and the Pytorch implementation https://github.com/christiancosgrove/pytorch-spectral-normalization-gan """ def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = nn.Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = nn.Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = nn.Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class LinearBlockNew(nn.Module): def __init__(self, input_dim, output_dim, norm='none', activation='relu'): super(LinearBlockNew, self).__init__() use_bias = True if norm == 'sn': self.fc = SpectralNorm(nn.Linear(input_dim, output_dim, bias= use_bias)) else: self.fc = nn.Linear(input_dim, output_dim, bias=use_bias) norm_dim = output_dim if norm == 'bn': self.norm = nn.BatchNorm1d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm1d(norm_dim) elif norm == 'ln': self.norm = LayerNorm(norm_dim) elif norm == 'none' or norm == 'sn': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'prelu': self.activation = nn.PReLU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AllenPu/mbdg
LinearBlock
false
7,664
[ "MIT" ]
27
243f53a57dcf4bfb6e717c0c9f64a839cff8d548
https://github.com/AllenPu/mbdg/tree/243f53a57dcf4bfb6e717c0c9f64a839cff8d548
FeatureExtractor
import torch import torch.nn as nn class FeatureExtractor(nn.Module): def __init__(self, num_inputs, num_outputs): super(FeatureExtractor, self).__init__() self.affine1 = nn.Linear(num_inputs, 64) self.affine2 = nn.Linear(64, 48) self.affine3 = nn.Linear(48, num_outputs) def forward(self, x): x = torch.tanh(self.affine1(x)) x = torch.tanh(self.affine2(x)) x = torch.tanh(self.affine3(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_inputs': 4, 'num_outputs': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, None) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 48 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_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, (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, (48, 64), (64, 1)) assert_size_stride(primals_5, (48,), (1,)) assert_size_stride(primals_6, (4, 48), (48, 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 get_raw_stream(0) triton_poi_fused_tanh_0[grid(4096)](buf1, primals_2, 4096, XBLOCK= 128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 48), (48, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 48), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 48), (768, 192, 48, 1), 0) del buf2 triton_poi_fused_tanh_1[grid(3072)](buf3, primals_5, 3072, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 48), (48, 1), 0), reinterpret_tensor(primals_6, (48, 4), (1, 48), 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 ), buf1, buf3, buf5, primals_6, primals_4 class FeatureExtractorNew(nn.Module): def __init__(self, num_inputs, num_outputs): super(FeatureExtractorNew, self).__init__() self.affine1 = nn.Linear(num_inputs, 64) self.affine2 = nn.Linear(64, 48) self.affine3 = nn.Linear(48, num_outputs) def forward(self, input_0): primals_1 = self.affine1.weight primals_2 = self.affine1.bias primals_4 = self.affine2.weight primals_5 = self.affine2.bias primals_6 = self.affine3.weight primals_7 = self.affine3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
Akella17/Deep-Bayesian-Quadrature-Policy-Optimization
FeatureExtractor
false
7,665
[ "MIT" ]
16
e98fd68046486c002c33cf019db2ce66da18615b
https://github.com/Akella17/Deep-Bayesian-Quadrature-Policy-Optimization/tree/e98fd68046486c002c33cf019db2ce66da18615b
mlp
import torch import torch.nn as nn class mlp(nn.Module): def __init__(self, seq_len): super(mlp, self).__init__() self.lin1 = nn.Linear(seq_len, 2048) self.lin2 = nn.Linear(2048, 2048) self.lin3 = nn.Linear(2048, seq_len) self.relu = nn.ReLU() def forward(self, input_): input_ = input_.reshape(input_.size(0), -1) out = self.lin1(input_) out = self.lin2(self.relu(out)) out = self.lin3(self.relu(out)) return out.view(input_.size(0), -1) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 2048 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) 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, (2048, 4), (4, 1)) assert_size_stride(primals_3, (2048,), (1,)) assert_size_stride(primals_4, (2048, 2048), (2048, 1)) assert_size_stride(primals_5, (2048,), (1,)) assert_size_stride(primals_6, (4, 2048), (2048, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 2048), (2048, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 2048 ), (1, 4), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(8192)](buf1, primals_3, 8192, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 2048), (2048, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (2048, 2048), (1, 2048), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_0[grid(8192)](buf3, primals_5, 8192, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (2048, 4), (1, 2048), 0), alpha=1, beta=1, out=buf4) del primals_7 return buf4, primals_1, buf1, buf3, primals_6, primals_4 class mlpNew(nn.Module): def __init__(self, seq_len): super(mlpNew, self).__init__() self.lin1 = nn.Linear(seq_len, 2048) self.lin2 = nn.Linear(2048, 2048) self.lin3 = nn.Linear(2048, seq_len) self.relu = nn.ReLU() def forward(self, input_0): primals_2 = self.lin1.weight primals_3 = self.lin1.bias primals_4 = self.lin2.weight primals_5 = self.lin2.bias primals_6 = self.lin3.weight primals_7 = self.lin3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
AliRoyat/MACS_IQA
mlp
false
7,666
[ "Apache-2.0" ]
16
d37ac72170dc0271065a7c54273b70ed52aee4b8
https://github.com/AliRoyat/MACS_IQA/tree/d37ac72170dc0271065a7c54273b70ed52aee4b8
Normalize_one
import torch from torch import nn class Normalize_one(nn.Module): def __init__(self, mean, std): super(Normalize_one, self).__init__() self.mean = mean self.std = std def forward(self, input): x = input.clone() x = (x - self.mean) / self.std return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'mean': 4, 'std': 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_div_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 4.0 tmp2 = tmp0 - tmp1 tmp3 = 0.25 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_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class Normalize_oneNew(nn.Module): def __init__(self, mean, std): super(Normalize_oneNew, self).__init__() self.mean = mean self.std = std def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Alibaba-AAIG/Beyond-ImageNet-Attack
Normalize_one
false
7,667
[ "MIT" ]
23
c14b4844b64a8035b8fe033a617c0567224a9fa4
https://github.com/Alibaba-AAIG/Beyond-ImageNet-Attack/tree/c14b4844b64a8035b8fe033a617c0567224a9fa4
FPNHead
import torch import torch.nn as nn class FPNHead(nn.Module): """"this is the FPNHead class common to all backbones""" def __init__(self, num_in, num_mid, num_out): super(FPNHead, self).__init__() self.block0 = nn.Conv2d(num_in, num_mid, kernel_size=3, padding=1, bias=False) self.block1 = nn.Conv2d(num_mid, num_out, kernel_size=3, padding=1, bias=False) def forward(self, x): x = nn.functional.relu(self.block0(x), inplace=True) x = nn.functional.relu(self.block1(x), inplace=True) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in': 4, 'num_mid': 4, 'num_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = 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_relu_threshold_backward_1(in_out_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(in_out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 3, 3), (36, 9, 3, 1)) 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, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(256)](buf1, 256, XBLOCK=128, num_warps =4, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf3, primals_1, primals_2, primals_3, buf1, buf4 class FPNHeadNew(nn.Module): """"this is the FPNHead class common to all backbones""" def __init__(self, num_in, num_mid, num_out): super(FPNHeadNew, self).__init__() self.block0 = nn.Conv2d(num_in, num_mid, kernel_size=3, padding=1, bias=False) self.block1 = nn.Conv2d(num_mid, num_out, kernel_size=3, padding=1, bias=False) def forward(self, input_0): primals_1 = self.block0.weight primals_3 = self.block1.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AmaldevHari/Ghost-DeblurGAN
FPNHead
false
7,668
[ "MIT" ]
16
e725e5dad6a5fa5865d317e6644d96d0e800eae6
https://github.com/AmaldevHari/Ghost-DeblurGAN/tree/e725e5dad6a5fa5865d317e6644d96d0e800eae6
LayerNorm
import torch import torch.nn as nn import torch.utils.data class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex r3 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp28 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp4 / tmp19 tmp21 = 63.0 tmp22 = tmp18 / tmp21 tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-05 tmp25 = tmp23 + tmp24 tmp26 = tmp0 - tmp20 tmp27 = tmp26 / tmp25 tmp29 = tmp27 * tmp28 tmp31 = tmp29 + tmp30 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp31, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) buf3 = empty_strided_cuda((4,), (1,), torch.float32) buf1 = buf0 del buf0 buf5 = reinterpret_tensor(buf3, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_std_sub_0[grid(4)](buf1, buf5, primals_1, primals_2, primals_3, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf6, primals_1, reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1, 1), 0), buf5 class LayerNormNew(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNormNew, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, input_0): primals_2 = self.gamma primals_3 = self.beta primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AllenPu/mbdg
LayerNorm
false
7,669
[ "MIT" ]
27
243f53a57dcf4bfb6e717c0c9f64a839cff8d548
https://github.com/AllenPu/mbdg/tree/243f53a57dcf4bfb6e717c0c9f64a839cff8d548
HintLoss
import torch from torch import nn class HintLoss(nn.Module): """Fitnets: hints for thin deep nets, ICLR 2015""" def __init__(self): super(HintLoss, self).__init__() self.crit = nn.MSELoss() def forward(self, f_s, f_t): loss = self.crit(f_s, f_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 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_mse_loss_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp8, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mse_loss_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 HintLossNew(nn.Module): """Fitnets: hints for thin deep nets, ICLR 2015""" def __init__(self): super(HintLossNew, self).__init__() self.crit = nn.MSELoss() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Alibaba-MIIL/HeadSharingKD
HintLoss
false
7,670
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
DeContraster
import torch import torch.distributions import torch.utils.data class AdversarialNoiseGenerator(torch.nn.Module): def __init__(self): super().__init__() return def forward(self, x): raise NotImplementedError() class DeContraster(AdversarialNoiseGenerator): def __init__(self, eps): super().__init__() self.eps = eps def forward(self, x): diff = torch.clamp(x.mean(dim=(1, 2, 3))[:, None, None, None] - x, -self.eps, self.eps) return diff def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'eps': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.distributions import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_clamp_mean_sub_0(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 64.0 tmp6 = tmp4 / tmp5 tmp7 = tmp6 - tmp0 tmp8 = -4.0 tmp9 = triton_helpers.maximum(tmp7, tmp8) tmp10 = 4.0 tmp11 = triton_helpers.minimum(tmp9, tmp10) tl.store(out_ptr1 + (r1 + 64 * x0), tmp11, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_clamp_mean_sub_0[grid(4)](arg0_1, buf1, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf1, class AdversarialNoiseGenerator(torch.nn.Module): def __init__(self): super().__init__() return def forward(self, x): raise NotImplementedError() class DeContrasterNew(AdversarialNoiseGenerator): def __init__(self, eps): super().__init__() self.eps = eps def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
AlexMeinke/Provable-OOD-Detection
DeContraster
false
7,671
[ "MIT" ]
21
9a132aec994ff718c96b81885736ab866df60d87
https://github.com/AlexMeinke/Provable-OOD-Detection/tree/9a132aec994ff718c96b81885736ab866df60d87
BinaryLoss
import torch import torch.nn as nn import torch.distributions import torch.utils.data class BinaryLoss(nn.Module): def __init__(self): super().__init__() def forward(self, output): return torch.logaddexp(torch.tensor([1.0], device=output.device), - output) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.distributions 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_logaddexp_neg_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = -tmp0 tmp2 = 1.0 tmp3 = tmp2 == tmp1 tmp4 = tl.full([1], False, tl.int1) tmp5 = tmp4 & tmp3 tmp6 = tmp2 >= tmp1 tmp7 = tl.where(tmp6, tmp2, tmp1) tmp8 = tl.where(tmp6, tmp1, tmp2) tmp9 = tmp8 - tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = libdevice.log1p(tmp10) tmp12 = tmp7 + tmp11 tmp13 = tl.where(tmp5, tmp2, tmp12) tl.store(out_ptr0 + x0, tmp13, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_logaddexp_neg_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class BinaryLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
AlexMeinke/Provable-OOD-Detection
BinaryLoss
false
7,672
[ "MIT" ]
21
9a132aec994ff718c96b81885736ab866df60d87
https://github.com/AlexMeinke/Provable-OOD-Detection/tree/9a132aec994ff718c96b81885736ab866df60d87
EncoderImageWeightNormPrecomp
import torch from collections import OrderedDict import torch.nn as nn import torch.nn.init from torch.nn.utils.weight_norm import weight_norm def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class EncoderImageWeightNormPrecomp(nn.Module): def __init__(self, img_dim, embed_size, no_imgnorm=False): super(EncoderImageWeightNormPrecomp, self).__init__() self.embed_size = embed_size self.no_imgnorm = no_imgnorm self.fc = weight_norm(nn.Linear(img_dim, embed_size), dim=None) def forward(self, images): """Extract image feature vectors.""" features = self.fc(images) if not self.no_imgnorm: features = l2norm(features, dim=-1) return features def load_state_dict(self, state_dict): """Copies parameters. overwritting the default one to accept state_dict from Full model """ own_state = self.state_dict() new_state = OrderedDict() for name, param in state_dict.items(): if name in own_state: new_state[name] = param super(EncoderImageWeightNormPrecomp, self).load_state_dict(new_state) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'img_dim': 4, 'embed_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from collections import OrderedDict import torch.nn as nn import torch.nn.init from torch.nn.utils.weight_norm import weight_norm assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_div_mul_norm_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): 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) tmp6 = tl.load(in_ptr1 + 0) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tmp5 = libdevice.sqrt(tmp4) tmp8 = tmp7 / tmp5 tmp9 = tmp0 * tmp8 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None) tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp9, None) @triton.jit def triton_poi_fused_add_div_pow_sqrt_sum_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') 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 = tmp12 + tmp13 tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_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, 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 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused_div_mul_norm_0[grid(1)](buf1, primals_2, primals_1, buf2, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(buf2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_3 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_pow_sqrt_sum_1[grid(256)](buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf4, buf2, primals_1, primals_2, buf1, reinterpret_tensor(primals_4 , (64, 4), (4, 1), 0), buf3 def l2norm(X, dim=-1, eps=1e-12): """L2-normalize columns of X """ norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps X = torch.div(X, norm) return X class EncoderImageWeightNormPrecompNew(nn.Module): def __init__(self, img_dim, embed_size, no_imgnorm=False): super(EncoderImageWeightNormPrecompNew, self).__init__() self.embed_size = embed_size self.no_imgnorm = no_imgnorm self.fc = weight_norm(nn.Linear(img_dim, embed_size), dim=None) def load_state_dict(self, state_dict): """Copies parameters. overwritting the default one to accept state_dict from Full model """ own_state = self.state_dict() new_state = OrderedDict() for name, param in state_dict.items(): if name in own_state: new_state[name] = param super(EncoderImageWeightNormPrecompNew, self).load_state_dict(new_state ) def forward(self, input_0): primals_3 = self.fc.bias primals_1 = self.fc.weight_g primals_2 = self.fc.weight_v primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
AndresPMD/semantic_adaptive_margin
EncoderImageWeightNormPrecomp
false
7,673
[ "Apache-2.0" ]
12
1e8bf2f1836498c48df030cb0a967b72b52e8460
https://github.com/AndresPMD/semantic_adaptive_margin/tree/1e8bf2f1836498c48df030cb0a967b72b52e8460
PKT
import torch from torch import nn class PKT(nn.Module): """Probabilistic Knowledge Transfer for deep representation learning Code from author: https://github.com/passalis/probabilistic_kt""" def __init__(self): super(PKT, self).__init__() def forward(self, f_s, f_t): return self.cosine_similarity_loss(f_s, f_t) @staticmethod def cosine_similarity_loss(output_net, target_net, eps=1e-07): output_net_norm = torch.sqrt(torch.sum(output_net ** 2, dim=1, keepdim=True)) output_net = output_net / (output_net_norm + eps) output_net[output_net != output_net] = 0 target_net_norm = torch.sqrt(torch.sum(target_net ** 2, dim=1, keepdim=True)) target_net = target_net / (target_net_norm + eps) target_net[target_net != target_net] = 0 model_similarity = torch.mm(output_net, output_net.transpose(0, 1)) target_similarity = torch.mm(target_net, target_net.transpose(0, 1)) model_similarity = (model_similarity + 1.0) / 2.0 target_similarity = (target_similarity + 1.0) / 2.0 model_similarity = model_similarity / torch.sum(model_similarity, dim=1, keepdim=True) target_similarity = target_similarity / torch.sum(target_similarity, dim=1, keepdim=True) loss = torch.mean(target_similarity * torch.log((target_similarity + eps) / (model_similarity + eps))) 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.triton_helpers import libdevice, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_index_put_lift_fresh_pow_sqrt_sum_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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-07 tmp14 = tmp12 + tmp13 tmp15 = tmp0 / tmp14 tmp16 = tmp15 != tmp15 tmp17 = 0.0 tmp18 = tl.where(tmp16, tmp17, tmp15) tl.store(in_out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_per_fused_add_div_log_mean_mul_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex r1 = rindex // 4 tmp0 = tl.load(in_ptr0 + r2, None) tmp5 = tl.load(in_ptr0 + 4 * r1, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * r1), None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (2 + 4 * r1), None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (3 + 4 * r1), None, eviction_policy='evict_last') tmp23 = tl.load(in_ptr1 + r2, None) tmp26 = tl.load(in_ptr1 + 4 * r1, None, eviction_policy='evict_last') tmp29 = tl.load(in_ptr1 + (1 + 4 * r1), None, eviction_policy='evict_last') tmp33 = tl.load(in_ptr1 + (2 + 4 * r1), None, eviction_policy='evict_last') tmp37 = tl.load(in_ptr1 + (3 + 4 * r1), None, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 + tmp1 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp6 = tmp5 + tmp1 tmp7 = tmp6 * tmp3 tmp9 = tmp8 + tmp1 tmp10 = tmp9 * tmp3 tmp11 = tmp7 + tmp10 tmp13 = tmp12 + tmp1 tmp14 = tmp13 * tmp3 tmp15 = tmp11 + tmp14 tmp17 = tmp16 + tmp1 tmp18 = tmp17 * tmp3 tmp19 = tmp15 + tmp18 tmp20 = tmp4 / tmp19 tmp21 = 1e-07 tmp22 = tmp20 + tmp21 tmp24 = tmp23 + tmp1 tmp25 = tmp24 * tmp3 tmp27 = tmp26 + tmp1 tmp28 = tmp27 * tmp3 tmp30 = tmp29 + tmp1 tmp31 = tmp30 * tmp3 tmp32 = tmp28 + tmp31 tmp34 = tmp33 + tmp1 tmp35 = tmp34 * tmp3 tmp36 = tmp32 + tmp35 tmp38 = tmp37 + tmp1 tmp39 = tmp38 * tmp3 tmp40 = tmp36 + tmp39 tmp41 = tmp25 / tmp40 tmp42 = tmp41 + tmp21 tmp43 = tmp22 / tmp42 tmp44 = tl_math.log(tmp43) tmp45 = tmp20 * tmp44 tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK]) tmp48 = tl.sum(tmp46, 1)[:, None] tmp49 = 16.0 tmp50 = tmp48 / tmp49 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp50, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_div_index_put_lift_fresh_pow_sqrt_sum_0[grid(16)]( buf1, arg1_1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2) buf4 = buf1 del buf1 buf5 = buf4 del buf4 triton_poi_fused_add_div_index_put_lift_fresh_pow_sqrt_sum_0[grid(16)]( buf5, arg0_1, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(buf5, (4, 4), (1, 4), 0), out=buf6) del buf5 buf7 = empty_strided_cuda((), (), torch.float32) buf8 = buf7 del buf7 triton_per_fused_add_div_log_mean_mul_sum_1[grid(1)](buf8, buf2, buf6, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf2 del buf6 return buf8, class PKTNew(nn.Module): """Probabilistic Knowledge Transfer for deep representation learning Code from author: https://github.com/passalis/probabilistic_kt""" def __init__(self): super(PKTNew, self).__init__() @staticmethod def cosine_similarity_loss(output_net, target_net, eps=1e-07): output_net_norm = torch.sqrt(torch.sum(output_net ** 2, dim=1, keepdim=True)) output_net = output_net / (output_net_norm + eps) output_net[output_net != output_net] = 0 target_net_norm = torch.sqrt(torch.sum(target_net ** 2, dim=1, keepdim=True)) target_net = target_net / (target_net_norm + eps) target_net[target_net != target_net] = 0 model_similarity = torch.mm(output_net, output_net.transpose(0, 1)) target_similarity = torch.mm(target_net, target_net.transpose(0, 1)) model_similarity = (model_similarity + 1.0) / 2.0 target_similarity = (target_similarity + 1.0) / 2.0 model_similarity = model_similarity / torch.sum(model_similarity, dim=1, keepdim=True) target_similarity = target_similarity / torch.sum(target_similarity, dim=1, keepdim=True) loss = torch.mean(target_similarity * torch.log((target_similarity + eps) / (model_similarity + eps))) return loss def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Alibaba-MIIL/HeadSharingKD
PKT
false
7,674
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
LinearVarianceUnif
import math import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from torch.nn import Parameter class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class LinearVarianceUnif(ModuleWrapper): def __init__(self, in_features, out_features, bias=True): super(LinearVarianceUnif, self).__init__() self.in_features = in_features self.out_features = out_features self.W = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(1, out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.W.size(1)) self.W.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.zero_() def forward(self, x): if self.training: eps = Variable(self.W.data.new(self.W.size()).uniform_() - 0.5) else: eps = 0.0 output = F.linear(x, self.W * eps) if self.bias is not None: output = output + self.bias return output def __repr__(self): return self.__class__.__name__ + '(' + 'in_features=' + str(self. in_features) + ', out_features=' + str(self.out_features ) + ', bias=' + str(self.bias is not None) + ')' def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (1, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf1) del buf0 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_add_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0) class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class LinearVarianceUnifNew(ModuleWrapper): def __init__(self, in_features, out_features, bias=True): super(LinearVarianceUnifNew, self).__init__() self.in_features = in_features self.out_features = out_features self.W = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(1, out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.W.size(1)) self.W.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.zero_() def __repr__(self): return self.__class__.__name__ + '(' + 'in_features=' + str(self. in_features) + ', out_features=' + str(self.out_features ) + ', bias=' + str(self.bias is not None) + ')' def forward(self, input_0): primals_1 = self.W primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AlliedToasters/elko_den
LinearVarianceUnif
false
7,675
[ "Apache-2.0" ]
38
4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
https://github.com/AlliedToasters/elko_den/tree/4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
KDE
import torch from torch import nn import torch.nn.functional as F class KDE(nn.Module): """KD on embeddings - KDE""" def __init__(self): super(KDE, self).__init__() def forward(self, embedding_s, embedding_t): inputs_embed = F.normalize(embedding_s, p=2.0, dim=1) targets_embed = F.normalize(embedding_t, p=2.0, dim=1) loss_kde = nn.MSELoss(reduction='sum')(inputs_embed, targets_embed) return loss_kde def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch 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_div_mse_loss_0(in_ptr0, in_ptr1, out_ptr1, xnumel, rnumel ): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r3 = rindex r0 = rindex % 16 r2 = rindex // 64 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp16 = tl.load(in_ptr1 + r3, None) tmp17 = tl.load(in_ptr1 + (r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr1 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr1 + (48 + r0 + 64 * r2), None, 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 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 tmp32 = tmp31 * tmp31 tmp33 = tl.broadcast_to(tmp32, [RBLOCK]) tmp35 = triton_helpers.promote_to_tensor(tl.sum(tmp33, 0)) tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp35, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_div_mse_loss_0[grid(1)](arg0_1, arg1_1, buf1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class KDENew(nn.Module): """KD on embeddings - KDE""" def __init__(self): super(KDENew, 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]
Alibaba-MIIL/HeadSharingKD
KDE
false
7,676
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
MNIST_CNN
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class MNIST_CNN(nn.Module): """ Hand-tuned architecture for MNIST. Weirdness I've noticed so far with this architecture: - adding a linear layer after the mean-pool in features hurts RotatedMNIST-100 generalization severely. """ n_outputs = 128 def __init__(self, input_shape): super(MNIST_CNN, self).__init__() self.conv1 = nn.Conv2d(input_shape[0], 64, 3, 1, padding=1) self.conv2 = nn.Conv2d(64, 128, 3, stride=2, padding=1) self.conv3 = nn.Conv2d(128, 128, 3, 1, padding=1) self.conv4 = nn.Conv2d(128, 128, 3, 1, padding=1) self.bn0 = nn.GroupNorm(8, 64) self.bn1 = nn.GroupNorm(8, 128) self.bn2 = nn.GroupNorm(8, 128) self.bn3 = nn.GroupNorm(8, 128) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) def forward(self, x): x = self.conv1(x) x = F.relu(x) x = self.bn0(x) x = self.conv2(x) x = F.relu(x) x = self.bn1(x) x = self.conv3(x) x = F.relu(x) x = self.bn2(x) x = self.conv4(x) x = F.relu(x) x = self.bn3(x) x = self.avgpool(x) x = x.view(len(x), -1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_shape': [4, 4]}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 256 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 % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 4 * x2 + 36 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask) tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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_convolution_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_5(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 32 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) r2 = rindex % 8 r3 = rindex // 8 x0 = xindex % 8 x1 = xindex // 8 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 64 * r3 + 1024 * x1), 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]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 128, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 128.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr2 + x4, tmp23, xmask) tl.store(out_ptr0 + x4, tmp12, xmask) tl.store(out_ptr1 + x4, tmp18, xmask) @triton.jit def triton_poi_fused_native_group_norm_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 64 x2 = xindex // 1024 tmp0 = tl.load(in_ptr0 + x3, None) tmp3 = tl.load(in_ptr1 + (8 * x2 + x0 // 8), None, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr2 + (8 * x2 + x0 // 8), None, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tmp2 - tmp3 tmp6 = 128.0 tmp7 = tmp5 / tmp6 tmp8 = 1e-05 tmp9 = tmp7 + tmp8 tmp10 = libdevice.rsqrt(tmp9) tmp11 = tmp4 * tmp10 tmp13 = tmp11 * tmp12 tmp15 = tmp13 + tmp14 tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_convolution_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 % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_per_fused_native_group_norm_8(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 32 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex % 16 r3 = rindex // 16 x0 = xindex % 8 x1 = xindex // 8 x4 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 128 * r3 + 512 * x1), 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]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr2 + x4, tmp23, xmask) tl.store(out_ptr0 + x4, tmp12, xmask) tl.store(out_ptr1 + x4, tmp18, xmask) @triton.jit def triton_poi_fused_native_group_norm_9(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 128 x2 = xindex // 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp3 = tl.load(in_ptr1 + (8 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr2 + (8 * x2 + x0 // 16), None, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tmp2 - tmp3 tmp6 = 64.0 tmp7 = tmp5 / tmp6 tmp8 = 1e-05 tmp9 = tmp7 + tmp8 tmp10 = libdevice.rsqrt(tmp9) tmp11 = tmp4 * tmp10 tmp13 = tmp11 * tmp12 tmp15 = tmp13 + tmp14 tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_mean_native_group_norm_10(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 128 x1 = xindex // 128 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1), xmask) tmp3 = tl.load(in_ptr1 + x2 // 16, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x2 // 16, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (128 + x0 + 512 * x1), xmask) tmp23 = tl.load(in_ptr0 + (256 + x0 + 512 * x1), xmask) tmp30 = tl.load(in_ptr0 + (384 + x0 + 512 * x1), xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tmp2 - tmp3 tmp6 = 64.0 tmp7 = tmp5 / tmp6 tmp8 = 1e-05 tmp9 = tmp7 + tmp8 tmp10 = libdevice.rsqrt(tmp9) tmp11 = tmp4 * tmp10 tmp13 = tmp11 * tmp12 tmp15 = tmp13 + tmp14 tmp17 = triton_helpers.maximum(tmp1, tmp16) tmp18 = tmp17 - tmp3 tmp19 = tmp18 * tmp10 tmp20 = tmp19 * tmp12 tmp21 = tmp20 + tmp14 tmp22 = tmp15 + tmp21 tmp24 = triton_helpers.maximum(tmp1, tmp23) tmp25 = tmp24 - tmp3 tmp26 = tmp25 * tmp10 tmp27 = tmp26 * tmp12 tmp28 = tmp27 + tmp14 tmp29 = tmp22 + tmp28 tmp31 = triton_helpers.maximum(tmp1, tmp30) tmp32 = tmp31 - tmp3 tmp33 = tmp32 * tmp10 tmp34 = tmp33 * tmp12 tmp35 = tmp34 + tmp14 tmp36 = tmp29 + tmp35 tmp37 = 4.0 tmp38 = tmp36 / tmp37 tl.store(out_ptr0 + x2, tmp38, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17) = args args.clear() assert_size_stride(primals_1, (64, 4, 3, 3), (36, 9, 3, 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, (64,), (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,), (1,)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (128,), (1,)) assert_size_stride(primals_13, (128,), (1,)) assert_size_stride(primals_14, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_15, (128,), (1,)) assert_size_stride(primals_16, (128,), (1,)) assert_size_stride(primals_17, (128,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4, 3, 3), (36, 1, 12, 4), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(256, 9)](primals_1, buf0, 256, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_1[grid(16, 16)](primals_3, buf1, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((128, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_2[grid(8192, 9)](primals_6, buf2, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf3 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_3[grid(16384, 9)](primals_10, buf3, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_10 buf4 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_3[grid(16384, 9)](primals_14, buf4, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_14 buf5 = extern_kernels.convolution(buf1, buf0, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 64, 4, 4), (1024, 1, 256, 64)) buf6 = buf5 del buf5 triton_poi_fused_convolution_4[grid(4096)](buf6, primals_2, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf7 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) buf8 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) buf11 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) triton_per_fused_native_group_norm_5[grid(32)](buf6, buf7, buf8, buf11, 32, 128, XBLOCK=8, num_warps=8, num_stages=1) buf10 = empty_strided_cuda((4, 64, 4, 4), (1024, 1, 256, 64), torch .float32) triton_poi_fused_native_group_norm_6[grid(4096)](buf6, buf7, buf8, primals_4, primals_5, buf10, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf12 = extern_kernels.convolution(buf10, buf2, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 128, 2, 2), (512, 1, 256, 128)) buf13 = buf12 del buf12 triton_poi_fused_convolution_7[grid(2048)](buf13, primals_7, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf14 = buf8 del buf8 buf15 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) buf18 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) triton_per_fused_native_group_norm_8[grid(32)](buf13, buf14, buf15, buf18, 32, 64, XBLOCK=8, num_warps=4, num_stages=1) buf17 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.float32) triton_poi_fused_native_group_norm_9[grid(2048)](buf13, buf14, buf15, primals_8, primals_9, buf17, 2048, XBLOCK=256, num_warps =4, num_stages=1) del primals_9 buf19 = extern_kernels.convolution(buf17, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 128, 2, 2), (512, 1, 256, 128)) buf20 = buf19 del buf19 triton_poi_fused_convolution_7[grid(2048)](buf20, primals_11, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_11 buf21 = buf15 del buf15 buf22 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) buf25 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) triton_per_fused_native_group_norm_8[grid(32)](buf20, buf21, buf22, buf25, 32, 64, XBLOCK=8, num_warps=4, num_stages=1) buf24 = empty_strided_cuda((4, 128, 2, 2), (512, 1, 256, 128), torch.float32) triton_poi_fused_native_group_norm_9[grid(2048)](buf20, buf21, buf22, primals_12, primals_13, buf24, 2048, XBLOCK=256, num_warps=4, num_stages=1) del primals_13 buf26 = extern_kernels.convolution(buf24, buf4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 128, 2, 2), (512, 1, 256, 128)) buf27 = buf26 del buf26 triton_poi_fused_convolution_7[grid(2048)](buf27, primals_15, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_15 buf28 = buf22 del buf22 buf29 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) buf31 = empty_strided_cuda((4, 8, 1, 1), (8, 1, 32, 32), torch.float32) triton_per_fused_native_group_norm_8[grid(32)](buf27, buf28, buf29, buf31, 32, 64, XBLOCK=8, num_warps=4, num_stages=1) buf32 = empty_strided_cuda((4, 128, 1, 1), (128, 1, 1, 1), torch. float32) triton_poi_fused_mean_native_group_norm_10[grid(512)](buf27, buf28, buf29, primals_16, primals_17, buf32, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf29 del primals_17 return (reinterpret_tensor(buf32, (4, 128), (128, 1), 0), buf0, buf1, primals_4, buf2, primals_8, buf3, primals_12, buf4, primals_16, buf6, buf10, reinterpret_tensor(buf7, (4, 8), (8, 1), 0), reinterpret_tensor(buf11, (4, 8), (8, 1), 0), buf13, buf17, reinterpret_tensor(buf14, (4, 8), (8, 1), 0), reinterpret_tensor( buf18, (4, 8), (8, 1), 0), buf20, buf24, reinterpret_tensor(buf21, (4, 8), (8, 1), 0), reinterpret_tensor(buf25, (4, 8), (8, 1), 0), buf27, reinterpret_tensor(buf28, (4, 8), (8, 1), 0), reinterpret_tensor(buf31, (4, 8), (8, 1), 0)) class MNIST_CNNNew(nn.Module): """ Hand-tuned architecture for MNIST. Weirdness I've noticed so far with this architecture: - adding a linear layer after the mean-pool in features hurts RotatedMNIST-100 generalization severely. """ n_outputs = 128 def __init__(self, input_shape): super(MNIST_CNNNew, self).__init__() self.conv1 = nn.Conv2d(input_shape[0], 64, 3, 1, padding=1) self.conv2 = nn.Conv2d(64, 128, 3, stride=2, padding=1) self.conv3 = nn.Conv2d(128, 128, 3, 1, padding=1) self.conv4 = nn.Conv2d(128, 128, 3, 1, padding=1) self.bn0 = nn.GroupNorm(8, 64) self.bn1 = nn.GroupNorm(8, 128) self.bn2 = nn.GroupNorm(8, 128) self.bn3 = nn.GroupNorm(8, 128) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_6 = self.conv2.weight primals_7 = self.conv2.bias primals_10 = self.conv3.weight primals_8 = self.conv3.bias primals_14 = self.conv4.weight primals_9 = self.conv4.bias primals_4 = self.bn0.weight primals_5 = self.bn0.bias primals_11 = self.bn1.weight primals_12 = self.bn1.bias primals_13 = self.bn2.weight primals_15 = self.bn2.bias primals_16 = self.bn3.weight primals_17 = self.bn3.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]) return output[0]
AllenPu/mbdg
MNIST_CNN
false
7,677
[ "MIT" ]
27
243f53a57dcf4bfb6e717c0c9f64a839cff8d548
https://github.com/AllenPu/mbdg/tree/243f53a57dcf4bfb6e717c0c9f64a839cff8d548
LinearVariance
import math import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable from torch.nn import Parameter class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class LinearVariance(ModuleWrapper): def __init__(self, in_features, out_features, bias=True): super(LinearVariance, self).__init__() self.in_features = in_features self.out_features = out_features self.sigma = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(1, out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.sigma.size(1)) self.sigma.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.zero_() def forward(self, x): lrt_mean = self.bias lrt_std = torch.sqrt_(1e-16 + F.linear(x * x, self.sigma * self.sigma)) if self.training: eps = Variable(lrt_std.data.new(lrt_std.size()).normal_()) else: eps = 0.0 return lrt_mean + eps * lrt_std def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 * tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_mul_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 * tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_add_mul_sqrt_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = 1e-16 tmp3 = tmp1 + tmp2 tmp4 = libdevice.sqrt(tmp3) tmp5 = 0.0 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + 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, (1, 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](primals_2, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_mul_1[grid(16)](primals_3, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2) del buf1 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_sqrt_2[grid(256)](primals_1, buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 return buf3, primals_3, reinterpret_tensor(buf0, (64, 4), (4, 1), 0), buf2 class ModuleWrapper(nn.Module): """Wrapper for nn.Module with support for arbitrary flags and a universal forward pass""" def __init__(self): super(ModuleWrapper, self).__init__() def set_flag(self, flag_name, value): setattr(self, flag_name, value) for m in self.children(): if hasattr(m, 'set_flag'): m.set_flag(flag_name, value) def forward(self, x): for module in self.children(): x = module(x) return x class LinearVarianceNew(ModuleWrapper): def __init__(self, in_features, out_features, bias=True): super(LinearVarianceNew, self).__init__() self.in_features = in_features self.out_features = out_features self.sigma = Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = Parameter(torch.Tensor(1, out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.sigma.size(1)) self.sigma.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.zero_() def forward(self, input_0): primals_3 = self.sigma primals_1 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AlliedToasters/elko_den
LinearVariance
false
7,678
[ "Apache-2.0" ]
38
4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
https://github.com/AlliedToasters/elko_den/tree/4e69f7f5c0dc7ffad54c7e190a2b75aba2eab7d2
DistillKL
import torch from torch import nn import torch.nn.functional as F class DistillKL(nn.Module): """Distilling the Knowledge in a Neural Network""" def __init__(self, T): super(DistillKL, self).__init__() self.T = T def forward(self, y_s, y_t): p_s = F.log_softmax(y_s / self.T, dim=1) p_t = F.softmax(y_t / self.T, dim=1) loss = F.kl_div(p_s, p_t, size_average=False ) * self.T ** 2 / y_s.shape[0] return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'T': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from 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__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.25 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x3, tmp17, 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 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.25 tmp16 = tmp14 * tmp15 tl.store(out_ptr0 + x3, tmp16, xmask) @triton.jit def triton_per_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r3 = rindex r0 = rindex % 16 r2 = rindex // 64 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last' ) tmp2 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr1 + r3, None) tmp18 = tl.load(in_ptr1 + (r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr1 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr1 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp26 = tl.load(in_ptr1 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp9 = libdevice.isnan(tmp8).to(tl.int1) tmp10 = 0.0 tmp11 = tmp8 == tmp10 tmp12 = tl_math.log(tmp8) tmp13 = tmp8 * tmp12 tmp14 = tl.where(tmp11, tmp10, tmp13) tmp15 = float('nan') tmp16 = tl.where(tmp9, tmp15, tmp14) tmp19 = tl_math.exp(tmp18) tmp21 = tl_math.exp(tmp20) tmp22 = tmp19 + tmp21 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tl_math.log(tmp28) tmp30 = tmp17 - tmp29 tmp31 = tmp8 * tmp30 tmp32 = tmp16 - tmp31 tmp33 = tl.broadcast_to(tmp32, [RBLOCK]) tmp35 = triton_helpers.promote_to_tensor(tl.sum(tmp33, 0)) tmp36 = 16.0 tmp37 = tmp35 * tmp36 tmp38 = 0.25 tmp39 = tmp37 * tmp38 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp39, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_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_per_fused__log_softmax__softmax_div_mul_sub_sum_xlogy_2[grid(1) ](buf4, buf0, buf2, 1, 256, num_warps=2, num_stages=1) del buf0 del buf2 return buf4, class DistillKLNew(nn.Module): """Distilling the Knowledge in a Neural Network""" def __init__(self, T): super(DistillKLNew, self).__init__() self.T = T def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Alibaba-MIIL/HeadSharingKD
DistillKL
false
7,679
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
Correlation
import torch from torch import nn class Correlation(nn.Module): """Correlation Congruence for Knowledge Distillation, ICCV 2019. The authors nicely shared the code with me. I restructured their code to be compatible with my running framework. Credits go to the original author""" def __init__(self): super(Correlation, self).__init__() def forward(self, f_s, f_t): delta = torch.abs(f_s - f_t) loss = torch.mean((delta[:-1] * delta[1:]).sum(1)) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.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_mean_mul_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): rnumel = 48 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), rmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), rmask, other=0.0) tmp4 = tl.load(in_ptr0 + (64 + r0 + 64 * r1), rmask, other=0.0) tmp5 = tl.load(in_ptr1 + (64 + r0 + 64 * r1), rmask, other=0.0) tmp9 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), rmask, other=0.0) tmp10 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), rmask, other=0.0) tmp13 = tl.load(in_ptr0 + (80 + r0 + 64 * r1), rmask, other=0.0) tmp14 = tl.load(in_ptr1 + (80 + r0 + 64 * r1), rmask, other=0.0) tmp19 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), rmask, other=0.0) tmp20 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), rmask, other=0.0) tmp23 = tl.load(in_ptr0 + (96 + r0 + 64 * r1), rmask, other=0.0) tmp24 = tl.load(in_ptr1 + (96 + r0 + 64 * r1), rmask, other=0.0) tmp29 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), rmask, other=0.0) tmp30 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), rmask, other=0.0) tmp33 = tl.load(in_ptr0 + (112 + r0 + 64 * r1), rmask, other=0.0) tmp34 = tl.load(in_ptr1 + (112 + r0 + 64 * r1), rmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp6 = tmp4 - tmp5 tmp7 = tl_math.abs(tmp6) tmp8 = tmp3 * tmp7 tmp11 = tmp9 - tmp10 tmp12 = tl_math.abs(tmp11) tmp15 = tmp13 - tmp14 tmp16 = tl_math.abs(tmp15) tmp17 = tmp12 * tmp16 tmp18 = tmp8 + tmp17 tmp21 = tmp19 - tmp20 tmp22 = tl_math.abs(tmp21) tmp25 = tmp23 - tmp24 tmp26 = tl_math.abs(tmp25) tmp27 = tmp22 * tmp26 tmp28 = tmp18 + tmp27 tmp31 = tmp29 - tmp30 tmp32 = tl_math.abs(tmp31) tmp35 = tmp33 - tmp34 tmp36 = tl_math.abs(tmp35) tmp37 = tmp32 * tmp36 tmp38 = tmp28 + tmp37 tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = tl.where(rmask, tmp39, 0) tmp42 = tl.sum(tmp41, 1)[:, None] tmp43 = 48.0 tmp44 = tmp42 / tmp43 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp44, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused_mean_mul_sum_0[grid(1)](buf2, arg0_1, arg1_1, 1, 48, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class CorrelationNew(nn.Module): """Correlation Congruence for Knowledge Distillation, ICCV 2019. The authors nicely shared the code with me. I restructured their code to be compatible with my running framework. Credits go to the original author""" def __init__(self): super(CorrelationNew, 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]
Alibaba-MIIL/HeadSharingKD
Correlation
false
7,680
[ "BSD-2-Clause" ]
15
8e2738bf069c7d12ec933f9b9107f267f7b6603a
https://github.com/Alibaba-MIIL/HeadSharingKD/tree/8e2738bf069c7d12ec933f9b9107f267f7b6603a
HINet
import torch import torch.nn as nn class HINet(nn.Module): def __init__(self, in_ch): super(HINet, self).__init__() self.instance_norm = nn.InstanceNorm2d(in_ch - in_ch // 2, affine=True) def forward(self, x): channels = x.shape[1] channels_i = channels - channels // 2 x_i = x[:, :channels_i, :, :] x_r = x[:, channels_i:, :, :] x_i = self.instance_norm(x_i) return torch.cat([x_i, x_r], dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__native_batch_norm_legit_cat_native_batch_norm_backward_0( in_ptr0, in_ptr1, in_ptr2, out_ptr2, out_ptr3, out_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 8 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 2 x3 = xindex // 2 tmp0 = tl.load(in_ptr0 + (r1 + 16 * (x0 % 2) + 64 * (x0 // 2)), xmask, other=0.0) tmp17 = tl.load(in_ptr0 + (r1 + 16 * x2 + 64 * x3), xmask, other=0.0) tmp25 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp18 = tmp17 - tmp10 tmp19 = 16.0 tmp20 = tmp16 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp18 * tmp23 tmp26 = tmp24 * tmp25 tmp28 = tmp26 + tmp27 tmp29 = tmp0 - tmp10 tl.store(out_ptr2 + (r1 + 16 * x2 + 64 * x3), tmp28, xmask) tl.store(out_ptr3 + (r1 + 16 * x0), tmp29, xmask) tl.store(out_ptr4 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 32 x1 = xindex // 32 tmp0 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + (x0 + 64 * x1), tmp0, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (2,), (1,)) assert_size_stride(primals_3, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = reinterpret_tensor(buf6, (4, 2, 4, 4), (64, 16, 4, 1), 0) buf7 = empty_strided_cuda((1, 8, 4, 4), (128, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((1, 8, 1, 1), (8, 1, 8, 8), torch.float32) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_cat_native_batch_norm_backward_0[ grid(8)](primals_1, primals_2, primals_3, buf4, buf7, buf3, 8, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 buf5 = reinterpret_tensor(buf6, (4, 2, 4, 4), (64, 16, 4, 1), 32) triton_poi_fused_cat_1[grid(128)](primals_1, buf5, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 return buf6, reinterpret_tensor(buf3, (8,), (1,), 0), buf7 class HINetNew(nn.Module): def __init__(self, in_ch): super(HINetNew, self).__init__() self.instance_norm = nn.InstanceNorm2d(in_ch - in_ch // 2, affine=True) def forward(self, input_0): primals_2 = self.instance_norm.weight primals_3 = self.instance_norm.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AmaldevHari/Ghost-DeblurGAN
HINet
false
7,681
[ "MIT" ]
16
e725e5dad6a5fa5865d317e6644d96d0e800eae6
https://github.com/AmaldevHari/Ghost-DeblurGAN/tree/e725e5dad6a5fa5865d317e6644d96d0e800eae6