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
SingleBlock
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class DyIntraModalityUpdate(nn.Module): """ Dynamic Intra-modality Attention Flow """ def __init__(self, v_size, q_size, output_size, num_head, drop=0.0): super(DyIntraModalityUpdate, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_head = num_head self.v4q_gate_lin = nn.Linear(v_size, output_size) self.q4v_gate_lin = nn.Linear(q_size, output_size) self.v_lin = nn.Linear(v_size, output_size * 3) self.q_lin = nn.Linear(q_size, output_size * 3) self.v_output = nn.Linear(output_size, output_size) self.q_output = nn.Linear(output_size, output_size) self.relu = nn.ReLU() self.sigmoid = nn.Sigmoid() self.drop = nn.Dropout(drop) def forward(self, v, q, v_mask, q_mask): """ v: visual feature [batch, num_obj, feat_size] q: question [batch, max_len, feat_size] v_mask [batch, num_obj] q_mask [batch, max_len] """ batch_size, num_obj = v_mask.shape _, max_len = q_mask.shape v_mean = (v * v_mask.unsqueeze(2)).sum(1) / v_mask.sum(1).unsqueeze(1) q_mean = (q * q_mask.unsqueeze(2)).sum(1) / q_mask.sum(1).unsqueeze(1) v4q_gate = self.sigmoid(self.v4q_gate_lin(self.drop(self.relu(v_mean))) ).unsqueeze(1) q4v_gate = self.sigmoid(self.q4v_gate_lin(self.drop(self.relu(q_mean))) ).unsqueeze(1) v_trans = self.v_lin(self.drop(self.relu(v))) q_trans = self.q_lin(self.drop(self.relu(q))) v_trans = v_trans * v_mask.unsqueeze(2) q_trans = q_trans * q_mask.unsqueeze(2) v_k, v_q, v_v = torch.split(v_trans, v_trans.size(2) // 3, dim=2) q_k, q_q, q_v = torch.split(q_trans, q_trans.size(2) // 3, dim=2) new_vq = (1 + q4v_gate) * v_q new_vk = (1 + q4v_gate) * v_k new_qq = (1 + v4q_gate) * q_q new_qk = (1 + v4q_gate) * q_k vk_set = torch.split(new_vk, new_vk.size(2) // self.num_head, dim=2) vq_set = torch.split(new_vq, new_vq.size(2) // self.num_head, dim=2) vv_set = torch.split(v_v, v_v.size(2) // self.num_head, dim=2) qk_set = torch.split(new_qk, new_qk.size(2) // self.num_head, dim=2) qq_set = torch.split(new_qq, new_qq.size(2) // self.num_head, dim=2) qv_set = torch.split(q_v, q_v.size(2) // self.num_head, dim=2) for i in range(self.num_head): vk_slice, vq_slice, vv_slice = vk_set[i], vq_set[i], vv_set[i] qk_slice, qq_slice, qv_slice = qk_set[i], qq_set[i], qv_set[i] v2v = (vq_slice @ vk_slice.transpose(1, 2)).masked_fill(v_mask. unsqueeze(1).expand([batch_size, num_obj, num_obj]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 q2q = (qq_slice @ qk_slice.transpose(1, 2)).masked_fill(q_mask. unsqueeze(1).expand([batch_size, max_len, max_len]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 dyIntraMAF_v2v = F.softmax(v2v, dim=2) dyIntraMAF_q2q = F.softmax(q2q, dim=2) v_update = dyIntraMAF_v2v @ vv_slice if i == 0 else torch.cat(( v_update, dyIntraMAF_v2v @ vv_slice), dim=2) q_update = dyIntraMAF_q2q @ qv_slice if i == 0 else torch.cat(( q_update, dyIntraMAF_q2q @ qv_slice), dim=2) updated_v = self.v_output(self.drop(v + v_update)) updated_q = self.q_output(self.drop(q + q_update)) return updated_v, updated_q class InterModalityUpdate(nn.Module): """ Inter-modality Attention Flow """ def __init__(self, v_size, q_size, output_size, num_head, drop=0.0): super(InterModalityUpdate, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_head = num_head self.v_lin = nn.Linear(v_size, output_size * 3) self.q_lin = nn.Linear(q_size, output_size * 3) self.v_output = nn.Linear(output_size + v_size, output_size) self.q_output = nn.Linear(output_size + q_size, output_size) self.relu = nn.ReLU() self.drop = nn.Dropout(drop) def forward(self, v, q, v_mask, q_mask): """ v: visual feature [batch, num_obj, feat_size] q: question [batch, max_len, feat_size] v_mask [batch, num_obj] q_mask [batch, max_len] """ batch_size, num_obj = v_mask.shape _, max_len = q_mask.shape v_trans = self.v_lin(self.drop(self.relu(v))) q_trans = self.q_lin(self.drop(self.relu(q))) v_trans = v_trans * v_mask.unsqueeze(2) q_trans = q_trans * q_mask.unsqueeze(2) v_k, v_q, v_v = torch.split(v_trans, v_trans.size(2) // 3, dim=2) q_k, q_q, q_v = torch.split(q_trans, q_trans.size(2) // 3, dim=2) vk_set = torch.split(v_k, v_k.size(2) // self.num_head, dim=2) vq_set = torch.split(v_q, v_q.size(2) // self.num_head, dim=2) vv_set = torch.split(v_v, v_v.size(2) // self.num_head, dim=2) qk_set = torch.split(q_k, q_k.size(2) // self.num_head, dim=2) qq_set = torch.split(q_q, q_q.size(2) // self.num_head, dim=2) qv_set = torch.split(q_v, q_v.size(2) // self.num_head, dim=2) for i in range(self.num_head): vk_slice, vq_slice, vv_slice = vk_set[i], vq_set[i], vv_set[i] qk_slice, qq_slice, qv_slice = qk_set[i], qq_set[i], qv_set[i] q2v = (vq_slice @ qk_slice.transpose(1, 2)).masked_fill(q_mask. unsqueeze(1).expand([batch_size, num_obj, max_len]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 v2q = (qq_slice @ vk_slice.transpose(1, 2)).masked_fill(v_mask. unsqueeze(1).expand([batch_size, max_len, num_obj]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 interMAF_q2v = F.softmax(q2v, dim=2) interMAF_v2q = F.softmax(v2q, dim=2) v_update = interMAF_q2v @ qv_slice if i == 0 else torch.cat(( v_update, interMAF_q2v @ qv_slice), dim=2) q_update = interMAF_v2q @ vv_slice if i == 0 else torch.cat(( q_update, interMAF_v2q @ vv_slice), dim=2) cat_v = torch.cat((v, v_update), dim=2) cat_q = torch.cat((q, q_update), dim=2) updated_v = self.v_output(self.drop(cat_v)) updated_q = self.q_output(self.drop(cat_q)) return updated_v, updated_q class SingleBlock(nn.Module): """ Single Block Inter-/Intra-modality stack multiple times """ def __init__(self, num_block, v_size, q_size, output_size, num_inter_head, num_intra_head, drop=0.0): super(SingleBlock, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_inter_head = num_inter_head self.num_intra_head = num_intra_head self.num_block = num_block self.v_lin = nn.Linear(v_size, output_size) self.q_lin = nn.Linear(q_size, output_size) self.interBlock = InterModalityUpdate(output_size, output_size, output_size, num_inter_head, drop) self.intraBlock = DyIntraModalityUpdate(output_size, output_size, output_size, num_intra_head, drop) self.drop = nn.Dropout(drop) def forward(self, v, q, v_mask, q_mask): """ v: visual feature [batch, num_obj, feat_size] q: question [batch, max_len, feat_size] v_mask [batch, num_obj] q_mask [batch, max_len] """ v = self.v_lin(self.drop(v)) q = self.q_lin(self.drop(q)) for i in range(self.num_block): v, q = self.interBlock(v, q, v_mask, q_mask) v, q = self.intraBlock(v, q, v_mask, q_mask) return v, q def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4] ), torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_block': 4, 'v_size': 4, 'q_size': 4, 'output_size': 4, 'num_inter_head': 4, 'num_intra_head': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.nn.functional as F import torch.utils.data 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_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_mul_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 12 x1 = xindex // 12 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_bmm_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (4 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 12 * x0, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (5 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (1 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (6 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (2 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_8(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 + (7 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (3 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused__softmax_eq_masked_fill_10(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp41 = tl.load(in_ptr2 + 4 * x2, xmask, eviction_policy='evict_last') tmp44 = tl.load(in_ptr2 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp48 = tl.load(in_ptr2 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp52 = tl.load(in_ptr2 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp71 = tl.load(in_ptr3 + 4 * x2, xmask, eviction_policy='evict_last') tmp74 = tl.load(in_ptr3 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp78 = tl.load(in_ptr3 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp82 = tl.load(in_ptr3 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp101 = tl.load(in_ptr4 + 4 * x2, xmask, eviction_policy='evict_last') tmp104 = tl.load(in_ptr4 + (1 + 4 * x2), xmask, eviction_policy= 'evict_last') tmp108 = tl.load(in_ptr4 + (2 + 4 * x2), xmask, eviction_policy= 'evict_last') tmp112 = tl.load(in_ptr4 + (3 + 4 * x2), xmask, eviction_policy= 'evict_last') tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1000000000.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp9 = tmp8 == tmp1 tmp11 = tl.where(tmp9, tmp4, tmp10) tmp12 = tmp11 * tmp6 tmp13 = triton_helpers.maximum(tmp7, tmp12) tmp15 = tmp14 == tmp1 tmp17 = tl.where(tmp15, tmp4, tmp16) tmp18 = tmp17 * tmp6 tmp19 = triton_helpers.maximum(tmp13, tmp18) tmp21 = tmp20 == tmp1 tmp23 = tl.where(tmp21, tmp4, tmp22) tmp24 = tmp23 * tmp6 tmp25 = triton_helpers.maximum(tmp19, tmp24) tmp26 = tmp7 - tmp25 tmp27 = tmp26 * tmp6 tmp28 = tl_math.exp(tmp27) tmp29 = tmp12 - tmp25 tmp30 = tmp29 * tmp6 tmp31 = tl_math.exp(tmp30) tmp32 = tmp28 + tmp31 tmp33 = tmp18 - tmp25 tmp34 = tmp33 * tmp6 tmp35 = tl_math.exp(tmp34) tmp36 = tmp32 + tmp35 tmp37 = tmp24 - tmp25 tmp38 = tmp37 * tmp6 tmp39 = tl_math.exp(tmp38) tmp40 = tmp36 + tmp39 tmp42 = tl.where(tmp2, tmp4, tmp41) tmp43 = tmp42 * tmp6 tmp45 = tl.where(tmp9, tmp4, tmp44) tmp46 = tmp45 * tmp6 tmp47 = triton_helpers.maximum(tmp43, tmp46) tmp49 = tl.where(tmp15, tmp4, tmp48) tmp50 = tmp49 * tmp6 tmp51 = triton_helpers.maximum(tmp47, tmp50) tmp53 = tl.where(tmp21, tmp4, tmp52) tmp54 = tmp53 * tmp6 tmp55 = triton_helpers.maximum(tmp51, tmp54) tmp56 = tmp43 - tmp55 tmp57 = tmp56 * tmp6 tmp58 = tl_math.exp(tmp57) tmp59 = tmp46 - tmp55 tmp60 = tmp59 * tmp6 tmp61 = tl_math.exp(tmp60) tmp62 = tmp58 + tmp61 tmp63 = tmp50 - tmp55 tmp64 = tmp63 * tmp6 tmp65 = tl_math.exp(tmp64) tmp66 = tmp62 + tmp65 tmp67 = tmp54 - tmp55 tmp68 = tmp67 * tmp6 tmp69 = tl_math.exp(tmp68) tmp70 = tmp66 + tmp69 tmp72 = tl.where(tmp2, tmp4, tmp71) tmp73 = tmp72 * tmp6 tmp75 = tl.where(tmp9, tmp4, tmp74) tmp76 = tmp75 * tmp6 tmp77 = triton_helpers.maximum(tmp73, tmp76) tmp79 = tl.where(tmp15, tmp4, tmp78) tmp80 = tmp79 * tmp6 tmp81 = triton_helpers.maximum(tmp77, tmp80) tmp83 = tl.where(tmp21, tmp4, tmp82) tmp84 = tmp83 * tmp6 tmp85 = triton_helpers.maximum(tmp81, tmp84) tmp86 = tmp73 - tmp85 tmp87 = tmp86 * tmp6 tmp88 = tl_math.exp(tmp87) tmp89 = tmp76 - tmp85 tmp90 = tmp89 * tmp6 tmp91 = tl_math.exp(tmp90) tmp92 = tmp88 + tmp91 tmp93 = tmp80 - tmp85 tmp94 = tmp93 * tmp6 tmp95 = tl_math.exp(tmp94) tmp96 = tmp92 + tmp95 tmp97 = tmp84 - tmp85 tmp98 = tmp97 * tmp6 tmp99 = tl_math.exp(tmp98) tmp100 = tmp96 + tmp99 tmp102 = tl.where(tmp2, tmp4, tmp101) tmp103 = tmp102 * tmp6 tmp105 = tl.where(tmp9, tmp4, tmp104) tmp106 = tmp105 * tmp6 tmp107 = triton_helpers.maximum(tmp103, tmp106) tmp109 = tl.where(tmp15, tmp4, tmp108) tmp110 = tmp109 * tmp6 tmp111 = triton_helpers.maximum(tmp107, tmp110) tmp113 = tl.where(tmp21, tmp4, tmp112) tmp114 = tmp113 * tmp6 tmp115 = triton_helpers.maximum(tmp111, tmp114) tmp116 = tmp103 - tmp115 tmp117 = tmp116 * tmp6 tmp118 = tl_math.exp(tmp117) tmp119 = tmp106 - tmp115 tmp120 = tmp119 * tmp6 tmp121 = tl_math.exp(tmp120) tmp122 = tmp118 + tmp121 tmp123 = tmp110 - tmp115 tmp124 = tmp123 * tmp6 tmp125 = tl_math.exp(tmp124) tmp126 = tmp122 + tmp125 tmp127 = tmp114 - tmp115 tmp128 = tmp127 * tmp6 tmp129 = tl_math.exp(tmp128) tmp130 = tmp126 + tmp129 tl.store(out_ptr0 + x2, tmp25, xmask) tl.store(out_ptr1 + x2, tmp40, xmask) tl.store(out_ptr2 + x2, tmp55, xmask) tl.store(out_ptr3 + x2, tmp70, xmask) tl.store(out_ptr4 + x2, tmp85, xmask) tl.store(out_ptr5 + x2, tmp100, xmask) tl.store(out_ptr6 + x2, tmp115, xmask) tl.store(out_ptr7 + x2, tmp130, xmask) @triton.jit def triton_poi_fused__softmax_eq_masked_fill_11(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 16 x3 = xindex x4 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_out_ptr0 + x3, xmask) tmp8 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_out_ptr1 + x3, xmask) tmp17 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr4 + x4, xmask, eviction_policy='evict_last') tmp23 = tl.load(in_out_ptr2 + x3, xmask) tmp26 = tl.load(in_ptr5 + x4, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr6 + x4, xmask, eviction_policy='evict_last') tmp32 = tl.load(in_out_ptr3 + x3, xmask) tmp35 = tl.load(in_ptr7 + x4, xmask, eviction_policy='evict_last') tmp39 = tl.load(in_ptr8 + x4, xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1000000000.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp9 = tmp7 - tmp8 tmp10 = tmp9 * tmp6 tmp11 = tl_math.exp(tmp10) tmp13 = tmp11 / tmp12 tmp15 = tl.where(tmp2, tmp4, tmp14) tmp16 = tmp15 * tmp6 tmp18 = tmp16 - tmp17 tmp19 = tmp18 * tmp6 tmp20 = tl_math.exp(tmp19) tmp22 = tmp20 / tmp21 tmp24 = tl.where(tmp2, tmp4, tmp23) tmp25 = tmp24 * tmp6 tmp27 = tmp25 - tmp26 tmp28 = tmp27 * tmp6 tmp29 = tl_math.exp(tmp28) tmp31 = tmp29 / tmp30 tmp33 = tl.where(tmp2, tmp4, tmp32) tmp34 = tmp33 * tmp6 tmp36 = tmp34 - tmp35 tmp37 = tmp36 * tmp6 tmp38 = tl_math.exp(tmp37) tmp40 = tmp38 / tmp39 tl.store(in_out_ptr0 + x3, tmp13, xmask) tl.store(in_out_ptr1 + x3, tmp22, xmask) tl.store(in_out_ptr2 + x3, tmp31, xmask) tl.store(in_out_ptr3 + x3, tmp40, xmask) @triton.jit def triton_poi_fused__softmax_eq_masked_fill_12(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp41 = tl.load(in_ptr2 + 4 * x2, xmask, eviction_policy='evict_last') tmp44 = tl.load(in_ptr2 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp48 = tl.load(in_ptr2 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp52 = tl.load(in_ptr2 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp71 = tl.load(in_ptr3 + 4 * x2, xmask, eviction_policy='evict_last') tmp74 = tl.load(in_ptr3 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp78 = tl.load(in_ptr3 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp82 = tl.load(in_ptr3 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1000000000.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp9 = tmp8 == tmp1 tmp11 = tl.where(tmp9, tmp4, tmp10) tmp12 = tmp11 * tmp6 tmp13 = triton_helpers.maximum(tmp7, tmp12) tmp15 = tmp14 == tmp1 tmp17 = tl.where(tmp15, tmp4, tmp16) tmp18 = tmp17 * tmp6 tmp19 = triton_helpers.maximum(tmp13, tmp18) tmp21 = tmp20 == tmp1 tmp23 = tl.where(tmp21, tmp4, tmp22) tmp24 = tmp23 * tmp6 tmp25 = triton_helpers.maximum(tmp19, tmp24) tmp26 = tmp7 - tmp25 tmp27 = tmp26 * tmp6 tmp28 = tl_math.exp(tmp27) tmp29 = tmp12 - tmp25 tmp30 = tmp29 * tmp6 tmp31 = tl_math.exp(tmp30) tmp32 = tmp28 + tmp31 tmp33 = tmp18 - tmp25 tmp34 = tmp33 * tmp6 tmp35 = tl_math.exp(tmp34) tmp36 = tmp32 + tmp35 tmp37 = tmp24 - tmp25 tmp38 = tmp37 * tmp6 tmp39 = tl_math.exp(tmp38) tmp40 = tmp36 + tmp39 tmp42 = tl.where(tmp2, tmp4, tmp41) tmp43 = tmp42 * tmp6 tmp45 = tl.where(tmp9, tmp4, tmp44) tmp46 = tmp45 * tmp6 tmp47 = triton_helpers.maximum(tmp43, tmp46) tmp49 = tl.where(tmp15, tmp4, tmp48) tmp50 = tmp49 * tmp6 tmp51 = triton_helpers.maximum(tmp47, tmp50) tmp53 = tl.where(tmp21, tmp4, tmp52) tmp54 = tmp53 * tmp6 tmp55 = triton_helpers.maximum(tmp51, tmp54) tmp56 = tmp43 - tmp55 tmp57 = tmp56 * tmp6 tmp58 = tl_math.exp(tmp57) tmp59 = tmp46 - tmp55 tmp60 = tmp59 * tmp6 tmp61 = tl_math.exp(tmp60) tmp62 = tmp58 + tmp61 tmp63 = tmp50 - tmp55 tmp64 = tmp63 * tmp6 tmp65 = tl_math.exp(tmp64) tmp66 = tmp62 + tmp65 tmp67 = tmp54 - tmp55 tmp68 = tmp67 * tmp6 tmp69 = tl_math.exp(tmp68) tmp70 = tmp66 + tmp69 tmp72 = tl.where(tmp2, tmp4, tmp71) tmp73 = tmp72 * tmp6 tmp75 = tl.where(tmp9, tmp4, tmp74) tmp76 = tmp75 * tmp6 tmp77 = triton_helpers.maximum(tmp73, tmp76) tmp79 = tl.where(tmp15, tmp4, tmp78) tmp80 = tmp79 * tmp6 tmp81 = triton_helpers.maximum(tmp77, tmp80) tmp83 = tl.where(tmp21, tmp4, tmp82) tmp84 = tmp83 * tmp6 tmp85 = triton_helpers.maximum(tmp81, tmp84) tmp86 = tmp73 - tmp85 tmp87 = tmp86 * tmp6 tmp88 = tl_math.exp(tmp87) tmp89 = tmp76 - tmp85 tmp90 = tmp89 * tmp6 tmp91 = tl_math.exp(tmp90) tmp92 = tmp88 + tmp91 tmp93 = tmp80 - tmp85 tmp94 = tmp93 * tmp6 tmp95 = tl_math.exp(tmp94) tmp96 = tmp92 + tmp95 tmp97 = tmp84 - tmp85 tmp98 = tmp97 * tmp6 tmp99 = tl_math.exp(tmp98) tmp100 = tmp96 + tmp99 tl.store(out_ptr0 + x2, tmp25, xmask) tl.store(out_ptr1 + x2, tmp40, xmask) tl.store(out_ptr2 + x2, tmp55, xmask) tl.store(out_ptr3 + x2, tmp70, xmask) tl.store(out_ptr4 + x2, tmp85, xmask) tl.store(out_ptr5 + x2, tmp100, xmask) @triton.jit def triton_poi_fused_bmm_13(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 + (8 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_14(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 + (9 + 12 * x0), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_15(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 + (10 + 12 * x0), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_16(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 + (11 + 12 * x0), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_cat_17(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 3, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 2, tl.int64) tmp6 = tmp0 < tmp5 tmp7 = tmp6 & tmp4 tmp8 = tl.full([1], 1, tl.int64) tmp9 = tmp0 < tmp8 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + x1, tmp10 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp0 >= tmp8 tmp13 = tmp12 & tmp7 tmp14 = tl.load(in_ptr1 + x1, tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.where(tmp9, tmp11, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp7, tmp15, tmp16) tmp18 = tmp0 >= tmp5 tmp19 = tmp18 & tmp4 tmp20 = tl.load(in_ptr2 + x1, tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.where(tmp6, tmp17, tmp20) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp4, tmp21, tmp22) tmp24 = tmp0 >= tmp3 tl.full([1], 4, tl.int64) tmp27 = tl.load(in_ptr3 + x1, tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.where(tmp4, tmp23, tmp27) tl.store(out_ptr0 + (x0 + 8 * x1), tmp28, xmask) @triton.jit def triton_poi_fused_cat_18(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 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 8 * x1), tmp0, xmask) @triton.jit def triton_poi_fused__softmax_div_eq_masked_fill_mul_relu_sum_19(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 x1 = xindex // 4 x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp41 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask) tmp42 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp45 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask) tmp49 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask) tmp53 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask) tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1000000000.0 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp9 = tmp8 == tmp1 tmp11 = tl.where(tmp9, tmp4, tmp10) tmp12 = tmp11 * tmp6 tmp13 = triton_helpers.maximum(tmp7, tmp12) tmp15 = tmp14 == tmp1 tmp17 = tl.where(tmp15, tmp4, tmp16) tmp18 = tmp17 * tmp6 tmp19 = triton_helpers.maximum(tmp13, tmp18) tmp21 = tmp20 == tmp1 tmp23 = tl.where(tmp21, tmp4, tmp22) tmp24 = tmp23 * tmp6 tmp25 = triton_helpers.maximum(tmp19, tmp24) tmp26 = tmp7 - tmp25 tmp27 = tmp26 * tmp6 tmp28 = tl_math.exp(tmp27) tmp29 = tmp12 - tmp25 tmp30 = tmp29 * tmp6 tmp31 = tl_math.exp(tmp30) tmp32 = tmp28 + tmp31 tmp33 = tmp18 - tmp25 tmp34 = tmp33 * tmp6 tmp35 = tl_math.exp(tmp34) tmp36 = tmp32 + tmp35 tmp37 = tmp24 - tmp25 tmp38 = tmp37 * tmp6 tmp39 = tl_math.exp(tmp38) tmp40 = tmp36 + tmp39 tmp43 = tmp41 + tmp42 tmp44 = tmp43 * tmp0 tmp46 = tmp45 + tmp42 tmp47 = tmp46 * tmp8 tmp48 = tmp44 + tmp47 tmp50 = tmp49 + tmp42 tmp51 = tmp50 * tmp14 tmp52 = tmp48 + tmp51 tmp54 = tmp53 + tmp42 tmp55 = tmp54 * tmp20 tmp56 = tmp52 + tmp55 tmp57 = tmp0 + tmp8 tmp58 = tmp57 + tmp14 tmp59 = tmp58 + tmp20 tmp60 = tmp56 / tmp59 tmp61 = tl.full([1], 0, tl.int32) tmp62 = triton_helpers.maximum(tmp61, tmp60) tl.store(out_ptr0 + x2, tmp25, xmask) tl.store(out_ptr1 + x2, tmp40, xmask) tl.store(in_out_ptr0 + x2, tmp62, xmask) @triton.jit def triton_poi_fused_div_mul_relu_sum_20(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp7 = tl.load(in_ptr2 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr2 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr2 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp5 + tmp1 tmp8 = tmp6 * tmp7 tmp9 = tmp4 + tmp8 tmp11 = tmp10 + tmp1 tmp13 = tmp11 * tmp12 tmp14 = tmp9 + tmp13 tmp16 = tmp15 + tmp1 tmp18 = tmp16 * tmp17 tmp19 = tmp14 + tmp18 tmp20 = tmp3 + tmp7 tmp21 = tmp20 + tmp12 tmp22 = tmp21 + tmp17 tmp23 = tmp19 / tmp22 tmp24 = tl.full([1], 0, tl.int32) tmp25 = triton_helpers.maximum(tmp24, tmp23) tl.store(in_out_ptr0 + x2, tmp25, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_21(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 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_add_mul_22(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 % 4 x2 = xindex // 16 x3 = xindex // 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp4 = tl.load(in_ptr1 + (4 + x0 + 12 * x3), xmask) tmp6 = tl.load(in_ptr1 + (x0 + 12 * x3), xmask) tmp1 = tl.sigmoid(tmp0) tmp2 = 1.0 tmp3 = tmp1 + tmp2 tmp5 = tmp3 * tmp4 tmp7 = tmp3 * tmp6 tl.store(out_ptr0 + x4, tmp5, xmask) tl.store(out_ptr1 + x4, tmp7, xmask) @triton.jit def triton_poi_fused_bmm_23(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') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_24(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 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_25(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 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_bmm_26(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 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_add_cat_27(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp29 = tl.load(in_ptr4 + x2, xmask) tmp30 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 3, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 2, tl.int64) tmp6 = tmp0 < tmp5 tmp7 = tmp6 & tmp4 tmp8 = tl.full([1], 1, tl.int64) tmp9 = tmp0 < tmp8 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + x1, tmp10 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp0 >= tmp8 tmp13 = tmp12 & tmp7 tmp14 = tl.load(in_ptr1 + x1, tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.where(tmp9, tmp11, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp7, tmp15, tmp16) tmp18 = tmp0 >= tmp5 tmp19 = tmp18 & tmp4 tmp20 = tl.load(in_ptr2 + x1, tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.where(tmp6, tmp17, tmp20) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp4, tmp21, tmp22) tmp24 = tmp0 >= tmp3 tl.full([1], 4, tl.int64) tmp27 = tl.load(in_ptr3 + x1, tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.where(tmp4, tmp23, tmp27) tmp31 = tmp29 + tmp30 tmp32 = tmp31 + tmp28 tl.store(in_out_ptr0 + x2, tmp32, xmask) @triton.jit def triton_poi_fused_add_cat_28(in_out_ptr0, 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 % 4 x1 = xindex // 4 x2 = xindex tmp29 = tl.load(in_out_ptr0 + x2, xmask) tmp30 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 3, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 2, tl.int64) tmp6 = tmp0 < tmp5 tmp7 = tmp6 & tmp4 tmp8 = tl.full([1], 1, tl.int64) tmp9 = tmp0 < tmp8 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + x1, tmp10 & xmask, eviction_policy= 'evict_last', other=0.0) tmp12 = tmp0 >= tmp8 tmp13 = tmp12 & tmp7 tmp14 = tl.load(in_ptr1 + x1, tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.where(tmp9, tmp11, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp7, tmp15, tmp16) tmp18 = tmp0 >= tmp5 tmp19 = tmp18 & tmp4 tmp20 = tl.load(in_ptr2 + x1, tmp19 & xmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.where(tmp6, tmp17, tmp20) tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp4, tmp21, tmp22) tmp24 = tmp0 >= tmp3 tl.full([1], 4, tl.int64) tmp27 = tl.load(in_ptr3 + x1, tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp28 = tl.where(tmp4, tmp23, tmp27) tmp31 = tmp29 + tmp30 tmp32 = tmp31 + tmp28 tl.store(in_out_ptr0 + x2, tmp32, 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 ) = 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), (16, 4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (12, 4), (4, 1)) assert_size_stride(primals_10, (12,), (1,)) assert_size_stride(primals_11, (12, 4), (4, 1)) assert_size_stride(primals_12, (12,), (1,)) assert_size_stride(primals_13, (4, 8), (8, 1)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (4, 8), (8, 1)) assert_size_stride(primals_16, (4,), (1,)) assert_size_stride(primals_17, (4, 4), (4, 1)) assert_size_stride(primals_18, (4,), (1,)) assert_size_stride(primals_19, (4, 4), (4, 1)) assert_size_stride(primals_20, (4,), (1,)) assert_size_stride(primals_21, (12, 4), (4, 1)) assert_size_stride(primals_22, (12,), (1,)) assert_size_stride(primals_23, (12, 4), (4, 1)) assert_size_stride(primals_24, (12,), (1,)) assert_size_stride(primals_25, (4, 4), (4, 1)) assert_size_stride(primals_26, (4,), (1,)) assert_size_stride(primals_27, (4, 4), (4, 1)) assert_size_stride(primals_28, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(primals_4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_5 del primals_6 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf673 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf0, buf2, buf673, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 12), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf672 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf1, buf4, buf672, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 12), (1, 4), 0), out=buf5) buf6 = reinterpret_tensor(buf3, (4, 4, 12), (48, 12, 1), 0) del buf3 triton_poi_fused_mul_1[grid(192)](buf6, primals_10, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf7 = reinterpret_tensor(buf5, (4, 4, 12), (48, 12, 1), 0) del buf5 triton_poi_fused_mul_1[grid(192)](buf7, primals_12, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_bmm_2[grid(16)](buf6, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32) triton_poi_fused_bmm_3[grid(16)](buf7, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1) buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf8, buf9, out=buf10) buf11 = reinterpret_tensor(buf9, (4, 4, 1), (4, 1, 16), 0) del buf9 triton_poi_fused_bmm_2[grid(16)](buf7, buf11, 16, XBLOCK=16, num_warps=1, num_stages=1) buf12 = reinterpret_tensor(buf8, (4, 1, 4), (4, 16, 1), 0) del buf8 triton_poi_fused_bmm_3[grid(16)](buf6, buf12, 16, XBLOCK=16, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf11, buf12, out=buf13) buf24 = reinterpret_tensor(buf12, (4, 4, 1), (4, 1, 16), 0) del buf12 triton_poi_fused_bmm_4[grid(16)](buf6, buf24, 16, XBLOCK=16, num_warps=1, num_stages=1) buf25 = reinterpret_tensor(buf11, (4, 1, 4), (4, 16, 1), 0) del buf11 triton_poi_fused_bmm_5[grid(16)](buf7, buf25, 16, XBLOCK=16, num_warps=1, num_stages=1) buf26 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf24, buf25, out=buf26) buf40 = reinterpret_tensor(buf25, (4, 4, 1), (4, 1, 16), 0) del buf25 triton_poi_fused_bmm_6[grid(16)](buf6, buf40, 16, XBLOCK=16, num_warps=1, num_stages=1) buf41 = reinterpret_tensor(buf24, (4, 1, 4), (4, 16, 1), 0) del buf24 triton_poi_fused_bmm_7[grid(16)](buf7, buf41, 16, XBLOCK=16, num_warps=1, num_stages=1) buf42 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf40, buf41, out=buf42) buf56 = reinterpret_tensor(buf41, (4, 4, 1), (4, 1, 16), 0) del buf41 triton_poi_fused_bmm_8[grid(16)](buf6, buf56, 16, XBLOCK=16, num_warps=1, num_stages=1) buf57 = reinterpret_tensor(buf40, (4, 1, 4), (4, 16, 1), 0) del buf40 triton_poi_fused_bmm_9[grid(16)](buf7, buf57, 16, XBLOCK=16, num_warps=1, num_stages=1) buf58 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf56, buf57, out=buf58) buf14 = reinterpret_tensor(buf57, (4, 4, 1), (4, 1, 16), 0) del buf57 buf15 = buf56 del buf56 buf30 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf31 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf46 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf47 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf62 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf63 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf10, buf26, buf42, buf58, buf14, buf15, buf30, buf31, buf46, buf47, buf62, buf63, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = buf10 del buf10 buf32 = buf26 del buf26 buf48 = buf42 del buf42 buf64 = buf58 del buf58 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf16, buf32, buf48, buf64, primals_8, buf14, buf15, buf30, buf31, buf46, buf47, buf62, buf63, 64, XBLOCK=64, num_warps=1, num_stages=1) buf27 = buf63 del buf63 triton_poi_fused_bmm_4[grid(16)](buf7, buf27, 16, XBLOCK=16, num_warps=1, num_stages=1) buf28 = reinterpret_tensor(buf62, (4, 1, 4), (4, 16, 1), 0) del buf62 triton_poi_fused_bmm_5[grid(16)](buf6, buf28, 16, XBLOCK=16, num_warps=1, num_stages=1) buf29 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf27, buf28, out=buf29) buf43 = reinterpret_tensor(buf28, (4, 4, 1), (4, 1, 16), 0) del buf28 triton_poi_fused_bmm_6[grid(16)](buf7, buf43, 16, XBLOCK=16, num_warps=1, num_stages=1) buf44 = reinterpret_tensor(buf27, (4, 1, 4), (4, 16, 1), 0) del buf27 triton_poi_fused_bmm_7[grid(16)](buf6, buf44, 16, XBLOCK=16, num_warps=1, num_stages=1) buf45 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf43, buf44, out=buf45) buf17 = reinterpret_tensor(buf44, (4, 4, 1), (4, 1, 16), 0) del buf44 buf18 = buf43 del buf43 buf33 = buf47 del buf47 buf34 = buf46 del buf46 buf49 = buf31 del buf31 buf50 = buf30 del buf30 triton_poi_fused__softmax_eq_masked_fill_12[grid(16)](primals_7, buf13, buf29, buf45, buf17, buf18, buf33, buf34, buf49, buf50, 16, XBLOCK=16, num_warps=1, num_stages=1) buf59 = buf15 del buf15 triton_poi_fused_bmm_8[grid(16)](buf7, buf59, 16, XBLOCK=16, num_warps=1, num_stages=1) buf60 = reinterpret_tensor(buf14, (4, 1, 4), (4, 16, 1), 0) del buf14 triton_poi_fused_bmm_9[grid(16)](buf6, buf60, 16, XBLOCK=16, num_warps=1, num_stages=1) buf61 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf59, buf60, out=buf61) buf20 = reinterpret_tensor(buf60, (4, 4, 1), (4, 1, 16), 0) del buf60 triton_poi_fused_bmm_13[grid(16)](buf7, buf20, 16, XBLOCK=16, num_warps=1, num_stages=1) buf21 = reinterpret_tensor(buf59, (4, 4, 1), (4, 1, 1), 0) del buf59 extern_kernels.bmm(buf16, buf20, out=buf21) buf36 = buf20 del buf20 triton_poi_fused_bmm_14[grid(16)](buf7, buf36, 16, XBLOCK=16, num_warps=1, num_stages=1) buf37 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf32, buf36, out=buf37) buf52 = buf36 del buf36 triton_poi_fused_bmm_15[grid(16)](buf7, buf52, 16, XBLOCK=16, num_warps=1, num_stages=1) buf53 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf48, buf52, out=buf53) buf68 = buf52 del buf52 triton_poi_fused_bmm_16[grid(16)](buf7, buf68, 16, XBLOCK=16, num_warps=1, num_stages=1) buf69 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf64, buf68, out=buf69) buf75 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf70 = reinterpret_tensor(buf75, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf21, buf37, buf53, buf69, buf70, 64, XBLOCK=64, num_warps=1, num_stages=1) buf74 = reinterpret_tensor(buf75, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf0, buf74, 64, XBLOCK=64, num_warps=1, num_stages=1) buf78 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf75, (16, 8), (8, 1), 0), reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf78) buf65 = reinterpret_tensor(buf69, (4, 4, 1), (4, 1, 16), 0) del buf69 buf66 = reinterpret_tensor(buf53, (4, 4, 1), (4, 1, 16), 0) del buf53 buf80 = reinterpret_tensor(buf37, (4, 4), (4, 1), 0) del buf37 buf82 = buf80 del buf80 triton_poi_fused__softmax_div_eq_masked_fill_mul_relu_sum_19[grid(16)]( buf82, primals_7, buf61, buf78, primals_14, buf65, buf66, 16, XBLOCK=16, num_warps=1, num_stages=1) buf19 = buf13 del buf13 buf35 = buf29 del buf29 buf51 = buf45 del buf45 buf67 = buf61 del buf61 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf19, buf35, buf51, buf67, primals_7, buf17, buf18, buf33, buf34, buf49, buf50, buf65, buf66, 64, XBLOCK=64, num_warps=1, num_stages=1) buf22 = buf66 del buf66 triton_poi_fused_bmm_13[grid(16)](buf6, buf22, 16, XBLOCK=16, num_warps=1, num_stages=1) buf23 = reinterpret_tensor(buf65, (4, 4, 1), (4, 1, 1), 0) del buf65 extern_kernels.bmm(buf19, buf22, out=buf23) buf38 = buf22 del buf22 triton_poi_fused_bmm_14[grid(16)](buf6, buf38, 16, XBLOCK=16, num_warps=1, num_stages=1) buf39 = reinterpret_tensor(buf50, (4, 4, 1), (4, 1, 1), 0) del buf50 extern_kernels.bmm(buf35, buf38, out=buf39) buf54 = buf38 del buf38 triton_poi_fused_bmm_15[grid(16)](buf6, buf54, 16, XBLOCK=16, num_warps=1, num_stages=1) buf55 = reinterpret_tensor(buf49, (4, 4, 1), (4, 1, 1), 0) del buf49 extern_kernels.bmm(buf51, buf54, out=buf55) buf71 = buf54 del buf54 triton_poi_fused_bmm_16[grid(16)](buf6, buf71, 16, XBLOCK=16, num_warps=1, num_stages=1) buf72 = reinterpret_tensor(buf34, (4, 4, 1), (4, 1, 1), 0) del buf34 extern_kernels.bmm(buf67, buf71, out=buf72) buf77 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf73 = reinterpret_tensor(buf77, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf23, buf39, buf55, buf72, buf73, 64, XBLOCK=64, num_warps=1, num_stages=1) buf76 = reinterpret_tensor(buf77, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf1, buf76, 64, XBLOCK=64, num_warps=1, num_stages=1) buf79 = buf1 del buf1 extern_kernels.mm(reinterpret_tensor(buf77, (16, 8), (8, 1), 0), reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf79) buf81 = reinterpret_tensor(buf72, (4, 4), (4, 1), 0) del buf72 buf84 = buf81 del buf81 triton_poi_fused_div_mul_relu_sum_20[grid(16)](buf84, buf79, primals_16, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf83 = reinterpret_tensor(buf55, (4, 4), (4, 1), 0) del buf55 extern_kernels.addmm(primals_18, buf82, reinterpret_tensor( primals_17, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf83) buf85 = reinterpret_tensor(buf39, (4, 4), (4, 1), 0) del buf39 extern_kernels.addmm(primals_20, buf84, reinterpret_tensor( primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf85) buf86 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf671 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf78, primals_14, buf86, buf671, 64, XBLOCK=64, num_warps=1, num_stages=1 ) buf87 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf86, (16, 4), (4, 1), 0), reinterpret_tensor(primals_21, (4, 12), (1, 4), 0), out=buf87) buf88 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf670 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf79, primals_16, buf88, buf670, 64, XBLOCK=64, num_warps=1, num_stages=1 ) buf89 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf88, (16, 4), (4, 1), 0), reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf89) buf90 = reinterpret_tensor(buf87, (4, 4, 12), (48, 12, 1), 0) del buf87 triton_poi_fused_mul_1[grid(192)](buf90, primals_22, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf91 = reinterpret_tensor(buf89, (4, 4, 12), (48, 12, 1), 0) del buf89 triton_poi_fused_mul_1[grid(192)](buf91, primals_24, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf92 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf93 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf85, buf90, buf92, buf93, 64, XBLOCK=64, num_warps=1, num_stages=1) buf94 = reinterpret_tensor(buf23, (4, 4, 1), (4, 1, 16), 0) del buf23 triton_poi_fused_bmm_23[grid(16)](buf92, buf94, 16, XBLOCK=16, num_warps=1, num_stages=1) buf95 = reinterpret_tensor(buf71, (4, 1, 4), (4, 16, 1), 0) del buf71 triton_poi_fused_bmm_23[grid(16)](buf93, buf95, 16, XBLOCK=16, num_warps=1, num_stages=1) buf96 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf94, buf95, out=buf96) buf97 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf98 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf83, buf91, buf97, buf98, 64, XBLOCK=64, num_warps=1, num_stages=1) buf99 = reinterpret_tensor(buf95, (4, 4, 1), (4, 1, 16), 0) del buf95 triton_poi_fused_bmm_23[grid(16)](buf97, buf99, 16, XBLOCK=16, num_warps=1, num_stages=1) buf100 = reinterpret_tensor(buf94, (4, 1, 4), (4, 16, 1), 0) del buf94 triton_poi_fused_bmm_23[grid(16)](buf98, buf100, 16, XBLOCK=16, num_warps=1, num_stages=1) buf101 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf99, buf100, out=buf101) buf112 = buf99 del buf99 triton_poi_fused_bmm_24[grid(16)](buf92, buf112, 16, XBLOCK=16, num_warps=1, num_stages=1) buf113 = buf100 del buf100 triton_poi_fused_bmm_24[grid(16)](buf93, buf113, 16, XBLOCK=16, num_warps=1, num_stages=1) buf114 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf112, buf113, out=buf114) buf128 = reinterpret_tensor(buf113, (4, 4, 1), (4, 1, 16), 0) del buf113 triton_poi_fused_bmm_25[grid(16)](buf92, buf128, 16, XBLOCK=16, num_warps=1, num_stages=1) buf129 = reinterpret_tensor(buf112, (4, 1, 4), (4, 16, 1), 0) del buf112 triton_poi_fused_bmm_25[grid(16)](buf93, buf129, 16, XBLOCK=16, num_warps=1, num_stages=1) buf130 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf128, buf129, out=buf130) buf144 = reinterpret_tensor(buf129, (4, 4, 1), (4, 1, 16), 0) del buf129 triton_poi_fused_bmm_26[grid(16)](buf92, buf144, 16, XBLOCK=16, num_warps=1, num_stages=1) buf145 = reinterpret_tensor(buf128, (4, 1, 4), (4, 16, 1), 0) del buf128 triton_poi_fused_bmm_26[grid(16)](buf93, buf145, 16, XBLOCK=16, num_warps=1, num_stages=1) buf146 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf144, buf145, out=buf146) buf102 = reinterpret_tensor(buf145, (4, 4, 1), (4, 1, 16), 0) del buf145 buf103 = buf144 del buf144 buf118 = buf33 del buf33 buf119 = buf18 del buf18 buf134 = buf17 del buf17 buf135 = reinterpret_tensor(buf21, (4, 4, 1), (4, 1, 16), 0) del buf21 buf150 = buf68 del buf68 buf151 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_7, buf96, buf114, buf130, buf146, buf102, buf103, buf118, buf119, buf134, buf135, buf150, buf151, 16, XBLOCK=16, num_warps=1, num_stages=1) buf104 = buf96 del buf96 buf120 = buf114 del buf114 buf136 = buf130 del buf130 buf152 = buf146 del buf146 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf104, buf120, buf136, buf152, primals_7, buf102, buf103, buf118, buf119, buf134, buf135, buf150, buf151, 64, XBLOCK=64, num_warps=1, num_stages=1) buf115 = buf151 del buf151 triton_poi_fused_bmm_24[grid(16)](buf97, buf115, 16, XBLOCK=16, num_warps=1, num_stages=1) buf116 = reinterpret_tensor(buf150, (4, 1, 4), (4, 16, 1), 0) del buf150 triton_poi_fused_bmm_24[grid(16)](buf98, buf116, 16, XBLOCK=16, num_warps=1, num_stages=1) buf117 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf115, buf116, out=buf117) buf131 = reinterpret_tensor(buf116, (4, 4, 1), (4, 1, 16), 0) del buf116 triton_poi_fused_bmm_25[grid(16)](buf97, buf131, 16, XBLOCK=16, num_warps=1, num_stages=1) buf132 = reinterpret_tensor(buf115, (4, 1, 4), (4, 16, 1), 0) del buf115 triton_poi_fused_bmm_25[grid(16)](buf98, buf132, 16, XBLOCK=16, num_warps=1, num_stages=1) buf133 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf131, buf132, out=buf133) buf147 = reinterpret_tensor(buf132, (4, 4, 1), (4, 1, 16), 0) del buf132 triton_poi_fused_bmm_26[grid(16)](buf97, buf147, 16, XBLOCK=16, num_warps=1, num_stages=1) buf148 = reinterpret_tensor(buf131, (4, 1, 4), (4, 16, 1), 0) del buf131 triton_poi_fused_bmm_26[grid(16)](buf98, buf148, 16, XBLOCK=16, num_warps=1, num_stages=1) buf149 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf147, buf148, out=buf149) buf105 = reinterpret_tensor(buf148, (4, 4, 1), (4, 1, 16), 0) del buf148 buf106 = buf147 del buf147 buf121 = buf135 del buf135 buf122 = buf134 del buf134 buf137 = buf119 del buf119 buf138 = buf118 del buf118 buf153 = buf103 del buf103 buf154 = buf102 del buf102 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf101, buf117, buf133, buf149, buf105, buf106, buf121, buf122, buf137, buf138, buf153, buf154, 16, XBLOCK=16, num_warps=1, num_stages=1) buf107 = buf101 del buf101 buf123 = buf117 del buf117 buf139 = buf133 del buf133 buf155 = buf149 del buf149 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf107, buf123, buf139, buf155, primals_8, buf105, buf106, buf121, buf122, buf137, buf138, buf153, buf154, 64, XBLOCK=64, num_warps=1, num_stages=1) buf108 = buf154 del buf154 triton_poi_fused_bmm_13[grid(16)](buf90, buf108, 16, XBLOCK=16, num_warps=1, num_stages=1) buf109 = reinterpret_tensor(buf153, (4, 4, 1), (4, 1, 1), 0) del buf153 extern_kernels.bmm(buf104, buf108, out=buf109) buf110 = buf108 del buf108 triton_poi_fused_bmm_13[grid(16)](buf91, buf110, 16, XBLOCK=16, num_warps=1, num_stages=1) buf111 = reinterpret_tensor(buf138, (4, 4, 1), (4, 1, 1), 0) del buf138 extern_kernels.bmm(buf107, buf110, out=buf111) buf124 = buf110 del buf110 triton_poi_fused_bmm_14[grid(16)](buf90, buf124, 16, XBLOCK=16, num_warps=1, num_stages=1) buf125 = reinterpret_tensor(buf137, (4, 4, 1), (4, 1, 1), 0) del buf137 extern_kernels.bmm(buf120, buf124, out=buf125) buf126 = buf124 del buf124 triton_poi_fused_bmm_14[grid(16)](buf91, buf126, 16, XBLOCK=16, num_warps=1, num_stages=1) buf127 = reinterpret_tensor(buf122, (4, 4, 1), (4, 1, 1), 0) del buf122 extern_kernels.bmm(buf123, buf126, out=buf127) buf140 = buf126 del buf126 triton_poi_fused_bmm_15[grid(16)](buf90, buf140, 16, XBLOCK=16, num_warps=1, num_stages=1) buf141 = reinterpret_tensor(buf121, (4, 4, 1), (4, 1, 1), 0) del buf121 extern_kernels.bmm(buf136, buf140, out=buf141) buf142 = buf140 del buf140 triton_poi_fused_bmm_15[grid(16)](buf91, buf142, 16, XBLOCK=16, num_warps=1, num_stages=1) buf143 = reinterpret_tensor(buf106, (4, 4, 1), (4, 1, 1), 0) del buf106 extern_kernels.bmm(buf139, buf142, out=buf143) buf156 = buf142 del buf142 triton_poi_fused_bmm_16[grid(16)](buf90, buf156, 16, XBLOCK=16, num_warps=1, num_stages=1) buf157 = reinterpret_tensor(buf105, (4, 4, 1), (4, 1, 1), 0) del buf105 extern_kernels.bmm(buf152, buf156, out=buf157) buf158 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf162 = buf158 del buf158 triton_poi_fused_add_cat_27[grid(64)](buf162, buf109, buf125, buf141, buf157, buf78, primals_14, 64, XBLOCK=64, num_warps=1, num_stages=1) buf159 = reinterpret_tensor(buf157, (4, 4, 1), (4, 1, 16), 0) del buf157 triton_poi_fused_bmm_16[grid(16)](buf91, buf159, 16, XBLOCK=16, num_warps=1, num_stages=1) buf160 = buf141 del buf141 extern_kernels.bmm(buf155, buf159, out=buf160) buf161 = reinterpret_tensor(buf78, (4, 4, 4), (16, 4, 1), 0) del buf78 buf164 = buf161 del buf161 triton_poi_fused_add_cat_27[grid(64)](buf164, buf111, buf127, buf143, buf160, buf79, primals_16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf163 = buf79 del buf79 extern_kernels.addmm(primals_26, reinterpret_tensor(buf162, (16, 4), (4, 1), 0), reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf163) buf165 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_28, reinterpret_tensor(buf164, (16, 4), (4, 1), 0), reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf165) buf166 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf669 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf163, buf166, buf669, 64, XBLOCK=64, num_warps=1, num_stages=1) buf167 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf166, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 12), (1, 4), 0), out=buf167) buf168 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf668 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf165, buf168, buf668, 64, XBLOCK=64, num_warps=1, num_stages=1) buf169 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf168, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 12), (1, 4), 0), out=buf169) buf170 = reinterpret_tensor(buf167, (4, 4, 12), (48, 12, 1), 0) del buf167 triton_poi_fused_mul_1[grid(192)](buf170, primals_10, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf171 = reinterpret_tensor(buf169, (4, 4, 12), (48, 12, 1), 0) del buf169 triton_poi_fused_mul_1[grid(192)](buf171, primals_12, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf172 = reinterpret_tensor(buf160, (4, 4, 1), (4, 1, 16), 0) del buf160 triton_poi_fused_bmm_2[grid(16)](buf170, buf172, 16, XBLOCK=16, num_warps=1, num_stages=1) buf173 = reinterpret_tensor(buf143, (4, 1, 4), (4, 16, 1), 0) del buf143 triton_poi_fused_bmm_3[grid(16)](buf171, buf173, 16, XBLOCK=16, num_warps=1, num_stages=1) buf174 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf172, buf173, out=buf174) buf175 = reinterpret_tensor(buf173, (4, 4, 1), (4, 1, 16), 0) del buf173 triton_poi_fused_bmm_2[grid(16)](buf171, buf175, 16, XBLOCK=16, num_warps=1, num_stages=1) buf176 = reinterpret_tensor(buf172, (4, 1, 4), (4, 16, 1), 0) del buf172 triton_poi_fused_bmm_3[grid(16)](buf170, buf176, 16, XBLOCK=16, num_warps=1, num_stages=1) buf177 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf175, buf176, out=buf177) buf188 = reinterpret_tensor(buf176, (4, 4, 1), (4, 1, 16), 0) del buf176 triton_poi_fused_bmm_4[grid(16)](buf170, buf188, 16, XBLOCK=16, num_warps=1, num_stages=1) buf189 = reinterpret_tensor(buf175, (4, 1, 4), (4, 16, 1), 0) del buf175 triton_poi_fused_bmm_5[grid(16)](buf171, buf189, 16, XBLOCK=16, num_warps=1, num_stages=1) buf190 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf188, buf189, out=buf190) buf204 = reinterpret_tensor(buf189, (4, 4, 1), (4, 1, 16), 0) del buf189 triton_poi_fused_bmm_6[grid(16)](buf170, buf204, 16, XBLOCK=16, num_warps=1, num_stages=1) buf205 = reinterpret_tensor(buf188, (4, 1, 4), (4, 16, 1), 0) del buf188 triton_poi_fused_bmm_7[grid(16)](buf171, buf205, 16, XBLOCK=16, num_warps=1, num_stages=1) buf206 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf204, buf205, out=buf206) buf220 = reinterpret_tensor(buf205, (4, 4, 1), (4, 1, 16), 0) del buf205 triton_poi_fused_bmm_8[grid(16)](buf170, buf220, 16, XBLOCK=16, num_warps=1, num_stages=1) buf221 = reinterpret_tensor(buf204, (4, 1, 4), (4, 16, 1), 0) del buf204 triton_poi_fused_bmm_9[grid(16)](buf171, buf221, 16, XBLOCK=16, num_warps=1, num_stages=1) buf222 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf220, buf221, out=buf222) buf178 = reinterpret_tensor(buf221, (4, 4, 1), (4, 1, 16), 0) del buf221 buf179 = buf220 del buf220 buf194 = reinterpret_tensor(buf127, (4, 4, 1), (4, 1, 16), 0) del buf127 buf195 = reinterpret_tensor(buf111, (4, 4, 1), (4, 1, 16), 0) del buf111 buf210 = buf159 del buf159 buf211 = reinterpret_tensor(buf125, (4, 4, 1), (4, 1, 16), 0) del buf125 buf226 = reinterpret_tensor(buf109, (4, 4, 1), (4, 1, 16), 0) del buf109 buf227 = buf156 del buf156 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf174, buf190, buf206, buf222, buf178, buf179, buf194, buf195, buf210, buf211, buf226, buf227, 16, XBLOCK=16, num_warps=1, num_stages=1) buf180 = buf174 del buf174 buf196 = buf190 del buf190 buf212 = buf206 del buf206 buf228 = buf222 del buf222 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf180, buf196, buf212, buf228, primals_8, buf178, buf179, buf194, buf195, buf210, buf211, buf226, buf227, 64, XBLOCK=64, num_warps=1, num_stages=1) buf191 = buf227 del buf227 triton_poi_fused_bmm_4[grid(16)](buf171, buf191, 16, XBLOCK=16, num_warps=1, num_stages=1) buf192 = reinterpret_tensor(buf226, (4, 1, 4), (4, 16, 1), 0) del buf226 triton_poi_fused_bmm_5[grid(16)](buf170, buf192, 16, XBLOCK=16, num_warps=1, num_stages=1) buf193 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf191, buf192, out=buf193) buf207 = reinterpret_tensor(buf192, (4, 4, 1), (4, 1, 16), 0) del buf192 triton_poi_fused_bmm_6[grid(16)](buf171, buf207, 16, XBLOCK=16, num_warps=1, num_stages=1) buf208 = reinterpret_tensor(buf191, (4, 1, 4), (4, 16, 1), 0) del buf191 triton_poi_fused_bmm_7[grid(16)](buf170, buf208, 16, XBLOCK=16, num_warps=1, num_stages=1) buf209 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf207, buf208, out=buf209) buf181 = reinterpret_tensor(buf208, (4, 4, 1), (4, 1, 16), 0) del buf208 buf182 = buf207 del buf207 buf197 = buf211 del buf211 buf198 = buf210 del buf210 buf213 = buf195 del buf195 buf214 = buf194 del buf194 triton_poi_fused__softmax_eq_masked_fill_12[grid(16)](primals_7, buf177, buf193, buf209, buf181, buf182, buf197, buf198, buf213, buf214, 16, XBLOCK=16, num_warps=1, num_stages=1) buf223 = buf179 del buf179 triton_poi_fused_bmm_8[grid(16)](buf171, buf223, 16, XBLOCK=16, num_warps=1, num_stages=1) buf224 = reinterpret_tensor(buf178, (4, 1, 4), (4, 16, 1), 0) del buf178 triton_poi_fused_bmm_9[grid(16)](buf170, buf224, 16, XBLOCK=16, num_warps=1, num_stages=1) buf225 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf223, buf224, out=buf225) buf184 = reinterpret_tensor(buf224, (4, 4, 1), (4, 1, 16), 0) del buf224 triton_poi_fused_bmm_13[grid(16)](buf171, buf184, 16, XBLOCK=16, num_warps=1, num_stages=1) buf185 = reinterpret_tensor(buf223, (4, 4, 1), (4, 1, 1), 0) del buf223 extern_kernels.bmm(buf180, buf184, out=buf185) buf200 = buf184 del buf184 triton_poi_fused_bmm_14[grid(16)](buf171, buf200, 16, XBLOCK=16, num_warps=1, num_stages=1) buf201 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf196, buf200, out=buf201) buf216 = buf200 del buf200 triton_poi_fused_bmm_15[grid(16)](buf171, buf216, 16, XBLOCK=16, num_warps=1, num_stages=1) buf217 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf212, buf216, out=buf217) buf232 = buf216 del buf216 triton_poi_fused_bmm_16[grid(16)](buf171, buf232, 16, XBLOCK=16, num_warps=1, num_stages=1) buf233 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf228, buf232, out=buf233) buf239 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf234 = reinterpret_tensor(buf239, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf185, buf201, buf217, buf233, buf234, 64, XBLOCK=64, num_warps=1, num_stages=1) buf238 = reinterpret_tensor(buf239, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf163, buf238, 64, XBLOCK=64, num_warps=1, num_stages=1) buf242 = buf163 del buf163 extern_kernels.mm(reinterpret_tensor(buf239, (16, 8), (8, 1), 0), reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf242) buf229 = reinterpret_tensor(buf233, (4, 4, 1), (4, 1, 16), 0) del buf233 buf230 = reinterpret_tensor(buf217, (4, 4, 1), (4, 1, 16), 0) del buf217 buf244 = reinterpret_tensor(buf201, (4, 4), (4, 1), 0) del buf201 buf246 = buf244 del buf244 triton_poi_fused__softmax_div_eq_masked_fill_mul_relu_sum_19[grid(16)]( buf246, primals_7, buf225, buf242, primals_14, buf229, buf230, 16, XBLOCK=16, num_warps=1, num_stages=1) buf183 = buf177 del buf177 buf199 = buf193 del buf193 buf215 = buf209 del buf209 buf231 = buf225 del buf225 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf183, buf199, buf215, buf231, primals_7, buf181, buf182, buf197, buf198, buf213, buf214, buf229, buf230, 64, XBLOCK=64, num_warps=1, num_stages=1) buf186 = buf230 del buf230 triton_poi_fused_bmm_13[grid(16)](buf170, buf186, 16, XBLOCK=16, num_warps=1, num_stages=1) buf187 = reinterpret_tensor(buf229, (4, 4, 1), (4, 1, 1), 0) del buf229 extern_kernels.bmm(buf183, buf186, out=buf187) buf202 = buf186 del buf186 triton_poi_fused_bmm_14[grid(16)](buf170, buf202, 16, XBLOCK=16, num_warps=1, num_stages=1) buf203 = reinterpret_tensor(buf214, (4, 4, 1), (4, 1, 1), 0) del buf214 extern_kernels.bmm(buf199, buf202, out=buf203) buf218 = buf202 del buf202 triton_poi_fused_bmm_15[grid(16)](buf170, buf218, 16, XBLOCK=16, num_warps=1, num_stages=1) buf219 = reinterpret_tensor(buf213, (4, 4, 1), (4, 1, 1), 0) del buf213 extern_kernels.bmm(buf215, buf218, out=buf219) buf235 = buf218 del buf218 triton_poi_fused_bmm_16[grid(16)](buf170, buf235, 16, XBLOCK=16, num_warps=1, num_stages=1) buf236 = reinterpret_tensor(buf198, (4, 4, 1), (4, 1, 1), 0) del buf198 extern_kernels.bmm(buf231, buf235, out=buf236) buf241 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf237 = reinterpret_tensor(buf241, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf187, buf203, buf219, buf236, buf237, 64, XBLOCK=64, num_warps=1, num_stages=1) buf240 = reinterpret_tensor(buf241, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf165, buf240, 64, XBLOCK=64, num_warps=1, num_stages=1) buf243 = buf165 del buf165 extern_kernels.mm(reinterpret_tensor(buf241, (16, 8), (8, 1), 0), reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf243) buf245 = reinterpret_tensor(buf236, (4, 4), (4, 1), 0) del buf236 buf248 = buf245 del buf245 triton_poi_fused_div_mul_relu_sum_20[grid(16)](buf248, buf243, primals_16, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf247 = reinterpret_tensor(buf219, (4, 4), (4, 1), 0) del buf219 extern_kernels.addmm(primals_18, buf246, reinterpret_tensor( primals_17, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf247) buf249 = reinterpret_tensor(buf203, (4, 4), (4, 1), 0) del buf203 extern_kernels.addmm(primals_20, buf248, reinterpret_tensor( primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf249) buf250 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf667 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf242, primals_14, buf250, buf667, 64, XBLOCK=64, num_warps=1, num_stages=1) buf251 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf250, (16, 4), (4, 1), 0), reinterpret_tensor(primals_21, (4, 12), (1, 4), 0), out=buf251) buf252 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf666 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf243, primals_16, buf252, buf666, 64, XBLOCK=64, num_warps=1, num_stages=1) buf253 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf252, (16, 4), (4, 1), 0), reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf253) buf254 = reinterpret_tensor(buf251, (4, 4, 12), (48, 12, 1), 0) del buf251 triton_poi_fused_mul_1[grid(192)](buf254, primals_22, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf255 = reinterpret_tensor(buf253, (4, 4, 12), (48, 12, 1), 0) del buf253 triton_poi_fused_mul_1[grid(192)](buf255, primals_24, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf256 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf257 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf249, buf254, buf256, buf257, 64, XBLOCK=64, num_warps=1, num_stages=1) buf258 = reinterpret_tensor(buf187, (4, 4, 1), (4, 1, 16), 0) del buf187 triton_poi_fused_bmm_23[grid(16)](buf256, buf258, 16, XBLOCK=16, num_warps=1, num_stages=1) buf259 = reinterpret_tensor(buf235, (4, 1, 4), (4, 16, 1), 0) del buf235 triton_poi_fused_bmm_23[grid(16)](buf257, buf259, 16, XBLOCK=16, num_warps=1, num_stages=1) buf260 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf258, buf259, out=buf260) buf261 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf262 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf247, buf255, buf261, buf262, 64, XBLOCK=64, num_warps=1, num_stages=1) buf263 = reinterpret_tensor(buf259, (4, 4, 1), (4, 1, 16), 0) del buf259 triton_poi_fused_bmm_23[grid(16)](buf261, buf263, 16, XBLOCK=16, num_warps=1, num_stages=1) buf264 = reinterpret_tensor(buf258, (4, 1, 4), (4, 16, 1), 0) del buf258 triton_poi_fused_bmm_23[grid(16)](buf262, buf264, 16, XBLOCK=16, num_warps=1, num_stages=1) buf265 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf263, buf264, out=buf265) buf276 = reinterpret_tensor(buf264, (4, 4, 1), (4, 1, 16), 0) del buf264 triton_poi_fused_bmm_24[grid(16)](buf256, buf276, 16, XBLOCK=16, num_warps=1, num_stages=1) buf277 = reinterpret_tensor(buf263, (4, 1, 4), (4, 16, 1), 0) del buf263 triton_poi_fused_bmm_24[grid(16)](buf257, buf277, 16, XBLOCK=16, num_warps=1, num_stages=1) buf278 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf276, buf277, out=buf278) buf292 = reinterpret_tensor(buf277, (4, 4, 1), (4, 1, 16), 0) del buf277 triton_poi_fused_bmm_25[grid(16)](buf256, buf292, 16, XBLOCK=16, num_warps=1, num_stages=1) buf293 = reinterpret_tensor(buf276, (4, 1, 4), (4, 16, 1), 0) del buf276 triton_poi_fused_bmm_25[grid(16)](buf257, buf293, 16, XBLOCK=16, num_warps=1, num_stages=1) buf294 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf292, buf293, out=buf294) buf308 = reinterpret_tensor(buf293, (4, 4, 1), (4, 1, 16), 0) del buf293 triton_poi_fused_bmm_26[grid(16)](buf256, buf308, 16, XBLOCK=16, num_warps=1, num_stages=1) buf309 = reinterpret_tensor(buf292, (4, 1, 4), (4, 16, 1), 0) del buf292 triton_poi_fused_bmm_26[grid(16)](buf257, buf309, 16, XBLOCK=16, num_warps=1, num_stages=1) buf310 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf308, buf309, out=buf310) buf266 = reinterpret_tensor(buf309, (4, 4, 1), (4, 1, 16), 0) del buf309 buf267 = buf308 del buf308 buf282 = buf197 del buf197 buf283 = buf182 del buf182 buf298 = buf181 del buf181 buf299 = reinterpret_tensor(buf185, (4, 4, 1), (4, 1, 16), 0) del buf185 buf314 = buf232 del buf232 buf315 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_7, buf260, buf278, buf294, buf310, buf266, buf267, buf282, buf283, buf298, buf299, buf314, buf315, 16, XBLOCK=16, num_warps=1, num_stages=1) buf268 = buf260 del buf260 buf284 = buf278 del buf278 buf300 = buf294 del buf294 buf316 = buf310 del buf310 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf268, buf284, buf300, buf316, primals_7, buf266, buf267, buf282, buf283, buf298, buf299, buf314, buf315, 64, XBLOCK=64, num_warps=1, num_stages=1) buf279 = buf315 del buf315 triton_poi_fused_bmm_24[grid(16)](buf261, buf279, 16, XBLOCK=16, num_warps=1, num_stages=1) buf280 = reinterpret_tensor(buf314, (4, 1, 4), (4, 16, 1), 0) del buf314 triton_poi_fused_bmm_24[grid(16)](buf262, buf280, 16, XBLOCK=16, num_warps=1, num_stages=1) buf281 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf279, buf280, out=buf281) buf295 = reinterpret_tensor(buf280, (4, 4, 1), (4, 1, 16), 0) del buf280 triton_poi_fused_bmm_25[grid(16)](buf261, buf295, 16, XBLOCK=16, num_warps=1, num_stages=1) buf296 = reinterpret_tensor(buf279, (4, 1, 4), (4, 16, 1), 0) del buf279 triton_poi_fused_bmm_25[grid(16)](buf262, buf296, 16, XBLOCK=16, num_warps=1, num_stages=1) buf297 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf295, buf296, out=buf297) buf311 = reinterpret_tensor(buf296, (4, 4, 1), (4, 1, 16), 0) del buf296 triton_poi_fused_bmm_26[grid(16)](buf261, buf311, 16, XBLOCK=16, num_warps=1, num_stages=1) buf312 = reinterpret_tensor(buf295, (4, 1, 4), (4, 16, 1), 0) del buf295 triton_poi_fused_bmm_26[grid(16)](buf262, buf312, 16, XBLOCK=16, num_warps=1, num_stages=1) buf313 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf311, buf312, out=buf313) buf269 = reinterpret_tensor(buf312, (4, 4, 1), (4, 1, 16), 0) del buf312 buf270 = buf311 del buf311 buf285 = buf299 del buf299 buf286 = buf298 del buf298 buf301 = buf283 del buf283 buf302 = buf282 del buf282 buf317 = buf267 del buf267 buf318 = buf266 del buf266 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf265, buf281, buf297, buf313, buf269, buf270, buf285, buf286, buf301, buf302, buf317, buf318, 16, XBLOCK=16, num_warps=1, num_stages=1) buf271 = buf265 del buf265 buf287 = buf281 del buf281 buf303 = buf297 del buf297 buf319 = buf313 del buf313 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf271, buf287, buf303, buf319, primals_8, buf269, buf270, buf285, buf286, buf301, buf302, buf317, buf318, 64, XBLOCK=64, num_warps=1, num_stages=1) buf272 = buf318 del buf318 triton_poi_fused_bmm_13[grid(16)](buf254, buf272, 16, XBLOCK=16, num_warps=1, num_stages=1) buf273 = reinterpret_tensor(buf317, (4, 4, 1), (4, 1, 1), 0) del buf317 extern_kernels.bmm(buf268, buf272, out=buf273) buf274 = buf272 del buf272 triton_poi_fused_bmm_13[grid(16)](buf255, buf274, 16, XBLOCK=16, num_warps=1, num_stages=1) buf275 = reinterpret_tensor(buf302, (4, 4, 1), (4, 1, 1), 0) del buf302 extern_kernels.bmm(buf271, buf274, out=buf275) buf288 = buf274 del buf274 triton_poi_fused_bmm_14[grid(16)](buf254, buf288, 16, XBLOCK=16, num_warps=1, num_stages=1) buf289 = reinterpret_tensor(buf301, (4, 4, 1), (4, 1, 1), 0) del buf301 extern_kernels.bmm(buf284, buf288, out=buf289) buf290 = buf288 del buf288 triton_poi_fused_bmm_14[grid(16)](buf255, buf290, 16, XBLOCK=16, num_warps=1, num_stages=1) buf291 = reinterpret_tensor(buf286, (4, 4, 1), (4, 1, 1), 0) del buf286 extern_kernels.bmm(buf287, buf290, out=buf291) buf304 = buf290 del buf290 triton_poi_fused_bmm_15[grid(16)](buf254, buf304, 16, XBLOCK=16, num_warps=1, num_stages=1) buf305 = reinterpret_tensor(buf285, (4, 4, 1), (4, 1, 1), 0) del buf285 extern_kernels.bmm(buf300, buf304, out=buf305) buf306 = buf304 del buf304 triton_poi_fused_bmm_15[grid(16)](buf255, buf306, 16, XBLOCK=16, num_warps=1, num_stages=1) buf307 = reinterpret_tensor(buf270, (4, 4, 1), (4, 1, 1), 0) del buf270 extern_kernels.bmm(buf303, buf306, out=buf307) buf320 = buf306 del buf306 triton_poi_fused_bmm_16[grid(16)](buf254, buf320, 16, XBLOCK=16, num_warps=1, num_stages=1) buf321 = reinterpret_tensor(buf269, (4, 4, 1), (4, 1, 1), 0) del buf269 extern_kernels.bmm(buf316, buf320, out=buf321) buf326 = reinterpret_tensor(buf242, (4, 4, 4), (16, 4, 1), 0) del buf242 triton_poi_fused_add_cat_28[grid(64)](buf326, buf273, buf289, buf305, buf321, primals_14, 64, XBLOCK=64, num_warps=1, num_stages=1) buf323 = reinterpret_tensor(buf321, (4, 4, 1), (4, 1, 16), 0) del buf321 triton_poi_fused_bmm_16[grid(16)](buf255, buf323, 16, XBLOCK=16, num_warps=1, num_stages=1) buf324 = buf305 del buf305 extern_kernels.bmm(buf319, buf323, out=buf324) buf328 = reinterpret_tensor(buf243, (4, 4, 4), (16, 4, 1), 0) del buf243 triton_poi_fused_add_cat_28[grid(64)](buf328, buf275, buf291, buf307, buf324, primals_16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf327 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_26, reinterpret_tensor(buf326, (16, 4), (4, 1), 0), reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf327) buf329 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_28, reinterpret_tensor(buf328, (16, 4), (4, 1), 0), reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf329) buf330 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf665 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf327, buf330, buf665, 64, XBLOCK=64, num_warps=1, num_stages=1) buf331 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf330, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 12), (1, 4), 0), out=buf331) buf332 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf664 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf329, buf332, buf664, 64, XBLOCK=64, num_warps=1, num_stages=1) buf333 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf332, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 12), (1, 4), 0), out=buf333) buf334 = reinterpret_tensor(buf331, (4, 4, 12), (48, 12, 1), 0) del buf331 triton_poi_fused_mul_1[grid(192)](buf334, primals_10, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf335 = reinterpret_tensor(buf333, (4, 4, 12), (48, 12, 1), 0) del buf333 triton_poi_fused_mul_1[grid(192)](buf335, primals_12, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf336 = reinterpret_tensor(buf324, (4, 4, 1), (4, 1, 16), 0) del buf324 triton_poi_fused_bmm_2[grid(16)](buf334, buf336, 16, XBLOCK=16, num_warps=1, num_stages=1) buf337 = reinterpret_tensor(buf307, (4, 1, 4), (4, 16, 1), 0) del buf307 triton_poi_fused_bmm_3[grid(16)](buf335, buf337, 16, XBLOCK=16, num_warps=1, num_stages=1) buf338 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf336, buf337, out=buf338) buf339 = reinterpret_tensor(buf337, (4, 4, 1), (4, 1, 16), 0) del buf337 triton_poi_fused_bmm_2[grid(16)](buf335, buf339, 16, XBLOCK=16, num_warps=1, num_stages=1) buf340 = reinterpret_tensor(buf336, (4, 1, 4), (4, 16, 1), 0) del buf336 triton_poi_fused_bmm_3[grid(16)](buf334, buf340, 16, XBLOCK=16, num_warps=1, num_stages=1) buf341 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf339, buf340, out=buf341) buf352 = reinterpret_tensor(buf340, (4, 4, 1), (4, 1, 16), 0) del buf340 triton_poi_fused_bmm_4[grid(16)](buf334, buf352, 16, XBLOCK=16, num_warps=1, num_stages=1) buf353 = reinterpret_tensor(buf339, (4, 1, 4), (4, 16, 1), 0) del buf339 triton_poi_fused_bmm_5[grid(16)](buf335, buf353, 16, XBLOCK=16, num_warps=1, num_stages=1) buf354 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf352, buf353, out=buf354) buf368 = reinterpret_tensor(buf353, (4, 4, 1), (4, 1, 16), 0) del buf353 triton_poi_fused_bmm_6[grid(16)](buf334, buf368, 16, XBLOCK=16, num_warps=1, num_stages=1) buf369 = reinterpret_tensor(buf352, (4, 1, 4), (4, 16, 1), 0) del buf352 triton_poi_fused_bmm_7[grid(16)](buf335, buf369, 16, XBLOCK=16, num_warps=1, num_stages=1) buf370 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf368, buf369, out=buf370) buf384 = reinterpret_tensor(buf369, (4, 4, 1), (4, 1, 16), 0) del buf369 triton_poi_fused_bmm_8[grid(16)](buf334, buf384, 16, XBLOCK=16, num_warps=1, num_stages=1) buf385 = reinterpret_tensor(buf368, (4, 1, 4), (4, 16, 1), 0) del buf368 triton_poi_fused_bmm_9[grid(16)](buf335, buf385, 16, XBLOCK=16, num_warps=1, num_stages=1) buf386 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf384, buf385, out=buf386) buf342 = reinterpret_tensor(buf385, (4, 4, 1), (4, 1, 16), 0) del buf385 buf343 = buf384 del buf384 buf358 = reinterpret_tensor(buf291, (4, 4, 1), (4, 1, 16), 0) del buf291 buf359 = reinterpret_tensor(buf275, (4, 4, 1), (4, 1, 16), 0) del buf275 buf374 = buf323 del buf323 buf375 = reinterpret_tensor(buf289, (4, 4, 1), (4, 1, 16), 0) del buf289 buf390 = reinterpret_tensor(buf273, (4, 4, 1), (4, 1, 16), 0) del buf273 buf391 = buf320 del buf320 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf338, buf354, buf370, buf386, buf342, buf343, buf358, buf359, buf374, buf375, buf390, buf391, 16, XBLOCK=16, num_warps=1, num_stages=1) buf344 = buf338 del buf338 buf360 = buf354 del buf354 buf376 = buf370 del buf370 buf392 = buf386 del buf386 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf344, buf360, buf376, buf392, primals_8, buf342, buf343, buf358, buf359, buf374, buf375, buf390, buf391, 64, XBLOCK=64, num_warps=1, num_stages=1) buf355 = buf391 del buf391 triton_poi_fused_bmm_4[grid(16)](buf335, buf355, 16, XBLOCK=16, num_warps=1, num_stages=1) buf356 = reinterpret_tensor(buf390, (4, 1, 4), (4, 16, 1), 0) del buf390 triton_poi_fused_bmm_5[grid(16)](buf334, buf356, 16, XBLOCK=16, num_warps=1, num_stages=1) buf357 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf355, buf356, out=buf357) buf371 = reinterpret_tensor(buf356, (4, 4, 1), (4, 1, 16), 0) del buf356 triton_poi_fused_bmm_6[grid(16)](buf335, buf371, 16, XBLOCK=16, num_warps=1, num_stages=1) buf372 = reinterpret_tensor(buf355, (4, 1, 4), (4, 16, 1), 0) del buf355 triton_poi_fused_bmm_7[grid(16)](buf334, buf372, 16, XBLOCK=16, num_warps=1, num_stages=1) buf373 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf371, buf372, out=buf373) buf345 = reinterpret_tensor(buf372, (4, 4, 1), (4, 1, 16), 0) del buf372 buf346 = buf371 del buf371 buf361 = buf375 del buf375 buf362 = buf374 del buf374 buf377 = buf359 del buf359 buf378 = buf358 del buf358 triton_poi_fused__softmax_eq_masked_fill_12[grid(16)](primals_7, buf341, buf357, buf373, buf345, buf346, buf361, buf362, buf377, buf378, 16, XBLOCK=16, num_warps=1, num_stages=1) buf387 = buf343 del buf343 triton_poi_fused_bmm_8[grid(16)](buf335, buf387, 16, XBLOCK=16, num_warps=1, num_stages=1) buf388 = reinterpret_tensor(buf342, (4, 1, 4), (4, 16, 1), 0) del buf342 triton_poi_fused_bmm_9[grid(16)](buf334, buf388, 16, XBLOCK=16, num_warps=1, num_stages=1) buf389 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf387, buf388, out=buf389) buf348 = reinterpret_tensor(buf388, (4, 4, 1), (4, 1, 16), 0) del buf388 triton_poi_fused_bmm_13[grid(16)](buf335, buf348, 16, XBLOCK=16, num_warps=1, num_stages=1) buf349 = reinterpret_tensor(buf387, (4, 4, 1), (4, 1, 1), 0) del buf387 extern_kernels.bmm(buf344, buf348, out=buf349) buf364 = buf348 del buf348 triton_poi_fused_bmm_14[grid(16)](buf335, buf364, 16, XBLOCK=16, num_warps=1, num_stages=1) buf365 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf360, buf364, out=buf365) buf380 = buf364 del buf364 triton_poi_fused_bmm_15[grid(16)](buf335, buf380, 16, XBLOCK=16, num_warps=1, num_stages=1) buf381 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf376, buf380, out=buf381) buf396 = buf380 del buf380 triton_poi_fused_bmm_16[grid(16)](buf335, buf396, 16, XBLOCK=16, num_warps=1, num_stages=1) buf397 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf392, buf396, out=buf397) buf403 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf398 = reinterpret_tensor(buf403, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf349, buf365, buf381, buf397, buf398, 64, XBLOCK=64, num_warps=1, num_stages=1) buf402 = reinterpret_tensor(buf403, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf327, buf402, 64, XBLOCK=64, num_warps=1, num_stages=1) buf406 = buf327 del buf327 extern_kernels.mm(reinterpret_tensor(buf403, (16, 8), (8, 1), 0), reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf406) buf393 = reinterpret_tensor(buf397, (4, 4, 1), (4, 1, 16), 0) del buf397 buf394 = reinterpret_tensor(buf381, (4, 4, 1), (4, 1, 16), 0) del buf381 buf408 = reinterpret_tensor(buf365, (4, 4), (4, 1), 0) del buf365 buf410 = buf408 del buf408 triton_poi_fused__softmax_div_eq_masked_fill_mul_relu_sum_19[grid(16)]( buf410, primals_7, buf389, buf406, primals_14, buf393, buf394, 16, XBLOCK=16, num_warps=1, num_stages=1) buf347 = buf341 del buf341 buf363 = buf357 del buf357 buf379 = buf373 del buf373 buf395 = buf389 del buf389 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf347, buf363, buf379, buf395, primals_7, buf345, buf346, buf361, buf362, buf377, buf378, buf393, buf394, 64, XBLOCK=64, num_warps=1, num_stages=1) buf350 = buf394 del buf394 triton_poi_fused_bmm_13[grid(16)](buf334, buf350, 16, XBLOCK=16, num_warps=1, num_stages=1) buf351 = reinterpret_tensor(buf393, (4, 4, 1), (4, 1, 1), 0) del buf393 extern_kernels.bmm(buf347, buf350, out=buf351) buf366 = buf350 del buf350 triton_poi_fused_bmm_14[grid(16)](buf334, buf366, 16, XBLOCK=16, num_warps=1, num_stages=1) buf367 = reinterpret_tensor(buf378, (4, 4, 1), (4, 1, 1), 0) del buf378 extern_kernels.bmm(buf363, buf366, out=buf367) buf382 = buf366 del buf366 triton_poi_fused_bmm_15[grid(16)](buf334, buf382, 16, XBLOCK=16, num_warps=1, num_stages=1) buf383 = reinterpret_tensor(buf377, (4, 4, 1), (4, 1, 1), 0) del buf377 extern_kernels.bmm(buf379, buf382, out=buf383) buf399 = buf382 del buf382 triton_poi_fused_bmm_16[grid(16)](buf334, buf399, 16, XBLOCK=16, num_warps=1, num_stages=1) buf400 = reinterpret_tensor(buf362, (4, 4, 1), (4, 1, 1), 0) del buf362 extern_kernels.bmm(buf395, buf399, out=buf400) buf405 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf401 = reinterpret_tensor(buf405, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf351, buf367, buf383, buf400, buf401, 64, XBLOCK=64, num_warps=1, num_stages=1) buf404 = reinterpret_tensor(buf405, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf329, buf404, 64, XBLOCK=64, num_warps=1, num_stages=1) buf407 = buf329 del buf329 extern_kernels.mm(reinterpret_tensor(buf405, (16, 8), (8, 1), 0), reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf407) buf409 = reinterpret_tensor(buf400, (4, 4), (4, 1), 0) del buf400 buf412 = buf409 del buf409 triton_poi_fused_div_mul_relu_sum_20[grid(16)](buf412, buf407, primals_16, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf411 = reinterpret_tensor(buf383, (4, 4), (4, 1), 0) del buf383 extern_kernels.addmm(primals_18, buf410, reinterpret_tensor( primals_17, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf411) buf413 = reinterpret_tensor(buf367, (4, 4), (4, 1), 0) del buf367 extern_kernels.addmm(primals_20, buf412, reinterpret_tensor( primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf413) buf414 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf663 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf406, primals_14, buf414, buf663, 64, XBLOCK=64, num_warps=1, num_stages=1) buf415 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf414, (16, 4), (4, 1), 0), reinterpret_tensor(primals_21, (4, 12), (1, 4), 0), out=buf415) buf416 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf662 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf407, primals_16, buf416, buf662, 64, XBLOCK=64, num_warps=1, num_stages=1) buf417 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf416, (16, 4), (4, 1), 0), reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf417) buf418 = reinterpret_tensor(buf415, (4, 4, 12), (48, 12, 1), 0) del buf415 triton_poi_fused_mul_1[grid(192)](buf418, primals_22, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) buf419 = reinterpret_tensor(buf417, (4, 4, 12), (48, 12, 1), 0) del buf417 triton_poi_fused_mul_1[grid(192)](buf419, primals_24, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) buf420 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf421 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf413, buf418, buf420, buf421, 64, XBLOCK=64, num_warps=1, num_stages=1) buf422 = reinterpret_tensor(buf351, (4, 4, 1), (4, 1, 16), 0) del buf351 triton_poi_fused_bmm_23[grid(16)](buf420, buf422, 16, XBLOCK=16, num_warps=1, num_stages=1) buf423 = reinterpret_tensor(buf399, (4, 1, 4), (4, 16, 1), 0) del buf399 triton_poi_fused_bmm_23[grid(16)](buf421, buf423, 16, XBLOCK=16, num_warps=1, num_stages=1) buf424 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf422, buf423, out=buf424) buf425 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf426 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf411, buf419, buf425, buf426, 64, XBLOCK=64, num_warps=1, num_stages=1) buf427 = reinterpret_tensor(buf423, (4, 4, 1), (4, 1, 16), 0) del buf423 triton_poi_fused_bmm_23[grid(16)](buf425, buf427, 16, XBLOCK=16, num_warps=1, num_stages=1) buf428 = reinterpret_tensor(buf422, (4, 1, 4), (4, 16, 1), 0) del buf422 triton_poi_fused_bmm_23[grid(16)](buf426, buf428, 16, XBLOCK=16, num_warps=1, num_stages=1) buf429 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf427, buf428, out=buf429) buf440 = reinterpret_tensor(buf428, (4, 4, 1), (4, 1, 16), 0) del buf428 triton_poi_fused_bmm_24[grid(16)](buf420, buf440, 16, XBLOCK=16, num_warps=1, num_stages=1) buf441 = reinterpret_tensor(buf427, (4, 1, 4), (4, 16, 1), 0) del buf427 triton_poi_fused_bmm_24[grid(16)](buf421, buf441, 16, XBLOCK=16, num_warps=1, num_stages=1) buf442 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf440, buf441, out=buf442) buf456 = reinterpret_tensor(buf441, (4, 4, 1), (4, 1, 16), 0) del buf441 triton_poi_fused_bmm_25[grid(16)](buf420, buf456, 16, XBLOCK=16, num_warps=1, num_stages=1) buf457 = reinterpret_tensor(buf440, (4, 1, 4), (4, 16, 1), 0) del buf440 triton_poi_fused_bmm_25[grid(16)](buf421, buf457, 16, XBLOCK=16, num_warps=1, num_stages=1) buf458 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf456, buf457, out=buf458) buf472 = reinterpret_tensor(buf457, (4, 4, 1), (4, 1, 16), 0) del buf457 triton_poi_fused_bmm_26[grid(16)](buf420, buf472, 16, XBLOCK=16, num_warps=1, num_stages=1) buf473 = reinterpret_tensor(buf456, (4, 1, 4), (4, 16, 1), 0) del buf456 triton_poi_fused_bmm_26[grid(16)](buf421, buf473, 16, XBLOCK=16, num_warps=1, num_stages=1) buf474 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf472, buf473, out=buf474) buf430 = reinterpret_tensor(buf473, (4, 4, 1), (4, 1, 16), 0) del buf473 buf431 = buf472 del buf472 buf446 = buf361 del buf361 buf447 = buf346 del buf346 buf462 = buf345 del buf345 buf463 = reinterpret_tensor(buf349, (4, 4, 1), (4, 1, 16), 0) del buf349 buf478 = buf396 del buf396 buf479 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_7, buf424, buf442, buf458, buf474, buf430, buf431, buf446, buf447, buf462, buf463, buf478, buf479, 16, XBLOCK=16, num_warps=1, num_stages=1) buf432 = buf424 del buf424 buf448 = buf442 del buf442 buf464 = buf458 del buf458 buf480 = buf474 del buf474 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf432, buf448, buf464, buf480, primals_7, buf430, buf431, buf446, buf447, buf462, buf463, buf478, buf479, 64, XBLOCK=64, num_warps=1, num_stages=1) buf443 = buf479 del buf479 triton_poi_fused_bmm_24[grid(16)](buf425, buf443, 16, XBLOCK=16, num_warps=1, num_stages=1) buf444 = reinterpret_tensor(buf478, (4, 1, 4), (4, 16, 1), 0) del buf478 triton_poi_fused_bmm_24[grid(16)](buf426, buf444, 16, XBLOCK=16, num_warps=1, num_stages=1) buf445 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf443, buf444, out=buf445) buf459 = reinterpret_tensor(buf444, (4, 4, 1), (4, 1, 16), 0) del buf444 triton_poi_fused_bmm_25[grid(16)](buf425, buf459, 16, XBLOCK=16, num_warps=1, num_stages=1) buf460 = reinterpret_tensor(buf443, (4, 1, 4), (4, 16, 1), 0) del buf443 triton_poi_fused_bmm_25[grid(16)](buf426, buf460, 16, XBLOCK=16, num_warps=1, num_stages=1) buf461 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf459, buf460, out=buf461) buf475 = reinterpret_tensor(buf460, (4, 4, 1), (4, 1, 16), 0) del buf460 triton_poi_fused_bmm_26[grid(16)](buf425, buf475, 16, XBLOCK=16, num_warps=1, num_stages=1) buf476 = reinterpret_tensor(buf459, (4, 1, 4), (4, 16, 1), 0) del buf459 triton_poi_fused_bmm_26[grid(16)](buf426, buf476, 16, XBLOCK=16, num_warps=1, num_stages=1) buf477 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf475, buf476, out=buf477) buf433 = reinterpret_tensor(buf476, (4, 4, 1), (4, 1, 16), 0) del buf476 buf434 = buf475 del buf475 buf449 = buf463 del buf463 buf450 = buf462 del buf462 buf465 = buf447 del buf447 buf466 = buf446 del buf446 buf481 = buf431 del buf431 buf482 = buf430 del buf430 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf429, buf445, buf461, buf477, buf433, buf434, buf449, buf450, buf465, buf466, buf481, buf482, 16, XBLOCK=16, num_warps=1, num_stages=1) buf435 = buf429 del buf429 buf451 = buf445 del buf445 buf467 = buf461 del buf461 buf483 = buf477 del buf477 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf435, buf451, buf467, buf483, primals_8, buf433, buf434, buf449, buf450, buf465, buf466, buf481, buf482, 64, XBLOCK=64, num_warps=1, num_stages=1) buf436 = buf482 del buf482 triton_poi_fused_bmm_13[grid(16)](buf418, buf436, 16, XBLOCK=16, num_warps=1, num_stages=1) buf437 = reinterpret_tensor(buf481, (4, 4, 1), (4, 1, 1), 0) del buf481 extern_kernels.bmm(buf432, buf436, out=buf437) buf438 = buf436 del buf436 triton_poi_fused_bmm_13[grid(16)](buf419, buf438, 16, XBLOCK=16, num_warps=1, num_stages=1) buf439 = reinterpret_tensor(buf466, (4, 4, 1), (4, 1, 1), 0) del buf466 extern_kernels.bmm(buf435, buf438, out=buf439) buf452 = buf438 del buf438 triton_poi_fused_bmm_14[grid(16)](buf418, buf452, 16, XBLOCK=16, num_warps=1, num_stages=1) buf453 = reinterpret_tensor(buf465, (4, 4, 1), (4, 1, 1), 0) del buf465 extern_kernels.bmm(buf448, buf452, out=buf453) buf454 = buf452 del buf452 triton_poi_fused_bmm_14[grid(16)](buf419, buf454, 16, XBLOCK=16, num_warps=1, num_stages=1) buf455 = reinterpret_tensor(buf450, (4, 4, 1), (4, 1, 1), 0) del buf450 extern_kernels.bmm(buf451, buf454, out=buf455) buf468 = buf454 del buf454 triton_poi_fused_bmm_15[grid(16)](buf418, buf468, 16, XBLOCK=16, num_warps=1, num_stages=1) buf469 = reinterpret_tensor(buf449, (4, 4, 1), (4, 1, 1), 0) del buf449 extern_kernels.bmm(buf464, buf468, out=buf469) buf470 = buf468 del buf468 triton_poi_fused_bmm_15[grid(16)](buf419, buf470, 16, XBLOCK=16, num_warps=1, num_stages=1) buf471 = reinterpret_tensor(buf434, (4, 4, 1), (4, 1, 1), 0) del buf434 extern_kernels.bmm(buf467, buf470, out=buf471) buf484 = buf470 del buf470 triton_poi_fused_bmm_16[grid(16)](buf418, buf484, 16, XBLOCK=16, num_warps=1, num_stages=1) buf485 = reinterpret_tensor(buf433, (4, 4, 1), (4, 1, 1), 0) del buf433 extern_kernels.bmm(buf480, buf484, out=buf485) buf490 = reinterpret_tensor(buf406, (4, 4, 4), (16, 4, 1), 0) del buf406 triton_poi_fused_add_cat_28[grid(64)](buf490, buf437, buf453, buf469, buf485, primals_14, 64, XBLOCK=64, num_warps=1, num_stages=1) buf487 = reinterpret_tensor(buf485, (4, 4, 1), (4, 1, 16), 0) del buf485 triton_poi_fused_bmm_16[grid(16)](buf419, buf487, 16, XBLOCK=16, num_warps=1, num_stages=1) buf488 = buf469 del buf469 extern_kernels.bmm(buf483, buf487, out=buf488) buf492 = reinterpret_tensor(buf407, (4, 4, 4), (16, 4, 1), 0) del buf407 triton_poi_fused_add_cat_28[grid(64)](buf492, buf439, buf455, buf471, buf488, primals_16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf491 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_26, reinterpret_tensor(buf490, (16, 4), (4, 1), 0), reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf491) buf493 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_28, reinterpret_tensor(buf492, (16, 4), (4, 1), 0), reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf493) buf494 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf661 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf491, buf494, buf661, 64, XBLOCK=64, num_warps=1, num_stages=1) buf495 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf494, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 12), (1, 4), 0), out=buf495) buf496 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf660 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf493, buf496, buf660, 64, XBLOCK=64, num_warps=1, num_stages=1) buf497 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf496, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 12), (1, 4), 0), out=buf497) buf498 = reinterpret_tensor(buf495, (4, 4, 12), (48, 12, 1), 0) del buf495 triton_poi_fused_mul_1[grid(192)](buf498, primals_10, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) del primals_10 buf499 = reinterpret_tensor(buf497, (4, 4, 12), (48, 12, 1), 0) del buf497 triton_poi_fused_mul_1[grid(192)](buf499, primals_12, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) del primals_12 buf500 = reinterpret_tensor(buf488, (4, 4, 1), (4, 1, 16), 0) del buf488 triton_poi_fused_bmm_2[grid(16)](buf498, buf500, 16, XBLOCK=16, num_warps=1, num_stages=1) buf501 = reinterpret_tensor(buf471, (4, 1, 4), (4, 16, 1), 0) del buf471 triton_poi_fused_bmm_3[grid(16)](buf499, buf501, 16, XBLOCK=16, num_warps=1, num_stages=1) buf502 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf500, buf501, out=buf502) buf503 = reinterpret_tensor(buf501, (4, 4, 1), (4, 1, 16), 0) del buf501 triton_poi_fused_bmm_2[grid(16)](buf499, buf503, 16, XBLOCK=16, num_warps=1, num_stages=1) buf504 = reinterpret_tensor(buf500, (4, 1, 4), (4, 16, 1), 0) del buf500 triton_poi_fused_bmm_3[grid(16)](buf498, buf504, 16, XBLOCK=16, num_warps=1, num_stages=1) buf505 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf503, buf504, out=buf505) buf516 = reinterpret_tensor(buf504, (4, 4, 1), (4, 1, 16), 0) del buf504 triton_poi_fused_bmm_4[grid(16)](buf498, buf516, 16, XBLOCK=16, num_warps=1, num_stages=1) buf517 = reinterpret_tensor(buf503, (4, 1, 4), (4, 16, 1), 0) del buf503 triton_poi_fused_bmm_5[grid(16)](buf499, buf517, 16, XBLOCK=16, num_warps=1, num_stages=1) buf518 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf516, buf517, out=buf518) buf532 = reinterpret_tensor(buf517, (4, 4, 1), (4, 1, 16), 0) del buf517 triton_poi_fused_bmm_6[grid(16)](buf498, buf532, 16, XBLOCK=16, num_warps=1, num_stages=1) buf533 = reinterpret_tensor(buf516, (4, 1, 4), (4, 16, 1), 0) del buf516 triton_poi_fused_bmm_7[grid(16)](buf499, buf533, 16, XBLOCK=16, num_warps=1, num_stages=1) buf534 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf532, buf533, out=buf534) buf548 = reinterpret_tensor(buf533, (4, 4, 1), (4, 1, 16), 0) del buf533 triton_poi_fused_bmm_8[grid(16)](buf498, buf548, 16, XBLOCK=16, num_warps=1, num_stages=1) buf549 = reinterpret_tensor(buf532, (4, 1, 4), (4, 16, 1), 0) del buf532 triton_poi_fused_bmm_9[grid(16)](buf499, buf549, 16, XBLOCK=16, num_warps=1, num_stages=1) buf550 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf548, buf549, out=buf550) buf506 = reinterpret_tensor(buf549, (4, 4, 1), (4, 1, 16), 0) del buf549 buf507 = buf548 del buf548 buf522 = reinterpret_tensor(buf455, (4, 4, 1), (4, 1, 16), 0) del buf455 buf523 = reinterpret_tensor(buf439, (4, 4, 1), (4, 1, 16), 0) del buf439 buf538 = buf487 del buf487 buf539 = reinterpret_tensor(buf453, (4, 4, 1), (4, 1, 16), 0) del buf453 buf554 = reinterpret_tensor(buf437, (4, 4, 1), (4, 1, 16), 0) del buf437 buf555 = buf484 del buf484 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf502, buf518, buf534, buf550, buf506, buf507, buf522, buf523, buf538, buf539, buf554, buf555, 16, XBLOCK=16, num_warps=1, num_stages=1) buf508 = buf502 del buf502 buf524 = buf518 del buf518 buf540 = buf534 del buf534 buf556 = buf550 del buf550 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf508, buf524, buf540, buf556, primals_8, buf506, buf507, buf522, buf523, buf538, buf539, buf554, buf555, 64, XBLOCK=64, num_warps=1, num_stages=1) buf519 = buf555 del buf555 triton_poi_fused_bmm_4[grid(16)](buf499, buf519, 16, XBLOCK=16, num_warps=1, num_stages=1) buf520 = reinterpret_tensor(buf554, (4, 1, 4), (4, 16, 1), 0) del buf554 triton_poi_fused_bmm_5[grid(16)](buf498, buf520, 16, XBLOCK=16, num_warps=1, num_stages=1) buf521 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf519, buf520, out=buf521) buf535 = reinterpret_tensor(buf520, (4, 4, 1), (4, 1, 16), 0) del buf520 triton_poi_fused_bmm_6[grid(16)](buf499, buf535, 16, XBLOCK=16, num_warps=1, num_stages=1) buf536 = reinterpret_tensor(buf519, (4, 1, 4), (4, 16, 1), 0) del buf519 triton_poi_fused_bmm_7[grid(16)](buf498, buf536, 16, XBLOCK=16, num_warps=1, num_stages=1) buf537 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf535, buf536, out=buf537) buf509 = reinterpret_tensor(buf536, (4, 4, 1), (4, 1, 16), 0) del buf536 buf510 = buf535 del buf535 buf525 = buf539 del buf539 buf526 = buf538 del buf538 buf541 = buf523 del buf523 buf542 = buf522 del buf522 triton_poi_fused__softmax_eq_masked_fill_12[grid(16)](primals_7, buf505, buf521, buf537, buf509, buf510, buf525, buf526, buf541, buf542, 16, XBLOCK=16, num_warps=1, num_stages=1) buf551 = buf507 del buf507 triton_poi_fused_bmm_8[grid(16)](buf499, buf551, 16, XBLOCK=16, num_warps=1, num_stages=1) buf552 = reinterpret_tensor(buf506, (4, 1, 4), (4, 16, 1), 0) del buf506 triton_poi_fused_bmm_9[grid(16)](buf498, buf552, 16, XBLOCK=16, num_warps=1, num_stages=1) buf553 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf551, buf552, out=buf553) buf512 = reinterpret_tensor(buf552, (4, 4, 1), (4, 1, 16), 0) del buf552 triton_poi_fused_bmm_13[grid(16)](buf499, buf512, 16, XBLOCK=16, num_warps=1, num_stages=1) buf513 = reinterpret_tensor(buf551, (4, 4, 1), (4, 1, 1), 0) del buf551 extern_kernels.bmm(buf508, buf512, out=buf513) buf528 = buf512 del buf512 triton_poi_fused_bmm_14[grid(16)](buf499, buf528, 16, XBLOCK=16, num_warps=1, num_stages=1) buf529 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf524, buf528, out=buf529) buf544 = buf528 del buf528 triton_poi_fused_bmm_15[grid(16)](buf499, buf544, 16, XBLOCK=16, num_warps=1, num_stages=1) buf545 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf540, buf544, out=buf545) buf560 = buf544 del buf544 triton_poi_fused_bmm_16[grid(16)](buf499, buf560, 16, XBLOCK=16, num_warps=1, num_stages=1) buf561 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf556, buf560, out=buf561) buf567 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf562 = reinterpret_tensor(buf567, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf513, buf529, buf545, buf561, buf562, 64, XBLOCK=64, num_warps=1, num_stages=1) buf566 = reinterpret_tensor(buf567, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf491, buf566, 64, XBLOCK=64, num_warps=1, num_stages=1) buf570 = buf491 del buf491 extern_kernels.mm(reinterpret_tensor(buf567, (16, 8), (8, 1), 0), reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf570) buf557 = reinterpret_tensor(buf561, (4, 4, 1), (4, 1, 16), 0) del buf561 buf558 = reinterpret_tensor(buf545, (4, 4, 1), (4, 1, 16), 0) del buf545 buf572 = reinterpret_tensor(buf529, (4, 4), (4, 1), 0) del buf529 buf574 = buf572 del buf572 triton_poi_fused__softmax_div_eq_masked_fill_mul_relu_sum_19[grid(16)]( buf574, primals_7, buf553, buf570, primals_14, buf557, buf558, 16, XBLOCK=16, num_warps=1, num_stages=1) buf511 = buf505 del buf505 buf527 = buf521 del buf521 buf543 = buf537 del buf537 buf559 = buf553 del buf553 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf511, buf527, buf543, buf559, primals_7, buf509, buf510, buf525, buf526, buf541, buf542, buf557, buf558, 64, XBLOCK=64, num_warps=1, num_stages=1) buf514 = buf558 del buf558 triton_poi_fused_bmm_13[grid(16)](buf498, buf514, 16, XBLOCK=16, num_warps=1, num_stages=1) buf515 = reinterpret_tensor(buf557, (4, 4, 1), (4, 1, 1), 0) del buf557 extern_kernels.bmm(buf511, buf514, out=buf515) buf530 = buf514 del buf514 triton_poi_fused_bmm_14[grid(16)](buf498, buf530, 16, XBLOCK=16, num_warps=1, num_stages=1) buf531 = reinterpret_tensor(buf542, (4, 4, 1), (4, 1, 1), 0) del buf542 extern_kernels.bmm(buf527, buf530, out=buf531) buf546 = buf530 del buf530 triton_poi_fused_bmm_15[grid(16)](buf498, buf546, 16, XBLOCK=16, num_warps=1, num_stages=1) buf547 = reinterpret_tensor(buf541, (4, 4, 1), (4, 1, 1), 0) del buf541 extern_kernels.bmm(buf543, buf546, out=buf547) buf563 = buf546 del buf546 triton_poi_fused_bmm_16[grid(16)](buf498, buf563, 16, XBLOCK=16, num_warps=1, num_stages=1) buf564 = reinterpret_tensor(buf526, (4, 4, 1), (4, 1, 1), 0) del buf526 extern_kernels.bmm(buf559, buf563, out=buf564) buf569 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) buf565 = reinterpret_tensor(buf569, (4, 4, 4), (32, 8, 1), 4) triton_poi_fused_cat_17[grid(64)](buf515, buf531, buf547, buf564, buf565, 64, XBLOCK=64, num_warps=1, num_stages=1) buf568 = reinterpret_tensor(buf569, (4, 4, 4), (32, 8, 1), 0) triton_poi_fused_cat_18[grid(64)](buf493, buf568, 64, XBLOCK=64, num_warps=1, num_stages=1) buf571 = buf493 del buf493 extern_kernels.mm(reinterpret_tensor(buf569, (16, 8), (8, 1), 0), reinterpret_tensor(primals_15, (8, 4), (1, 8), 0), out=buf571) buf573 = reinterpret_tensor(buf564, (4, 4), (4, 1), 0) del buf564 buf576 = buf573 del buf573 triton_poi_fused_div_mul_relu_sum_20[grid(16)](buf576, buf571, primals_16, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) buf575 = reinterpret_tensor(buf547, (4, 4), (4, 1), 0) del buf547 extern_kernels.addmm(primals_18, buf574, reinterpret_tensor( primals_17, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf575) del primals_18 buf577 = reinterpret_tensor(buf531, (4, 4), (4, 1), 0) del buf531 extern_kernels.addmm(primals_20, buf576, reinterpret_tensor( primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf577) del primals_20 buf578 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf659 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf570, primals_14, buf578, buf659, 64, XBLOCK=64, num_warps=1, num_stages=1) buf579 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf578, (16, 4), (4, 1), 0), reinterpret_tensor(primals_21, (4, 12), (1, 4), 0), out=buf579) buf580 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf658 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_21[grid(64)](buf571, primals_16, buf580, buf658, 64, XBLOCK=64, num_warps=1, num_stages=1) buf581 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf580, (16, 4), (4, 1), 0), reinterpret_tensor(primals_23, (4, 12), (1, 4), 0), out=buf581) buf582 = reinterpret_tensor(buf579, (4, 4, 12), (48, 12, 1), 0) del buf579 triton_poi_fused_mul_1[grid(192)](buf582, primals_22, primals_7, 192, XBLOCK=256, num_warps=4, num_stages=1) del primals_22 buf583 = reinterpret_tensor(buf581, (4, 4, 12), (48, 12, 1), 0) del buf581 triton_poi_fused_mul_1[grid(192)](buf583, primals_24, primals_8, 192, XBLOCK=256, num_warps=4, num_stages=1) del primals_24 buf584 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf585 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf577, buf582, buf584, buf585, 64, XBLOCK=64, num_warps=1, num_stages=1) buf586 = reinterpret_tensor(buf515, (4, 4, 1), (4, 1, 16), 0) del buf515 triton_poi_fused_bmm_23[grid(16)](buf584, buf586, 16, XBLOCK=16, num_warps=1, num_stages=1) buf587 = reinterpret_tensor(buf563, (4, 1, 4), (4, 16, 1), 0) del buf563 triton_poi_fused_bmm_23[grid(16)](buf585, buf587, 16, XBLOCK=16, num_warps=1, num_stages=1) buf588 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf586, buf587, out=buf588) buf589 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf590 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_22[grid(64)](buf575, buf583, buf589, buf590, 64, XBLOCK=64, num_warps=1, num_stages=1) buf591 = reinterpret_tensor(buf587, (4, 4, 1), (4, 1, 16), 0) del buf587 triton_poi_fused_bmm_23[grid(16)](buf589, buf591, 16, XBLOCK=16, num_warps=1, num_stages=1) buf592 = reinterpret_tensor(buf586, (4, 1, 4), (4, 16, 1), 0) del buf586 triton_poi_fused_bmm_23[grid(16)](buf590, buf592, 16, XBLOCK=16, num_warps=1, num_stages=1) buf593 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf591, buf592, out=buf593) buf604 = reinterpret_tensor(buf592, (4, 4, 1), (4, 1, 16), 0) del buf592 triton_poi_fused_bmm_24[grid(16)](buf584, buf604, 16, XBLOCK=16, num_warps=1, num_stages=1) buf605 = reinterpret_tensor(buf591, (4, 1, 4), (4, 16, 1), 0) del buf591 triton_poi_fused_bmm_24[grid(16)](buf585, buf605, 16, XBLOCK=16, num_warps=1, num_stages=1) buf606 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf604, buf605, out=buf606) buf620 = reinterpret_tensor(buf605, (4, 4, 1), (4, 1, 16), 0) del buf605 triton_poi_fused_bmm_25[grid(16)](buf584, buf620, 16, XBLOCK=16, num_warps=1, num_stages=1) buf621 = reinterpret_tensor(buf604, (4, 1, 4), (4, 16, 1), 0) del buf604 triton_poi_fused_bmm_25[grid(16)](buf585, buf621, 16, XBLOCK=16, num_warps=1, num_stages=1) buf622 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf620, buf621, out=buf622) buf636 = reinterpret_tensor(buf621, (4, 4, 1), (4, 1, 16), 0) del buf621 triton_poi_fused_bmm_26[grid(16)](buf584, buf636, 16, XBLOCK=16, num_warps=1, num_stages=1) buf637 = reinterpret_tensor(buf620, (4, 1, 4), (4, 16, 1), 0) del buf620 triton_poi_fused_bmm_26[grid(16)](buf585, buf637, 16, XBLOCK=16, num_warps=1, num_stages=1) buf638 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf636, buf637, out=buf638) buf594 = reinterpret_tensor(buf637, (4, 4, 1), (4, 1, 16), 0) del buf637 buf595 = buf636 del buf636 buf610 = buf525 del buf525 buf611 = buf510 del buf510 buf626 = buf509 del buf509 buf627 = reinterpret_tensor(buf513, (4, 4, 1), (4, 1, 16), 0) del buf513 buf642 = buf560 del buf560 buf643 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_7, buf588, buf606, buf622, buf638, buf594, buf595, buf610, buf611, buf626, buf627, buf642, buf643, 16, XBLOCK=16, num_warps=1, num_stages=1) buf596 = buf588 del buf588 buf612 = buf606 del buf606 buf628 = buf622 del buf622 buf644 = buf638 del buf638 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf596, buf612, buf628, buf644, primals_7, buf594, buf595, buf610, buf611, buf626, buf627, buf642, buf643, 64, XBLOCK=64, num_warps=1, num_stages=1) buf607 = buf643 del buf643 triton_poi_fused_bmm_24[grid(16)](buf589, buf607, 16, XBLOCK=16, num_warps=1, num_stages=1) buf608 = reinterpret_tensor(buf642, (4, 1, 4), (4, 16, 1), 0) del buf642 triton_poi_fused_bmm_24[grid(16)](buf590, buf608, 16, XBLOCK=16, num_warps=1, num_stages=1) buf609 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf607, buf608, out=buf609) buf623 = reinterpret_tensor(buf608, (4, 4, 1), (4, 1, 16), 0) del buf608 triton_poi_fused_bmm_25[grid(16)](buf589, buf623, 16, XBLOCK=16, num_warps=1, num_stages=1) buf624 = reinterpret_tensor(buf607, (4, 1, 4), (4, 16, 1), 0) del buf607 triton_poi_fused_bmm_25[grid(16)](buf590, buf624, 16, XBLOCK=16, num_warps=1, num_stages=1) buf625 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf623, buf624, out=buf625) buf639 = reinterpret_tensor(buf624, (4, 4, 1), (4, 1, 16), 0) del buf624 triton_poi_fused_bmm_26[grid(16)](buf589, buf639, 16, XBLOCK=16, num_warps=1, num_stages=1) buf640 = reinterpret_tensor(buf623, (4, 1, 4), (4, 16, 1), 0) del buf623 triton_poi_fused_bmm_26[grid(16)](buf590, buf640, 16, XBLOCK=16, num_warps=1, num_stages=1) buf641 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf639, buf640, out=buf641) buf597 = reinterpret_tensor(buf640, (4, 4, 1), (4, 1, 16), 0) del buf640 buf598 = buf639 del buf639 buf613 = buf627 del buf627 buf614 = buf626 del buf626 buf629 = buf611 del buf611 buf630 = buf610 del buf610 buf645 = buf595 del buf595 buf646 = buf594 del buf594 triton_poi_fused__softmax_eq_masked_fill_10[grid(16)](primals_8, buf593, buf609, buf625, buf641, buf597, buf598, buf613, buf614, buf629, buf630, buf645, buf646, 16, XBLOCK=16, num_warps=1, num_stages=1) buf599 = buf593 del buf593 buf615 = buf609 del buf609 buf631 = buf625 del buf625 buf647 = buf641 del buf641 triton_poi_fused__softmax_eq_masked_fill_11[grid(64)](buf599, buf615, buf631, buf647, primals_8, buf597, buf598, buf613, buf614, buf629, buf630, buf645, buf646, 64, XBLOCK=64, num_warps=1, num_stages=1) buf600 = buf646 del buf646 triton_poi_fused_bmm_13[grid(16)](buf582, buf600, 16, XBLOCK=16, num_warps=1, num_stages=1) buf601 = reinterpret_tensor(buf645, (4, 4, 1), (4, 1, 1), 0) del buf645 extern_kernels.bmm(buf596, buf600, out=buf601) buf602 = buf600 del buf600 triton_poi_fused_bmm_13[grid(16)](buf583, buf602, 16, XBLOCK=16, num_warps=1, num_stages=1) buf603 = reinterpret_tensor(buf630, (4, 4, 1), (4, 1, 1), 0) del buf630 extern_kernels.bmm(buf599, buf602, out=buf603) buf616 = buf602 del buf602 triton_poi_fused_bmm_14[grid(16)](buf582, buf616, 16, XBLOCK=16, num_warps=1, num_stages=1) buf617 = reinterpret_tensor(buf629, (4, 4, 1), (4, 1, 1), 0) del buf629 extern_kernels.bmm(buf612, buf616, out=buf617) buf618 = buf616 del buf616 triton_poi_fused_bmm_14[grid(16)](buf583, buf618, 16, XBLOCK=16, num_warps=1, num_stages=1) buf619 = reinterpret_tensor(buf614, (4, 4, 1), (4, 1, 1), 0) del buf614 extern_kernels.bmm(buf615, buf618, out=buf619) buf632 = buf618 del buf618 triton_poi_fused_bmm_15[grid(16)](buf582, buf632, 16, XBLOCK=16, num_warps=1, num_stages=1) buf633 = reinterpret_tensor(buf613, (4, 4, 1), (4, 1, 1), 0) del buf613 extern_kernels.bmm(buf628, buf632, out=buf633) buf634 = buf632 del buf632 triton_poi_fused_bmm_15[grid(16)](buf583, buf634, 16, XBLOCK=16, num_warps=1, num_stages=1) buf635 = reinterpret_tensor(buf598, (4, 4, 1), (4, 1, 1), 0) del buf598 extern_kernels.bmm(buf631, buf634, out=buf635) buf648 = buf634 del buf634 triton_poi_fused_bmm_16[grid(16)](buf582, buf648, 16, XBLOCK=16, num_warps=1, num_stages=1) buf649 = reinterpret_tensor(buf597, (4, 4, 1), (4, 1, 1), 0) del buf597 extern_kernels.bmm(buf644, buf648, out=buf649) del buf648 buf654 = reinterpret_tensor(buf570, (4, 4, 4), (16, 4, 1), 0) del buf570 triton_poi_fused_add_cat_28[grid(64)](buf654, buf601, buf617, buf633, buf649, primals_14, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf601 del buf617 del primals_14 buf651 = reinterpret_tensor(buf649, (4, 4, 1), (4, 1, 16), 0) del buf649 triton_poi_fused_bmm_16[grid(16)](buf583, buf651, 16, XBLOCK=16, num_warps=1, num_stages=1) buf652 = buf633 del buf633 extern_kernels.bmm(buf647, buf651, out=buf652) del buf651 buf656 = reinterpret_tensor(buf571, (4, 4, 4), (16, 4, 1), 0) del buf571 triton_poi_fused_add_cat_28[grid(64)](buf656, buf603, buf619, buf635, buf652, primals_16, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf603 del buf619 del buf635 del buf652 del primals_16 buf655 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_26, reinterpret_tensor(buf654, (16, 4), (4, 1), 0), reinterpret_tensor(primals_25, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf655) del primals_26 buf657 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_28, reinterpret_tensor(buf656, (16, 4), (4, 1), 0), reinterpret_tensor(primals_27, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf657) del primals_28 return (reinterpret_tensor(buf655, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf657, (4, 4, 4), (16, 4, 1), 0), primals_7, primals_8, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (16, 4), (4, 1), 0), reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor( buf4, (16, 4), (4, 1), 0), buf16, buf19, buf32, buf35, buf48, buf51, buf64, buf67, reinterpret_tensor(buf75, (16, 8), (8, 1), 0), reinterpret_tensor(buf77, (16, 8), (8, 1), 0), buf82, buf83, buf84, buf85, reinterpret_tensor(buf86, (16, 4), (4, 1), 0), reinterpret_tensor(buf88, (16, 4), (4, 1), 0), reinterpret_tensor( buf90, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf90, (4, 4, 4), (48, 12, 1), 4), reinterpret_tensor(buf91, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf91, (4, 4, 4), (48, 12, 1), 4), buf104, buf107, buf120, buf123, buf136, buf139, buf152, buf155, reinterpret_tensor(buf162, (16, 4), (4, 1), 0), reinterpret_tensor( buf164, (16, 4), (4, 1), 0), reinterpret_tensor(buf166, (16, 4), (4, 1), 0), reinterpret_tensor(buf168, (16, 4), (4, 1), 0), buf180, buf183, buf196, buf199, buf212, buf215, buf228, buf231, reinterpret_tensor(buf239, (16, 8), (8, 1), 0), reinterpret_tensor( buf241, (16, 8), (8, 1), 0), buf246, buf247, buf248, buf249, reinterpret_tensor(buf250, (16, 4), (4, 1), 0), reinterpret_tensor( buf252, (16, 4), (4, 1), 0), reinterpret_tensor(buf254, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf254, (4, 4, 4), (48, 12, 1), 4), reinterpret_tensor(buf255, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf255, (4, 4, 4), (48, 12, 1), 4), buf268, buf271, buf284, buf287, buf300, buf303, buf316, buf319, reinterpret_tensor(buf326, (16, 4), (4, 1), 0), reinterpret_tensor( buf328, (16, 4), (4, 1), 0), reinterpret_tensor(buf330, (16, 4), (4, 1), 0), reinterpret_tensor(buf332, (16, 4), (4, 1), 0), buf344, buf347, buf360, buf363, buf376, buf379, buf392, buf395, reinterpret_tensor(buf403, (16, 8), (8, 1), 0), reinterpret_tensor( buf405, (16, 8), (8, 1), 0), buf410, buf411, buf412, buf413, reinterpret_tensor(buf414, (16, 4), (4, 1), 0), reinterpret_tensor( buf416, (16, 4), (4, 1), 0), reinterpret_tensor(buf418, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf418, (4, 4, 4), (48, 12, 1), 4), reinterpret_tensor(buf419, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf419, (4, 4, 4), (48, 12, 1), 4), buf432, buf435, buf448, buf451, buf464, buf467, buf480, buf483, reinterpret_tensor(buf490, (16, 4), (4, 1), 0), reinterpret_tensor( buf492, (16, 4), (4, 1), 0), reinterpret_tensor(buf494, (16, 4), (4, 1), 0), reinterpret_tensor(buf496, (16, 4), (4, 1), 0), buf508, buf511, buf524, buf527, buf540, buf543, buf556, buf559, reinterpret_tensor(buf567, (16, 8), (8, 1), 0), reinterpret_tensor( buf569, (16, 8), (8, 1), 0), buf574, buf575, buf576, buf577, reinterpret_tensor(buf578, (16, 4), (4, 1), 0), reinterpret_tensor( buf580, (16, 4), (4, 1), 0), reinterpret_tensor(buf582, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf582, (4, 4, 4), (48, 12, 1), 4), reinterpret_tensor(buf583, (4, 4, 4), (48, 12, 1), 0), reinterpret_tensor(buf583, (4, 4, 4), (48, 12, 1), 4), buf596, buf599, buf612, buf615, buf628, buf631, buf644, buf647, reinterpret_tensor(buf654, (16, 4), (4, 1), 0), reinterpret_tensor( buf656, (16, 4), (4, 1), 0), primals_27, primals_25, reinterpret_tensor(buf583, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf582, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf589, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf590, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf584, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf585, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf583, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf582, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf589, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf590, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf584, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf585, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf583, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf582, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf589, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf590, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf584, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf585, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf583, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf582, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf589, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf590, (4, 4, 1), (16, 4, 1), 0), reinterpret_tensor(buf584, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf585, (4, 4, 1), (16, 4, 1), 0), primals_23, buf658, primals_21, buf659, primals_19, primals_17, primals_15, primals_13, reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf498, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf499, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf498, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf499, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf498, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf499, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf499, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf498, (4, 4, 1), (48, 12, 1), 0), reinterpret_tensor(buf498, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf499, (4, 4, 1), (48, 12, 1), 0), primals_11, buf660, primals_9, buf661, reinterpret_tensor(buf419, (4, 1, 4), ( 48, 1, 12), 11), reinterpret_tensor(buf418, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf425, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf426, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf420, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf421, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf419, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf418, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf425, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf426, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf420, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf421, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf419, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf418, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf425, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf426, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf420, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf421, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf419, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf418, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf425, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf426, (4, 4, 1), (16, 4, 1), 0), reinterpret_tensor(buf420, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf421, (4, 4, 1), (16, 4, 1), 0), buf662, buf663, reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf334, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf335, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf334, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf335, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf334, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf335, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf335, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf334, (4, 4, 1), (48, 12, 1), 0), reinterpret_tensor(buf334, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf335, (4, 4, 1), (48, 12, 1), 0), buf664, buf665, reinterpret_tensor(buf255, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf254, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf262, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf256, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf257, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf255, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf254, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf262, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf256, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf257, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf255, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf254, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf262, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf256, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf257, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf255, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf254, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf261, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf262, (4, 4, 1), (16, 4, 1), 0), reinterpret_tensor(buf256, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf257, (4, 4, 1), (16, 4, 1), 0), buf666, buf667, reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf170, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf171, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf170, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf171, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf170, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf171, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf171, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf170, (4, 4, 1), (48, 12, 1), 0), reinterpret_tensor(buf170, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf171, (4, 4, 1), (48, 12, 1), 0), buf668, buf669, reinterpret_tensor(buf91, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf90, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf97, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf98, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf92, (4, 1, 4), (16, 1, 4), 3), reinterpret_tensor(buf93, (4, 4, 1), (16, 4, 1), 3), reinterpret_tensor(buf91, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf90, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf97, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf98, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf92, (4, 1, 4), (16, 1, 4), 2), reinterpret_tensor(buf93, (4, 4, 1), (16, 4, 1), 2), reinterpret_tensor(buf91, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf90, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf97, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf98, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf92, (4, 1, 4), (16, 1, 4), 1), reinterpret_tensor(buf93, (4, 4, 1), (16, 4, 1), 1), reinterpret_tensor(buf91, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf90, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf97, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf98, (4, 4, 1), (16, 4, 1), 0), reinterpret_tensor(buf92, (4, 1, 4), (16, 1, 4), 0), reinterpret_tensor(buf93, (4, 4, 1), (16, 4, 1), 0), buf670, buf671, reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 11), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf6, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 7), reinterpret_tensor(buf7, (4, 4, 1), (48, 12, 1), 3), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 10), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf6, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 6), reinterpret_tensor(buf7, (4, 4, 1), (48, 12, 1), 2), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 9), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf6, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 5), reinterpret_tensor(buf7, (4, 4, 1), (48, 12, 1), 1), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 8), reinterpret_tensor(buf7, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf6, (4, 4, 1), (48, 12, 1), 0), reinterpret_tensor(buf6, (4, 1, 4), (48, 1, 12), 4), reinterpret_tensor(buf7, (4, 4, 1), (48, 12, 1), 0), buf672, buf673) class DyIntraModalityUpdate(nn.Module): """ Dynamic Intra-modality Attention Flow """ def __init__(self, v_size, q_size, output_size, num_head, drop=0.0): super(DyIntraModalityUpdate, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_head = num_head self.v4q_gate_lin = nn.Linear(v_size, output_size) self.q4v_gate_lin = nn.Linear(q_size, output_size) self.v_lin = nn.Linear(v_size, output_size * 3) self.q_lin = nn.Linear(q_size, output_size * 3) self.v_output = nn.Linear(output_size, output_size) self.q_output = nn.Linear(output_size, output_size) self.relu = nn.ReLU() self.sigmoid = nn.Sigmoid() self.drop = nn.Dropout(drop) def forward(self, v, q, v_mask, q_mask): """ v: visual feature [batch, num_obj, feat_size] q: question [batch, max_len, feat_size] v_mask [batch, num_obj] q_mask [batch, max_len] """ batch_size, num_obj = v_mask.shape _, max_len = q_mask.shape v_mean = (v * v_mask.unsqueeze(2)).sum(1) / v_mask.sum(1).unsqueeze(1) q_mean = (q * q_mask.unsqueeze(2)).sum(1) / q_mask.sum(1).unsqueeze(1) v4q_gate = self.sigmoid(self.v4q_gate_lin(self.drop(self.relu(v_mean))) ).unsqueeze(1) q4v_gate = self.sigmoid(self.q4v_gate_lin(self.drop(self.relu(q_mean))) ).unsqueeze(1) v_trans = self.v_lin(self.drop(self.relu(v))) q_trans = self.q_lin(self.drop(self.relu(q))) v_trans = v_trans * v_mask.unsqueeze(2) q_trans = q_trans * q_mask.unsqueeze(2) v_k, v_q, v_v = torch.split(v_trans, v_trans.size(2) // 3, dim=2) q_k, q_q, q_v = torch.split(q_trans, q_trans.size(2) // 3, dim=2) new_vq = (1 + q4v_gate) * v_q new_vk = (1 + q4v_gate) * v_k new_qq = (1 + v4q_gate) * q_q new_qk = (1 + v4q_gate) * q_k vk_set = torch.split(new_vk, new_vk.size(2) // self.num_head, dim=2) vq_set = torch.split(new_vq, new_vq.size(2) // self.num_head, dim=2) vv_set = torch.split(v_v, v_v.size(2) // self.num_head, dim=2) qk_set = torch.split(new_qk, new_qk.size(2) // self.num_head, dim=2) qq_set = torch.split(new_qq, new_qq.size(2) // self.num_head, dim=2) qv_set = torch.split(q_v, q_v.size(2) // self.num_head, dim=2) for i in range(self.num_head): vk_slice, vq_slice, vv_slice = vk_set[i], vq_set[i], vv_set[i] qk_slice, qq_slice, qv_slice = qk_set[i], qq_set[i], qv_set[i] v2v = (vq_slice @ vk_slice.transpose(1, 2)).masked_fill(v_mask. unsqueeze(1).expand([batch_size, num_obj, num_obj]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 q2q = (qq_slice @ qk_slice.transpose(1, 2)).masked_fill(q_mask. unsqueeze(1).expand([batch_size, max_len, max_len]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 dyIntraMAF_v2v = F.softmax(v2v, dim=2) dyIntraMAF_q2q = F.softmax(q2q, dim=2) v_update = dyIntraMAF_v2v @ vv_slice if i == 0 else torch.cat(( v_update, dyIntraMAF_v2v @ vv_slice), dim=2) q_update = dyIntraMAF_q2q @ qv_slice if i == 0 else torch.cat(( q_update, dyIntraMAF_q2q @ qv_slice), dim=2) updated_v = self.v_output(self.drop(v + v_update)) updated_q = self.q_output(self.drop(q + q_update)) return updated_v, updated_q class InterModalityUpdate(nn.Module): """ Inter-modality Attention Flow """ def __init__(self, v_size, q_size, output_size, num_head, drop=0.0): super(InterModalityUpdate, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_head = num_head self.v_lin = nn.Linear(v_size, output_size * 3) self.q_lin = nn.Linear(q_size, output_size * 3) self.v_output = nn.Linear(output_size + v_size, output_size) self.q_output = nn.Linear(output_size + q_size, output_size) self.relu = nn.ReLU() self.drop = nn.Dropout(drop) def forward(self, v, q, v_mask, q_mask): """ v: visual feature [batch, num_obj, feat_size] q: question [batch, max_len, feat_size] v_mask [batch, num_obj] q_mask [batch, max_len] """ batch_size, num_obj = v_mask.shape _, max_len = q_mask.shape v_trans = self.v_lin(self.drop(self.relu(v))) q_trans = self.q_lin(self.drop(self.relu(q))) v_trans = v_trans * v_mask.unsqueeze(2) q_trans = q_trans * q_mask.unsqueeze(2) v_k, v_q, v_v = torch.split(v_trans, v_trans.size(2) // 3, dim=2) q_k, q_q, q_v = torch.split(q_trans, q_trans.size(2) // 3, dim=2) vk_set = torch.split(v_k, v_k.size(2) // self.num_head, dim=2) vq_set = torch.split(v_q, v_q.size(2) // self.num_head, dim=2) vv_set = torch.split(v_v, v_v.size(2) // self.num_head, dim=2) qk_set = torch.split(q_k, q_k.size(2) // self.num_head, dim=2) qq_set = torch.split(q_q, q_q.size(2) // self.num_head, dim=2) qv_set = torch.split(q_v, q_v.size(2) // self.num_head, dim=2) for i in range(self.num_head): vk_slice, vq_slice, vv_slice = vk_set[i], vq_set[i], vv_set[i] qk_slice, qq_slice, qv_slice = qk_set[i], qq_set[i], qv_set[i] q2v = (vq_slice @ qk_slice.transpose(1, 2)).masked_fill(q_mask. unsqueeze(1).expand([batch_size, num_obj, max_len]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 v2q = (qq_slice @ vk_slice.transpose(1, 2)).masked_fill(v_mask. unsqueeze(1).expand([batch_size, max_len, num_obj]) == 0, - 1000000000.0) / (self.output_size // self.num_head) ** 0.5 interMAF_q2v = F.softmax(q2v, dim=2) interMAF_v2q = F.softmax(v2q, dim=2) v_update = interMAF_q2v @ qv_slice if i == 0 else torch.cat(( v_update, interMAF_q2v @ qv_slice), dim=2) q_update = interMAF_v2q @ vv_slice if i == 0 else torch.cat(( q_update, interMAF_v2q @ vv_slice), dim=2) cat_v = torch.cat((v, v_update), dim=2) cat_q = torch.cat((q, q_update), dim=2) updated_v = self.v_output(self.drop(cat_v)) updated_q = self.q_output(self.drop(cat_q)) return updated_v, updated_q class SingleBlockNew(nn.Module): """ Single Block Inter-/Intra-modality stack multiple times """ def __init__(self, num_block, v_size, q_size, output_size, num_inter_head, num_intra_head, drop=0.0): super(SingleBlockNew, self).__init__() self.v_size = v_size self.q_size = q_size self.output_size = output_size self.num_inter_head = num_inter_head self.num_intra_head = num_intra_head self.num_block = num_block self.v_lin = nn.Linear(v_size, output_size) self.q_lin = nn.Linear(q_size, output_size) self.interBlock = InterModalityUpdate(output_size, output_size, output_size, num_inter_head, drop) self.intraBlock = DyIntraModalityUpdate(output_size, output_size, output_size, num_intra_head, drop) self.drop = nn.Dropout(drop) def forward(self, input_0, input_1, input_2, input_3): primals_2 = self.v_lin.weight primals_3 = self.v_lin.bias primals_5 = self.q_lin.weight primals_6 = self.q_lin.bias primals_9 = self.interBlock.v_lin.weight primals_10 = self.interBlock.v_lin.bias primals_11 = self.interBlock.q_lin.weight primals_12 = self.interBlock.q_lin.bias primals_13 = self.interBlock.v_output.weight primals_14 = self.interBlock.v_output.bias primals_15 = self.interBlock.q_output.weight primals_16 = self.interBlock.q_output.bias primals_7 = self.intraBlock.v4q_gate_lin.weight primals_18 = self.intraBlock.v4q_gate_lin.bias primals_8 = self.intraBlock.q4v_gate_lin.weight primals_20 = self.intraBlock.q4v_gate_lin.bias primals_21 = self.intraBlock.v_lin.weight primals_22 = self.intraBlock.v_lin.bias primals_23 = self.intraBlock.q_lin.weight primals_24 = self.intraBlock.q_lin.bias primals_17 = self.intraBlock.v_output.weight primals_26 = self.intraBlock.v_output.bias primals_19 = self.intraBlock.q_output.weight primals_28 = self.intraBlock.q_output.bias primals_1 = input_0 primals_4 = input_1 primals_25 = input_2 primals_27 = input_3 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]) return output[0], output[1]
TranTony/DFAF-for-VQA.pytorch
SingleBlock
false
12,053
[ "MIT" ]
0
eba1a893e8e5d3d8bf85078611b0bcf4d56eea86
https://github.com/TranTony/DFAF-for-VQA.pytorch/tree/eba1a893e8e5d3d8bf85078611b0bcf4d56eea86
PatchEmbed3D
import torch import torch.nn.functional as F import torch.nn as nn class PatchEmbed3D(nn.Module): """ Video to Patch Embedding. Args: patch_size (int): Patch token size. Default: (2,4,4). in_chans (int): Number of input video channels. Default: 3. embed_dim (int): Number of linear projection output channels. Default: 96. norm_layer (nn.Module, optional): Normalization layer. Default: None """ def __init__(self, patch_size=(2, 4, 4), in_chans=3, embed_dim=96, norm_layer=None): super().__init__() self.patch_size = patch_size self.in_chans = in_chans self.embed_dim = embed_dim self.proj = nn.Conv3d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size) if norm_layer is not None: self.norm = norm_layer(embed_dim) else: self.norm = None def forward(self, x): """Forward function.""" _, _, D, H, W = x.size() if W % self.patch_size[2] != 0: x = F.pad(x, (0, self.patch_size[2] - W % self.patch_size[2])) if H % self.patch_size[1] != 0: x = F.pad(x, (0, 0, 0, self.patch_size[1] - H % self.patch_size[1]) ) if D % self.patch_size[0] != 0: x = F.pad(x, (0, 0, 0, 0, 0, self.patch_size[0] - D % self. patch_size[0])) x = self.proj(x) if self.norm is not None: D, Wh, Ww = x.size(2), x.size(3), x.size(4) x = x.flatten(2).transpose(1, 2) x = self.norm(x) x = x.transpose(1, 2).view(-1, self.embed_dim, D, Wh, Ww) return x def get_inputs(): return [torch.rand([4, 3, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 8192 % 96 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 3, 64, 64, 64), (786432, 262144, 4096, 64, 1)) assert_size_stride(primals_2, (96, 3, 2, 4, 4), (96, 32, 16, 4, 1)) assert_size_stride(primals_3, (96,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(2, 4, 4), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 96, 32, 16, 16), (786432, 8192, 256, 16, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(3145728)](buf1, primals_3, 3145728, XBLOCK=512, num_warps=8, num_stages=1) del primals_3 return buf1, primals_1, primals_2 class PatchEmbed3DNew(nn.Module): """ Video to Patch Embedding. Args: patch_size (int): Patch token size. Default: (2,4,4). in_chans (int): Number of input video channels. Default: 3. embed_dim (int): Number of linear projection output channels. Default: 96. norm_layer (nn.Module, optional): Normalization layer. Default: None """ def __init__(self, patch_size=(2, 4, 4), in_chans=3, embed_dim=96, norm_layer=None): super().__init__() self.patch_size = patch_size self.in_chans = in_chans self.embed_dim = embed_dim self.proj = nn.Conv3d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size) if norm_layer is not None: self.norm = norm_layer(embed_dim) else: self.norm = None def forward(self, input_0): primals_2 = self.proj.weight primals_3 = self.proj.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
acewjh/Video-Swin-Transformer
PatchEmbed3D
false
12,054
[ "Apache-2.0" ]
0
bfbc8dde12e991455b34b921ca45a978b4dbfdbc
https://github.com/acewjh/Video-Swin-Transformer/tree/bfbc8dde12e991455b34b921ca45a978b4dbfdbc
Vgg16
import torch from torch import nn import torch.nn.functional as F class Vgg16(nn.Module): def __init__(self): super(Vgg16, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, stride=1, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) def forward(self, X): h = F.relu(self.conv1_1(X), inplace=True) h = F.relu(self.conv1_2(h), inplace=True) h = F.max_pool2d(h, kernel_size=2, stride=2) h = F.relu(self.conv2_1(h), inplace=True) h = F.relu(self.conv2_2(h), inplace=True) h = F.max_pool2d(h, kernel_size=2, stride=2) h = F.relu(self.conv3_1(h), inplace=True) h = F.relu(self.conv3_2(h), inplace=True) h = F.relu(self.conv3_3(h), inplace=True) h = F.max_pool2d(h, kernel_size=2, stride=2) h = F.relu(self.conv4_1(h), inplace=True) h = F.relu(self.conv4_2(h), inplace=True) h = F.relu(self.conv4_3(h), inplace=True) h = F.relu(self.conv5_1(h), inplace=True) h = F.relu(self.conv5_2(h), inplace=True) h = F.relu(self.conv5_3(h), inplace=True) relu5_3 = h return relu5_3 def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 192 xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 27 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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_4(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_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 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_7(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_8(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_10(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 % 32 x2 = xindex // 2048 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 128 * x1 + 8192 * x2), None) tmp1 = tl.load(in_ptr0 + (64 + x0 + 128 * x1 + 8192 * x2), None) tmp3 = tl.load(in_ptr0 + (4096 + x0 + 128 * x1 + 8192 * x2), None) tmp5 = tl.load(in_ptr0 + (4160 + x0 + 128 * x1 + 8192 * x2), None) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_11(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_12(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 % 16 x2 = xindex // 2048 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 256 * x1 + 8192 * x2), None) tmp1 = tl.load(in_ptr0 + (128 + x0 + 256 * x1 + 8192 * x2), None) tmp3 = tl.load(in_ptr0 + (4096 + x0 + 256 * x1 + 8192 * x2), None) tmp5 = tl.load(in_ptr0 + (4224 + x0 + 256 * x1 + 8192 * x2), None) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_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 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_14(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 % 8 x2 = xindex // 2048 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 8192 * x2), None) tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 8192 * x2), None) tmp3 = tl.load(in_ptr0 + (4096 + x0 + 512 * x1 + 8192 * x2), None) tmp5 = tl.load(in_ptr0 + (4352 + x0 + 512 * x1 + 8192 * x2), None) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_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) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_16(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 64 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 512 y1 = yindex // 512 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 512 * x2 + 32768 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 64 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 512 * x2 + 32768 * y1), tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27) = args args.clear() assert_size_stride(primals_1, (64, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_15, (256,), (1,)) assert_size_stride(primals_16, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_17, (512,), (1,)) assert_size_stride(primals_18, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_19, (512,), (1,)) assert_size_stride(primals_20, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_21, (512,), (1,)) assert_size_stride(primals_22, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_23, (512,), (1,)) assert_size_stride(primals_24, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_25, (512,), (1,)) assert_size_stride(primals_26, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_27, (512,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 3, 3, 3), (27, 1, 9, 3), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(192, 9)](primals_1, buf0, 192, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) triton_poi_fused_1[grid(12, 4096)](primals_3, buf1, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 64, 3, 3), (576, 1, 192, 64), torch. float32) triton_poi_fused_2[grid(4096, 9)](primals_4, buf2, 4096, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((128, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_3[grid(8192, 9)](primals_6, buf3, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_4[grid(16384, 9)](primals_8, buf4, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf5 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_5[grid(32768, 9)](primals_10, buf5, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_10 buf6 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_6[grid(65536, 9)](primals_12, buf6, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf7 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_6[grid(65536, 9)](primals_14, buf7, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_14 buf8 = empty_strided_cuda((512, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_7[grid(131072, 9)](primals_16, buf8, 131072, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_16 buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_8[grid(262144, 9)](primals_18, buf9, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_18 buf10 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_8[grid(262144, 9)](primals_20, buf10, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_20 buf11 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_8[grid(262144, 9)](primals_22, buf11, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_22 buf12 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_8[grid(262144, 9)](primals_24, buf12, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_24 buf13 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_8[grid(262144, 9)](primals_26, buf13, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_26 buf14 = 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(buf14, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_9[grid(1048576)](buf15, primals_2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf16 = extern_kernels.convolution(buf15, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf17 = buf16 del buf16 triton_poi_fused_convolution_relu_9[grid(1048576)](buf17, primals_5, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf18 = empty_strided_cuda((4, 64, 32, 32), (65536, 1, 2048, 64), torch.float32) buf19 = empty_strided_cuda((4, 64, 32, 32), (65536, 1, 2048, 64), torch.int8) triton_poi_fused_max_pool2d_with_indices_10[grid(262144)](buf17, buf18, buf19, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf20 = extern_kernels.convolution(buf18, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_11[grid(524288)](buf21, primals_7, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf22 = extern_kernels.convolution(buf21, buf4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_11[grid(524288)](buf23, primals_9, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf24 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.float32) buf25 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.int8) triton_poi_fused_max_pool2d_with_indices_12[grid(131072)](buf23, buf24, buf25, 131072, XBLOCK=1024, num_warps=4, num_stages=1) buf26 = extern_kernels.convolution(buf24, buf5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf27 = buf26 del buf26 triton_poi_fused_convolution_relu_13[grid(262144)](buf27, primals_11, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf28 = extern_kernels.convolution(buf27, buf6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_13[grid(262144)](buf29, primals_13, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_13 buf30 = extern_kernels.convolution(buf29, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf31 = buf30 del buf30 triton_poi_fused_convolution_relu_13[grid(262144)](buf31, primals_15, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf32 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.float32) buf33 = empty_strided_cuda((4, 256, 8, 8), (16384, 1, 2048, 256), torch.int8) triton_poi_fused_max_pool2d_with_indices_14[grid(65536)](buf31, buf32, buf33, 65536, XBLOCK=512, num_warps=4, num_stages=1) buf34 = extern_kernels.convolution(buf32, buf8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf34, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf35 = buf34 del buf34 triton_poi_fused_convolution_relu_15[grid(131072)](buf35, primals_17, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf36 = extern_kernels.convolution(buf35, buf9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf37 = buf36 del buf36 triton_poi_fused_convolution_relu_15[grid(131072)](buf37, primals_19, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_19 buf38 = extern_kernels.convolution(buf37, buf10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_15[grid(131072)](buf39, primals_21, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_21 buf40 = extern_kernels.convolution(buf39, buf11, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf40, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf41 = buf40 del buf40 triton_poi_fused_convolution_relu_15[grid(131072)](buf41, primals_23, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_23 buf42 = extern_kernels.convolution(buf41, buf12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf42, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf43 = buf42 del buf42 triton_poi_fused_convolution_relu_15[grid(131072)](buf43, primals_25, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_25 buf44 = extern_kernels.convolution(buf43, buf13, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf45 = empty_strided_cuda((4, 512, 8, 8), (32768, 64, 8, 1), torch .float32) buf46 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_16[grid(2048, 64) ](buf44, primals_27, buf45, buf46, 2048, 64, XBLOCK=32, YBLOCK= 32, num_warps=4, num_stages=1) del buf44 del primals_27 return (buf45, buf0, buf1, buf2, buf3, buf4, buf5, buf6, buf7, buf8, buf9, buf10, buf11, buf12, buf13, buf15, buf17, buf18, buf19, buf21, buf23, buf24, buf25, buf27, buf29, buf31, buf32, buf33, buf35, buf37, buf39, buf41, buf43, buf46) class Vgg16New(nn.Module): def __init__(self): super(Vgg16New, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, stride=1, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) def forward(self, input_0): primals_1 = self.conv1_1.weight primals_2 = self.conv1_1.bias primals_4 = self.conv1_2.weight primals_5 = self.conv1_2.bias primals_6 = self.conv2_1.weight primals_7 = self.conv2_1.bias primals_8 = self.conv2_2.weight primals_9 = self.conv2_2.bias primals_10 = self.conv3_1.weight primals_11 = self.conv3_1.bias primals_12 = self.conv3_2.weight primals_13 = self.conv3_2.bias primals_14 = self.conv3_3.weight primals_15 = self.conv3_3.bias primals_16 = self.conv4_1.weight primals_17 = self.conv4_1.bias primals_18 = self.conv4_2.weight primals_19 = self.conv4_2.bias primals_20 = self.conv4_3.weight primals_21 = self.conv4_3.bias primals_22 = self.conv5_1.weight primals_23 = self.conv5_1.bias primals_24 = self.conv5_2.weight primals_25 = self.conv5_2.bias primals_26 = self.conv5_3.weight primals_27 = self.conv5_3.bias primals_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]) return output[0]
YueZHOU0926/MUNIT_3D
Vgg16
false
12,055
[ "MIT" ]
0
5cb22b5f3cb127d5b2c4eea038254a7881bab372
https://github.com/YueZHOU0926/MUNIT_3D/tree/5cb22b5f3cb127d5b2c4eea038254a7881bab372
SequenceBias
import torch import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel from torch.nn.parameter import Parameter class SequenceBias(nn.Module): """ Adds one bias element to the end of the sequence. so if the input has a shape ``(L, N, E)``, where ``L`` is the sequence length, ``N`` is the batch size, and ``E`` is the embedding dimension, the output will have a shape ``(L+1, N, E)``. Attributes: bias (:class:`torch.nn.parameter.Parameter`): the learnable bias of the module of shape ``(E)``, where ``E`` is the embedding dimension. Example: >>> m = SequenceBias(16) >>> input = torch.randn(20, 4, 16) >>> output = m(input) >>> print(output.size()) torch.Size([21, 4, 16]) """ def __init__(self, embed_dim: 'int'): """ Args: embed_dim: Embedding dimension """ super(SequenceBias, self).__init__() self.bias = Parameter(torch.empty(embed_dim)) self._reset_parameters() def _reset_parameters(self): """ assing's Normally distributed random values to bias. """ nn.init.normal_(self.bias) def forward(self, x): _, bsz, _ = x.shape return torch.cat([x, self.bias.repeat(1, bsz, 1)]) def get_inputs(): return [torch.rand([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 import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel from torch.nn.parameter import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 x3 = xindex % 16 x0 = xindex % 4 x4 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x3 + 16 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 5, tl.int64) tmp9 = tl.load(in_ptr1 + x0, tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x4, tmp10, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((5, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(80)](primals_1, primals_2, buf0, 80, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, class SequenceBiasNew(nn.Module): """ Adds one bias element to the end of the sequence. so if the input has a shape ``(L, N, E)``, where ``L`` is the sequence length, ``N`` is the batch size, and ``E`` is the embedding dimension, the output will have a shape ``(L+1, N, E)``. Attributes: bias (:class:`torch.nn.parameter.Parameter`): the learnable bias of the module of shape ``(E)``, where ``E`` is the embedding dimension. Example: >>> m = SequenceBias(16) >>> input = torch.randn(20, 4, 16) >>> output = m(input) >>> print(output.size()) torch.Size([21, 4, 16]) """ def __init__(self, embed_dim: 'int'): """ Args: embed_dim: Embedding dimension """ super(SequenceBiasNew, self).__init__() self.bias = Parameter(torch.empty(embed_dim)) self._reset_parameters() def _reset_parameters(self): """ assing's Normally distributed random values to bias. """ nn.init.normal_(self.bias) def forward(self, input_0): primals_2 = self.bias primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
adriansarstedt/opacus
SequenceBias
false
12,056
[ "Apache-2.0" ]
0
a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
https://github.com/adriansarstedt/opacus/tree/a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
SimpleCNN32Filter
import torch import torch.nn as nn import torch.nn.functional as F class SimpleCNN32Filter(nn.Module): """ Defines a simple CNN arhcitecture with 1 layer """ def __init__(self, num_classes): super().__init__() self.conv1 = nn.Conv2d(3, 32, kernel_size=10, stride=2) self.fc1 = nn.Linear(144 * 32, num_classes) def forward(self, x): x = F.relu(self.conv1(x)) x = x.view(-1, 144 * 32) x = self.fc1(x) return x def get_inputs(): return [torch.rand([4, 3, 32, 32])] def get_init_inputs(): return [[], {'num_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 144 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, None) tl.store(out_ptr0 + x3, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (32, 3, 10, 10), (300, 100, 10, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1)) assert_size_stride(primals_4, (4, 4608), (4608, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 12, 12), (4608, 144, 12, 1)) buf1 = buf0 del buf0 buf3 = empty_strided_cuda((4, 32, 12, 12), (4608, 144, 12, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(18432)]( buf1, primals_2, buf3, 18432, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_2 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (4, 4608), (4608, 1), 0), reinterpret_tensor(primals_4, (4608, 4), (1, 4608), 0), alpha=1, beta=1, out=buf2) del primals_5 return buf2, primals_1, primals_3, reinterpret_tensor(buf1, (4, 4608), (4608, 1), 0), primals_4, buf3 class SimpleCNN32FilterNew(nn.Module): """ Defines a simple CNN arhcitecture with 1 layer """ def __init__(self, num_classes): super().__init__() self.conv1 = nn.Conv2d(3, 32, kernel_size=10, stride=2) self.fc1 = nn.Linear(144 * 32, num_classes) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.fc1.weight primals_5 = self.fc1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
adwaykanhere/df-dn-paper
SimpleCNN32Filter
false
12,057
[ "MIT" ]
0
5df413e06ce33c6be5d005e6d1141de9fcd45cb4
https://github.com/adwaykanhere/df-dn-paper/tree/5df413e06ce33c6be5d005e6d1141de9fcd45cb4
BinaryFocalLossWithLogits
import torch import torch.nn as nn def binary_focal_loss_with_logits(input: 'torch.Tensor', target: 'torch.Tensor', alpha: 'float'=0.25, gamma: 'float'=2.0, reduction: 'str'='none', eps: 'float'=1e-08) ->torch.Tensor: """Function that computes Binary Focal loss. .. math:: \\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t) where: - :math:`p_t` is the model's estimated probability for each class. Args: input (torch.Tensor): input data tensor with shape :math:`(N, 1, *)`. target (torch.Tensor): the target tensor with shape :math:`(N, 1, *)`. alpha (float): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`. Default: 0.25. gamma (float): Focusing parameter :math:`\\gamma >= 0`. Default: 2.0. reduction (str, optional): Specifies the reduction to apply to the. Default: 'none'. eps (float): for numerically stability when dividing. Default: 1e-8. Returns: torch.tensor: the computed loss. Examples: >>> num_classes = 1 >>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'} >>> logits = torch.tensor([[[[6.325]]],[[[5.26]]],[[[87.49]]]]) >>> labels = torch.tensor([[[1.]],[[1.]],[[0.]]]) >>> binary_focal_loss_with_logits(logits, labels, **kwargs) tensor(4.6052) """ if not isinstance(input, torch.Tensor): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(input))) if not len(input.shape) >= 2: raise ValueError('Invalid input shape, we expect BxCx*. Got: {}'. format(input.shape)) if input.size(0) != target.size(0): raise ValueError( 'Expected input batch_size ({}) to match target batch_size ({}).' .format(input.size(0), target.size(0))) probs = torch.sigmoid(input) target = target.unsqueeze(dim=1) loss_tmp = -alpha * torch.pow(1.0 - probs, gamma) * target * torch.log( probs + eps) - (1 - alpha) * torch.pow(probs, gamma) * (1.0 - target ) * torch.log(1.0 - probs + eps) loss_tmp = loss_tmp.squeeze(dim=1) if reduction == 'none': loss = loss_tmp elif reduction == 'mean': loss = torch.mean(loss_tmp) elif reduction == 'sum': loss = torch.sum(loss_tmp) else: raise NotImplementedError('Invalid reduction mode: {}'.format( reduction)) return loss class BinaryFocalLossWithLogits(nn.Module): """Criterion that computes Focal loss. According to :cite:`lin2017focal`, the Focal loss is computed as follows: .. math:: \\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t) where: - :math:`p_t` is the model's estimated probability for each class. Args: alpha (float): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`. gamma (float): Focusing parameter :math:`\\gamma >= 0`. reduction (str, optional): Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the sum of the output will be divided by the number of elements in the output, ‘sum’: the output will be summed. Default: ‘none’. Shape: - Input: :math:`(N, 1, *)`. - Target: :math:`(N, 1, *)`. Examples: >>> N = 1 # num_classes >>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'} >>> loss = BinaryFocalLossWithLogits(**kwargs) >>> input = torch.randn(1, N, 3, 5, requires_grad=True) >>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N) >>> output = loss(input, target) >>> output.backward() """ def __init__(self, alpha: 'float', gamma: 'float'=2.0, reduction: 'str' ='none') ->None: super(BinaryFocalLossWithLogits, self).__init__() self.alpha: 'float' = alpha self.gamma: 'float' = gamma self.reduction: 'str' = reduction self.eps: 'float' = 1e-08 def forward(self, input: 'torch.Tensor', target: 'torch.Tensor' ) ->torch.Tensor: return binary_focal_loss_with_logits(input, target, self.alpha, self.gamma, self.reduction, self.eps) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_log_mul_pow_rsub_sigmoid_squeeze_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex % 256 x0 = xindex % 64 x2 = xindex // 256 x4 = xindex tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.sigmoid(tmp0) tmp2 = 1.0 tmp3 = tmp2 - tmp1 tmp4 = tmp3 * tmp3 tmp5 = -4.0 tmp6 = tmp4 * tmp5 tmp8 = tmp6 * tmp7 tmp9 = 1e-08 tmp10 = tmp1 + tmp9 tmp11 = tl_math.log(tmp10) tmp12 = tmp8 * tmp11 tmp13 = tmp1 * tmp1 tmp14 = -3.0 tmp15 = tmp13 * tmp14 tmp16 = tmp2 - tmp7 tmp17 = tmp15 * tmp16 tmp18 = tmp3 + tmp9 tmp19 = tl_math.log(tmp18) tmp20 = tmp17 * tmp19 tmp21 = tmp12 - tmp20 tl.store(out_ptr0 + x4, tmp21, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_log_mul_pow_rsub_sigmoid_squeeze_sub_0[grid(1024) ](arg0_1, arg1_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1 ) del arg0_1 del arg1_1 return buf0, def binary_focal_loss_with_logits(input: 'torch.Tensor', target: 'torch.Tensor', alpha: 'float'=0.25, gamma: 'float'=2.0, reduction: 'str'='none', eps: 'float'=1e-08) ->torch.Tensor: """Function that computes Binary Focal loss. .. math:: \\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t) where: - :math:`p_t` is the model's estimated probability for each class. Args: input (torch.Tensor): input data tensor with shape :math:`(N, 1, *)`. target (torch.Tensor): the target tensor with shape :math:`(N, 1, *)`. alpha (float): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`. Default: 0.25. gamma (float): Focusing parameter :math:`\\gamma >= 0`. Default: 2.0. reduction (str, optional): Specifies the reduction to apply to the. Default: 'none'. eps (float): for numerically stability when dividing. Default: 1e-8. Returns: torch.tensor: the computed loss. Examples: >>> num_classes = 1 >>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'} >>> logits = torch.tensor([[[[6.325]]],[[[5.26]]],[[[87.49]]]]) >>> labels = torch.tensor([[[1.]],[[1.]],[[0.]]]) >>> binary_focal_loss_with_logits(logits, labels, **kwargs) tensor(4.6052) """ if not isinstance(input, torch.Tensor): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(input))) if not len(input.shape) >= 2: raise ValueError('Invalid input shape, we expect BxCx*. Got: {}'. format(input.shape)) if input.size(0) != target.size(0): raise ValueError( 'Expected input batch_size ({}) to match target batch_size ({}).' .format(input.size(0), target.size(0))) probs = torch.sigmoid(input) target = target.unsqueeze(dim=1) loss_tmp = -alpha * torch.pow(1.0 - probs, gamma) * target * torch.log( probs + eps) - (1 - alpha) * torch.pow(probs, gamma) * (1.0 - target ) * torch.log(1.0 - probs + eps) loss_tmp = loss_tmp.squeeze(dim=1) if reduction == 'none': loss = loss_tmp elif reduction == 'mean': loss = torch.mean(loss_tmp) elif reduction == 'sum': loss = torch.sum(loss_tmp) else: raise NotImplementedError('Invalid reduction mode: {}'.format( reduction)) return loss class BinaryFocalLossWithLogitsNew(nn.Module): """Criterion that computes Focal loss. According to :cite:`lin2017focal`, the Focal loss is computed as follows: .. math:: \\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t) where: - :math:`p_t` is the model's estimated probability for each class. Args: alpha (float): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`. gamma (float): Focusing parameter :math:`\\gamma >= 0`. reduction (str, optional): Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the sum of the output will be divided by the number of elements in the output, ‘sum’: the output will be summed. Default: ‘none’. Shape: - Input: :math:`(N, 1, *)`. - Target: :math:`(N, 1, *)`. Examples: >>> N = 1 # num_classes >>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'} >>> loss = BinaryFocalLossWithLogits(**kwargs) >>> input = torch.randn(1, N, 3, 5, requires_grad=True) >>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N) >>> output = loss(input, target) >>> output.backward() """ def __init__(self, alpha: 'float', gamma: 'float'=2.0, reduction: 'str' ='none') ->None: super(BinaryFocalLossWithLogitsNew, self).__init__() self.alpha: 'float' = alpha self.gamma: 'float' = gamma self.reduction: 'str' = reduction self.eps: 'float' = 1e-08 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
adi1999/kornia
BinaryFocalLossWithLogits
false
12,058
[ "ECL-2.0", "Apache-2.0" ]
0
bb476a36e2725d687d1879b5a0d877c1ba860c25
https://github.com/adi1999/kornia/tree/bb476a36e2725d687d1879b5a0d877c1ba860c25
NeuralNetwork
import torch import torch.nn as nn class NeuralNetwork(nn.Module): def __init__(self, in_dim, out_dim, hidden_dim=None): """ Simple two-layer neural network. """ super(NeuralNetwork, self).__init__() if hidden_dim is None: hidden_dim = in_dim * 2 self.l1 = nn.Linear(in_dim, hidden_dim) self.ac1 = nn.LeakyReLU() self.l2 = nn.Linear(hidden_dim, out_dim) self.ac2 = nn.Softmax(dim=0) def forward(self, x): x = self.ac1(self.l1(x.float())) return self.ac2(self.l2(x)) 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._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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.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_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (192 + x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_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 x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (64 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (128 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (192 + x0), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (8, 4), (4, 1)) assert_size_stride(primals_3, (8,), (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 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 8), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(512)](buf0, primals_3, buf1, buf2, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_3 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 8), ( 8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf3) del primals_5 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused__softmax_2[grid(256)](buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf4 return buf5, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 8), (8, 1), 0), buf5, primals_4 class NeuralNetworkNew(nn.Module): def __init__(self, in_dim, out_dim, hidden_dim=None): """ Simple two-layer neural network. """ super(NeuralNetworkNew, self).__init__() if hidden_dim is None: hidden_dim = in_dim * 2 self.l1 = nn.Linear(in_dim, hidden_dim) self.ac1 = nn.LeakyReLU() self.l2 = nn.Linear(hidden_dim, out_dim) self.ac2 = nn.Softmax(dim=0) def forward(self, input_0): primals_2 = self.l1.weight primals_3 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
adewynter/Lightboard
NeuralNetwork
false
12,059
[ "Apache-2.0" ]
0
f02eae64f11a989030b52314aa66709477274eb3
https://github.com/adewynter/Lightboard/tree/f02eae64f11a989030b52314aa66709477274eb3
bodypose_model
import torch from collections import OrderedDict import torch.nn as nn def make_layers(block, no_relu_layers): layers = [] for layer_name, v in block.items(): if 'pool' in layer_name: layer = nn.MaxPool2d(kernel_size=v[0], stride=v[1], padding=v[2]) layers.append((layer_name, layer)) else: conv2d = nn.Conv2d(in_channels=v[0], out_channels=v[1], kernel_size=v[2], stride=v[3], padding=v[4]) layers.append((layer_name, conv2d)) if layer_name not in no_relu_layers: layers.append(('relu_' + layer_name, nn.ReLU(inplace=True))) return nn.Sequential(OrderedDict(layers)) class bodypose_model(nn.Module): def __init__(self): super(bodypose_model, self).__init__() no_relu_layers = ['conv5_5_CPM_L1', 'conv5_5_CPM_L2', 'Mconv7_stage2_L1', 'Mconv7_stage2_L2', 'Mconv7_stage3_L1', 'Mconv7_stage3_L2', 'Mconv7_stage4_L1', 'Mconv7_stage4_L2', 'Mconv7_stage5_L1', 'Mconv7_stage5_L2', 'Mconv7_stage6_L1', 'Mconv7_stage6_L1'] blocks = {} block0 = OrderedDict({'conv1_1': [3, 64, 3, 1, 1], 'conv1_2': [64, 64, 3, 1, 1], 'pool1_stage1': [2, 2, 0], 'conv2_1': [64, 128, 3, 1, 1], 'conv2_2': [128, 128, 3, 1, 1], 'pool2_stage1': [2, 2, 0 ], 'conv3_1': [128, 256, 3, 1, 1], 'conv3_2': [256, 256, 3, 1, 1], 'conv3_3': [256, 256, 3, 1, 1], 'conv3_4': [256, 256, 3, 1, 1], 'pool3_stage1': [2, 2, 0], 'conv4_1': [256, 512, 3, 1, 1], 'conv4_2': [512, 512, 3, 1, 1], 'conv4_3_CPM': [512, 256, 3, 1, 1], 'conv4_4_CPM': [256, 128, 3, 1, 1]}) block1_1 = OrderedDict({'conv5_1_CPM_L1': [128, 128, 3, 1, 1], 'conv5_2_CPM_L1': [128, 128, 3, 1, 1], 'conv5_3_CPM_L1': [128, 128, 3, 1, 1], 'conv5_4_CPM_L1': [128, 512, 1, 1, 0], 'conv5_5_CPM_L1': [512, 38, 1, 1, 0]}) block1_2 = OrderedDict({'conv5_1_CPM_L2': [128, 128, 3, 1, 1], 'conv5_2_CPM_L2': [128, 128, 3, 1, 1], 'conv5_3_CPM_L2': [128, 128, 3, 1, 1], 'conv5_4_CPM_L2': [128, 512, 1, 1, 0], 'conv5_5_CPM_L2': [512, 19, 1, 1, 0]}) blocks['block1_1'] = block1_1 blocks['block1_2'] = block1_2 self.model0 = make_layers(block0, no_relu_layers) for i in range(2, 7): blocks['block%d_1' % i] = OrderedDict({('Mconv1_stage%d_L1' % i ): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L1' % i): [128, 128, 7, 1, 3], ('Mconv3_stage%d_L1' % i): [128, 128, 7, 1, 3], ('Mconv4_stage%d_L1' % i): [128, 128, 7, 1, 3], ( 'Mconv5_stage%d_L1' % i): [128, 128, 7, 1, 3], ( 'Mconv6_stage%d_L1' % i): [128, 128, 1, 1, 0], ( 'Mconv7_stage%d_L1' % i): [128, 38, 1, 1, 0]}) blocks['block%d_2' % i] = OrderedDict({('Mconv1_stage%d_L2' % i ): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L2' % i): [128, 128, 7, 1, 3], ('Mconv3_stage%d_L2' % i): [128, 128, 7, 1, 3], ('Mconv4_stage%d_L2' % i): [128, 128, 7, 1, 3], ( 'Mconv5_stage%d_L2' % i): [128, 128, 7, 1, 3], ( 'Mconv6_stage%d_L2' % i): [128, 128, 1, 1, 0], ( 'Mconv7_stage%d_L2' % i): [128, 19, 1, 1, 0]}) for k in blocks.keys(): blocks[k] = make_layers(blocks[k], no_relu_layers) self.model1_1 = blocks['block1_1'] self.model2_1 = blocks['block2_1'] self.model3_1 = blocks['block3_1'] self.model4_1 = blocks['block4_1'] self.model5_1 = blocks['block5_1'] self.model6_1 = blocks['block6_1'] self.model1_2 = blocks['block1_2'] self.model2_2 = blocks['block2_2'] self.model3_2 = blocks['block3_2'] self.model4_2 = blocks['block4_2'] self.model5_2 = blocks['block5_2'] self.model6_2 = blocks['block6_2'] def forward(self, x): out1 = self.model0(x) out1_1 = self.model1_1(out1) out1_2 = self.model1_2(out1) out2 = torch.cat([out1_1, out1_2, out1], 1) out2_1 = self.model2_1(out2) out2_2 = self.model2_2(out2) out3 = torch.cat([out2_1, out2_2, out1], 1) out3_1 = self.model3_1(out3) out3_2 = self.model3_2(out3) out4 = torch.cat([out3_1, out3_2, out1], 1) out4_1 = self.model4_1(out4) out4_2 = self.model4_2(out4) out5 = torch.cat([out4_1, out4_2, out1], 1) out5_1 = self.model5_1(out5) out5_2 = self.model5_2(out5) out6 = torch.cat([out5_1, out5_2, out1], 1) out6_1 = self.model6_1(out6) out6_2 = self.model6_2(out6) return out6_1, out6_2 def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from collections import OrderedDict import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy ='evict_last') 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_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 64 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x1), None, eviction_policy ='evict_last') tmp5 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x1), None, eviction_policy ='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 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 % 8 x1 = xindex // 8 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 32 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 32 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + 2 * x0 + 32 * x1), None, eviction_policy ='evict_last') tmp5 = tl.load(in_ptr0 + (17 + 2 * x0 + 32 * x1), None, eviction_policy ='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_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 // 64 % 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_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) 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_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 // 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_cat_9(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 47360 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 64 % 185 x0 = xindex % 64 x2 = xindex // 11840 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 38, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x1 + 2432 * x2), tmp4 & xmask, other=0.0) tmp6 = tl.load(in_ptr1 + x1, 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], 57, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (x0 + 64 * (-38 + x1) + 1216 * x2), tmp13 & xmask, other=0.0) tmp15 = tl.load(in_ptr3 + (-38 + x1), tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tl.full([1], 185, tl.int64) tmp22 = tl.load(in_ptr4 + (x0 + 64 * (-57 + x1) + 8192 * x2), tmp19 & xmask, other=0.0) tmp23 = tl.where(tmp13, tmp18, tmp22) tmp24 = tl.where(tmp4, tmp9, tmp23) tl.store(out_ptr0 + x3, tmp24, xmask) @triton.jit def triton_poi_fused_convolution_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 9728 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 38 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_11(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4864 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x1 = xindex // 64 % 19 x2 = xindex // 1216 x3 = xindex % 1216 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + (x3 + 1280 * 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, 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, primals_171, primals_172, primals_173, primals_174, primals_175, primals_176, primals_177, primals_178, primals_179, primals_180, primals_181, primals_182, primals_183, primals_184, primals_185) = args args.clear() assert_size_stride(primals_1, (64, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_15, (256,), (1,)) assert_size_stride(primals_16, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_17, (256,), (1,)) assert_size_stride(primals_18, (512, 256, 3, 3), (2304, 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, (256, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_23, (256,), (1,)) assert_size_stride(primals_24, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_25, (128,), (1,)) assert_size_stride(primals_26, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_27, (128,), (1,)) assert_size_stride(primals_28, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_29, (128,), (1,)) assert_size_stride(primals_30, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_31, (128,), (1,)) assert_size_stride(primals_32, (512, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_33, (512,), (1,)) assert_size_stride(primals_34, (38, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_35, (38,), (1,)) assert_size_stride(primals_36, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_37, (128,), (1,)) assert_size_stride(primals_38, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_39, (128,), (1,)) assert_size_stride(primals_40, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_41, (128,), (1,)) assert_size_stride(primals_42, (512, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_43, (512,), (1,)) assert_size_stride(primals_44, (19, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_45, (19,), (1,)) assert_size_stride(primals_46, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_47, (128,), (1,)) assert_size_stride(primals_48, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_49, (128,), (1,)) assert_size_stride(primals_50, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_51, (128,), (1,)) assert_size_stride(primals_52, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_53, (128,), (1,)) assert_size_stride(primals_54, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_55, (128,), (1,)) assert_size_stride(primals_56, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_57, (128,), (1,)) assert_size_stride(primals_58, (38, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_59, (38,), (1,)) assert_size_stride(primals_60, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_61, (128,), (1,)) assert_size_stride(primals_62, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_63, (128,), (1,)) assert_size_stride(primals_64, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_65, (128,), (1,)) assert_size_stride(primals_66, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_67, (128,), (1,)) assert_size_stride(primals_68, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_69, (128,), (1,)) assert_size_stride(primals_70, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_71, (128,), (1,)) assert_size_stride(primals_72, (19, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_73, (19,), (1,)) assert_size_stride(primals_74, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_75, (128,), (1,)) assert_size_stride(primals_76, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_77, (128,), (1,)) assert_size_stride(primals_78, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_79, (128,), (1,)) assert_size_stride(primals_80, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_81, (128,), (1,)) assert_size_stride(primals_82, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_83, (128,), (1,)) assert_size_stride(primals_84, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_85, (128,), (1,)) assert_size_stride(primals_86, (38, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_87, (38,), (1,)) assert_size_stride(primals_88, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_89, (128,), (1,)) assert_size_stride(primals_90, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_91, (128,), (1,)) assert_size_stride(primals_92, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_93, (128,), (1,)) assert_size_stride(primals_94, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_95, (128,), (1,)) assert_size_stride(primals_96, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_97, (128,), (1,)) assert_size_stride(primals_98, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_99, (128,), (1,)) assert_size_stride(primals_100, (19, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_101, (19,), (1,)) assert_size_stride(primals_102, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_103, (128,), (1,)) assert_size_stride(primals_104, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_105, (128,), (1,)) assert_size_stride(primals_106, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_107, (128,), (1,)) assert_size_stride(primals_108, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_109, (128,), (1,)) assert_size_stride(primals_110, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_111, (128,), (1,)) assert_size_stride(primals_112, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_113, (128,), (1,)) assert_size_stride(primals_114, (38, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_115, (38,), (1,)) assert_size_stride(primals_116, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_117, (128,), (1,)) assert_size_stride(primals_118, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_119, (128,), (1,)) assert_size_stride(primals_120, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_121, (128,), (1,)) assert_size_stride(primals_122, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_123, (128,), (1,)) assert_size_stride(primals_124, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_125, (128,), (1,)) assert_size_stride(primals_126, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_127, (128,), (1,)) assert_size_stride(primals_128, (19, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_129, (19,), (1,)) assert_size_stride(primals_130, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_131, (128,), (1,)) assert_size_stride(primals_132, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_133, (128,), (1,)) assert_size_stride(primals_134, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_135, (128,), (1,)) assert_size_stride(primals_136, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_137, (128,), (1,)) assert_size_stride(primals_138, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_139, (128,), (1,)) assert_size_stride(primals_140, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_141, (128,), (1,)) assert_size_stride(primals_142, (38, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_143, (38,), (1,)) assert_size_stride(primals_144, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_145, (128,), (1,)) assert_size_stride(primals_146, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_147, (128,), (1,)) assert_size_stride(primals_148, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_149, (128,), (1,)) assert_size_stride(primals_150, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_151, (128,), (1,)) assert_size_stride(primals_152, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_153, (128,), (1,)) assert_size_stride(primals_154, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_155, (128,), (1,)) assert_size_stride(primals_156, (19, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_157, (19,), (1,)) assert_size_stride(primals_158, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_159, (128,), (1,)) assert_size_stride(primals_160, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_161, (128,), (1,)) assert_size_stride(primals_162, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_163, (128,), (1,)) assert_size_stride(primals_164, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_165, (128,), (1,)) assert_size_stride(primals_166, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_167, (128,), (1,)) assert_size_stride(primals_168, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_169, (128,), (1,)) assert_size_stride(primals_170, (38, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_171, (38,), (1,)) assert_size_stride(primals_172, (128, 185, 7, 7), (9065, 49, 7, 1)) assert_size_stride(primals_173, (128,), (1,)) assert_size_stride(primals_174, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_175, (128,), (1,)) assert_size_stride(primals_176, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_177, (128,), (1,)) assert_size_stride(primals_178, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_179, (128,), (1,)) assert_size_stride(primals_180, (128, 128, 7, 7), (6272, 49, 7, 1)) assert_size_stride(primals_181, (128,), (1,)) assert_size_stride(primals_182, (128, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_183, (128,), (1,)) assert_size_stride(primals_184, (19, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_185, (19,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1048576)](buf1, primals_2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(1048576)](buf3, primals_5, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.float32) buf5 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(262144)](buf3, buf4, buf5, 262144, 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, 32, 32), (131072, 1024, 32, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_2[grid(524288)](buf7, primals_7, 524288, XBLOCK=1024, num_warps=4, 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, 32, 32), (131072, 1024, 32, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_2[grid(524288)](buf9, primals_9, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(131072)](buf9, buf10, buf11, 131072, 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, 16, 16), (65536, 256, 16, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_4[grid(262144)](buf13, primals_11, 262144, XBLOCK=1024, num_warps=4, 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, 16, 16), (65536, 256, 16, 1)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_4[grid(262144)](buf15, primals_13, 262144, XBLOCK=1024, num_warps=4, 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, 16, 16), (65536, 256, 16, 1)) buf17 = buf16 del buf16 triton_poi_fused_convolution_relu_4[grid(262144)](buf17, primals_15, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf18 = extern_kernels.convolution(buf17, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 256, 16, 16), (65536, 256, 16, 1)) buf19 = buf18 del buf18 triton_poi_fused_convolution_relu_4[grid(262144)](buf19, primals_17, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf20 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .float32) buf21 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_5[grid(65536)](buf19, buf20, buf21, 65536, XBLOCK=256, num_warps=4, num_stages=1) buf22 = extern_kernels.convolution(buf20, 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, 8, 8), (32768, 64, 8, 1)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_6[grid(131072)](buf23, primals_19, 131072, 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, 8, 8), (32768, 64, 8, 1)) buf25 = buf24 del buf24 triton_poi_fused_convolution_relu_6[grid(131072)](buf25, primals_21, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_21 buf26 = extern_kernels.convolution(buf25, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 256, 8, 8), (16384, 64, 8, 1)) buf27 = buf26 del buf26 triton_poi_fused_convolution_relu_7[grid(65536)](buf27, primals_23, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_23 buf28 = extern_kernels.convolution(buf27, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 128, 8, 8), (8192, 64, 8, 1)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_8[grid(32768)](buf29, primals_25, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_25 buf30 = extern_kernels.convolution(buf29, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 128, 8, 8), (8192, 64, 8, 1)) buf31 = buf30 del buf30 triton_poi_fused_convolution_relu_8[grid(32768)](buf31, primals_27, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_27 buf32 = extern_kernels.convolution(buf31, primals_28, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 128, 8, 8), (8192, 64, 8, 1)) buf33 = buf32 del buf32 triton_poi_fused_convolution_relu_8[grid(32768)](buf33, primals_29, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_29 buf34 = extern_kernels.convolution(buf33, primals_30, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf34, (4, 128, 8, 8), (8192, 64, 8, 1)) buf35 = buf34 del buf34 triton_poi_fused_convolution_relu_8[grid(32768)](buf35, primals_31, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_31 buf36 = extern_kernels.convolution(buf35, primals_32, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 512, 8, 8), (32768, 64, 8, 1)) buf37 = buf36 del buf36 triton_poi_fused_convolution_relu_6[grid(131072)](buf37, primals_33, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_33 buf38 = extern_kernels.convolution(buf37, primals_34, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 38, 8, 8), (2432, 64, 8, 1)) buf39 = extern_kernels.convolution(buf29, primals_36, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf39, (4, 128, 8, 8), (8192, 64, 8, 1)) buf40 = buf39 del buf39 triton_poi_fused_convolution_relu_8[grid(32768)](buf40, primals_37, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_37 buf41 = extern_kernels.convolution(buf40, primals_38, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf41, (4, 128, 8, 8), (8192, 64, 8, 1)) buf42 = buf41 del buf41 triton_poi_fused_convolution_relu_8[grid(32768)](buf42, primals_39, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_39 buf43 = extern_kernels.convolution(buf42, primals_40, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf43, (4, 128, 8, 8), (8192, 64, 8, 1)) buf44 = buf43 del buf43 triton_poi_fused_convolution_relu_8[grid(32768)](buf44, primals_41, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_41 buf45 = extern_kernels.convolution(buf44, primals_42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf45, (4, 512, 8, 8), (32768, 64, 8, 1)) buf46 = buf45 del buf45 triton_poi_fused_convolution_relu_6[grid(131072)](buf46, primals_43, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_43 buf47 = extern_kernels.convolution(buf46, primals_44, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf47, (4, 19, 8, 8), (1216, 64, 8, 1)) buf48 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch .float32) triton_poi_fused_cat_9[grid(47360)](buf38, primals_35, buf47, primals_45, buf29, buf48, 47360, XBLOCK=512, num_warps=4, num_stages=1) del buf38 del buf47 del primals_35 del primals_45 buf49 = extern_kernels.convolution(buf48, primals_46, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf49, (4, 128, 8, 8), (8192, 64, 8, 1)) buf50 = buf49 del buf49 triton_poi_fused_convolution_relu_8[grid(32768)](buf50, primals_47, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_47 buf51 = extern_kernels.convolution(buf50, primals_48, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf51, (4, 128, 8, 8), (8192, 64, 8, 1)) buf52 = buf51 del buf51 triton_poi_fused_convolution_relu_8[grid(32768)](buf52, primals_49, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_49 buf53 = extern_kernels.convolution(buf52, primals_50, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf53, (4, 128, 8, 8), (8192, 64, 8, 1)) buf54 = buf53 del buf53 triton_poi_fused_convolution_relu_8[grid(32768)](buf54, primals_51, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_51 buf55 = extern_kernels.convolution(buf54, primals_52, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf55, (4, 128, 8, 8), (8192, 64, 8, 1)) buf56 = buf55 del buf55 triton_poi_fused_convolution_relu_8[grid(32768)](buf56, primals_53, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_53 buf57 = extern_kernels.convolution(buf56, primals_54, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf57, (4, 128, 8, 8), (8192, 64, 8, 1)) buf58 = buf57 del buf57 triton_poi_fused_convolution_relu_8[grid(32768)](buf58, primals_55, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_55 buf59 = extern_kernels.convolution(buf58, primals_56, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf59, (4, 128, 8, 8), (8192, 64, 8, 1)) buf60 = buf59 del buf59 triton_poi_fused_convolution_relu_8[grid(32768)](buf60, primals_57, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_57 buf61 = extern_kernels.convolution(buf60, primals_58, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 38, 8, 8), (2432, 64, 8, 1)) buf62 = extern_kernels.convolution(buf48, primals_60, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 128, 8, 8), (8192, 64, 8, 1)) buf63 = buf62 del buf62 triton_poi_fused_convolution_relu_8[grid(32768)](buf63, primals_61, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_61 buf64 = extern_kernels.convolution(buf63, primals_62, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 128, 8, 8), (8192, 64, 8, 1)) buf65 = buf64 del buf64 triton_poi_fused_convolution_relu_8[grid(32768)](buf65, primals_63, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_63 buf66 = extern_kernels.convolution(buf65, primals_64, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf66, (4, 128, 8, 8), (8192, 64, 8, 1)) buf67 = buf66 del buf66 triton_poi_fused_convolution_relu_8[grid(32768)](buf67, primals_65, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_65 buf68 = extern_kernels.convolution(buf67, primals_66, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf68, (4, 128, 8, 8), (8192, 64, 8, 1)) buf69 = buf68 del buf68 triton_poi_fused_convolution_relu_8[grid(32768)](buf69, primals_67, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_67 buf70 = extern_kernels.convolution(buf69, primals_68, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 128, 8, 8), (8192, 64, 8, 1)) buf71 = buf70 del buf70 triton_poi_fused_convolution_relu_8[grid(32768)](buf71, primals_69, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_69 buf72 = extern_kernels.convolution(buf71, primals_70, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf72, (4, 128, 8, 8), (8192, 64, 8, 1)) buf73 = buf72 del buf72 triton_poi_fused_convolution_relu_8[grid(32768)](buf73, primals_71, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_71 buf74 = extern_kernels.convolution(buf73, primals_72, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf74, (4, 19, 8, 8), (1216, 64, 8, 1)) buf75 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch .float32) triton_poi_fused_cat_9[grid(47360)](buf61, primals_59, buf74, primals_73, buf29, buf75, 47360, XBLOCK=512, num_warps=4, num_stages=1) del buf61 del buf74 del primals_59 del primals_73 buf76 = extern_kernels.convolution(buf75, primals_74, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf76, (4, 128, 8, 8), (8192, 64, 8, 1)) buf77 = buf76 del buf76 triton_poi_fused_convolution_relu_8[grid(32768)](buf77, primals_75, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_75 buf78 = extern_kernels.convolution(buf77, primals_76, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf78, (4, 128, 8, 8), (8192, 64, 8, 1)) buf79 = buf78 del buf78 triton_poi_fused_convolution_relu_8[grid(32768)](buf79, primals_77, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_77 buf80 = extern_kernels.convolution(buf79, primals_78, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf80, (4, 128, 8, 8), (8192, 64, 8, 1)) buf81 = buf80 del buf80 triton_poi_fused_convolution_relu_8[grid(32768)](buf81, primals_79, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_79 buf82 = extern_kernels.convolution(buf81, primals_80, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf82, (4, 128, 8, 8), (8192, 64, 8, 1)) buf83 = buf82 del buf82 triton_poi_fused_convolution_relu_8[grid(32768)](buf83, primals_81, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_81 buf84 = extern_kernels.convolution(buf83, primals_82, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf84, (4, 128, 8, 8), (8192, 64, 8, 1)) buf85 = buf84 del buf84 triton_poi_fused_convolution_relu_8[grid(32768)](buf85, primals_83, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_83 buf86 = extern_kernels.convolution(buf85, primals_84, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf86, (4, 128, 8, 8), (8192, 64, 8, 1)) buf87 = buf86 del buf86 triton_poi_fused_convolution_relu_8[grid(32768)](buf87, primals_85, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_85 buf88 = extern_kernels.convolution(buf87, primals_86, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf88, (4, 38, 8, 8), (2432, 64, 8, 1)) buf89 = extern_kernels.convolution(buf75, primals_88, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf89, (4, 128, 8, 8), (8192, 64, 8, 1)) buf90 = buf89 del buf89 triton_poi_fused_convolution_relu_8[grid(32768)](buf90, primals_89, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_89 buf91 = extern_kernels.convolution(buf90, primals_90, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf91, (4, 128, 8, 8), (8192, 64, 8, 1)) buf92 = buf91 del buf91 triton_poi_fused_convolution_relu_8[grid(32768)](buf92, primals_91, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_91 buf93 = extern_kernels.convolution(buf92, primals_92, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf93, (4, 128, 8, 8), (8192, 64, 8, 1)) buf94 = buf93 del buf93 triton_poi_fused_convolution_relu_8[grid(32768)](buf94, primals_93, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_93 buf95 = extern_kernels.convolution(buf94, primals_94, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf95, (4, 128, 8, 8), (8192, 64, 8, 1)) buf96 = buf95 del buf95 triton_poi_fused_convolution_relu_8[grid(32768)](buf96, primals_95, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_95 buf97 = extern_kernels.convolution(buf96, primals_96, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf97, (4, 128, 8, 8), (8192, 64, 8, 1)) buf98 = buf97 del buf97 triton_poi_fused_convolution_relu_8[grid(32768)](buf98, primals_97, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_97 buf99 = extern_kernels.convolution(buf98, primals_98, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf99, (4, 128, 8, 8), (8192, 64, 8, 1)) buf100 = buf99 del buf99 triton_poi_fused_convolution_relu_8[grid(32768)](buf100, primals_99, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_99 buf101 = extern_kernels.convolution(buf100, primals_100, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf101, (4, 19, 8, 8), (1216, 64, 8, 1)) buf102 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch.float32) triton_poi_fused_cat_9[grid(47360)](buf88, primals_87, buf101, primals_101, buf29, buf102, 47360, XBLOCK=512, num_warps=4, num_stages=1) del buf101 del buf88 del primals_101 del primals_87 buf103 = extern_kernels.convolution(buf102, primals_102, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf103, (4, 128, 8, 8), (8192, 64, 8, 1)) buf104 = buf103 del buf103 triton_poi_fused_convolution_relu_8[grid(32768)](buf104, primals_103, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_103 buf105 = extern_kernels.convolution(buf104, primals_104, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf105, (4, 128, 8, 8), (8192, 64, 8, 1)) buf106 = buf105 del buf105 triton_poi_fused_convolution_relu_8[grid(32768)](buf106, primals_105, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_105 buf107 = extern_kernels.convolution(buf106, primals_106, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf107, (4, 128, 8, 8), (8192, 64, 8, 1)) buf108 = buf107 del buf107 triton_poi_fused_convolution_relu_8[grid(32768)](buf108, primals_107, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_107 buf109 = extern_kernels.convolution(buf108, primals_108, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf109, (4, 128, 8, 8), (8192, 64, 8, 1)) buf110 = buf109 del buf109 triton_poi_fused_convolution_relu_8[grid(32768)](buf110, primals_109, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_109 buf111 = extern_kernels.convolution(buf110, primals_110, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf111, (4, 128, 8, 8), (8192, 64, 8, 1)) buf112 = buf111 del buf111 triton_poi_fused_convolution_relu_8[grid(32768)](buf112, primals_111, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_111 buf113 = extern_kernels.convolution(buf112, primals_112, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf113, (4, 128, 8, 8), (8192, 64, 8, 1)) buf114 = buf113 del buf113 triton_poi_fused_convolution_relu_8[grid(32768)](buf114, primals_113, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_113 buf115 = extern_kernels.convolution(buf114, primals_114, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf115, (4, 38, 8, 8), (2432, 64, 8, 1)) buf116 = extern_kernels.convolution(buf102, primals_116, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf116, (4, 128, 8, 8), (8192, 64, 8, 1)) buf117 = buf116 del buf116 triton_poi_fused_convolution_relu_8[grid(32768)](buf117, primals_117, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_117 buf118 = extern_kernels.convolution(buf117, primals_118, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf118, (4, 128, 8, 8), (8192, 64, 8, 1)) buf119 = buf118 del buf118 triton_poi_fused_convolution_relu_8[grid(32768)](buf119, primals_119, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_119 buf120 = extern_kernels.convolution(buf119, primals_120, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf120, (4, 128, 8, 8), (8192, 64, 8, 1)) buf121 = buf120 del buf120 triton_poi_fused_convolution_relu_8[grid(32768)](buf121, primals_121, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_121 buf122 = extern_kernels.convolution(buf121, primals_122, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf122, (4, 128, 8, 8), (8192, 64, 8, 1)) buf123 = buf122 del buf122 triton_poi_fused_convolution_relu_8[grid(32768)](buf123, primals_123, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_123 buf124 = extern_kernels.convolution(buf123, primals_124, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf124, (4, 128, 8, 8), (8192, 64, 8, 1)) buf125 = buf124 del buf124 triton_poi_fused_convolution_relu_8[grid(32768)](buf125, primals_125, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_125 buf126 = extern_kernels.convolution(buf125, primals_126, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf126, (4, 128, 8, 8), (8192, 64, 8, 1)) buf127 = buf126 del buf126 triton_poi_fused_convolution_relu_8[grid(32768)](buf127, primals_127, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_127 buf128 = extern_kernels.convolution(buf127, primals_128, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf128, (4, 19, 8, 8), (1216, 64, 8, 1)) buf129 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch.float32) triton_poi_fused_cat_9[grid(47360)](buf115, primals_115, buf128, primals_129, buf29, buf129, 47360, XBLOCK=512, num_warps=4, num_stages=1) del buf115 del buf128 del primals_115 del primals_129 buf130 = extern_kernels.convolution(buf129, primals_130, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf130, (4, 128, 8, 8), (8192, 64, 8, 1)) buf131 = buf130 del buf130 triton_poi_fused_convolution_relu_8[grid(32768)](buf131, primals_131, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_131 buf132 = extern_kernels.convolution(buf131, primals_132, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf132, (4, 128, 8, 8), (8192, 64, 8, 1)) buf133 = buf132 del buf132 triton_poi_fused_convolution_relu_8[grid(32768)](buf133, primals_133, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_133 buf134 = extern_kernels.convolution(buf133, primals_134, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf134, (4, 128, 8, 8), (8192, 64, 8, 1)) buf135 = buf134 del buf134 triton_poi_fused_convolution_relu_8[grid(32768)](buf135, primals_135, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_135 buf136 = extern_kernels.convolution(buf135, primals_136, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf136, (4, 128, 8, 8), (8192, 64, 8, 1)) buf137 = buf136 del buf136 triton_poi_fused_convolution_relu_8[grid(32768)](buf137, primals_137, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_137 buf138 = extern_kernels.convolution(buf137, primals_138, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf138, (4, 128, 8, 8), (8192, 64, 8, 1)) buf139 = buf138 del buf138 triton_poi_fused_convolution_relu_8[grid(32768)](buf139, primals_139, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_139 buf140 = extern_kernels.convolution(buf139, primals_140, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf140, (4, 128, 8, 8), (8192, 64, 8, 1)) buf141 = buf140 del buf140 triton_poi_fused_convolution_relu_8[grid(32768)](buf141, primals_141, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_141 buf142 = extern_kernels.convolution(buf141, primals_142, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf142, (4, 38, 8, 8), (2432, 64, 8, 1)) buf143 = extern_kernels.convolution(buf129, primals_144, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf143, (4, 128, 8, 8), (8192, 64, 8, 1)) buf144 = buf143 del buf143 triton_poi_fused_convolution_relu_8[grid(32768)](buf144, primals_145, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_145 buf145 = extern_kernels.convolution(buf144, primals_146, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf145, (4, 128, 8, 8), (8192, 64, 8, 1)) buf146 = buf145 del buf145 triton_poi_fused_convolution_relu_8[grid(32768)](buf146, primals_147, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_147 buf147 = extern_kernels.convolution(buf146, primals_148, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf147, (4, 128, 8, 8), (8192, 64, 8, 1)) buf148 = buf147 del buf147 triton_poi_fused_convolution_relu_8[grid(32768)](buf148, primals_149, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_149 buf149 = extern_kernels.convolution(buf148, primals_150, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf149, (4, 128, 8, 8), (8192, 64, 8, 1)) buf150 = buf149 del buf149 triton_poi_fused_convolution_relu_8[grid(32768)](buf150, primals_151, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_151 buf151 = extern_kernels.convolution(buf150, primals_152, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf151, (4, 128, 8, 8), (8192, 64, 8, 1)) buf152 = buf151 del buf151 triton_poi_fused_convolution_relu_8[grid(32768)](buf152, primals_153, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_153 buf153 = extern_kernels.convolution(buf152, primals_154, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf153, (4, 128, 8, 8), (8192, 64, 8, 1)) buf154 = buf153 del buf153 triton_poi_fused_convolution_relu_8[grid(32768)](buf154, primals_155, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_155 buf155 = extern_kernels.convolution(buf154, primals_156, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf155, (4, 19, 8, 8), (1216, 64, 8, 1)) buf156 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch.float32) triton_poi_fused_cat_9[grid(47360)](buf142, primals_143, buf155, primals_157, buf29, buf156, 47360, XBLOCK=512, num_warps=4, num_stages=1) del buf142 del buf155 del primals_143 del primals_157 buf157 = extern_kernels.convolution(buf156, primals_158, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf157, (4, 128, 8, 8), (8192, 64, 8, 1)) buf158 = buf157 del buf157 triton_poi_fused_convolution_relu_8[grid(32768)](buf158, primals_159, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_159 buf159 = extern_kernels.convolution(buf158, primals_160, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf159, (4, 128, 8, 8), (8192, 64, 8, 1)) buf160 = buf159 del buf159 triton_poi_fused_convolution_relu_8[grid(32768)](buf160, primals_161, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_161 buf161 = extern_kernels.convolution(buf160, primals_162, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf161, (4, 128, 8, 8), (8192, 64, 8, 1)) buf162 = buf161 del buf161 triton_poi_fused_convolution_relu_8[grid(32768)](buf162, primals_163, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_163 buf163 = extern_kernels.convolution(buf162, primals_164, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf163, (4, 128, 8, 8), (8192, 64, 8, 1)) buf164 = buf163 del buf163 triton_poi_fused_convolution_relu_8[grid(32768)](buf164, primals_165, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_165 buf165 = extern_kernels.convolution(buf164, primals_166, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf165, (4, 128, 8, 8), (8192, 64, 8, 1)) buf166 = buf165 del buf165 triton_poi_fused_convolution_relu_8[grid(32768)](buf166, primals_167, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_167 buf167 = extern_kernels.convolution(buf166, primals_168, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf167, (4, 128, 8, 8), (8192, 64, 8, 1)) buf168 = buf167 del buf167 triton_poi_fused_convolution_relu_8[grid(32768)](buf168, primals_169, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_169 buf169 = extern_kernels.convolution(buf168, primals_170, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf169, (4, 38, 8, 8), (2432, 64, 8, 1)) buf170 = buf169 del buf169 triton_poi_fused_convolution_10[grid(9728)](buf170, primals_171, 9728, XBLOCK=256, num_warps=4, num_stages=1) del primals_171 buf171 = extern_kernels.convolution(buf156, primals_172, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf171, (4, 128, 8, 8), (8192, 64, 8, 1)) buf172 = buf171 del buf171 triton_poi_fused_convolution_relu_8[grid(32768)](buf172, primals_173, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_173 buf173 = extern_kernels.convolution(buf172, primals_174, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf173, (4, 128, 8, 8), (8192, 64, 8, 1)) buf174 = buf173 del buf173 triton_poi_fused_convolution_relu_8[grid(32768)](buf174, primals_175, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_175 buf175 = extern_kernels.convolution(buf174, primals_176, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf175, (4, 128, 8, 8), (8192, 64, 8, 1)) buf176 = buf175 del buf175 triton_poi_fused_convolution_relu_8[grid(32768)](buf176, primals_177, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_177 buf177 = extern_kernels.convolution(buf176, primals_178, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf177, (4, 128, 8, 8), (8192, 64, 8, 1)) buf178 = buf177 del buf177 triton_poi_fused_convolution_relu_8[grid(32768)](buf178, primals_179, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_179 buf179 = extern_kernels.convolution(buf178, primals_180, stride=(1, 1), padding=(3, 3), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf179, (4, 128, 8, 8), (8192, 64, 8, 1)) buf180 = buf179 del buf179 triton_poi_fused_convolution_relu_8[grid(32768)](buf180, primals_181, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_181 buf181 = extern_kernels.convolution(buf180, primals_182, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf181, (4, 128, 8, 8), (8192, 64, 8, 1)) buf182 = buf181 del buf181 triton_poi_fused_convolution_relu_8[grid(32768)](buf182, primals_183, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_183 buf183 = extern_kernels.convolution(buf182, primals_184, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf183, (4, 19, 8, 8), (1216, 64, 8, 1)) buf184 = buf183 del buf183 buf185 = empty_strided_cuda((4, 19, 8, 8), (1280, 64, 8, 1), torch.bool ) triton_poi_fused_convolution_relu_threshold_backward_11[grid(4864)]( buf184, primals_185, buf185, 4864, XBLOCK=256, num_warps=4, num_stages=1) del primals_185 return (buf170, buf184, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, primals_28, primals_30, primals_32, primals_34, primals_36, primals_38, primals_40, primals_42, primals_44, primals_46, primals_48, primals_50, primals_52, primals_54, primals_56, primals_58, primals_60, primals_62, primals_64, primals_66, primals_68, primals_70, primals_72, primals_74, primals_76, primals_78, primals_80, primals_82, primals_84, primals_86, primals_88, primals_90, primals_92, primals_94, primals_96, primals_98, primals_100, primals_102, primals_104, primals_106, primals_108, primals_110, primals_112, primals_114, primals_116, primals_118, primals_120, primals_122, primals_124, primals_126, primals_128, primals_130, primals_132, primals_134, primals_136, primals_138, primals_140, primals_142, primals_144, primals_146, primals_148, primals_150, primals_152, primals_154, primals_156, primals_158, primals_160, primals_162, primals_164, primals_166, primals_168, primals_170, primals_172, primals_174, primals_176, primals_178, primals_180, primals_182, primals_184, buf1, buf3, buf4, buf5, buf7, buf9, buf10, buf11, buf13, buf15, buf17, buf19, buf20, buf21, buf23, buf25, buf27, buf29, buf31, buf33, buf35, buf37, buf40, buf42, buf44, buf46, buf48, buf50, buf52, buf54, buf56, buf58, buf60, buf63, buf65, buf67, buf69, buf71, buf73, buf75, buf77, buf79, buf81, buf83, buf85, buf87, buf90, buf92, buf94, buf96, buf98, buf100, buf102, buf104, buf106, buf108, buf110, buf112, buf114, buf117, buf119, buf121, buf123, buf125, buf127, buf129, buf131, buf133, buf135, buf137, buf139, buf141, buf144, buf146, buf148, buf150, buf152, buf154, buf156, buf158, buf160, buf162, buf164, buf166, buf168, buf172, buf174, buf176, buf178, buf180, buf182, buf185) def make_layers(block, no_relu_layers): layers = [] for layer_name, v in block.items(): if 'pool' in layer_name: layer = nn.MaxPool2d(kernel_size=v[0], stride=v[1], padding=v[2]) layers.append((layer_name, layer)) else: conv2d = nn.Conv2d(in_channels=v[0], out_channels=v[1], kernel_size=v[2], stride=v[3], padding=v[4]) layers.append((layer_name, conv2d)) if layer_name not in no_relu_layers: layers.append(('relu_' + layer_name, nn.ReLU(inplace=True))) return nn.Sequential(OrderedDict(layers)) class bodypose_modelNew(nn.Module): def __init__(self): super(bodypose_modelNew, self).__init__() no_relu_layers = ['conv5_5_CPM_L1', 'conv5_5_CPM_L2', 'Mconv7_stage2_L1', 'Mconv7_stage2_L2', 'Mconv7_stage3_L1', 'Mconv7_stage3_L2', 'Mconv7_stage4_L1', 'Mconv7_stage4_L2', 'Mconv7_stage5_L1', 'Mconv7_stage5_L2', 'Mconv7_stage6_L1', 'Mconv7_stage6_L1'] blocks = {} block0 = OrderedDict({'conv1_1': [3, 64, 3, 1, 1], 'conv1_2': [64, 64, 3, 1, 1], 'pool1_stage1': [2, 2, 0], 'conv2_1': [64, 128, 3, 1, 1], 'conv2_2': [128, 128, 3, 1, 1], 'pool2_stage1': [2, 2, 0 ], 'conv3_1': [128, 256, 3, 1, 1], 'conv3_2': [256, 256, 3, 1, 1], 'conv3_3': [256, 256, 3, 1, 1], 'conv3_4': [256, 256, 3, 1, 1], 'pool3_stage1': [2, 2, 0], 'conv4_1': [256, 512, 3, 1, 1], 'conv4_2': [512, 512, 3, 1, 1], 'conv4_3_CPM': [512, 256, 3, 1, 1], 'conv4_4_CPM': [256, 128, 3, 1, 1]}) block1_1 = OrderedDict({'conv5_1_CPM_L1': [128, 128, 3, 1, 1], 'conv5_2_CPM_L1': [128, 128, 3, 1, 1], 'conv5_3_CPM_L1': [128, 128, 3, 1, 1], 'conv5_4_CPM_L1': [128, 512, 1, 1, 0], 'conv5_5_CPM_L1': [512, 38, 1, 1, 0]}) block1_2 = OrderedDict({'conv5_1_CPM_L2': [128, 128, 3, 1, 1], 'conv5_2_CPM_L2': [128, 128, 3, 1, 1], 'conv5_3_CPM_L2': [128, 128, 3, 1, 1], 'conv5_4_CPM_L2': [128, 512, 1, 1, 0], 'conv5_5_CPM_L2': [512, 19, 1, 1, 0]}) blocks['block1_1'] = block1_1 blocks['block1_2'] = block1_2 self.model0 = make_layers(block0, no_relu_layers) for i in range(2, 7): blocks['block%d_1' % i] = OrderedDict({('Mconv1_stage%d_L1' % i ): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L1' % i): [128, 128, 7, 1, 3], ('Mconv3_stage%d_L1' % i): [128, 128, 7, 1, 3], ('Mconv4_stage%d_L1' % i): [128, 128, 7, 1, 3], ( 'Mconv5_stage%d_L1' % i): [128, 128, 7, 1, 3], ( 'Mconv6_stage%d_L1' % i): [128, 128, 1, 1, 0], ( 'Mconv7_stage%d_L1' % i): [128, 38, 1, 1, 0]}) blocks['block%d_2' % i] = OrderedDict({('Mconv1_stage%d_L2' % i ): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L2' % i): [128, 128, 7, 1, 3], ('Mconv3_stage%d_L2' % i): [128, 128, 7, 1, 3], ('Mconv4_stage%d_L2' % i): [128, 128, 7, 1, 3], ( 'Mconv5_stage%d_L2' % i): [128, 128, 7, 1, 3], ( 'Mconv6_stage%d_L2' % i): [128, 128, 1, 1, 0], ( 'Mconv7_stage%d_L2' % i): [128, 19, 1, 1, 0]}) for k in blocks.keys(): blocks[k] = make_layers(blocks[k], no_relu_layers) self.model1_1 = blocks['block1_1'] self.model2_1 = blocks['block2_1'] self.model3_1 = blocks['block3_1'] self.model4_1 = blocks['block4_1'] self.model5_1 = blocks['block5_1'] self.model6_1 = blocks['block6_1'] self.model1_2 = blocks['block1_2'] self.model2_2 = blocks['block2_2'] self.model3_2 = blocks['block3_2'] self.model4_2 = blocks['block4_2'] self.model5_2 = blocks['block5_2'] self.model6_2 = blocks['block6_2'] def forward(self, input_0): primals_1 = self.model0.conv1_1.weight primals_2 = self.model0.conv1_1.bias primals_4 = self.model0.conv1_2.weight primals_5 = self.model0.conv1_2.bias primals_6 = self.model0.conv2_1.weight primals_7 = self.model0.conv2_1.bias primals_8 = self.model0.conv2_2.weight primals_9 = self.model0.conv2_2.bias primals_10 = self.model0.conv3_1.weight primals_11 = self.model0.conv3_1.bias primals_12 = self.model0.conv3_2.weight primals_13 = self.model0.conv3_2.bias primals_14 = self.model0.conv3_3.weight primals_15 = self.model0.conv3_3.bias primals_16 = self.model0.conv3_4.weight primals_17 = self.model0.conv3_4.bias primals_18 = self.model0.conv4_1.weight primals_19 = self.model0.conv4_1.bias primals_20 = self.model0.conv4_2.weight primals_21 = self.model0.conv4_2.bias primals_22 = self.model0.conv4_3_CPM.weight primals_23 = self.model0.conv4_3_CPM.bias primals_24 = self.model0.conv4_4_CPM.weight primals_25 = self.model0.conv4_4_CPM.bias primals_26 = self.model1_1.conv5_1_CPM_L1.weight primals_27 = self.model1_1.conv5_1_CPM_L1.bias primals_28 = self.model1_1.conv5_2_CPM_L1.weight primals_29 = self.model1_1.conv5_2_CPM_L1.bias primals_30 = self.model1_1.conv5_3_CPM_L1.weight primals_31 = self.model1_1.conv5_3_CPM_L1.bias primals_32 = self.model1_1.conv5_4_CPM_L1.weight primals_33 = self.model1_1.conv5_4_CPM_L1.bias primals_34 = self.model1_1.conv5_5_CPM_L1.weight primals_35 = self.model1_1.conv5_5_CPM_L1.bias primals_46 = self.model2_1.Mconv1_stage2_L1.weight primals_37 = self.model2_1.Mconv1_stage2_L1.bias primals_48 = self.model2_1.Mconv2_stage2_L1.weight primals_39 = self.model2_1.Mconv2_stage2_L1.bias primals_50 = self.model2_1.Mconv3_stage2_L1.weight primals_41 = self.model2_1.Mconv3_stage2_L1.bias primals_52 = self.model2_1.Mconv4_stage2_L1.weight primals_47 = self.model2_1.Mconv4_stage2_L1.bias primals_54 = self.model2_1.Mconv5_stage2_L1.weight primals_49 = self.model2_1.Mconv5_stage2_L1.bias primals_56 = self.model2_1.Mconv6_stage2_L1.weight primals_51 = self.model2_1.Mconv6_stage2_L1.bias primals_58 = self.model2_1.Mconv7_stage2_L1.weight primals_59 = self.model2_1.Mconv7_stage2_L1.bias primals_60 = self.model3_1.Mconv1_stage3_L1.weight primals_53 = self.model3_1.Mconv1_stage3_L1.bias primals_62 = self.model3_1.Mconv2_stage3_L1.weight primals_55 = self.model3_1.Mconv2_stage3_L1.bias primals_64 = self.model3_1.Mconv3_stage3_L1.weight primals_57 = self.model3_1.Mconv3_stage3_L1.bias primals_66 = self.model3_1.Mconv4_stage3_L1.weight primals_61 = self.model3_1.Mconv4_stage3_L1.bias primals_68 = self.model3_1.Mconv5_stage3_L1.weight primals_63 = self.model3_1.Mconv5_stage3_L1.bias primals_70 = self.model3_1.Mconv6_stage3_L1.weight primals_65 = self.model3_1.Mconv6_stage3_L1.bias primals_86 = self.model3_1.Mconv7_stage3_L1.weight primals_87 = self.model3_1.Mconv7_stage3_L1.bias primals_74 = self.model4_1.Mconv1_stage4_L1.weight primals_67 = self.model4_1.Mconv1_stage4_L1.bias primals_76 = self.model4_1.Mconv2_stage4_L1.weight primals_69 = self.model4_1.Mconv2_stage4_L1.bias primals_78 = self.model4_1.Mconv3_stage4_L1.weight primals_71 = self.model4_1.Mconv3_stage4_L1.bias primals_80 = self.model4_1.Mconv4_stage4_L1.weight primals_75 = self.model4_1.Mconv4_stage4_L1.bias primals_82 = self.model4_1.Mconv5_stage4_L1.weight primals_77 = self.model4_1.Mconv5_stage4_L1.bias primals_84 = self.model4_1.Mconv6_stage4_L1.weight primals_79 = self.model4_1.Mconv6_stage4_L1.bias primals_114 = self.model4_1.Mconv7_stage4_L1.weight primals_115 = self.model4_1.Mconv7_stage4_L1.bias primals_88 = self.model5_1.Mconv1_stage5_L1.weight primals_81 = self.model5_1.Mconv1_stage5_L1.bias primals_90 = self.model5_1.Mconv2_stage5_L1.weight primals_83 = self.model5_1.Mconv2_stage5_L1.bias primals_92 = self.model5_1.Mconv3_stage5_L1.weight primals_85 = self.model5_1.Mconv3_stage5_L1.bias primals_94 = self.model5_1.Mconv4_stage5_L1.weight primals_89 = self.model5_1.Mconv4_stage5_L1.bias primals_96 = self.model5_1.Mconv5_stage5_L1.weight primals_91 = self.model5_1.Mconv5_stage5_L1.bias primals_98 = self.model5_1.Mconv6_stage5_L1.weight primals_93 = self.model5_1.Mconv6_stage5_L1.bias primals_142 = self.model5_1.Mconv7_stage5_L1.weight primals_143 = self.model5_1.Mconv7_stage5_L1.bias primals_102 = self.model6_1.Mconv1_stage6_L1.weight primals_95 = self.model6_1.Mconv1_stage6_L1.bias primals_104 = self.model6_1.Mconv2_stage6_L1.weight primals_97 = self.model6_1.Mconv2_stage6_L1.bias primals_106 = self.model6_1.Mconv3_stage6_L1.weight primals_99 = self.model6_1.Mconv3_stage6_L1.bias primals_108 = self.model6_1.Mconv4_stage6_L1.weight primals_103 = self.model6_1.Mconv4_stage6_L1.bias primals_110 = self.model6_1.Mconv5_stage6_L1.weight primals_105 = self.model6_1.Mconv5_stage6_L1.bias primals_112 = self.model6_1.Mconv6_stage6_L1.weight primals_107 = self.model6_1.Mconv6_stage6_L1.bias primals_170 = self.model6_1.Mconv7_stage6_L1.weight primals_171 = self.model6_1.Mconv7_stage6_L1.bias primals_36 = self.model1_2.conv5_1_CPM_L2.weight primals_109 = self.model1_2.conv5_1_CPM_L2.bias primals_38 = self.model1_2.conv5_2_CPM_L2.weight primals_111 = self.model1_2.conv5_2_CPM_L2.bias primals_40 = self.model1_2.conv5_3_CPM_L2.weight primals_113 = self.model1_2.conv5_3_CPM_L2.bias primals_42 = self.model1_2.conv5_4_CPM_L2.weight primals_43 = self.model1_2.conv5_4_CPM_L2.bias primals_44 = self.model1_2.conv5_5_CPM_L2.weight primals_45 = self.model1_2.conv5_5_CPM_L2.bias primals_116 = self.model2_2.Mconv1_stage2_L2.weight primals_117 = self.model2_2.Mconv1_stage2_L2.bias primals_118 = self.model2_2.Mconv2_stage2_L2.weight primals_119 = self.model2_2.Mconv2_stage2_L2.bias primals_120 = self.model2_2.Mconv3_stage2_L2.weight primals_121 = self.model2_2.Mconv3_stage2_L2.bias primals_122 = self.model2_2.Mconv4_stage2_L2.weight primals_123 = self.model2_2.Mconv4_stage2_L2.bias primals_124 = self.model2_2.Mconv5_stage2_L2.weight primals_125 = self.model2_2.Mconv5_stage2_L2.bias primals_126 = self.model2_2.Mconv6_stage2_L2.weight primals_127 = self.model2_2.Mconv6_stage2_L2.bias primals_72 = self.model2_2.Mconv7_stage2_L2.weight primals_73 = self.model2_2.Mconv7_stage2_L2.bias primals_130 = self.model3_2.Mconv1_stage3_L2.weight primals_131 = self.model3_2.Mconv1_stage3_L2.bias primals_132 = self.model3_2.Mconv2_stage3_L2.weight primals_133 = self.model3_2.Mconv2_stage3_L2.bias primals_134 = self.model3_2.Mconv3_stage3_L2.weight primals_135 = self.model3_2.Mconv3_stage3_L2.bias primals_136 = self.model3_2.Mconv4_stage3_L2.weight primals_137 = self.model3_2.Mconv4_stage3_L2.bias primals_138 = self.model3_2.Mconv5_stage3_L2.weight primals_139 = self.model3_2.Mconv5_stage3_L2.bias primals_140 = self.model3_2.Mconv6_stage3_L2.weight primals_141 = self.model3_2.Mconv6_stage3_L2.bias primals_100 = self.model3_2.Mconv7_stage3_L2.weight primals_101 = self.model3_2.Mconv7_stage3_L2.bias primals_144 = self.model4_2.Mconv1_stage4_L2.weight primals_145 = self.model4_2.Mconv1_stage4_L2.bias primals_146 = self.model4_2.Mconv2_stage4_L2.weight primals_147 = self.model4_2.Mconv2_stage4_L2.bias primals_148 = self.model4_2.Mconv3_stage4_L2.weight primals_149 = self.model4_2.Mconv3_stage4_L2.bias primals_150 = self.model4_2.Mconv4_stage4_L2.weight primals_151 = self.model4_2.Mconv4_stage4_L2.bias primals_152 = self.model4_2.Mconv5_stage4_L2.weight primals_153 = self.model4_2.Mconv5_stage4_L2.bias primals_154 = self.model4_2.Mconv6_stage4_L2.weight primals_155 = self.model4_2.Mconv6_stage4_L2.bias primals_128 = self.model4_2.Mconv7_stage4_L2.weight primals_129 = self.model4_2.Mconv7_stage4_L2.bias primals_158 = self.model5_2.Mconv1_stage5_L2.weight primals_159 = self.model5_2.Mconv1_stage5_L2.bias primals_160 = self.model5_2.Mconv2_stage5_L2.weight primals_161 = self.model5_2.Mconv2_stage5_L2.bias primals_162 = self.model5_2.Mconv3_stage5_L2.weight primals_163 = self.model5_2.Mconv3_stage5_L2.bias primals_164 = self.model5_2.Mconv4_stage5_L2.weight primals_165 = self.model5_2.Mconv4_stage5_L2.bias primals_166 = self.model5_2.Mconv5_stage5_L2.weight primals_167 = self.model5_2.Mconv5_stage5_L2.bias primals_168 = self.model5_2.Mconv6_stage5_L2.weight primals_169 = self.model5_2.Mconv6_stage5_L2.bias primals_156 = self.model5_2.Mconv7_stage5_L2.weight primals_157 = self.model5_2.Mconv7_stage5_L2.bias primals_172 = self.model6_2.Mconv1_stage6_L2.weight primals_173 = self.model6_2.Mconv1_stage6_L2.bias primals_174 = self.model6_2.Mconv2_stage6_L2.weight primals_175 = self.model6_2.Mconv2_stage6_L2.bias primals_176 = self.model6_2.Mconv3_stage6_L2.weight primals_177 = self.model6_2.Mconv3_stage6_L2.bias primals_178 = self.model6_2.Mconv4_stage6_L2.weight primals_179 = self.model6_2.Mconv4_stage6_L2.bias primals_180 = self.model6_2.Mconv5_stage6_L2.weight primals_181 = self.model6_2.Mconv5_stage6_L2.bias primals_182 = self.model6_2.Mconv6_stage6_L2.weight primals_183 = self.model6_2.Mconv6_stage6_L2.bias primals_184 = self.model6_2.Mconv7_stage6_L2.weight primals_185 = self.model6_2.Mconv7_stage6_L2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72, primals_73, primals_74, primals_75, primals_76, primals_77, primals_78, primals_79, primals_80, primals_81, primals_82, primals_83, primals_84, primals_85, primals_86, primals_87, primals_88, primals_89, primals_90, primals_91, primals_92, primals_93, primals_94, primals_95, primals_96, primals_97, primals_98, primals_99, primals_100, primals_101, primals_102, primals_103, primals_104, primals_105, primals_106, primals_107, primals_108, primals_109, primals_110, primals_111, primals_112, primals_113, primals_114, primals_115, primals_116, primals_117, 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, primals_171, primals_172, primals_173, primals_174, primals_175, primals_176, primals_177, primals_178, primals_179, primals_180, primals_181, primals_182, primals_183, primals_184, primals_185]) return output[0], output[1]
Schwartz-Zha/My_Pose_Estimation
bodypose_model
false
12,060
[ "MIT" ]
0
0ccaccf58498b2200842c155b735e1103c28c5ba
https://github.com/Schwartz-Zha/My_Pose_Estimation/tree/0ccaccf58498b2200842c155b735e1103c28c5ba
Scale
import torch from torch import nn import torch.nn.parallel class Scale(nn.Module): def __init__(self, init_value=1.0): super(Scale, self).__init__() self.scale = nn.Parameter(torch.FloatTensor([init_value])) def forward(self, input): return input * 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 from torch import nn import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_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, (1,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 return buf0, primals_2 class ScaleNew(nn.Module): def __init__(self, init_value=1.0): super(ScaleNew, self).__init__() self.scale = nn.Parameter(torch.FloatTensor([init_value])) def forward(self, input_0): primals_1 = self.scale primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
XDong18/AdelaiDet
Scale
false
12,061
[ "BSD-2-Clause" ]
0
837cd1078923892fe6e84ac29fd0963f1b2c474f
https://github.com/XDong18/AdelaiDet/tree/837cd1078923892fe6e84ac29fd0963f1b2c474f
GCN
import torch from torch import nn import torch.nn.functional as F import torch.nn.parallel class Conv2D(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, padding= 'same', stride=1, dilation=1, groups=1): super(Conv2D, self).__init__() assert type(kernel_size) in [int, tuple ], 'Allowed kernel type [int or tuple], not {}'.format(type( kernel_size)) assert padding == 'same', 'Allowed padding type {}, not {}'.format( 'same', padding) self.kernel_size = kernel_size if isinstance(kernel_size, tuple): self.h_kernel = kernel_size[0] self.w_kernel = kernel_size[1] else: self.h_kernel = kernel_size self.w_kernel = kernel_size self.padding = padding self.stride = stride self.dilation = dilation self.groups = groups self.conv = nn.Conv2d(in_channels=in_channels, out_channels= out_channels, kernel_size=kernel_size, stride=self.stride, dilation=self.dilation, groups=self.groups) def forward(self, x): if self.padding == 'same': height, width = x.shape[2:] h_pad_need = max(0, (height - 1) * self.stride + self.h_kernel - height) w_pad_need = max(0, (width - 1) * self.stride + self.w_kernel - width) pad_left = w_pad_need // 2 pad_right = w_pad_need - pad_left pad_top = h_pad_need // 2 pad_bottom = h_pad_need - pad_top padding = pad_left, pad_right, pad_top, pad_bottom x = F.pad(x, padding, 'constant', 0) x = self.conv(x) return x class GCN(nn.Module): """ Large Kernel Matters -- https://arxiv.org/abs/1703.02719 """ def __init__(self, in_channels, out_channels, k=3): super(GCN, self).__init__() self.conv_l1 = Conv2D(in_channels=in_channels, out_channels= out_channels, kernel_size=(k, 1), padding='same') self.conv_l2 = Conv2D(in_channels=out_channels, out_channels= out_channels, kernel_size=(1, k), padding='same') self.conv_r1 = Conv2D(in_channels=in_channels, out_channels= out_channels, kernel_size=(1, k), padding='same') self.conv_r2 = Conv2D(in_channels=out_channels, out_channels= out_channels, kernel_size=(k, 1), padding='same') def forward(self, x): x1 = self.conv_l1(x) x1 = self.conv_l2(x1) x2 = self.conv_r1(x) x2 = self.conv_r2(x2) out = x1 + x2 return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.nn.functional as F import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 6 x2 = xindex // 24 x3 = xindex % 24 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-4 + x3 + 16 * x2), tmp5 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_convolution_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x4 = xindex // 6 x2 = xindex // 24 % 4 x5 = xindex tmp0 = -1 + x0 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-1 + x0 + 4 * x4), tmp5 & xmask, other=0.0) tmp7 = tl.load(in_ptr1 + x2, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype) tmp10 = tl.where(tmp5, tmp8, tmp9) tl.store(out_ptr0 + x5, tmp10, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 x2 = xindex tmp0 = -1 + x0 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1), tmp5 & xmask, other=0.0) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_constant_pad_nd_convolution_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 6 x4 = xindex // 24 x5 = xindex % 24 x2 = xindex // 24 % 4 x6 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (-4 + x5 + 16 * x4), tmp5 & xmask, other=0.0) tmp7 = tl.load(in_ptr1 + x2, tmp5 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype) tmp10 = tl.where(tmp5, tmp8, tmp9) tl.store(out_ptr0 + x6, tmp10, xmask) @triton.jit def triton_poi_fused_add_convolution_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tl.store(in_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) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 1), (12, 3, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1, 3), (12, 3, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 1, 3), (12, 3, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 3, 1), (12, 3, 1, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 4), (96, 24, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(384)](primals_1, buf0, 384, 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, 6), (96, 24, 6, 1), torch.float32) triton_poi_fused_constant_pad_nd_convolution_1[grid(384)](buf1, primals_3, buf2, 384, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = empty_strided_cuda((4, 4, 4, 6), (96, 24, 6, 1), torch.float32) triton_poi_fused_constant_pad_nd_2[grid(384)](primals_1, buf4, 384, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf5 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1)) buf6 = empty_strided_cuda((4, 4, 6, 4), (96, 24, 4, 1), torch.float32) triton_poi_fused_constant_pad_nd_convolution_3[grid(384)](buf5, primals_7, buf6, 384, XBLOCK=256, num_warps=4, num_stages=1) del buf5 del primals_7 buf7 = extern_kernels.convolution(buf6, primals_8, 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, 4, 4), (64, 16, 4, 1)) buf8 = buf3 del buf3 triton_poi_fused_add_convolution_4[grid(256)](buf8, primals_5, buf7, primals_9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf7 del primals_5 del primals_9 return (buf8, primals_2, primals_4, primals_6, primals_8, buf0, buf2, buf4, buf6) class Conv2D(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, padding= 'same', stride=1, dilation=1, groups=1): super(Conv2D, self).__init__() assert type(kernel_size) in [int, tuple ], 'Allowed kernel type [int or tuple], not {}'.format(type( kernel_size)) assert padding == 'same', 'Allowed padding type {}, not {}'.format( 'same', padding) self.kernel_size = kernel_size if isinstance(kernel_size, tuple): self.h_kernel = kernel_size[0] self.w_kernel = kernel_size[1] else: self.h_kernel = kernel_size self.w_kernel = kernel_size self.padding = padding self.stride = stride self.dilation = dilation self.groups = groups self.conv = nn.Conv2d(in_channels=in_channels, out_channels= out_channels, kernel_size=kernel_size, stride=self.stride, dilation=self.dilation, groups=self.groups) def forward(self, x): if self.padding == 'same': height, width = x.shape[2:] h_pad_need = max(0, (height - 1) * self.stride + self.h_kernel - height) w_pad_need = max(0, (width - 1) * self.stride + self.w_kernel - width) pad_left = w_pad_need // 2 pad_right = w_pad_need - pad_left pad_top = h_pad_need // 2 pad_bottom = h_pad_need - pad_top padding = pad_left, pad_right, pad_top, pad_bottom x = F.pad(x, padding, 'constant', 0) x = self.conv(x) return x class GCNNew(nn.Module): """ Large Kernel Matters -- https://arxiv.org/abs/1703.02719 """ def __init__(self, in_channels, out_channels, k=3): super(GCNNew, self).__init__() self.conv_l1 = Conv2D(in_channels=in_channels, out_channels= out_channels, kernel_size=(k, 1), padding='same') self.conv_l2 = Conv2D(in_channels=out_channels, out_channels= out_channels, kernel_size=(1, k), padding='same') self.conv_r1 = Conv2D(in_channels=in_channels, out_channels= out_channels, kernel_size=(1, k), padding='same') self.conv_r2 = Conv2D(in_channels=out_channels, out_channels= out_channels, kernel_size=(k, 1), padding='same') def forward(self, input_0): primals_2 = self.conv_l1.conv.weight primals_3 = self.conv_l1.conv.bias primals_4 = self.conv_l2.conv.weight primals_5 = self.conv_l2.conv.bias primals_6 = self.conv_r1.conv.weight primals_7 = self.conv_r1.conv.bias primals_8 = self.conv_r2.conv.weight primals_9 = self.conv_r2.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
XDong18/AdelaiDet
GCN
false
12,062
[ "BSD-2-Clause" ]
0
837cd1078923892fe6e84ac29fd0963f1b2c474f
https://github.com/XDong18/AdelaiDet/tree/837cd1078923892fe6e84ac29fd0963f1b2c474f
DPLSTMCell
import math import torch import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel from typing import Tuple class LSTMLinear(nn.Linear): """ This function is the same as a nn.Linear layer, except that in the backward pass the grad_samples get accumulated (instead of being concatenated as in the standard nn.Linear) """ def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True): super().__init__(in_features, out_features, bias) class DPLSTMCell(nn.Module): """ Internal-only class. Implements *one* step of LSTM so that a LSTM layer can be seen as repeated applications of this class. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.ih = LSTMLinear(input_size, 4 * hidden_size, bias=self.bias) self.hh = LSTMLinear(hidden_size, 4 * hidden_size, bias=self.bias) self.reset_parameters() def reset_parameters(self): """ Resets parameters by initializing them from an uniform distribution. """ stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): nn.init.uniform_(weight, -stdv, stdv) def forward(self, x: 'torch.Tensor', h_prev: 'torch.Tensor', c_prev: 'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor]: gates = self.ih(x) + self.hh(h_prev) i_t_input, f_t_input, g_t_input, o_t_input = torch.split(gates, self.hidden_size, 1) i_t = torch.sigmoid(i_t_input) f_t = torch.sigmoid(f_t_input) g_t = torch.tanh(g_t_input) o_t = torch.sigmoid(o_t_input) c_t = f_t * c_prev + i_t * g_t h_t = o_t * torch.tanh(c_t) return h_t, c_t def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4, 'bias': 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 import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp9 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr3 + (12 + x0), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask) tmp20 = tl.load(in_ptr3 + (8 + x0), xmask, eviction_policy='evict_last') tmp24 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp25 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask) tmp28 = tl.load(in_ptr3 + (4 + x0), xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr4 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp10 = tmp8 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = tl.sigmoid(tmp14) tmp18 = tmp16 + tmp17 tmp21 = tmp19 + tmp20 tmp22 = tmp18 + tmp21 tmp23 = libdevice.tanh(tmp22) tmp26 = tmp24 + tmp25 tmp29 = tmp27 + tmp28 tmp30 = tmp26 + tmp29 tmp31 = tl.sigmoid(tmp30) tmp33 = tmp31 * tmp32 tmp34 = tmp7 * tmp23 tmp35 = tmp33 + tmp34 tmp36 = 1.0 tmp37 = tmp36 - tmp31 tmp38 = tmp31 * tmp37 tmp39 = libdevice.tanh(tmp35) tmp40 = tmp15 * tmp39 tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp15, xmask) tl.store(out_ptr2 + x2, tmp23, xmask) tl.store(out_ptr3 + x2, tmp35, xmask) tl.store(out_ptr4 + x2, tmp38, xmask) tl.store(out_ptr5 + x2, tmp40, 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, (16, 4), (4, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(primals_6, reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_0[grid(16)](buf0 , primals_2, buf1, primals_5, primals_7, buf2, buf4, buf3, buf5, buf7, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 del buf1 del primals_2 del primals_5 return (buf6, buf5, primals_3, primals_6, primals_7, buf2, buf3, buf4, buf5, buf7) class LSTMLinear(nn.Linear): """ This function is the same as a nn.Linear layer, except that in the backward pass the grad_samples get accumulated (instead of being concatenated as in the standard nn.Linear) """ def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True): super().__init__(in_features, out_features, bias) class DPLSTMCellNew(nn.Module): """ Internal-only class. Implements *one* step of LSTM so that a LSTM layer can be seen as repeated applications of this class. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.ih = LSTMLinear(input_size, 4 * hidden_size, bias=self.bias) self.hh = LSTMLinear(hidden_size, 4 * hidden_size, bias=self.bias) self.reset_parameters() def reset_parameters(self): """ Resets parameters by initializing them from an uniform distribution. """ stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): nn.init.uniform_(weight, -stdv, stdv) def forward(self, input_0, input_1, input_2): primals_1 = self.ih.weight primals_2 = self.ih.bias primals_4 = self.hh.weight primals_5 = self.hh.bias primals_3 = input_0 primals_6 = input_1 primals_7 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0], output[1]
adriansarstedt/opacus
DPLSTMCell
false
12,063
[ "Apache-2.0" ]
0
a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
https://github.com/adriansarstedt/opacus/tree/a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
SimpleAtariNet
import torch import torch.nn as nn import torch.nn.functional as functional class SimpleAtariNet(nn.Module): def __init__(self): super(SimpleAtariNet, self).__init__() self.conv0 = nn.Conv2d(3, 16, 12, stride=(2, 8)) self.conv1 = nn.Conv2d(16, 32, 8, stride=4) self.conv2 = nn.Conv2d(32, 64, 4, stride=2) self.conv3 = nn.Conv2d(64, 64, 3, stride=1) self.lin1 = nn.Linear(1280, 512) self.lin2 = nn.Linear(512, 2) def forward(self, x): x = functional.relu(self.conv0(x)) x = functional.relu(self.conv1(x)) x = functional.relu(self.conv2(x)) x = functional.relu(self.conv3(x)) x = functional.relu(self.lin1(x.view(-1, 1280))) x = self.lin2(x) return x def get_inputs(): return [torch.rand([4, 3, 576, 576])] 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_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1285952 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 20093 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1104 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 59136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 231 % 64 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 39680 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x1 = xindex // 155 % 64 x2 = xindex // 9920 x3 = xindex % 9920 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + (x3 + 9984 * x2), tmp6, xmask) @triton.jit def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 15872 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 512 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, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (16, 3, 12, 12), (432, 144, 12, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 3, 576, 576), (995328, 331776, 576, 1)) assert_size_stride(primals_4, (32, 16, 8, 8), (1024, 64, 8, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (512, 1280), (1280, 1)) assert_size_stride(primals_11, (512,), (1,)) assert_size_stride(primals_12, (2, 512), (512, 1)) assert_size_stride(primals_13, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 8), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 283, 71), (321488, 20093, 71, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1285952)](buf1, primals_2, 1285952, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(4, 4), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 32, 69, 16), (35328, 1104, 16, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(141312)](buf3, primals_5, 141312, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 64, 33, 7), (14784, 231, 7, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(59136)](buf5, primals_7, 59136, XBLOCK=512, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 31, 5), (9920, 155, 5, 1)) buf7 = buf6 del buf6 buf11 = empty_strided_cuda((4, 64, 31, 5), (9984, 155, 5, 1), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_3[grid(39680)]( buf7, primals_9, buf11, 39680, XBLOCK=512, num_warps=4, num_stages=1) del primals_9 buf8 = empty_strided_cuda((31, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (31, 1280), (1280, 1), 0 ), reinterpret_tensor(primals_10, (1280, 512), (1, 1280), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_4[grid(15872)](buf9, primals_11, 15872, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf10 = empty_strided_cuda((31, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_13, buf9, reinterpret_tensor( primals_12, (512, 2), (1, 512), 0), alpha=1, beta=1, out=buf10) del primals_13 return (buf10, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf3, buf5, reinterpret_tensor(buf7, (31, 1280), (1280, 1), 0 ), buf9, primals_12, primals_10, buf11) class SimpleAtariNetNew(nn.Module): def __init__(self): super(SimpleAtariNetNew, self).__init__() self.conv0 = nn.Conv2d(3, 16, 12, stride=(2, 8)) self.conv1 = nn.Conv2d(16, 32, 8, stride=4) self.conv2 = nn.Conv2d(32, 64, 4, stride=2) self.conv3 = nn.Conv2d(64, 64, 3, stride=1) self.lin1 = nn.Linear(1280, 512) self.lin2 = nn.Linear(512, 2) def forward(self, input_0): primals_1 = self.conv0.weight primals_2 = self.conv0.bias primals_4 = self.conv1.weight primals_5 = self.conv1.bias primals_6 = self.conv2.weight primals_7 = self.conv2.bias primals_8 = self.conv3.weight primals_9 = self.conv3.bias primals_10 = self.lin1.weight primals_11 = self.lin1.bias primals_12 = self.lin2.weight primals_13 = self.lin2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0]
aaronmckinstry706/pytorch-practice
SimpleAtariNet
false
12,064
[ "MIT" ]
0
d3fd28733ea6de6a2e522ec52ff3e748df21b85a
https://github.com/aaronmckinstry706/pytorch-practice/tree/d3fd28733ea6de6a2e522ec52ff3e748df21b85a
Conv_ReLU_Block
import torch import torch.nn as nn class Conv_ReLU_Block(nn.Module): def __init__(self): super(Conv_ReLU_Block, self).__init__() self.conv = nn.Conv2d(in_channels=64, out_channels=64, kernel_size= 3, stride=1, padding=1, bias=False) self.relu = nn.ReLU(inplace=True) def forward(self, x): return self.relu(self.conv(x)) def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) 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, None) tl.store(out_ptr0 + x0, tmp4, None) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_2, (4, 64, 64, 64), (262144, 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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(1048576)](buf1, buf2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) return buf1, primals_1, primals_2, buf2 class Conv_ReLU_BlockNew(nn.Module): def __init__(self): super(Conv_ReLU_BlockNew, self).__init__() self.conv = nn.Conv2d(in_channels=64, out_channels=64, kernel_size= 3, stride=1, padding=1, bias=False) self.relu = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
advaza/pytorch-vdsr
Conv_ReLU_Block
false
12,065
[ "MIT" ]
0
8011f7323de3c7756df3828612addfb122c2bfef
https://github.com/advaza/pytorch-vdsr/tree/8011f7323de3c7756df3828612addfb122c2bfef
Gate
import torch import torch.nn as nn import torch.nn.functional as F class Gate(nn.Module): """Gate Unit g = sigmoid(Wx) x = g * x """ def __init__(self, input_size): super(Gate, self).__init__() self.linear = nn.Linear(input_size, input_size, bias=False) def forward(self, x): """ Args: x: batch * len * dim x_mask: batch * len (1 for padding, 0 for true) Output: res: batch * len * dim """ x_proj = self.linear(x) gate = F.sigmoid(x) return x_proj * gate def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](buf1, primals_2, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf1, primals_2 class GateNew(nn.Module): """Gate Unit g = sigmoid(Wx) x = g * x """ def __init__(self, input_size): super(GateNew, self).__init__() self.linear = nn.Linear(input_size, input_size, bias=False) def forward(self, input_0): primals_1 = self.linear.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
albert-dot-ai/MnemonicReader
Gate
false
12,066
[ "BSD-3-Clause" ]
0
eb51eb679a58677a405953c0c579568377c0b0f8
https://github.com/albert-dot-ai/MnemonicReader/tree/eb51eb679a58677a405953c0c579568377c0b0f8
ScoreLayer
import torch from torchvision.transforms import functional as F from torch.nn import functional as F import torch.nn as nn class ScoreLayer(nn.Module): def __init__(self, k): super(ScoreLayer, self).__init__() self.score = nn.Conv2d(k, 1, 1, 1) def forward(self, x, x_size=None): x = self.score(x) if x_size is not None: x = F.interpolate(x, x_size[2:], mode='bilinear', align_corners =True) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'k': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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, 1, 4, 4), (16, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(64)](buf1, primals_2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 return buf1, primals_1, primals_3 class ScoreLayerNew(nn.Module): def __init__(self, k): super(ScoreLayerNew, self).__init__() self.score = nn.Conv2d(k, 1, 1, 1) def forward(self, input_0): primals_1 = self.score.weight primals_2 = self.score.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
alejodosr/PoolNet
ScoreLayer
false
12,067
[ "MIT" ]
0
a6a19379933fe02c22f0eb0dd92038fe87cf0bd3
https://github.com/alejodosr/PoolNet/tree/a6a19379933fe02c22f0eb0dd92038fe87cf0bd3
NaiveGroupNorm
from torch.nn import Module import torch from torch.nn import Parameter from torch.nn import init import torch.nn.parallel class NaiveGroupNorm(Module): """NaiveGroupNorm implements Group Normalization with the high-level matrix operations in PyTorch. It is a temporary solution to export GN by ONNX before the official GN can be exported by ONNX. The usage of NaiveGroupNorm is exactly the same as the official :class:`torch.nn.GroupNorm`. Args: num_groups (int): number of groups to separate the channels into num_channels (int): number of channels expected in input eps: a value added to the denominator for numerical stability. Default: 1e-5 affine: a boolean value that when set to ``True``, this module has learnable per-channel affine parameters initialized to ones (for weights) and zeros (for biases). Default: ``True``. Shape: - Input: :math:`(N, C, *)` where :math:`C=\\text{num\\_channels}` - Output: :math:`(N, C, *)` (same shape as input) Examples:: >>> input = torch.randn(20, 6, 10, 10) >>> # Separate 6 channels into 3 groups >>> m = NaiveGroupNorm(3, 6) >>> # Separate 6 channels into 6 groups (equivalent with InstanceNorm) >>> m = NaiveGroupNorm(6, 6) >>> # Put all 6 channels into a single group (equivalent with LayerNorm) >>> m = NaiveGroupNorm(1, 6) >>> # Activating the module >>> output = m(input) .. _`Group Normalization`: https://arxiv.org/abs/1803.08494 """ __constants__ = ['num_groups', 'num_channels', 'eps', 'affine', 'weight', 'bias'] def __init__(self, num_groups, num_channels, eps=1e-05, affine=True): super(NaiveGroupNorm, self).__init__() self.num_groups = num_groups self.num_channels = num_channels self.eps = eps self.affine = affine if self.affine: self.weight = Parameter(torch.Tensor(num_channels)) self.bias = Parameter(torch.Tensor(num_channels)) else: self.register_parameter('weight', None) self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): if self.affine: init.ones_(self.weight) init.zeros_(self.bias) def forward(self, input): N, C, H, W = input.size() assert C % self.num_groups == 0 input = input.reshape(N, self.num_groups, -1) mean = input.mean(dim=-1, keepdim=True) var = (input ** 2).mean(dim=-1, keepdim=True) - mean ** 2 std = torch.sqrt(var + self.eps) input = (input - mean) / std input = input.reshape(N, C, H, W) if self.affine: input = input * self.weight.reshape(1, C, 1, 1 ) + self.bias.reshape(1, C, 1, 1) return input def extra_repr(self): return ('{num_groups}, {num_channels}, eps={eps}, affine={affine}'. format(**self.__dict__)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_groups': 1, 'num_channels': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch.nn import Module from torch.nn import Parameter from torch.nn import init import torch.nn.parallel assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_mean_mul_pow_sqrt_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) tmp20 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last') tmp22 = 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] tmp5 = tmp0 * tmp0 tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = 64.0 tmp11 = tmp4 / tmp10 tmp12 = tmp9 / tmp10 tmp13 = tmp11 * tmp11 tmp14 = tmp12 - tmp13 tmp15 = 1e-05 tmp16 = tmp14 + tmp15 tmp17 = libdevice.sqrt(tmp16) tmp18 = tmp0 - tmp11 tmp19 = tmp18 / tmp17 tmp21 = tmp19 * tmp20 tmp23 = tmp21 + tmp22 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp11, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp17, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp23, 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, 1), (1, 4, 4), torch.float32) buf2 = empty_strided_cuda((4, 1, 1), (1, 4, 4), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1, 1), (1, 1, 1), 0) del buf0 buf3 = reinterpret_tensor(buf2, (4, 1, 1), (1, 1, 1), 0) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_mean_mul_pow_sqrt_sub_0[grid(4)](buf1, buf3, primals_1, primals_2, primals_3, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf4, primals_1, buf1, buf3 class NaiveGroupNormNew(Module): """NaiveGroupNorm implements Group Normalization with the high-level matrix operations in PyTorch. It is a temporary solution to export GN by ONNX before the official GN can be exported by ONNX. The usage of NaiveGroupNorm is exactly the same as the official :class:`torch.nn.GroupNorm`. Args: num_groups (int): number of groups to separate the channels into num_channels (int): number of channels expected in input eps: a value added to the denominator for numerical stability. Default: 1e-5 affine: a boolean value that when set to ``True``, this module has learnable per-channel affine parameters initialized to ones (for weights) and zeros (for biases). Default: ``True``. Shape: - Input: :math:`(N, C, *)` where :math:`C=\\text{num\\_channels}` - Output: :math:`(N, C, *)` (same shape as input) Examples:: >>> input = torch.randn(20, 6, 10, 10) >>> # Separate 6 channels into 3 groups >>> m = NaiveGroupNorm(3, 6) >>> # Separate 6 channels into 6 groups (equivalent with InstanceNorm) >>> m = NaiveGroupNorm(6, 6) >>> # Put all 6 channels into a single group (equivalent with LayerNorm) >>> m = NaiveGroupNorm(1, 6) >>> # Activating the module >>> output = m(input) .. _`Group Normalization`: https://arxiv.org/abs/1803.08494 """ __constants__ = ['num_groups', 'num_channels', 'eps', 'affine', 'weight', 'bias'] def __init__(self, num_groups, num_channels, eps=1e-05, affine=True): super(NaiveGroupNormNew, self).__init__() self.num_groups = num_groups self.num_channels = num_channels self.eps = eps self.affine = affine if self.affine: self.weight = Parameter(torch.Tensor(num_channels)) self.bias = Parameter(torch.Tensor(num_channels)) else: self.register_parameter('weight', None) self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): if self.affine: init.ones_(self.weight) init.zeros_(self.bias) def extra_repr(self): return ('{num_groups}, {num_channels}, eps={eps}, affine={affine}'. format(**self.__dict__)) def forward(self, input_0): primals_2 = self.weight primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
XDong18/AdelaiDet
NaiveGroupNorm
false
12,068
[ "BSD-2-Clause" ]
0
837cd1078923892fe6e84ac29fd0963f1b2c474f
https://github.com/XDong18/AdelaiDet/tree/837cd1078923892fe6e84ac29fd0963f1b2c474f
SFU
import torch import torch.nn as nn import torch.nn.functional as F class SFU(nn.Module): """Semantic Fusion Unit The ouput vector is expected to not only retrieve correlative information from fusion vectors, but also retain partly unchange as the input vector """ def __init__(self, input_size, fusion_size): super(SFU, self).__init__() self.linear_r = nn.Linear(input_size + fusion_size, input_size) self.linear_g = nn.Linear(input_size + fusion_size, input_size) def forward(self, x, fusions): r_f = torch.cat([x, fusions], 2) r = F.tanh(self.linear_r(r_f)) g = F.sigmoid(self.linear_g(r_f)) o = g * r + (1 - g) * x return o def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'fusion_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_sigmoid_tanh_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp7 = tl.load(in_ptr2 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp3 = libdevice.tanh(tmp2) tmp4 = tmp1 * tmp3 tmp5 = 1.0 tmp6 = tmp5 - tmp1 tmp8 = tmp6 * tmp7 tmp9 = tmp4 + tmp8 tl.store(out_ptr0 + x0, tmp9, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 8), (8, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_1, primals_2, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(buf0, (16, 8), ( 8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf1) del primals_3 del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(buf0, (16, 8), ( 8, 1), 0), reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf2) del primals_5 del primals_6 buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_rsub_sigmoid_tanh_1[grid(64)](buf2, buf1, primals_1, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf3, primals_1, reinterpret_tensor(buf0, (16, 8), (8, 1), 0 ), buf1, buf2 class SFUNew(nn.Module): """Semantic Fusion Unit The ouput vector is expected to not only retrieve correlative information from fusion vectors, but also retain partly unchange as the input vector """ def __init__(self, input_size, fusion_size): super(SFUNew, self).__init__() self.linear_r = nn.Linear(input_size + fusion_size, input_size) self.linear_g = nn.Linear(input_size + fusion_size, input_size) def forward(self, input_0, input_1): primals_3 = self.linear_r.weight primals_4 = self.linear_r.bias primals_5 = self.linear_g.weight primals_6 = self.linear_g.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
albert-dot-ai/MnemonicReader
SFU
false
12,069
[ "BSD-3-Clause" ]
0
eb51eb679a58677a405953c0c579568377c0b0f8
https://github.com/albert-dot-ai/MnemonicReader/tree/eb51eb679a58677a405953c0c579568377c0b0f8
GraphNet
import torch import torch.nn as nn class GraphNet(nn.Module): def __init__(self, input_size, n_classes, num_neurons=32): super(GraphNet, self).__init__() self.fc1 = nn.Linear(input_size, num_neurons) self.fc2 = nn.Linear(num_neurons, num_neurons) self.fc3 = nn.Linear(num_neurons, n_classes) self.relu = nn.ReLU() self.sigmoid = nn.Softmax(dim=1) def forward(self, x): x = self.fc1(x) x = self.relu(x) x = self.fc2(x) x = self.relu(x) x = self.fc3(x) x = self.sigmoid(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'n_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (32, 4), (4, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (32, 32), (32, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (4, 32), (32, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 32), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 32), (512, 128, 32, 1), 0) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(2048)](buf1, primals_2, buf8, 2048, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 32), (1, 32), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 32), (512, 128, 32, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(2048)](buf3, primals_5, buf7, 2048, XBLOCK=256, 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, 32), (32, 1), 0), reinterpret_tensor(primals_6, (32, 4), (1, 32), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf5 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 32), (32, 1), 0), reinterpret_tensor( buf3, (64, 32), (32, 1), 0), buf6, primals_6, buf7, primals_4, buf8 class GraphNetNew(nn.Module): def __init__(self, input_size, n_classes, num_neurons=32): super(GraphNetNew, self).__init__() self.fc1 = nn.Linear(input_size, num_neurons) self.fc2 = nn.Linear(num_neurons, num_neurons) self.fc3 = nn.Linear(num_neurons, n_classes) self.relu = nn.ReLU() self.sigmoid = nn.Softmax(dim=1) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
adam2392/dldo
GraphNet
false
12,070
[ "MIT" ]
0
fc57f8700eb048558ab205c2c77a064f1a7cc7f6
https://github.com/adam2392/dldo/tree/fc57f8700eb048558ab205c2c77a064f1a7cc7f6
FCLayer
import torch import torch.nn as nn class FCLayer(nn.Module): def __init__(self, input_dim, output_dim, dropout_rate=0.0, use_activation=True): super().__init__() self.use_activation = use_activation self.dropout = nn.Dropout(dropout_rate) self.linear = nn.Linear(input_dim, output_dim) self.tanh = nn.Tanh() def forward(self, x): x = self.dropout(x) if self.use_activation: x = self.tanh(x) return self.linear(x) 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tl.store(out_ptr0 + x0, tmp1, xmask) 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, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_tanh_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1) del primals_2 del primals_3 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf0, (64, 4), (4, 1), 0) class FCLayerNew(nn.Module): def __init__(self, input_dim, output_dim, dropout_rate=0.0, use_activation=True): super().__init__() self.use_activation = use_activation self.dropout = nn.Dropout(dropout_rate) self.linear = nn.Linear(input_dim, output_dim) self.tanh = nn.Tanh() def forward(self, input_0): primals_2 = self.linear.weight primals_3 = self.linear.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
alexandre-do/r-bert
FCLayer
false
12,071
[ "Apache-2.0" ]
0
4e35bcbb0fe0602e708e18010e2394ebbfb074c4
https://github.com/alexandre-do/r-bert/tree/4e35bcbb0fe0602e708e18010e2394ebbfb074c4
SimpleGCN
import math import torch import torch.nn as nn from torch.nn.parameter import Parameter from torch.nn import Parameter import torch.nn import torch.autograd class SimpleGCN(nn.Module): """A simple graph convolution layer, similar to the one defined in Kipf et al. https://arxiv.org/abs/1609.02907 .. note:: If you use this code, please cite the original paper in addition to Kaolin. .. code-block:: @article{kipf2016semi, title={Semi-Supervised Classification with Graph Convolutional Networks}, author={Kipf, Thomas N and Welling, Max}, journal={arXiv preprint arXiv:1609.02907}, year={2016} } """ def __init__(self, in_features, out_features, bias=True): super(SimpleGCN, self).__init__() self.in_features = in_features self.out_features = out_features self.weight1 = Parameter(torch.Tensor(in_features, out_features)) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 6.0 / math.sqrt(self.weight1.size(1) + self.weight1.size(0)) stdv *= 0.6 self.weight1.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.uniform_(-0.1, 0.1) def forward(self, input, adj): support = torch.mm(input, self.weight1) side_len = max(support.shape[1] // 3, 2) if adj.type() == 'torch.cuda.sparse.FloatTensor': norm = torch.sparse.mm(adj, torch.ones((support.shape[0], 1))) normalized_support = support[:, :side_len] / norm side_1 = torch.sparse.mm(adj, normalized_support) else: side_1 = torch.mm(adj, support[:, :side_len]) side_2 = support[:, side_len:] output = torch.cat((side_1, side_2), dim=1) if self.bias is not None: output = output + self.bias return output def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math import torch.nn as nn from torch.nn.parameter import Parameter from torch.nn import Parameter import torch.nn import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp11 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (2 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 4, tl.int64) tmp9 = tl.load(in_ptr1 + (2 + 4 * x1 + (-2 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tmp12 = tmp10 + tmp11 tl.store(out_ptr0 + x2, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (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) extern_kernels.mm(primals_2, primals_1, out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 2), (2, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(buf0, (4, 2), (4, 1 ), 0), out=buf1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_cat_0[grid(16)](buf1, buf0, primals_4, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 del buf1 del primals_4 return buf2, reinterpret_tensor(primals_3, (4, 4), (1, 4), 0 ), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0) class SimpleGCNNew(nn.Module): """A simple graph convolution layer, similar to the one defined in Kipf et al. https://arxiv.org/abs/1609.02907 .. note:: If you use this code, please cite the original paper in addition to Kaolin. .. code-block:: @article{kipf2016semi, title={Semi-Supervised Classification with Graph Convolutional Networks}, author={Kipf, Thomas N and Welling, Max}, journal={arXiv preprint arXiv:1609.02907}, year={2016} } """ def __init__(self, in_features, out_features, bias=True): super(SimpleGCNNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight1 = Parameter(torch.Tensor(in_features, out_features)) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 6.0 / math.sqrt(self.weight1.size(1) + self.weight1.size(0)) stdv *= 0.6 self.weight1.data.uniform_(-stdv, stdv) if self.bias is not None: self.bias.data.uniform_(-0.1, 0.1) def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' def forward(self, input_0, input_1): primals_1 = self.weight1 primals_4 = self.bias primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
acivgin1/kaolin
SimpleGCN
false
12,072
[ "ECL-2.0", "Apache-2.0" ]
0
4c4e0098b2cd9a73709c81fea82de03abbd6cdd5
https://github.com/acivgin1/kaolin/tree/4c4e0098b2cd9a73709c81fea82de03abbd6cdd5
DepthwiseSeperableConv1d
import torch import torch.nn as nn class DepthwiseSeperableConv1d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size): super(DepthwiseSeperableConv1d, self).__init__() self.depthwise_conv1d = nn.Conv1d(in_channels, in_channels, kernel_size, groups=in_channels, padding=kernel_size // 2) self.pointwise_conv1d = nn.Conv1d(in_channels, out_channels, 1) def forward(self, x): x = self.depthwise_conv1d(x) x = self.pointwise_conv1d(x) return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 20 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 5 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 1, 4), (4, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_1, stride=(1,), padding=(2,), dilation=(1,), transposed=False, output_padding=(0,), groups=4, bias=None) assert_size_stride(buf0, (1, 4, 5), (20, 5, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(20)](buf1, primals_2, 20, XBLOCK=32, num_warps=1, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (1, 4, 5 ), (0, 5, 1), 0), primals_4, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 5), (20, 5, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(20)](buf3, primals_5, 20, XBLOCK=32, num_warps=1, num_stages=1) del primals_5 return reinterpret_tensor(buf3, (4, 5), (5, 1), 0 ), primals_1, primals_4, reinterpret_tensor(primals_3, (1, 4, 4), ( 16, 4, 1), 0), buf1 class DepthwiseSeperableConv1dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size): super(DepthwiseSeperableConv1dNew, self).__init__() self.depthwise_conv1d = nn.Conv1d(in_channels, in_channels, kernel_size, groups=in_channels, padding=kernel_size // 2) self.pointwise_conv1d = nn.Conv1d(in_channels, out_channels, 1) def forward(self, input_0): primals_1 = self.depthwise_conv1d.weight primals_2 = self.depthwise_conv1d.bias primals_4 = self.pointwise_conv1d.weight primals_5 = self.pointwise_conv1d.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
allenye0119/pytorch-modules
DepthwiseSeperableConv1d
false
12,074
[ "MIT" ]
0
c7683ef63478becca3b79a7498840450da33f468
https://github.com/allenye0119/pytorch-modules/tree/c7683ef63478becca3b79a7498840450da33f468
LRN
import torch import torch.nn as nn class LRN(nn.Module): def __init__(self, local_size=1, alpha=1.0, beta=0.75, ACROSS_CHANNELS=True ): super(LRN, self).__init__() self.ACROSS_CHANNELS = ACROSS_CHANNELS if ACROSS_CHANNELS: self.average = nn.AvgPool3d(kernel_size=(local_size, 1, 1), stride=1, padding=(int((local_size - 1.0) / 2), 0, 0)) else: self.average = nn.AvgPool2d(kernel_size=local_size, stride=1, padding=int((local_size - 1.0) / 2)) self.alpha = alpha self.beta = beta def forward(self, x): if self.ACROSS_CHANNELS: div = x.pow(2).unsqueeze(1) div = self.average(div).squeeze(1) div = div.mul(self.alpha).add(1.0).pow(self.beta) else: div = x.pow(2) div = self.average(div) div = div.mul(self.alpha).add(1.0).pow(self.beta) x = x.div(div) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_pow_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 tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = tmp3 * tmp2 tmp5 = tmp4 + tmp2 tmp6 = 0.75 tmp7 = libdevice.pow(tmp5, tmp6) tmp8 = tmp0 / 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_mul_pow_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class LRNNew(nn.Module): def __init__(self, local_size=1, alpha=1.0, beta=0.75, ACROSS_CHANNELS=True ): super(LRNNew, self).__init__() self.ACROSS_CHANNELS = ACROSS_CHANNELS if ACROSS_CHANNELS: self.average = nn.AvgPool3d(kernel_size=(local_size, 1, 1), stride=1, padding=(int((local_size - 1.0) / 2), 0, 0)) else: self.average = nn.AvgPool2d(kernel_size=local_size, stride=1, padding=int((local_size - 1.0) / 2)) self.alpha = alpha self.beta = beta def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
anas-awadalla/dissect
LRN
false
12,075
[ "MIT" ]
0
d74e9147731c6160274405a39ab1c98191929269
https://github.com/anas-awadalla/dissect/tree/d74e9147731c6160274405a39ab1c98191929269
LayerNorm
import math import torch from torch import Tensor import torch.nn as nn from torch.nn import Parameter from torch.autograd import Variable class LayerNorm(nn.Module): """ Layer Normalization based on Ba & al.: 'Layer Normalization' https://arxiv.org/pdf/1607.06450.pdf """ def __init__(self, input_size, learnable=True, epsilon=1e-06): super(LayerNorm, self).__init__() self.input_size = input_size self.learnable = learnable self.alpha = Tensor(1, input_size).fill_(1) self.beta = Tensor(1, input_size).fill_(0) self.epsilon = epsilon if learnable: W = Parameter else: W = Variable self.alpha = W(self.alpha) self.beta = W(self.beta) self.reset_parameters() def reset_parameters(self): std = 1.0 / math.sqrt(self.input_size) for w in self.parameters(): w.data.uniform_(-std, std) def forward(self, x): size = x.size() x = x.view(x.size(0), -1) x = (x - torch.mean(x, 1).unsqueeze(1).expand_as(x)) / torch.sqrt( torch.var(x, 1).unsqueeze(1).expand_as(x) + self.epsilon) if self.learnable: x = self.alpha.expand_as(x) * x + self.beta.expand_as(x) return x.view(size) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math from torch import Tensor import torch.nn as nn from torch.nn import Parameter from torch.autograd import Variable assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_sqrt_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 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') tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp9 = 4.0 tmp10 = tmp8 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp2 - tmp10 tmp13 = tmp12 * tmp12 tmp14 = tmp3 - tmp10 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp10 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp7 - tmp10 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp23 = 3.0 tmp24 = tmp22 / tmp23 tmp25 = 1e-06 tmp26 = tmp24 + tmp25 tmp27 = libdevice.sqrt(tmp26) tmp28 = tmp11 / tmp27 tmp29 = tmp0 * tmp28 tmp31 = tmp29 + tmp30 tl.store(out_ptr0 + x2, tmp31, 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, (1, 4), (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_add_div_mul_sqrt_sub_0[grid(16)](primals_2, primals_1, primals_3, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class LayerNormNew(nn.Module): """ Layer Normalization based on Ba & al.: 'Layer Normalization' https://arxiv.org/pdf/1607.06450.pdf """ def __init__(self, input_size, learnable=True, epsilon=1e-06): super(LayerNormNew, self).__init__() self.input_size = input_size self.learnable = learnable self.alpha = Tensor(1, input_size).fill_(1) self.beta = Tensor(1, input_size).fill_(0) self.epsilon = epsilon if learnable: W = Parameter else: W = Variable self.alpha = W(self.alpha) self.beta = W(self.beta) self.reset_parameters() def reset_parameters(self): std = 1.0 / math.sqrt(self.input_size) for w in self.parameters(): w.data.uniform_(-std, std) def forward(self, input_0): primals_2 = self.alpha primals_3 = self.beta primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
alex-kj-chin/universal-computation
LayerNorm
false
12,076
[ "MIT" ]
0
a41cc7d685a3e0c56c11bc346c25394464da2e06
https://github.com/alex-kj-chin/universal-computation/tree/a41cc7d685a3e0c56c11bc346c25394464da2e06
ResidualBlock
import torch import torch.nn as nn class ConvLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride, norm =None, bias=True): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, bias=bias) self.norm = norm if norm == 'BN': self.norm_layer = nn.BatchNorm2d(out_channels) elif norm == 'IN': self.norm_layer = nn.InstanceNorm2d(out_channels, track_running_stats=True) def forward(self, x): out = self.reflection_pad(x) out = self.conv2d(out) if self.norm in ['BN' or 'IN']: out = self.norm_layer(out) return out class ResidualBlock(nn.Module): def __init__(self, channels, norm=None, bias=True): super(ResidualBlock, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1, bias=bias, norm=norm) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1, bias=bias, norm=norm) self.relu = nn.LeakyReLU(negative_slope=0.2, inplace=True) def forward(self, x): input = x out = self.relu(self.conv1(x)) out = self.conv2(out) out = out + input return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x2 = xindex // 36 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_reflection_pad2d_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x5, tmp7, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = 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_reflection_pad2d_0[grid(576)](primals_1, buf0, 576, XBLOCK=256, 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, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_reflection_pad2d_1[grid(576)]( buf1, primals_3, buf2, 576, XBLOCK=256, num_warps=4, num_stages=1) buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_add_convolution_2[grid(256)](buf4, primals_5, primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_5 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_3[grid(256) ](buf1, primals_3, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1 ) del buf1 del primals_3 return buf4, primals_2, primals_4, buf0, buf2, buf5 class ConvLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride, norm =None, bias=True): super(ConvLayer, self).__init__() reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReflectionPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, bias=bias) self.norm = norm if norm == 'BN': self.norm_layer = nn.BatchNorm2d(out_channels) elif norm == 'IN': self.norm_layer = nn.InstanceNorm2d(out_channels, track_running_stats=True) def forward(self, x): out = self.reflection_pad(x) out = self.conv2d(out) if self.norm in ['BN' or 'IN']: out = self.norm_layer(out) return out class ResidualBlockNew(nn.Module): def __init__(self, channels, norm=None, bias=True): super(ResidualBlockNew, self).__init__() self.conv1 = ConvLayer(channels, channels, kernel_size=3, stride=1, bias=bias, norm=norm) self.conv2 = ConvLayer(channels, channels, kernel_size=3, stride=1, bias=bias, norm=norm) self.relu = nn.LeakyReLU(negative_slope=0.2, inplace=True) def forward(self, input_0): primals_2 = self.conv1.conv2d.weight primals_3 = self.conv1.conv2d.bias primals_4 = self.conv2.conv2d.weight primals_5 = self.conv2.conv2d.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
alhsu713/fast_blind_video_consistency
ResidualBlock
false
12,078
[ "MIT" ]
0
2037ec5f68a361b926c31b3a12c1cd04e2331797
https://github.com/alhsu713/fast_blind_video_consistency/tree/2037ec5f68a361b926c31b3a12c1cd04e2331797
InnerProductModel
import torch class InnerProductModel(torch.nn.Module): @staticmethod def is_valid_model_type(model_type): raise NotImplementedError @staticmethod def get_model_from_type(model_type): raise NotImplementedError @property def loss_criterion(self): return torch.nn.MSELoss() def __init__(self, n): super().__init__() self.layer = torch.nn.Linear(n, 1, bias=False) self.layer.weight.data = torch.arange(n, dtype=torch.float32) def forward(self, x): return self.layer(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n': 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mv_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 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_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp3 = tmp0 * tmp2 tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp12 = tmp9 * tmp11 tmp13 = tmp8 + tmp12 tmp17 = tmp14 * tmp16 tmp18 = tmp13 + tmp17 tl.store(out_ptr0 + x0, tmp18, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_mv_0[grid(64)](primals_2, primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 return reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0), primals_2 class InnerProductModelNew(torch.nn.Module): @staticmethod def is_valid_model_type(model_type): raise NotImplementedError @staticmethod def get_model_from_type(model_type): raise NotImplementedError @property def loss_criterion(self): return torch.nn.MSELoss() def __init__(self, n): super().__init__() self.layer = torch.nn.Linear(n, 1, bias=False) self.layer.weight.data = torch.arange(n, dtype=torch.float32) def forward(self, input_0): primals_1 = self.layer.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
SheepiesLab/plato
InnerProductModel
false
12,079
[ "Apache-2.0" ]
0
9f5bbfa4b6952d1b3af24be409982d303d54a169
https://github.com/SheepiesLab/plato/tree/9f5bbfa4b6952d1b3af24be409982d303d54a169
Critic
import torch import torch.nn as nn import torch.nn.functional as F class Critic(nn.Module): def __init__(self, state_dim, action_dim): super(Critic, self).__init__() self.l1 = nn.Linear(state_dim + action_dim, 400) self.l2 = nn.Linear(400, 300) self.l3 = nn.Linear(300, 1) def forward(self, x, u): x = F.relu(self.l1(torch.cat([x, u], 1))) x = F.relu(self.l2(x)) x = self.l3(x) return x def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'action_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 400 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 300 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) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (400, 8), (8, 1)) assert_size_stride(primals_4, (400,), (1,)) assert_size_stride(primals_5, (300, 400), (400, 1)) assert_size_stride(primals_6, (300,), (1,)) assert_size_stride(primals_7, (1, 300), (300, 1)) assert_size_stride(primals_8, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 400), (400, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (8, 400), (1, 8), 0), out=buf1) del primals_3 buf2 = buf1 del buf1 triton_poi_fused_relu_1[grid(1600)](buf2, primals_4, 1600, XBLOCK= 256, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 300), (300, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (400, 300), ( 1, 400), 0), out=buf3) buf4 = buf3 del buf3 triton_poi_fused_relu_2[grid(1200)](buf4, primals_6, 1200, XBLOCK= 256, num_warps=4, num_stages=1) del primals_6 buf6 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, buf4, reinterpret_tensor(primals_7, (300, 1), (1, 300), 0), alpha=1, beta=1, out=buf6) del primals_8 return buf6, buf0, buf2, buf4, primals_7, primals_5 class CriticNew(nn.Module): def __init__(self, state_dim, action_dim): super(CriticNew, self).__init__() self.l1 = nn.Linear(state_dim + action_dim, 400) self.l2 = nn.Linear(400, 300) self.l3 = nn.Linear(300, 1) def forward(self, input_0, input_1): primals_3 = self.l1.weight primals_4 = self.l1.bias primals_5 = self.l2.weight primals_6 = self.l2.bias primals_7 = self.l3.weight primals_8 = self.l3.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
SheepiesLab/plato
Critic
false
12,080
[ "Apache-2.0" ]
0
9f5bbfa4b6952d1b3af24be409982d303d54a169
https://github.com/SheepiesLab/plato/tree/9f5bbfa4b6952d1b3af24be409982d303d54a169
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.a1 = nn.Conv2d(19, 64, kernel_size=3, padding=1) self.a2 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.a3 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.b1 = nn.Conv2d(256, 256, kernel_size=3, padding=0) self.b2 = nn.Conv2d(256, 256, kernel_size=3, padding=0) self.b3 = nn.Conv2d(256, 256, kernel_size=4, padding=0) self.linear = nn.Linear(256, 7) def forward(self, x): x = F.relu(self.a1(x)) x = F.relu(self.a2(x)) x = F.relu(self.a3(x)) x = F.relu(self.b1(x)) x = F.relu(self.b2(x)) x = F.relu(self.b3(x)) x = x.view(-1, 256) x = self.linear(x) return x def get_inputs(): return [torch.rand([4, 19, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 1216 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 % 19 y1 = yindex // 19 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 19 * x2 + 171 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 76 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 % 19 y1 = yindex // 19 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 19 * x2 + 77824 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 16 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 + 16 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 256 * x2 + 4096 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_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 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_11(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 3249 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 256 y1 = yindex // 256 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 831744 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 3264 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 256 * x2 + 831744 * y1), tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_view_12(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3326976 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (3264 * (x0 // 3249) + x0 % 3249), xmask) tl.store(out_ptr0 + x0, tmp0, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15) = args args.clear() assert_size_stride(primals_1, (64, 19, 3, 3), (171, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 19, 64, 64), (77824, 4096, 64, 1)) assert_size_stride(primals_4, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 4, 4), (4096, 16, 4, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (7, 256), (256, 1)) assert_size_stride(primals_15, (7,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 19, 3, 3), (171, 1, 57, 19), torch. float32) get_raw_stream(0) triton_poi_fused_0[grid(1216, 9)](primals_1, buf0, 1216, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 19, 64, 64), (77824, 1, 1216, 19), torch.float32) triton_poi_fused_1[grid(76, 4096)](primals_3, buf1, 76, 4096, XBLOCK=32, YBLOCK=32, 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_4, buf2, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_3[grid(32768, 9)](primals_6, buf3, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_4[grid(65536, 9)](primals_8, buf4, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf5 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_4[grid(65536, 9)](primals_10, buf5, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_10 buf6 = empty_strided_cuda((256, 256, 4, 4), (4096, 1, 1024, 256), torch.float32) triton_poi_fused_5[grid(65536, 16)](primals_12, buf6, 65536, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf7 = 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(buf7, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf8 = buf7 del buf7 triton_poi_fused_convolution_relu_6[grid(1048576)](buf8, primals_2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf9 = extern_kernels.convolution(buf8, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 128, 64, 64), (524288, 1, 8192, 128)) buf10 = buf9 del buf9 triton_poi_fused_convolution_relu_7[grid(2097152)](buf10, primals_5, 2097152, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf11 = extern_kernels.convolution(buf10, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 256, 64, 64), (1048576, 1, 16384, 256)) buf12 = buf11 del buf11 triton_poi_fused_convolution_relu_8[grid(4194304)](buf12, primals_7, 4194304, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf13 = extern_kernels.convolution(buf12, buf4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (4, 256, 62, 62), (984064, 1, 15872, 256)) buf14 = buf13 del buf13 triton_poi_fused_convolution_relu_9[grid(3936256)](buf14, primals_9, 3936256, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf15 = extern_kernels.convolution(buf14, buf5, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 256, 60, 60), (921600, 1, 15360, 256)) buf16 = buf15 del buf15 triton_poi_fused_convolution_relu_10[grid(3686400)](buf16, primals_11, 3686400, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf17 = extern_kernels.convolution(buf16, buf6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf17, (4, 256, 57, 57), (831744, 1, 14592, 256)) buf18 = empty_strided_cuda((4, 256, 57, 57), (835584, 3264, 57, 1), torch.float32) buf21 = empty_strided_cuda((4, 256, 57, 57), (831744, 1, 14592, 256 ), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_11[grid(1024, 3249)](buf17, primals_13, buf18, buf21, 1024, 3249, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_13 buf19 = reinterpret_tensor(buf17, (12996, 256), (256, 1), 0) del buf17 triton_poi_fused_convolution_relu_view_12[grid(3326976)](buf18, buf19, 3326976, XBLOCK=512, num_warps=8, num_stages=1) del buf18 buf20 = empty_strided_cuda((12996, 7), (7, 1), torch.float32) extern_kernels.addmm(primals_15, buf19, reinterpret_tensor( primals_14, (256, 7), (1, 256), 0), alpha=1, beta=1, out=buf20) del primals_15 return (buf20, buf0, buf1, buf2, buf3, buf4, buf5, buf6, buf8, buf10, buf12, buf14, buf16, buf19, primals_14, buf21) class NetNew(nn.Module): def __init__(self): super(NetNew, self).__init__() self.a1 = nn.Conv2d(19, 64, kernel_size=3, padding=1) self.a2 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.a3 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.b1 = nn.Conv2d(256, 256, kernel_size=3, padding=0) self.b2 = nn.Conv2d(256, 256, kernel_size=3, padding=0) self.b3 = nn.Conv2d(256, 256, kernel_size=4, padding=0) self.linear = nn.Linear(256, 7) def forward(self, input_0): primals_1 = self.a1.weight primals_2 = self.a1.bias primals_4 = self.a2.weight primals_5 = self.a2.bias primals_6 = self.a3.weight primals_7 = self.a3.bias primals_8 = self.b1.weight primals_9 = self.b1.bias primals_10 = self.b2.weight primals_11 = self.b2.bias primals_12 = self.b3.weight primals_13 = self.b3.bias primals_14 = self.linear.weight primals_15 = self.linear.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]) return output[0]
afozk95/chess-dataset
Net
false
12,081
[ "MIT" ]
0
08de7b251f67cb8553a5ee66f6fd76cefeb14bb4
https://github.com/afozk95/chess-dataset/tree/08de7b251f67cb8553a5ee66f6fd76cefeb14bb4
SimmatModule
import torch class SimmatModule(torch.nn.Module): def __init__(self, padding=-1): super().__init__() self.padding = padding self._hamming_index_loaded = None self._hamming_index = None def forward(self, query_embed, doc_embed, query_tok, doc_tok): simmat = [] for a_emb, b_emb in zip(query_embed, doc_embed): BAT, A, B = a_emb.shape[0], a_emb.shape[1], b_emb.shape[1] a_denom = a_emb.norm(p=2, dim=2).reshape(BAT, A, 1).expand(BAT, A, B) + 1e-09 b_denom = b_emb.norm(p=2, dim=2).reshape(BAT, 1, B).expand(BAT, A, B) + 1e-09 perm = b_emb.permute(0, 2, 1) sim = a_emb.bmm(perm) sim = sim / (a_denom * b_denom) nul = torch.zeros_like(sim) sim = torch.where(query_tok.reshape(BAT, A, 1).expand(BAT, A, B ) == self.padding, nul, sim) sim = torch.where(doc_tok.reshape(BAT, 1, B).expand(BAT, A, B) == self.padding, nul, sim) simmat.append(sim) return torch.stack(simmat, dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 1]), torch.rand([4, 1, 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 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_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + 4 * x4, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x4), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x4), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x4), xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-09 tmp14 = tmp12 + tmp13 tmp16 = tmp15 * tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = tmp26 + tmp13 tmp28 = tmp14 * tmp27 tmp29 = tmp0 / tmp28 tl.store(in_out_ptr0 + x3, tmp29, xmask) @triton.jit def triton_poi_fused_add_div_mul_1(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 x3 = xindex x4 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (64 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (65 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp6 = tl.load(in_ptr0 + (66 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (67 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + (64 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (65 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + (66 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr1 + (67 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-09 tmp14 = tmp12 + tmp13 tmp16 = tmp15 * tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = tmp26 + tmp13 tmp28 = tmp14 * tmp27 tmp29 = tmp0 / tmp28 tl.store(in_out_ptr0 + x3, tmp29, xmask) @triton.jit def triton_poi_fused_add_div_mul_2(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 x3 = xindex x4 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (128 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (129 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (130 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (131 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (128 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (129 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + (130 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr1 + (131 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-09 tmp14 = tmp12 + tmp13 tmp16 = tmp15 * tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = tmp26 + tmp13 tmp28 = tmp14 * tmp27 tmp29 = tmp0 / tmp28 tl.store(in_out_ptr0 + x3, tmp29, xmask) @triton.jit def triton_poi_fused_add_div_mul_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (192 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (193 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (194 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (195 + 4 * x4), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (192 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr1 + (193 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + (194 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr1 + (195 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-09 tmp14 = tmp12 + tmp13 tmp16 = tmp15 * tmp15 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp21 = tmp20 * tmp20 tmp22 = tmp19 + tmp21 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = tmp26 + tmp13 tmp28 = tmp14 * tmp27 tmp29 = tmp0 / tmp28 tl.store(in_out_ptr0 + x3, tmp29, xmask) @triton.jit def triton_poi_fused_stack_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 16 x0 = xindex % 4 x2 = xindex // 64 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = -1.0 tmp7 = tmp5 == tmp6 tmp8 = tl.load(in_ptr1 + (4 * x2 + x1), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tmp8 == tmp6 tmp10 = tl.load(in_ptr2 + (x0 + 4 * x1 + 16 * x2), tmp4 & xmask, other=0.0) tmp11 = 0.0 tmp12 = tl.where(tmp9, tmp11, tmp10) tmp13 = tl.where(tmp7, tmp11, tmp12) tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp4, tmp13, tmp14) tmp16 = tmp0 >= tmp3 tmp17 = tl.full([1], 8, tl.int64) tmp18 = tmp0 < tmp17 tmp19 = tmp16 & tmp18 tmp20 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp19 & xmask, eviction_policy ='evict_last', other=0.0) tmp21 = tmp20 == tmp6 tmp22 = tl.load(in_ptr1 + (4 * x2 + (-4 + x1)), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp23 = tmp22 == tmp6 tmp24 = tl.load(in_ptr3 + (x0 + 4 * (-4 + x1) + 16 * x2), tmp19 & xmask, other=0.0) tmp25 = tl.where(tmp23, tmp11, tmp24) tmp26 = tl.where(tmp21, tmp11, tmp25) tmp27 = tl.full(tmp26.shape, 0.0, tmp26.dtype) tmp28 = tl.where(tmp19, tmp26, tmp27) tmp29 = tmp0 >= tmp17 tmp30 = tl.full([1], 12, tl.int64) tmp31 = tmp0 < tmp30 tmp32 = tmp29 & tmp31 tmp33 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp32 & xmask, eviction_policy ='evict_last', other=0.0) tmp34 = tmp33 == tmp6 tmp35 = tl.load(in_ptr1 + (4 * x2 + (-8 + x1)), tmp32 & xmask, eviction_policy='evict_last', other=0.0) tmp36 = tmp35 == tmp6 tmp37 = tl.load(in_ptr4 + (x0 + 4 * (-8 + x1) + 16 * x2), tmp32 & xmask, other=0.0) tmp38 = tl.where(tmp36, tmp11, tmp37) tmp39 = tl.where(tmp34, tmp11, tmp38) tmp40 = tl.full(tmp39.shape, 0.0, tmp39.dtype) tmp41 = tl.where(tmp32, tmp39, tmp40) tmp42 = tmp0 >= tmp30 tl.full([1], 16, tl.int64) tmp45 = tl.load(in_ptr0 + (x0 + 4 * x2), tmp42 & xmask, eviction_policy ='evict_last', other=0.0) tmp46 = tmp45 == tmp6 tmp47 = tl.load(in_ptr1 + (4 * x2 + (-12 + x1)), tmp42 & xmask, eviction_policy='evict_last', other=0.0) tmp48 = tmp47 == tmp6 tmp49 = tl.load(in_ptr5 + (x0 + 4 * (-12 + x1) + 16 * x2), tmp42 & xmask, other=0.0) tmp50 = tl.where(tmp48, tmp11, tmp49) tmp51 = tl.where(tmp46, tmp11, tmp50) tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp42, tmp51, tmp52) tmp54 = tl.where(tmp32, tmp41, tmp53) tmp55 = tl.where(tmp19, tmp28, tmp54) tmp56 = tl.where(tmp4, tmp15, tmp55) tl.store(out_ptr0 + x3, tmp56, 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, 1), (4, 1, 1)) assert_size_stride(arg3_1, (4, 1, 4), (4, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 0), out=buf0) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_div_mul_0[grid(64)](buf1, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1), 64), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 64), out =buf2) buf3 = buf2 del buf2 triton_poi_fused_add_div_mul_1[grid(64)](buf3, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1), 128), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 128), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_add_div_mul_2[grid(64)](buf5, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1), 192), reinterpret_tensor(arg1_1, (4, 4, 4), (16, 1, 4), 192), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_add_div_mul_3[grid(64)](buf7, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf8 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32) triton_poi_fused_stack_4[grid(256)](arg3_1, arg2_1, buf1, buf3, buf5, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg2_1 del arg3_1 del buf1 del buf3 del buf5 del buf7 return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0), class SimmatModuleNew(torch.nn.Module): def __init__(self, padding=-1): super().__init__() self.padding = padding self._hamming_index_loaded = None self._hamming_index = None 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]
alpers/FlexNeuART
SimmatModule
false
12,082
[ "Apache-2.0" ]
0
2ae263f46b6eb2f1435b9073dad629a2fef23ab9
https://github.com/alpers/FlexNeuART/tree/2ae263f46b6eb2f1435b9073dad629a2fef23ab9
PACRRConvMax2dModule
import torch class PACRRConvMax2dModule(torch.nn.Module): def __init__(self, shape, n_filters, k, channels): super().__init__() self.shape = shape if shape != 1: self.pad = torch.nn.ConstantPad2d((0, shape - 1, 0, shape - 1), 0) else: self.pad = None self.conv = torch.nn.Conv2d(channels, n_filters, shape) self.activation = torch.nn.ReLU() self.k = k self.shape = shape self.channels = channels def forward(self, simmat): BATCH, _CHANNELS, QLEN, DLEN = simmat.shape if self.pad: simmat = self.pad(simmat) conv = self.activation(self.conv(simmat)) top_filters, _ = conv.max(dim=1) if DLEN < self.k: top_filters = torch.nn.functional.pad(top_filters, (0, self.k - DLEN)) top_toks, _ = top_filters.topk(self.k, dim=2) result = top_toks.reshape(BATCH, QLEN, self.k) return result def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'shape': 4, 'n_filters': 4, 'k': 4, 'channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 7 % 7 x0 = xindex % 7 x2 = xindex // 49 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp5 & xmask, other=0.0) tl.store(out_ptr0 + x3, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_max_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 x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp7 = tl.load(in_ptr1 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp26 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp27 = tl.load(in_ptr1 + 2) tmp28 = tl.broadcast_to(tmp27, [XBLOCK]) tmp45 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp46 = tl.load(in_ptr1 + 3) tmp47 = tl.broadcast_to(tmp46, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp9 = tmp6 + tmp8 tmp10 = triton_helpers.maximum(tmp4, tmp9) tmp11 = tmp5 > tmp10 tmp12 = tmp5 == tmp10 tmp13 = tmp5 != tmp5 tmp14 = tmp10 != tmp10 tmp15 = tmp13 > tmp14 tmp16 = tmp11 | tmp15 tmp17 = tmp13 & tmp14 tmp18 = tmp12 | tmp17 tmp19 = tl.full([1], 0, tl.int64) tmp20 = tl.full([1], 1, tl.int64) tmp21 = tmp19 < tmp20 tmp22 = tmp18 & tmp21 tmp23 = tmp16 | tmp22 tmp24 = tl.where(tmp23, tmp5, tmp10) tmp25 = tl.where(tmp23, tmp19, tmp20) tmp29 = tmp26 + tmp28 tmp30 = triton_helpers.maximum(tmp4, tmp29) tmp31 = tmp24 > tmp30 tmp32 = tmp24 == tmp30 tmp33 = tmp24 != tmp24 tmp34 = tmp30 != tmp30 tmp35 = tmp33 > tmp34 tmp36 = tmp31 | tmp35 tmp37 = tmp33 & tmp34 tmp38 = tmp32 | tmp37 tmp39 = tl.full([1], 2, tl.int64) tmp40 = tmp25 < tmp39 tmp41 = tmp38 & tmp40 tmp42 = tmp36 | tmp41 tmp43 = tl.where(tmp42, tmp24, tmp30) tmp44 = tl.where(tmp42, tmp25, tmp39) tmp48 = tmp45 + tmp47 tmp49 = triton_helpers.maximum(tmp4, tmp48) tmp50 = tmp43 > tmp49 tmp51 = tmp43 == tmp49 tmp52 = tmp43 != tmp43 tmp53 = tmp49 != tmp49 tmp54 = tmp52 > tmp53 tmp55 = tmp50 | tmp54 tmp56 = tmp52 & tmp53 tmp57 = tmp51 | tmp56 tmp58 = tl.full([1], 3, tl.int64) tmp59 = tmp44 < tmp58 tmp60 = tmp57 & tmp59 tmp61 = tmp55 | tmp60 tl.where(tmp61, tmp43, tmp49) tmp63 = tl.where(tmp61, tmp44, tmp58) tmp64 = triton_helpers.maximum(tmp5, tmp10) tmp65 = triton_helpers.maximum(tmp64, tmp30) tmp66 = triton_helpers.maximum(tmp65, tmp49) tl.store(out_ptr0 + x2, tmp63, xmask) tl.store(out_ptr1 + x2, tmp66, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 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, 7, 7), (196, 49, 7, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(784)](primals_1, buf0, 784, 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, 4, 4), (64, 16, 4, 1)) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_convolution_max_relu_1[grid(64)](buf1, primals_3, buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = torch.ops.aten.topk.default(buf3, 4, 2) del buf3 buf5 = buf4[0] buf6 = buf4[1] del buf4 buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_2[grid(256)](buf1, primals_3, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_3 return buf5, primals_2, buf0, buf6, reinterpret_tensor(buf2, (4, 1, 4, 4), (16, 16, 4, 1), 0), buf7 class PACRRConvMax2dModuleNew(torch.nn.Module): def __init__(self, shape, n_filters, k, channels): super().__init__() self.shape = shape if shape != 1: self.pad = torch.nn.ConstantPad2d((0, shape - 1, 0, shape - 1), 0) else: self.pad = None self.conv = torch.nn.Conv2d(channels, n_filters, shape) self.activation = torch.nn.ReLU() self.k = k self.shape = shape self.channels = channels 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]
alpers/FlexNeuART
PACRRConvMax2dModule
false
12,083
[ "Apache-2.0" ]
0
2ae263f46b6eb2f1435b9073dad629a2fef23ab9
https://github.com/alpers/FlexNeuART/tree/2ae263f46b6eb2f1435b9073dad629a2fef23ab9
AverageAttention
import torch import torch.nn as nn import torch.cuda import torch.distributed class PositionwiseFeedForward(nn.Module): """ A two-layer Feed-Forward-Network with residual layer norm. Args: d_model (int): the size of input for the first-layer of the FFN. d_ff (int): the hidden layer size of the second-layer of the FNN. dropout (float): dropout probability in :math:`[0, 1)`. """ def __init__(self, d_model, d_ff, dropout=0.1): super(PositionwiseFeedForward, self).__init__() self.w_1 = nn.Linear(d_model, d_ff) self.w_2 = nn.Linear(d_ff, d_model) self.layer_norm = nn.LayerNorm(d_model, eps=1e-06) self.dropout_1 = nn.Dropout(dropout) self.relu = nn.ReLU() self.dropout_2 = nn.Dropout(dropout) def forward(self, x): """Layer definition. Args: x: ``(batch_size, input_len, model_dim)`` Returns: (FloatTensor): Output ``(batch_size, input_len, model_dim)``. """ inter = self.dropout_1(self.relu(self.w_1(self.layer_norm(x)))) output = self.dropout_2(self.w_2(inter)) return output + x def update_dropout(self, dropout): self.dropout_1.p = dropout self.dropout_2.p = dropout class AverageAttention(nn.Module): """ Average Attention module from "Accelerating Neural Transformer via an Average Attention Network" :cite:`DBLP:journals/corr/abs-1805-00631`. Args: model_dim (int): the dimension of keys/values/queries, must be divisible by head_count dropout (float): dropout parameter """ def __init__(self, model_dim, dropout=0.1, aan_useffn=False): self.model_dim = model_dim self.aan_useffn = aan_useffn super(AverageAttention, self).__init__() if aan_useffn: self.average_layer = PositionwiseFeedForward(model_dim, model_dim, dropout) self.gating_layer = nn.Linear(model_dim * 2, model_dim * 2) def cumulative_average_mask(self, batch_size, inputs_len, device): """ Builds the mask to compute the cumulative average as described in :cite:`DBLP:journals/corr/abs-1805-00631` -- Figure 3 Args: batch_size (int): batch size inputs_len (int): length of the inputs Returns: (FloatTensor): * A Tensor of shape ``(batch_size, input_len, input_len)`` """ triangle = torch.tril(torch.ones(inputs_len, inputs_len, dtype= torch.float, device=device)) weights = torch.ones(1, inputs_len, dtype=torch.float, device=device ) / torch.arange(1, inputs_len + 1, dtype=torch.float, device= device) mask = triangle * weights.transpose(0, 1) return mask.unsqueeze(0).expand(batch_size, inputs_len, inputs_len) def cumulative_average(self, inputs, mask_or_step, layer_cache=None, step=None): """ Computes the cumulative average as described in :cite:`DBLP:journals/corr/abs-1805-00631` -- Equations (1) (5) (6) Args: inputs (FloatTensor): sequence to average ``(batch_size, input_len, dimension)`` mask_or_step: if cache is set, this is assumed to be the current step of the dynamic decoding. Otherwise, it is the mask matrix used to compute the cumulative average. layer_cache: a dictionary containing the cumulative average of the previous step. Returns: a tensor of the same shape and type as ``inputs``. """ if layer_cache is not None: step = mask_or_step average_attention = (inputs + step * layer_cache['prev_g']) / (step + 1) layer_cache['prev_g'] = average_attention return average_attention else: mask = mask_or_step return torch.matmul(mask, inputs) def forward(self, inputs, mask=None, layer_cache=None, step=None): """ Args: inputs (FloatTensor): ``(batch_size, input_len, model_dim)`` Returns: (FloatTensor, FloatTensor): * gating_outputs ``(batch_size, input_len, model_dim)`` * average_outputs average attention ``(batch_size, input_len, model_dim)`` """ batch_size = inputs.size(0) inputs_len = inputs.size(1) average_outputs = self.cumulative_average(inputs, self. cumulative_average_mask(batch_size, inputs_len, inputs.device) if layer_cache is None else step, layer_cache=layer_cache) if self.aan_useffn: average_outputs = self.average_layer(average_outputs) gating_outputs = self.gating_layer(torch.cat((inputs, average_outputs), -1)) input_gate, forget_gate = torch.chunk(gating_outputs, 2, dim=2) gating_outputs = torch.sigmoid(input_gate) * inputs + torch.sigmoid( forget_gate) * average_outputs return gating_outputs, average_outputs def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'model_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.cuda import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_ones_tril_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = x0 + -1 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 <= tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = 1 + x1 tmp7 = tmp6.to(tl.float32) tmp8 = tmp3 / tmp7 tmp9 = tmp5 * tmp8 tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_mul_sigmoid_sigmoid_backward_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x2, xmask) tmp6 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp7 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tmp8 = tmp6 + tmp7 tmp9 = tl.sigmoid(tmp8) tmp11 = tmp9 * tmp10 tmp12 = tmp5 + tmp11 tmp13 = 1.0 tmp14 = tmp13 - tmp9 tmp15 = tmp9 * tmp14 tmp16 = tmp13 - tmp3 tmp17 = tmp3 * tmp16 tl.store(out_ptr0 + x2, tmp12, xmask) tl.store(out_ptr1 + x2, tmp15, xmask) tl.store(out_ptr2 + x2, tmp17, 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, (8, 8), (8, 1)) assert_size_stride(primals_3, (8,), (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_ones_tril_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (0, 4, 1), 0 ), primals_1, out=buf1) del buf0 buf2 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_1[grid(128)](primals_1, buf1, buf2, 128, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((16, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 8), (8, 1), 0), reinterpret_tensor(primals_2, (8, 8), (1, 8), 0), out=buf3) del primals_2 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_sigmoid_backward_2[grid(64)](buf3, primals_3, primals_1, buf1, buf4, buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 del primals_3 return buf4, buf1, primals_1, buf1, reinterpret_tensor(buf2, (16, 8), ( 8, 1), 0), buf5, buf6 class PositionwiseFeedForward(nn.Module): """ A two-layer Feed-Forward-Network with residual layer norm. Args: d_model (int): the size of input for the first-layer of the FFN. d_ff (int): the hidden layer size of the second-layer of the FNN. dropout (float): dropout probability in :math:`[0, 1)`. """ def __init__(self, d_model, d_ff, dropout=0.1): super(PositionwiseFeedForward, self).__init__() self.w_1 = nn.Linear(d_model, d_ff) self.w_2 = nn.Linear(d_ff, d_model) self.layer_norm = nn.LayerNorm(d_model, eps=1e-06) self.dropout_1 = nn.Dropout(dropout) self.relu = nn.ReLU() self.dropout_2 = nn.Dropout(dropout) def forward(self, x): """Layer definition. Args: x: ``(batch_size, input_len, model_dim)`` Returns: (FloatTensor): Output ``(batch_size, input_len, model_dim)``. """ inter = self.dropout_1(self.relu(self.w_1(self.layer_norm(x)))) output = self.dropout_2(self.w_2(inter)) return output + x def update_dropout(self, dropout): self.dropout_1.p = dropout self.dropout_2.p = dropout class AverageAttentionNew(nn.Module): """ Average Attention module from "Accelerating Neural Transformer via an Average Attention Network" :cite:`DBLP:journals/corr/abs-1805-00631`. Args: model_dim (int): the dimension of keys/values/queries, must be divisible by head_count dropout (float): dropout parameter """ def __init__(self, model_dim, dropout=0.1, aan_useffn=False): self.model_dim = model_dim self.aan_useffn = aan_useffn super(AverageAttentionNew, self).__init__() if aan_useffn: self.average_layer = PositionwiseFeedForward(model_dim, model_dim, dropout) self.gating_layer = nn.Linear(model_dim * 2, model_dim * 2) def cumulative_average_mask(self, batch_size, inputs_len, device): """ Builds the mask to compute the cumulative average as described in :cite:`DBLP:journals/corr/abs-1805-00631` -- Figure 3 Args: batch_size (int): batch size inputs_len (int): length of the inputs Returns: (FloatTensor): * A Tensor of shape ``(batch_size, input_len, input_len)`` """ triangle = torch.tril(torch.ones(inputs_len, inputs_len, dtype= torch.float, device=device)) weights = torch.ones(1, inputs_len, dtype=torch.float, device=device ) / torch.arange(1, inputs_len + 1, dtype=torch.float, device= device) mask = triangle * weights.transpose(0, 1) return mask.unsqueeze(0).expand(batch_size, inputs_len, inputs_len) def cumulative_average(self, inputs, mask_or_step, layer_cache=None, step=None): """ Computes the cumulative average as described in :cite:`DBLP:journals/corr/abs-1805-00631` -- Equations (1) (5) (6) Args: inputs (FloatTensor): sequence to average ``(batch_size, input_len, dimension)`` mask_or_step: if cache is set, this is assumed to be the current step of the dynamic decoding. Otherwise, it is the mask matrix used to compute the cumulative average. layer_cache: a dictionary containing the cumulative average of the previous step. Returns: a tensor of the same shape and type as ``inputs``. """ if layer_cache is not None: step = mask_or_step average_attention = (inputs + step * layer_cache['prev_g']) / (step + 1) layer_cache['prev_g'] = average_attention return average_attention else: mask = mask_or_step return torch.matmul(mask, inputs) def forward(self, input_0): primals_2 = self.gating_layer.weight primals_3 = self.gating_layer.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0], output[1]
Zer0-dev115/OpenNMT-py
AverageAttention
false
12,084
[ "MIT" ]
0
028c76b34779223ee6b3eb224b99617552987100
https://github.com/Zer0-dev115/OpenNMT-py/tree/028c76b34779223ee6b3eb224b99617552987100
BatchLinear
import torch from torch import nn from collections import OrderedDict class MetaModule(nn.Module): """ Base class for PyTorch meta-learning modules. These modules accept an additional argument `params` in their `forward` method. Notes ----- Objects inherited from `MetaModule` are fully compatible with PyTorch modules from `torch.nn.Module`. The argument `params` is a dictionary of tensors, with full support of the computation graph (for differentiation). """ def meta_named_parameters(self, prefix='', recurse=True): gen = self._named_members(lambda module: module._parameters.items() if isinstance(module, MetaModule) else [], prefix=prefix, recurse= recurse) for elem in gen: yield elem def meta_parameters(self, recurse=True): for name, param in self.meta_named_parameters(recurse=recurse): yield param class BatchLinear(nn.Linear, MetaModule): """A linear meta-layer that can deal with batched weight matrices and biases, as for instance output by a hypernetwork.""" __doc__ = nn.Linear.__doc__ def forward(self, input, params=None): if params is None: params = OrderedDict(self.named_parameters()) bias = params.get('bias', None) weight = params['weight'] output = input.matmul(weight.permute(*[i for i in range(len(weight. shape) - 2)], -1, -2)) output += bias.unsqueeze(-2) return output 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 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_view_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 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 tl.store(in_out_ptr0 + x4, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_add_view_0[grid(256)](buf2, primals_2, 256, XBLOCK =256, num_warps=4, num_stages=1) del primals_2 return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0) class MetaModule(nn.Module): """ Base class for PyTorch meta-learning modules. These modules accept an additional argument `params` in their `forward` method. Notes ----- Objects inherited from `MetaModule` are fully compatible with PyTorch modules from `torch.nn.Module`. The argument `params` is a dictionary of tensors, with full support of the computation graph (for differentiation). """ def meta_named_parameters(self, prefix='', recurse=True): gen = self._named_members(lambda module: module._parameters.items() if isinstance(module, MetaModule) else [], prefix=prefix, recurse= recurse) for elem in gen: yield elem def meta_parameters(self, recurse=True): for name, param in self.meta_named_parameters(recurse=recurse): yield param class BatchLinearNew(nn.Linear, MetaModule): """A linear meta-layer that can deal with batched weight matrices and biases, as for instance output by a hypernetwork.""" __doc__ = nn.Linear.__doc__ 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]
aneesh-dandime/siren
BatchLinear
false
12,085
[ "MIT" ]
0
7bc652e32d66c5792d24e8df2fffa565157679bd
https://github.com/aneesh-dandime/siren/tree/7bc652e32d66c5792d24e8df2fffa565157679bd
BertTextPooler
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class BertTextPooler(nn.Module): def __init__(self, config): super(BertTextPooler, self).__init__() self.dense = nn.Linear(config.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(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.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (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 BertTextPoolerNew(nn.Module): def __init__(self, config): super(BertTextPoolerNew, self).__init__() self.dense = nn.Linear(config.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]
amitakamath/vilbert-multi-task
BertTextPooler
false
12,086
[ "MIT" ]
0
5a11b8265fab3598fcdcd7f7c33453b914d8ff2c
https://github.com/amitakamath/vilbert-multi-task/tree/5a11b8265fab3598fcdcd7f7c33453b914d8ff2c
IOUloss
import torch import torch.nn as nn class IOUloss(nn.Module): def __init__(self, reduction='none', loss_type='iou'): super(IOUloss, self).__init__() self.reduction = reduction self.loss_type = loss_type def forward(self, pred, target): assert pred.shape[0] == target.shape[0] pred = pred.view(-1, 4) target = target.view(-1, 4) tl = torch.max(pred[:, :2] - pred[:, 2:] / 2, target[:, :2] - target[:, 2:] / 2) br = torch.min(pred[:, :2] + pred[:, 2:] / 2, target[:, :2] + target[:, 2:] / 2) area_p = torch.prod(pred[:, 2:], 1) area_g = torch.prod(target[:, 2:], 1) en = (tl < br).type(tl.type()).prod(dim=1) area_i = torch.prod(br - tl, 1) * en area_u = area_p + area_g - area_i iou = area_i / (area_u + 1e-16) if self.loss_type == 'iou': loss = 1 - iou ** 2 elif self.loss_type == 'giou': c_tl = torch.min(pred[:, :2] - pred[:, 2:] / 2, target[:, :2] - target[:, 2:] / 2) c_br = torch.max(pred[:, :2] + pred[:, 2:] / 2, target[:, :2] + target[:, 2:] / 2) area_c = torch.prod(c_br - c_tl, 1) giou = iou - (area_c - area_u) / area_c.clamp(1e-16) loss = 1 - giou.clamp(min=-1.0, max=1.0) if self.reduction == 'mean': loss = loss.mean() elif self.reduction == 'sum': loss = 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy_add_div_lt_maximum_minimum_mul_pow_prod_rsub_sub_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp0 + tmp3 tmp7 = tmp6 * tmp2 tmp8 = tmp5 + tmp7 tmp9 = triton_helpers.minimum(tmp4, tmp8) tmp10 = tmp0 - tmp3 tmp11 = tmp5 - tmp7 tmp12 = triton_helpers.maximum(tmp10, tmp11) tmp13 = tmp9 - tmp12 tmp16 = tmp15 * tmp2 tmp17 = tmp14 + tmp16 tmp20 = tmp19 * tmp2 tmp21 = tmp18 + tmp20 tmp22 = triton_helpers.minimum(tmp17, tmp21) tmp23 = tmp14 - tmp16 tmp24 = tmp18 - tmp20 tmp25 = triton_helpers.maximum(tmp23, tmp24) tmp26 = tmp22 - tmp25 tmp27 = tmp13 * tmp26 tmp28 = tmp12 < tmp9 tmp29 = tmp28.to(tl.float32) tmp30 = tmp25 < tmp22 tmp31 = tmp30.to(tl.float32) tmp32 = tmp29 * tmp31 tmp33 = tmp27 * tmp32 tmp34 = tmp1 * tmp15 tmp35 = tmp6 * tmp19 tmp36 = tmp34 + tmp35 tmp37 = tmp36 - tmp33 tmp38 = 1e-16 tmp39 = tmp37 + tmp38 tmp40 = tmp33 / tmp39 tmp41 = tmp40 * tmp40 tmp42 = 1.0 tmp43 = tmp42 - tmp41 tl.store(in_out_ptr0 + x0, tmp43, 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((64,), (1,), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused__to_copy_add_div_lt_maximum_minimum_mul_pow_prod_rsub_sub_0[ grid(64)](buf1, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf1, class IOUlossNew(nn.Module): def __init__(self, reduction='none', loss_type='iou'): super(IOUlossNew, self).__init__() self.reduction = reduction self.loss_type = loss_type def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
ankandrew/YOLOX
IOUloss
false
12,087
[ "Apache-2.0" ]
0
28da975944887d550f052ebadd8cbdd82d14aed6
https://github.com/ankandrew/YOLOX/tree/28da975944887d550f052ebadd8cbdd82d14aed6
Correct
import torch from torch import nn import torch.utils.data.distributed class Correct(nn.Module): def forward(self, classifier, target): return classifier.max(dim=1)[1] == target def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import 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_max_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp17 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp32 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tl.store(out_ptr0 + x2, tmp46, xmask) @triton.jit def triton_poi_fused_eq_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + x2, xmask) tmp1 = tmp0.to(tl.float32) tmp3 = tmp1 == tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) get_raw_stream(0) triton_poi_fused_max_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_eq_1[grid(256)](buf0, arg1_1, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg1_1 del buf0 return buf1, class CorrectNew(nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
amitport/grace
Correct
false
12,088
[ "BSD-2-Clause" ]
0
b0e442057d2f36f09cd1817a4acb966c6b0b780f
https://github.com/amitport/grace/tree/b0e442057d2f36f09cd1817a4acb966c6b0b780f
Actor
import torch import torch.nn as nn import torch.nn.functional as F class Actor(nn.Module): def __init__(self, state_dim, action_dim, max_action): super(Actor, self).__init__() self.l1 = nn.Linear(state_dim, 400) self.l2 = nn.Linear(400, 300) self.l3 = nn.Linear(300, action_dim) self.max_action = max_action def forward(self, x): x = F.relu(self.l1(x)) x = F.relu(self.l2(x)) x = self.max_action * torch.tanh(self.l3(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'action_dim': 4, 'max_action': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 25600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 400 x2 = xindex % 1600 x3 = xindex // 1600 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + (x2 + 1664 * x3), tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 19200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 300 x2 = xindex // 1200 x3 = xindex % 1200 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x3 + 1216 * x2), tmp4, xmask) tl.store(out_ptr1 + (x3 + 1280 * x2), tmp6, xmask) @triton.jit def triton_poi_fused_relu_view_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 19200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 300 x1 = xindex // 300 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 300 * (x1 % 4) + 1216 * (x1 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_mul_tanh_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tmp2 = 4.0 tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (400, 4), (4, 1)) assert_size_stride(primals_2, (400,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (300, 400), (400, 1)) assert_size_stride(primals_5, (300,), (1,)) assert_size_stride(primals_6, (4, 300), (300, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 400), (400, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 400), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 400), (6400, 1600, 400, 1), 0 ) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 400), (6656, 1664, 400, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(25600)](buf1, primals_2, buf8, 25600, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 300), (300, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 400), (400, 1), 0), reinterpret_tensor(primals_4, (400, 300), (1, 400), 0), out=buf2) buf3 = empty_strided_cuda((4, 4, 4, 300), (4864, 1216, 300, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 300), (5120, 1280, 300, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(19200)](buf2, primals_5, buf3, buf7, 19200, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_5 buf4 = buf2 del buf2 triton_poi_fused_relu_view_2[grid(19200)](buf3, buf4, 19200, XBLOCK =256, num_warps=4, num_stages=1) del buf3 buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf4, reinterpret_tensor(primals_6, (300, 4), (1, 300), 0), alpha=1, beta=1, out=buf5) del primals_7 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_tanh_3[grid(256)](buf5, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 400), (400, 1), 0 ), buf4, buf5, primals_6, buf7, primals_4, buf8 class ActorNew(nn.Module): def __init__(self, state_dim, action_dim, max_action): super(ActorNew, self).__init__() self.l1 = nn.Linear(state_dim, 400) self.l2 = nn.Linear(400, 300) self.l3 = nn.Linear(300, action_dim) self.max_action = max_action def forward(self, input_0): primals_1 = self.l1.weight primals_2 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_6 = self.l3.weight primals_7 = self.l3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
SheepiesLab/plato
Actor
false
12,089
[ "Apache-2.0" ]
0
9f5bbfa4b6952d1b3af24be409982d303d54a169
https://github.com/SheepiesLab/plato/tree/9f5bbfa4b6952d1b3af24be409982d303d54a169
QNetwork
import torch import torch.nn as nn import torch.nn.functional as F def weights_init_(m): if isinstance(m, nn.Linear): torch.nn.init.xavier_uniform_(m.weight, gain=1) torch.nn.init.constant_(m.bias, 0) class QNetwork(nn.Module): def __init__(self, num_inputs, num_actions, hidden_dim): super(QNetwork, self).__init__() self.linear1 = nn.Linear(num_inputs + num_actions, hidden_dim) self.linear2 = nn.Linear(hidden_dim, hidden_dim) self.linear3 = nn.Linear(hidden_dim, 1) self.linear4 = nn.Linear(num_inputs + num_actions, hidden_dim) self.linear5 = nn.Linear(hidden_dim, hidden_dim) self.linear6 = nn.Linear(hidden_dim, 1) self.apply(weights_init_) def forward(self, state, action): xu = torch.cat([state, action], 1) x1 = F.relu(self.linear1(xu)) x1 = F.relu(self.linear2(x1)) x1 = self.linear3(x1) x2 = F.relu(self.linear4(xu)) x2 = F.relu(self.linear5(x2)) x2 = self.linear6(x2) return x1, x2 def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_inputs': 4, 'num_actions': 4, 'hidden_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) 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, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (1, 4), (4, 1)) assert_size_stride(primals_8, (1,), (1,)) assert_size_stride(primals_9, (4, 8), (8, 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, (1, 4), (4, 1)) assert_size_stride(primals_14, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (8, 4), (1, 8 ), 0), out=buf1) del primals_3 buf2 = buf1 del buf1 triton_poi_fused_relu_1[grid(16)](buf2, primals_4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (4, 4), (1, 4 ), 0), out=buf3) buf4 = buf3 del buf3 triton_poi_fused_relu_1[grid(16)](buf4, primals_6, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_6 buf6 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, buf4, reinterpret_tensor(primals_7, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf6) del primals_8 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_9, (8, 4), (1, 8 ), 0), out=buf7) del primals_9 buf8 = buf7 del buf7 triton_poi_fused_relu_1[grid(16)](buf8, primals_10, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_10 buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf9) buf10 = buf9 del buf9 triton_poi_fused_relu_1[grid(16)](buf10, primals_12, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_12 buf12 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_14, buf10, reinterpret_tensor( primals_13, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_14 return (buf6, buf12, buf0, buf2, buf4, buf8, buf10, primals_13, primals_11, primals_7, primals_5) def weights_init_(m): if isinstance(m, nn.Linear): torch.nn.init.xavier_uniform_(m.weight, gain=1) torch.nn.init.constant_(m.bias, 0) class QNetworkNew(nn.Module): def __init__(self, num_inputs, num_actions, hidden_dim): super(QNetworkNew, self).__init__() self.linear1 = nn.Linear(num_inputs + num_actions, hidden_dim) self.linear2 = nn.Linear(hidden_dim, hidden_dim) self.linear3 = nn.Linear(hidden_dim, 1) self.linear4 = nn.Linear(num_inputs + num_actions, hidden_dim) self.linear5 = nn.Linear(hidden_dim, hidden_dim) self.linear6 = nn.Linear(hidden_dim, 1) self.apply(weights_init_) def forward(self, input_0, input_1): primals_3 = self.linear1.weight primals_4 = self.linear1.bias primals_1 = self.linear2.weight primals_6 = self.linear2.bias primals_7 = self.linear3.weight primals_8 = self.linear3.bias primals_9 = self.linear4.weight primals_10 = self.linear4.bias primals_2 = self.linear5.weight primals_12 = self.linear5.bias primals_13 = self.linear6.weight primals_14 = self.linear6.bias primals_5 = input_0 primals_11 = 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], output[1]
SheepiesLab/plato
QNetwork
false
12,090
[ "Apache-2.0" ]
0
9f5bbfa4b6952d1b3af24be409982d303d54a169
https://github.com/SheepiesLab/plato/tree/9f5bbfa4b6952d1b3af24be409982d303d54a169
UniverseHead
import torch import torch.nn as nn import torch.nn.functional as F class UniverseHead(torch.nn.Module): """ universe agent example input: [None, 42, 42, 1]; output: [None, 288]; """ def __init__(self, n): super(UniverseHead, self).__init__() self.conv1 = nn.Conv2d(n, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv2 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv3 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv4 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.output_size = 288 def forward(self, state): output = F.elu(self.conv1(state)) output = F.elu(self.conv2(output)) output = F.elu(self.conv3(output)) output = F.elu(self.conv4(output)) return output.view(-1, self.output_size) def get_inputs(): return [torch.rand([4, 4, 48, 48])] def get_init_inputs(): return [[], {'n': 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_convolution_elu_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 576 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x3, tmp2, None) tl.store(out_ptr0 + x3, tmp9, None) @triton.jit def triton_poi_fused_convolution_elu_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 144 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x3, tmp2, None) tl.store(out_ptr0 + x3, tmp9, None) @triton.jit def triton_poi_fused_convolution_elu_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4608 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 36 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_elu_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1152 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 9 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp9, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (32, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 48, 48), (9216, 2304, 48, 1)) assert_size_stride(primals_4, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_9, (32,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 24, 24), (18432, 576, 24, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 32, 24, 24), (18432, 576, 24, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_elu_0[grid(73728)](buf1, primals_2, buf2, 73728, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 32, 12, 12), (4608, 144, 12, 1)) buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 32, 12, 12), (4608, 144, 12, 1), torch.float32) triton_poi_fused_convolution_elu_1[grid(18432)](buf4, primals_5, buf5, 18432, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = extern_kernels.convolution(buf5, primals_6, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 32, 6, 6), (1152, 36, 6, 1)) buf7 = buf6 del buf6 buf8 = empty_strided_cuda((4, 32, 6, 6), (1152, 36, 6, 1), torch. float32) triton_poi_fused_convolution_elu_2[grid(4608)](buf7, primals_7, buf8, 4608, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf9 = extern_kernels.convolution(buf8, primals_8, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 32, 3, 3), (288, 9, 3, 1)) buf10 = buf9 del buf9 buf11 = empty_strided_cuda((4, 32, 3, 3), (288, 9, 3, 1), torch.float32 ) triton_poi_fused_convolution_elu_3[grid(1152)](buf10, primals_9, buf11, 1152, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 return (reinterpret_tensor(buf11, (4, 288), (288, 1), 0), primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf2, buf4, buf5, buf7, buf8, buf10) class UniverseHeadNew(torch.nn.Module): """ universe agent example input: [None, 42, 42, 1]; output: [None, 288]; """ def __init__(self, n): super(UniverseHeadNew, self).__init__() self.conv1 = nn.Conv2d(n, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv2 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv3 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.conv4 = nn.Conv2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1)) self.output_size = 288 def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
andy920262/pytorch-a2c-ppo-acktr
UniverseHead
false
12,091
[ "MIT" ]
0
2e7e85219dfe737cb4036de3cf0c8b00706d640e
https://github.com/andy920262/pytorch-a2c-ppo-acktr/tree/2e7e85219dfe737cb4036de3cf0c8b00706d640e
DQN
import torch import torch.nn as nn class DQN(nn.Module): def __init__(self, state_dim, nb_actions, hidden1=50, hidden2=50): super(DQN, self).__init__() self.fc1 = nn.Linear(state_dim, hidden1) self.fc2 = nn.Linear(hidden1, hidden2) self.fc3 = nn.Linear(hidden2, nb_actions) self.relu = nn.ReLU() self.tanh = nn.Tanh() def forward(self, x): out = self.fc1(x) out = self.relu(out) out = self.fc2(out) out = self.relu(out) return self.fc3(out.view(out.size(0), -1)) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'nb_actions': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 50 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_view_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 50 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp6, 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, (50, 4), (4, 1)) assert_size_stride(primals_2, (50,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (50, 50), (50, 1)) assert_size_stride(primals_5, (50,), (1,)) assert_size_stride(primals_6, (4, 50), (50, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 50), (50, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 50), (1, 4), 0), out=buf0) del primals_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(200)](buf1, primals_2, 200, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 50), (50, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (50, 50), (1, 50), 0), out=buf2) buf3 = empty_strided_cuda((4, 50), (50, 1), torch.float32) buf5 = empty_strided_cuda((4, 50), (50, 1), torch.bool) triton_poi_fused_relu_threshold_backward_view_1[grid(200)](buf2, primals_5, buf3, buf5, 200, XBLOCK=256, num_warps=4, num_stages=1) del buf2 del primals_5 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (50, 4), (1, 50), 0), alpha=1, beta=1, out=buf4) del primals_7 return buf4, primals_3, buf1, buf3, primals_6, buf5, primals_4 class DQNNew(nn.Module): def __init__(self, state_dim, nb_actions, hidden1=50, hidden2=50): super(DQNNew, self).__init__() self.fc1 = nn.Linear(state_dim, hidden1) self.fc2 = nn.Linear(hidden1, hidden2) self.fc3 = nn.Linear(hidden2, nb_actions) self.relu = nn.ReLU() self.tanh = nn.Tanh() def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
alvinwan/explore
DQN
false
12,092
[ "MIT" ]
0
358c076b8250f561394e32b1ee2de9bc5562dcdb
https://github.com/alvinwan/explore/tree/358c076b8250f561394e32b1ee2de9bc5562dcdb
Block
import torch class Block(torch.nn.Module): def __init__(self, in_channels, mid_channel, out_channels, batch_norm=False ): super().__init__() self.conv1 = torch.nn.Conv2d(in_channels=in_channels, out_channels= mid_channel, kernel_size=3, padding=1) self.conv2 = torch.nn.Conv2d(in_channels=mid_channel, out_channels= out_channels, kernel_size=3, padding=1) self.batch_norm = batch_norm if batch_norm: self.bn1 = torch.nn.BatchNorm2d(mid_channel) self.bn2 = torch.nn.BatchNorm2d(out_channels) def forward(self, x): x = self.conv1(x) if self.batch_norm: x = self.bn1(x) x = torch.nn.ReLU(inplace=True)(x) x = self.conv2(x) if self.batch_norm: x = self.bn2(x) out = torch.nn.ReLU(inplace=True)(x) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'mid_channel': 4, 'out_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(256)](buf1, primals_2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_1[grid(256)](buf3, primals_5, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1, buf4 class BlockNew(torch.nn.Module): def __init__(self, in_channels, mid_channel, out_channels, batch_norm=False ): super().__init__() self.conv1 = torch.nn.Conv2d(in_channels=in_channels, out_channels= mid_channel, kernel_size=3, padding=1) self.conv2 = torch.nn.Conv2d(in_channels=mid_channel, out_channels= out_channels, kernel_size=3, padding=1) self.batch_norm = batch_norm if batch_norm: self.bn1 = torch.nn.BatchNorm2d(mid_channel) self.bn2 = torch.nn.BatchNorm2d(out_channels) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
amrane99/lung-segmentation
Block
false
12,093
[ "MIT" ]
0
ab29db75ac78918da5cbf66b830acaf36cf7b44a
https://github.com/amrane99/lung-segmentation/tree/ab29db75ac78918da5cbf66b830acaf36cf7b44a
ConvNet
import torch import torch.nn as nn import torch.nn.functional as F class ConvNet(nn.Module): """ convolutional neural network """ def __init__(self): super(ConvNet, self).__init__() nf = 8 self.conv1 = nn.Conv2d(1, nf * 1, 5, 1, 0) self.conv2 = nn.Conv2d(nf * 1, nf * 2, 4, 2, 1) self.conv3 = nn.Conv2d(nf * 2, nf * 4, 5, 1, 0) self.conv4 = nn.Conv2d(nf * 4, nf * 8, 4, 2, 1) self.conv5 = nn.Conv2d(nf * 8, 10, 4, 1, 0) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = F.relu(self.conv4(x)) x = self.conv5(x) x = torch.flatten(x, 1) return F.log_softmax(x, dim=1) def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 115200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3600 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 57600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 900 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 86528 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 676 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 43264 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 169 % 64 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_per_fused__log_softmax_4(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel ): XBLOCK: tl.constexpr = 1 rnumel = 1000 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)[:] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 1000 * x0), rmask, other=0.0) tmp1 = tl.load(in_ptr1 + r1 // 100, rmask, eviction_policy='evict_last', other=0.0) tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [RBLOCK]) tmp5 = tl.where(rmask, tmp3, float('-inf')) tmp6 = triton_helpers.promote_to_tensor(triton_helpers.max2(tmp5, 0)) tmp7 = tmp2 - tmp6 tmp8 = tl_math.exp(tmp7) tmp9 = tl.broadcast_to(tmp8, [RBLOCK]) tmp11 = tl.where(rmask, tmp9, 0) tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp13 = tl_math.log(tmp12) tmp14 = tmp7 - tmp13 tl.store(out_ptr2 + (r1 + 1000 * x0), tmp14, rmask) 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, (8, 1, 5, 5), (25, 25, 5, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (16, 8, 4, 4), (128, 16, 4, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (32, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (64, 32, 4, 4), (512, 16, 4, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (10, 64, 4, 4), (1024, 16, 4, 1)) assert_size_stride(primals_11, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 60, 60), (28800, 3600, 60, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(115200)](buf1, primals_2, 115200, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 16, 30, 30), (14400, 900, 30, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(57600)](buf3, primals_5, 57600, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 32, 26, 26), (21632, 676, 26, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(86528)](buf5, primals_7, 86528, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 64, 13, 13), (10816, 169, 13, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_3[grid(43264)](buf7, primals_9, 43264, XBLOCK=512, num_warps=4, num_stages=1) del primals_9 buf8 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 10, 10, 10), (1000, 100, 10, 1)) buf11 = empty_strided_cuda((4, 1000), (1000, 1), torch.float32) triton_per_fused__log_softmax_4[grid(4)](buf8, primals_11, buf11, 4, 1000, num_warps=8, num_stages=1) del buf8 del primals_11 return (buf11, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, buf1, buf3, buf5, buf7, buf11) class ConvNetNew(nn.Module): """ convolutional neural network """ def __init__(self): super(ConvNetNew, self).__init__() nf = 8 self.conv1 = nn.Conv2d(1, nf * 1, 5, 1, 0) self.conv2 = nn.Conv2d(nf * 1, nf * 2, 4, 2, 1) self.conv3 = nn.Conv2d(nf * 2, nf * 4, 5, 1, 0) self.conv4 = nn.Conv2d(nf * 4, nf * 8, 4, 2, 1) self.conv5 = nn.Conv2d(nf * 8, 10, 4, 1, 0) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.conv5.weight primals_11 = self.conv5.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
animeshbchowdhury/robust-pnr-time
ConvNet
false
12,094
[ "BSD-3-Clause" ]
0
301c5d973b8c024a85fdab915986ecf257e7698b
https://github.com/animeshbchowdhury/robust-pnr-time/tree/301c5d973b8c024a85fdab915986ecf257e7698b
NatureHead
import torch import torch.nn as nn import torch.nn.functional as F class NatureHead(torch.nn.Module): """ DQN Nature 2015 paper input: [None, 84, 84, 4]; output: [None, 3136] -> [None, 512]; """ def __init__(self, n): super(NatureHead, self).__init__() self.conv1 = nn.Conv2d(n, 32, kernel_size=(8, 8), stride=(4, 4)) self.conv2 = nn.Conv2d(32, 64, kernel_size=(4, 4), stride=(2, 2)) self.conv3 = nn.Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1)) self.dense = nn.Linear(32 * 7 * 7, 512) self.output_size = 512 def forward(self, state): output = F.relu(self.conv1(state)) output = F.relu(self.conv2(output)) output = F.relu(self.conv3(output)) output = F.relu(self.dense(output.view(-1, 32 * 7 * 7))) return output def get_inputs(): return [torch.rand([4, 4, 144, 144])] def get_init_inputs(): return [[], {'n': 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_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 156800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 1225 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 25088 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 196 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (32, 4, 8, 8), (256, 64, 8, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 4, 144, 144), (82944, 20736, 144, 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, (32, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (512, 1568), (1568, 1)) assert_size_stride(primals_9, (512,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(4, 4), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 35, 35), (39200, 1225, 35, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(156800)](buf1, primals_2, 156800, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 16, 16), (16384, 256, 16, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(65536)](buf3, primals_5, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 32, 14, 14), (6272, 196, 14, 1)) buf5 = buf4 del buf4 buf9 = empty_strided_cuda((4, 32, 14, 14), (6272, 196, 14, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_2[grid(25088)]( buf5, primals_7, buf9, 25088, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_7 buf6 = empty_strided_cuda((16, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (16, 1568), (1568, 1), 0 ), reinterpret_tensor(primals_8, (1568, 512), (1, 1568), 0), out=buf6) buf7 = buf6 del buf6 buf8 = empty_strided_cuda((16, 512), (512, 1), torch.bool) triton_poi_fused_relu_threshold_backward_3[grid(8192)](buf7, primals_9, buf8, 8192, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 return (buf7, primals_1, primals_3, primals_4, primals_6, buf1, buf3, reinterpret_tensor(buf5, (16, 1568), (1568, 1), 0), buf8, primals_8, buf9) class NatureHeadNew(torch.nn.Module): """ DQN Nature 2015 paper input: [None, 84, 84, 4]; output: [None, 3136] -> [None, 512]; """ def __init__(self, n): super(NatureHeadNew, self).__init__() self.conv1 = nn.Conv2d(n, 32, kernel_size=(8, 8), stride=(4, 4)) self.conv2 = nn.Conv2d(32, 64, kernel_size=(4, 4), stride=(2, 2)) self.conv3 = nn.Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1)) self.dense = nn.Linear(32 * 7 * 7, 512) self.output_size = 512 def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.dense.weight primals_9 = self.dense.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
andy920262/pytorch-a2c-ppo-acktr
NatureHead
false
12,095
[ "MIT" ]
0
2e7e85219dfe737cb4036de3cf0c8b00706d640e
https://github.com/andy920262/pytorch-a2c-ppo-acktr/tree/2e7e85219dfe737cb4036de3cf0c8b00706d640e
SelfAttnPooler
import torch import torch.nn as nn class SelfAttnPooler(nn.Module): def __init__(self, input_dim): super().__init__() self.proj = nn.Linear(input_dim, 1) def forward(self, encoder_out, padding_mask): """ encoder_out: T, B, C padding_mask: T, B (True for padded positions) """ attn_weights = self.proj(encoder_out).squeeze(-1).float() if padding_mask is not None: attn_weights[padding_mask] = float('-inf') attn_weights = attn_weights.softmax(dim=0) out = torch.einsum('tb,tbc->bc', attn_weights.float(), encoder_out. float()) return out def get_inputs(): return [torch.rand([4, 4, 4]), torch.ones([4, 4, 4], dtype=torch.int64)] def get_init_inputs(): return [[], {'input_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_index_put_lift_fresh_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 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask, 'index out of bounds: 0 <= tmp4 < 4') tmp6 = float('-inf') tl.store(out_ptr0 + (x0 + 4 * tmp4), tmp6, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 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, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_1 del primals_2 get_raw_stream(0) triton_poi_fused_index_put_lift_fresh_0[grid(256)](primals_4, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_1[grid(16)](buf1, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_2[grid(16)](buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 1, 4), (4, 4, 1), 0) del buf3 extern_kernels.bmm(reinterpret_tensor(buf4, (4, 1, 4), (1, 0, 4), 0 ), reinterpret_tensor(primals_3, (4, 4, 4), (4, 16, 1), 0), out =buf5) del buf4 return reinterpret_tensor(buf5, (4, 4), (4, 1), 0 ), primals_3, primals_4, reinterpret_tensor(buf1, (4, 4), (4, 1), 0) class SelfAttnPoolerNew(nn.Module): def __init__(self, input_dim): super().__init__() self.proj = nn.Linear(input_dim, 1) def forward(self, input_0, input_1): primals_1 = self.proj.weight primals_2 = self.proj.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
ankitapasad/slue-toolkit
SelfAttnPooler
false
12,096
[ "MIT" ]
0
db8155cf0fc803e21890cf4eee2ef87152aafbfc
https://github.com/ankitapasad/slue-toolkit/tree/db8155cf0fc803e21890cf4eee2ef87152aafbfc
DPSLTMAdapter
import math import torch from torch import Tensor import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel from typing import Tuple from typing import List from typing import Optional from typing import Dict from typing import Union from torch.nn.modules.module import _IncompatibleKeys def filter_out_old_keys(self, state_dict, prefix, local_metadata): new_state_dict = {param_name: param_value for param_name, param_value in state_dict.items() if param_name not in self.old_to_new} return new_state_dict class LSTMLinear(nn.Linear): """ This function is the same as a nn.Linear layer, except that in the backward pass the grad_samples get accumulated (instead of being concatenated as in the standard nn.Linear) """ def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True): super().__init__(in_features, out_features, bias) class DPLSTMCell(nn.Module): """ Internal-only class. Implements *one* step of LSTM so that a LSTM layer can be seen as repeated applications of this class. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.ih = LSTMLinear(input_size, 4 * hidden_size, bias=self.bias) self.hh = LSTMLinear(hidden_size, 4 * hidden_size, bias=self.bias) self.reset_parameters() def reset_parameters(self): """ Resets parameters by initializing them from an uniform distribution. """ stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): nn.init.uniform_(weight, -stdv, stdv) def forward(self, x: 'torch.Tensor', h_prev: 'torch.Tensor', c_prev: 'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor]: gates = self.ih(x) + self.hh(h_prev) i_t_input, f_t_input, g_t_input, o_t_input = torch.split(gates, self.hidden_size, 1) i_t = torch.sigmoid(i_t_input) f_t = torch.sigmoid(f_t_input) g_t = torch.tanh(g_t_input) o_t = torch.sigmoid(o_t_input) c_t = f_t * c_prev + i_t * g_t h_t = o_t * torch.tanh(c_t) return h_t, c_t class DPLSTMLayer(nn.Module): """ Implements *one* layer of LSTM in a way amenable to differential privacy. We don't expect you to use this directly: use DPLSTM instead :) """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool', dropout: 'float', reverse: 'bool'=False): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.dropout = dropout self.reverse = reverse self.cell = DPLSTMCell(input_size=input_size, hidden_size= hidden_size, bias=bias) self.dropout_layer = nn.Dropout(dropout) if dropout > 0 else None def forward(self, x: 'torch.Tensor', state_init: 'Tuple[torch.Tensor, torch.Tensor]') ->Tuple[torch.Tensor, Tuple[ torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTMLayer when a sequence is given in input. Args: x: Input sequence to the DPLSTMCell of shape ``[T, B, D]``. state_init: Initial state of the LSTMCell as a tuple ``(h_0, c_0)`` where ``h_0`` is the initial hidden state and ``c_0`` is the initial cell state of the DPLSTMCell Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTMCell for each timestep ``t``. - ``h_n`` is of shape ``[B, H]`` and is a tensor containing the hidden state for ``t = T``. - ``c_n`` is of shape ``[B, H]`` tensor containing the cell state for ``t = T``. """ seq_length, _batch_sz, _ = x.shape if self.reverse: x = x.flip(0) x = torch.unbind(x, dim=0) h_0, c_0 = state_init h_n = [h_0] c_n = [c_0] for t in range(seq_length): h_next, c_next = self.cell(x[t], h_n[t], c_n[t]) if self.dropout: h_next = self.dropout_layer(h_next) h_n.append(h_next) c_n.append(c_next) h_n = torch.stack(h_n[1:], dim=0) return h_n.flip(0) if self.reverse else h_n, (h_n[-1], c_n[-1]) class BidirectionalDPLSTMLayer(nn.Module): """ Implements *one* layer of Bidirectional LSTM in a way amenable to differential privacy. We don't expect you to use this directly: use DPLSTM instead :) """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool', dropout: 'float'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.dropout = dropout self.forward_layer = DPLSTMLayer(input_size=input_size, hidden_size =hidden_size, bias=bias, dropout=dropout, reverse=False) self.reverse_layer = DPLSTMLayer(input_size=input_size, hidden_size =hidden_size, bias=bias, dropout=dropout, reverse=True) def forward(self, x: 'torch.Tensor', state_init: 'Tuple[torch.Tensor, torch.Tensor]') ->Tuple[torch.Tensor, Tuple[ torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTM when a sequence is input. Dimensions as follows: - B: Batch size - T: Sequence length - D: LSTM input hidden size (eg from a word embedding) - H: LSTM output hidden size - P: number of directions (2 if bidirectional, else 1) Args: x: Input sequence to the DPLSTM of shape ``[T, B, D]`` state_init: Initial state of the LSTM as a tuple ``(h_0, c_0)``, where: - h_0 of shape ``[P, B, H] contains the initial hidden state - c_0 of shape ``[P, B, H] contains the initial cell state This argument can be (and defaults to) None, in which case zero tensors will be used. Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H * P]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTM for each timestep ``t``. - ``h_n`` is of shape ``[P, B, H]`` and contains the hidden state for ``t = T``. - ``c_n`` is of shape ``[P, B, H]`` and contains the cell state for ``t = T``. """ h0, c0 = state_init h0_f, h0_r = h0.unbind(0) c0_f, c0_r = c0.unbind(0) out_f, (h_f, c_f) = self.forward_layer(x, (h0_f, c0_f)) out_r, (h_r, c_r) = self.reverse_layer(x, (h0_r, c0_r)) out = torch.cat([out_f, out_r], dim=-1) h = torch.stack([h_f, h_r], dim=0) c = torch.stack([c_f, c_r], dim=0) return out, (h, c) class ParamRenamedModule(nn.Module): """ This class defines a nn.Module whose parameters are renamed. This is useful when you want to reimplement a layer but make sure its state_dict and list of parameters are exactly the same as another reference layer so that you can have a drop-in replacement that does not depend on how your layer is actually implemented. In Opacus, this is used for DPLSTM, where our implementation leverages submodules and requires alignment to the state_dict of nn.LSTM. """ def __init__(self, rename_map: 'Dict[str, str]'): """ Initializes internal state. Subclass this instead of ``torch.nn.Module`` whenever you need to rename your model's state. Args: rename_map: mapping from old name -> new name for each parameter you want renamed. Note that this must be a 1:1 mapping! """ super().__init__() self.old_to_new = rename_map self.new_to_old = {v: k for k, v in rename_map.items()} self._register_state_dict_hook(filter_out_old_keys) def _register_renamed_parameters(self): """ Internal function. This function simply registers parameters under their new name. They will automatically mask their duplicates coming from submodules. This trick works because self.parameters() proceeds recursively from the top, going into submodules after processing items at the current level, and will not return duplicates. """ for old_name, param in super().named_parameters(): if old_name in self.old_to_new: new_name = self.old_to_new[old_name] self.register_parameter(new_name, param) def __setattr__(self, name: 'str', value: 'Union[Tensor, nn.Module]' ) ->None: """ Whenever you set an attribute, eg `self.linear`, this is called to actually register it in any nn.Module. We rely on the masking trick explained in the docs for ``_register_renamed_parameters`` to make sure we replace things only once. If a new parameter in the rename list is detected, we rename and mask it so next time this is called we will no longer find it. """ super().__setattr__(name, value) try: self._register_renamed_parameters() except AttributeError: pass def load_state_dict(self, state_dict: 'Dict[str, Tensor]', strict: 'bool'=True): """ Identical to ``torch.nn.Module.load_state_dict()`` but handles the renamed keys. """ missing_keys, unexpected_keys = super().load_state_dict(state_dict, strict=False) missing_keys = [k for k in missing_keys if k not in self.old_to_new] if strict: error_msgs = [] if len(unexpected_keys) > 0: error_msgs.insert(0, 'Unexpected key(s) in state_dict: {}. '.format(', '. join('"{}"'.format(k) for k in unexpected_keys))) if len(missing_keys) > 0: error_msgs.insert(0, 'Missing key(s) in state_dict: {}. '. format(', '.join('"{}"'.format(k) for k in missing_keys))) if len(error_msgs) > 0: raise RuntimeError( 'Error(s) in loading state_dict for {}:\n\t{}'.format( self.__class__.__name__, '\n\t'.join(error_msgs))) return _IncompatibleKeys(missing_keys, unexpected_keys) class DPLSTM(ParamRenamedModule): """ DP-friendly drop-in replacement of the ``torch.nn.LSTM`` module. Its state_dict matches that of nn.LSTM exactly, so that after training it can be exported and loaded by an nn.LSTM for inference. Refer to nn.LSTM's documentation for all parameters and inputs. """ def __init__(self, input_size: 'int', hidden_size: 'int', num_layers: 'int'=1, bias: 'bool'=True, batch_first: 'bool'=False, dropout: 'float'=0, bidirectional: 'bool'=False): rename_dict = self._make_rename_dict(num_layers, bias, bidirectional) super().__init__(rename_dict) self.input_size = input_size self.hidden_size = hidden_size self.num_layers = num_layers self.bias = bias self.batch_first = batch_first self.dropout = dropout self.bidirectional = bidirectional self.num_directions = 2 if self.bidirectional else 1 LayerClass = BidirectionalDPLSTMLayer if bidirectional else DPLSTMLayer self.layers = nn.ModuleList([LayerClass(input_size=self.input_size if i == 0 else self.hidden_size * self.num_directions, hidden_size =self.hidden_size, bias=self.bias, dropout=self.dropout if i < self.num_layers - 1 else 0) for i in range(num_layers)]) def forward(self, x: 'torch.Tensor', state_init: 'Optional[Tuple[torch.Tensor, torch.Tensor]]'=None) ->Tuple[torch. Tensor, Tuple[torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTM when a sequence is input. Dimensions as follows: - B: Batch size - T: Sequence length - D: LSTM input hidden size (eg from a word embedding) - H: LSTM output hidden size - L: number of layers in the LSTM - P: number of directions (2 if bidirectional, else 1) Args: x: Input sequence to the DPLSTM of shape ``[T, B, D]`` state_init: Initial state of the LSTM as a tuple ``(h_0, c_0)``, where: - h_0 of shape ``[L*P, B, H] contains the initial hidden state - c_0 of shape ``[L*P, B, H] contains the initial cell state This argument can be (and defaults to) None, in which case zero tensors will be used. Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H * P]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTM for each timestep ``t``. - ``h_n`` is of shape ``[L * P, B, H]`` and contains the hidden state for ``t = T``. - ``c_n`` is of shape ``[L * P, B, H]`` and contains the cell state for ``t = T``. """ x = self._rearrange_batch_dim(x) _T, B, _D = x.shape L = self.num_layers P = 2 if self.bidirectional else 1 H = self.hidden_size h_0s, c_0s = state_init or (None, None) if h_0s is None: h_0s = torch.zeros(L, P, B, self.hidden_size, dtype=x[0].dtype, device=x[0].device) else: h_0s = h_0s.reshape([L, P, B, H]) if c_0s is None: c_0s = torch.zeros(L, P, B, self.hidden_size, dtype=x[0].dtype, device=x[0].device) else: c_0s = c_0s.reshape([L, P, B, H]) hs: 'List[torch.Tensor]' = [] cs: 'List[torch.Tensor]' = [] for layer, h0, c0 in zip(self.layers, h_0s, c_0s): if not self.bidirectional: h0 = h0.squeeze(0) c0 = c0.squeeze(0) x, (h, c) = layer(x, (h0, c0)) if not self.bidirectional: h = h.unsqueeze(0) c = c.unsqueeze(0) hs.append(h) cs.append(c) hs = torch.cat(hs, dim=0) cs = torch.cat(cs, dim=0) out = self._rearrange_batch_dim(x) return out, (hs, cs) def _rearrange_batch_dim(self, x: 'torch.Tensor') ->torch.Tensor: if self.batch_first: x = x.transpose(0, 1) return x def __repr__(self): s = f'DPLSTM({self.input_size}, {self.hidden_size}, bias={self.bias}' if self.batch_first: s += f', batch_first={self.batch_first}' if self.num_layers > 1: s += f', num_layers={self.num_layers}' if self.dropout: s += f', dropout={self.dropout}' if self.bidirectional: s += f', bidirectional={self.bidirectional}' return s def _make_rename_dict(self, num_layers, bias, bidirectional): """ Programmatically constructs a dictionary old_name -> new_name to align with the param names used in ``torch.nn.LSTM``. """ d = {} components = ['weight'] + ['bias' if bias else []] matrices = ['ih', 'hh'] for i in range(num_layers): for c in components: for m in matrices: nn_name = f'{c}_{m}_l{i}' if bidirectional: d[f'layers.{i}.forward_layer.cell.{m}.{c}'] = nn_name d[f'layers.{i}.reverse_layer.cell.{m}.{c}' ] = nn_name + '_reverse' else: d[f'layers.{i}.cell.{m}.{c}'] = nn_name return d class DPSLTMAdapter(nn.Module): """ Adapter for DPLSTM. LSTM returns a tuple, but our testing tools need the model to return a single tensor in output. We do this adaption here. """ def __init__(self, *args, **kwargs): super().__init__() self.dplstm = DPLSTM(*args, **kwargs) def forward(self, x): out, _rest = self.dplstm(x) return out def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import math from torch import Tensor import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.parallel from typing import Tuple from typing import List from typing import Optional from typing import Dict from typing import Union from torch.nn.modules.module import _IncompatibleKeys 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_zeros_0(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 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp9 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr3 + (12 + x0), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask) tmp20 = tl.load(in_ptr3 + (8 + x0), xmask, eviction_policy='evict_last') tmp24 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp25 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask) tmp28 = tl.load(in_ptr3 + (4 + x0), xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr4 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp10 = tmp8 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = tl.sigmoid(tmp14) tmp18 = tmp16 + tmp17 tmp21 = tmp19 + tmp20 tmp22 = tmp18 + tmp21 tmp23 = libdevice.tanh(tmp22) tmp26 = tmp24 + tmp25 tmp29 = tmp27 + tmp28 tmp30 = tmp26 + tmp29 tmp31 = tl.sigmoid(tmp30) tmp33 = tmp31 * tmp32 tmp34 = tmp7 * tmp23 tmp35 = tmp33 + tmp34 tmp36 = 1.0 tmp37 = tmp36 - tmp31 tmp38 = tmp31 * tmp37 tmp39 = libdevice.tanh(tmp35) tmp40 = tmp15 * tmp39 tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp15, xmask) tl.store(out_ptr2 + x2, tmp23, xmask) tl.store(out_ptr3 + x2, tmp35, xmask) tl.store(out_ptr4 + x2, tmp38, xmask) tl.store(out_ptr5 + x2, tmp40, xmask) @triton.jit def triton_poi_fused_add_mul_sigmoid_tanh_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp9 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr3 + (4 + x0), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask) tmp20 = tl.load(in_ptr3 + (12 + x0), xmask, eviction_policy='evict_last') tmp24 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp25 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask) tmp28 = tl.load(in_ptr3 + (8 + x0), xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr4 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp10 = tmp8 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = tl.sigmoid(tmp14) tmp18 = tmp16 + tmp17 tmp21 = tmp19 + tmp20 tmp22 = tmp18 + tmp21 tmp23 = tl.sigmoid(tmp22) tmp26 = tmp24 + tmp25 tmp29 = tmp27 + tmp28 tmp30 = tmp26 + tmp29 tmp31 = libdevice.tanh(tmp30) tmp33 = tmp15 * tmp32 tmp34 = tmp7 * tmp31 tmp35 = tmp33 + tmp34 tmp36 = libdevice.tanh(tmp35) tmp37 = tmp23 * tmp36 tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp15, xmask) tl.store(out_ptr2 + x2, tmp23, xmask) tl.store(out_ptr3 + x2, tmp31, xmask) tl.store(out_ptr4 + x2, tmp35, xmask) tl.store(out_ptr5 + x2, tmp37, xmask) @triton.jit def triton_poi_fused_add_mul_sigmoid_tanh_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 16 * x1), xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp9 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr2 + (4 + x0 + 16 * x1), xmask) tmp12 = tl.load(in_ptr3 + (4 + x0), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp17 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr2 + (8 + x0 + 16 * x1), xmask) tmp20 = tl.load(in_ptr3 + (8 + x0), xmask, eviction_policy='evict_last') tmp24 = tl.load(in_ptr4 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp10 = tmp8 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = tl.sigmoid(tmp14) tmp18 = tmp16 + tmp17 tmp21 = tmp19 + tmp20 tmp22 = tmp18 + tmp21 tmp23 = libdevice.tanh(tmp22) tmp25 = tmp15 * tmp24 tmp26 = tmp7 * tmp23 tmp27 = tmp25 + tmp26 tmp28 = libdevice.tanh(tmp27) tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp15, xmask) tl.store(out_ptr2 + x2, tmp23, xmask) tl.store(out_ptr3 + x2, tmp28, xmask) @triton.jit def triton_poi_fused_sigmoid_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + (12 + x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (12 + x0 + 16 * x1), xmask) tmp4 = tl.load(in_ptr3 + (12 + x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tl.store(out_ptr0 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_stack_5(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 x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (x0 + 4 * (-4 + x1)), tmp9 & xmask, other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr2 + (x0 + 4 * (-8 + x1)), tmp14 & xmask, other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp19 = tl.load(in_ptr3 + (x0 + 4 * (-12 + x1)), tmp16 & xmask, other=0.0) tmp20 = tl.load(in_ptr4 + (x0 + 4 * (-12 + x1)), tmp16 & xmask, other=0.0) tmp21 = tmp19 * tmp20 tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp16, tmp21, tmp22) tmp24 = tl.where(tmp14, tmp15, tmp23) tmp25 = tl.where(tmp9, tmp10, tmp24) tmp26 = tl.where(tmp4, tmp5, tmp25) tl.store(out_ptr0 + x2, tmp26, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (16, 4), (4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 1, 4, 4), (16, 1, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf1) buf2 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (4, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf2) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf32 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_sigmoid_backward_tanh_1[grid(16)](buf1 , primals_3, buf2, primals_5, buf0, buf3, buf5, buf4, buf6, buf32, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) buf8 = buf2 del buf2 extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf8) buf9 = buf1 del buf1 extern_kernels.mm(buf7, reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf9) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_tanh_2[grid(16)](buf8, primals_3, buf9, primals_5, buf6, buf10, buf11, buf13, buf12, buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) buf16 = buf9 del buf9 extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 32), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf16) buf17 = buf8 del buf8 extern_kernels.mm(buf15, reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf17) buf18 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf19 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf21 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf20 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf22 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf23 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_tanh_2[grid(16)](buf16, primals_3, buf17, primals_5, buf14, buf18, buf19, buf21, buf20, buf22, buf23, 16, XBLOCK=16, num_warps=1, num_stages=1) buf24 = buf17 del buf17 extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (4, 1), 48), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf24) del primals_2 buf25 = buf16 del buf16 extern_kernels.mm(buf23, reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf25) buf26 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf27 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf28 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf30 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_tanh_3[grid(16)](buf24, primals_3, buf25, primals_5, buf22, buf26, buf27, buf28, buf30, 16, XBLOCK =16, num_warps=1, num_stages=1) buf29 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_sigmoid_4[grid(16)](buf24, primals_3, buf25, primals_5, buf29, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf24 del primals_3 del primals_5 buf31 = reinterpret_tensor(buf25, (16, 4), (4, 1), 0) del buf25 triton_poi_fused_stack_5[grid(64)](buf7, buf15, buf23, buf29, buf30, buf31, 64, XBLOCK=64, num_warps=1, num_stages=1) return (reinterpret_tensor(buf31, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf0, (4, 4), (4, 1), 0), reinterpret_tensor( primals_1, (4, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (4, 1), 16), reinterpret_tensor(primals_1, (4, 4), (4, 1), 32), reinterpret_tensor(primals_1, (4, 4), (4, 1), 48), buf3, buf4, buf5, buf6, buf7, buf10, buf11, buf12, buf13, buf14, buf15, buf18, buf19, buf20, buf21, buf22, buf23, buf26, buf27, buf28, buf29, buf30, primals_4, buf32) def filter_out_old_keys(self, state_dict, prefix, local_metadata): new_state_dict = {param_name: param_value for param_name, param_value in state_dict.items() if param_name not in self.old_to_new} return new_state_dict class LSTMLinear(nn.Linear): """ This function is the same as a nn.Linear layer, except that in the backward pass the grad_samples get accumulated (instead of being concatenated as in the standard nn.Linear) """ def __init__(self, in_features: 'int', out_features: 'int', bias: 'bool'=True): super().__init__(in_features, out_features, bias) class DPLSTMCell(nn.Module): """ Internal-only class. Implements *one* step of LSTM so that a LSTM layer can be seen as repeated applications of this class. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.ih = LSTMLinear(input_size, 4 * hidden_size, bias=self.bias) self.hh = LSTMLinear(hidden_size, 4 * hidden_size, bias=self.bias) self.reset_parameters() def reset_parameters(self): """ Resets parameters by initializing them from an uniform distribution. """ stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): nn.init.uniform_(weight, -stdv, stdv) def forward(self, x: 'torch.Tensor', h_prev: 'torch.Tensor', c_prev: 'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor]: gates = self.ih(x) + self.hh(h_prev) i_t_input, f_t_input, g_t_input, o_t_input = torch.split(gates, self.hidden_size, 1) i_t = torch.sigmoid(i_t_input) f_t = torch.sigmoid(f_t_input) g_t = torch.tanh(g_t_input) o_t = torch.sigmoid(o_t_input) c_t = f_t * c_prev + i_t * g_t h_t = o_t * torch.tanh(c_t) return h_t, c_t class DPLSTMLayer(nn.Module): """ Implements *one* layer of LSTM in a way amenable to differential privacy. We don't expect you to use this directly: use DPLSTM instead :) """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool', dropout: 'float', reverse: 'bool'=False): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.dropout = dropout self.reverse = reverse self.cell = DPLSTMCell(input_size=input_size, hidden_size= hidden_size, bias=bias) self.dropout_layer = nn.Dropout(dropout) if dropout > 0 else None def forward(self, x: 'torch.Tensor', state_init: 'Tuple[torch.Tensor, torch.Tensor]') ->Tuple[torch.Tensor, Tuple[ torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTMLayer when a sequence is given in input. Args: x: Input sequence to the DPLSTMCell of shape ``[T, B, D]``. state_init: Initial state of the LSTMCell as a tuple ``(h_0, c_0)`` where ``h_0`` is the initial hidden state and ``c_0`` is the initial cell state of the DPLSTMCell Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTMCell for each timestep ``t``. - ``h_n`` is of shape ``[B, H]`` and is a tensor containing the hidden state for ``t = T``. - ``c_n`` is of shape ``[B, H]`` tensor containing the cell state for ``t = T``. """ seq_length, _batch_sz, _ = x.shape if self.reverse: x = x.flip(0) x = torch.unbind(x, dim=0) h_0, c_0 = state_init h_n = [h_0] c_n = [c_0] for t in range(seq_length): h_next, c_next = self.cell(x[t], h_n[t], c_n[t]) if self.dropout: h_next = self.dropout_layer(h_next) h_n.append(h_next) c_n.append(c_next) h_n = torch.stack(h_n[1:], dim=0) return h_n.flip(0) if self.reverse else h_n, (h_n[-1], c_n[-1]) class BidirectionalDPLSTMLayer(nn.Module): """ Implements *one* layer of Bidirectional LSTM in a way amenable to differential privacy. We don't expect you to use this directly: use DPLSTM instead :) """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool', dropout: 'float'): super().__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.dropout = dropout self.forward_layer = DPLSTMLayer(input_size=input_size, hidden_size =hidden_size, bias=bias, dropout=dropout, reverse=False) self.reverse_layer = DPLSTMLayer(input_size=input_size, hidden_size =hidden_size, bias=bias, dropout=dropout, reverse=True) def forward(self, x: 'torch.Tensor', state_init: 'Tuple[torch.Tensor, torch.Tensor]') ->Tuple[torch.Tensor, Tuple[ torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTM when a sequence is input. Dimensions as follows: - B: Batch size - T: Sequence length - D: LSTM input hidden size (eg from a word embedding) - H: LSTM output hidden size - P: number of directions (2 if bidirectional, else 1) Args: x: Input sequence to the DPLSTM of shape ``[T, B, D]`` state_init: Initial state of the LSTM as a tuple ``(h_0, c_0)``, where: - h_0 of shape ``[P, B, H] contains the initial hidden state - c_0 of shape ``[P, B, H] contains the initial cell state This argument can be (and defaults to) None, in which case zero tensors will be used. Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H * P]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTM for each timestep ``t``. - ``h_n`` is of shape ``[P, B, H]`` and contains the hidden state for ``t = T``. - ``c_n`` is of shape ``[P, B, H]`` and contains the cell state for ``t = T``. """ h0, c0 = state_init h0_f, h0_r = h0.unbind(0) c0_f, c0_r = c0.unbind(0) out_f, (h_f, c_f) = self.forward_layer(x, (h0_f, c0_f)) out_r, (h_r, c_r) = self.reverse_layer(x, (h0_r, c0_r)) out = torch.cat([out_f, out_r], dim=-1) h = torch.stack([h_f, h_r], dim=0) c = torch.stack([c_f, c_r], dim=0) return out, (h, c) class ParamRenamedModule(nn.Module): """ This class defines a nn.Module whose parameters are renamed. This is useful when you want to reimplement a layer but make sure its state_dict and list of parameters are exactly the same as another reference layer so that you can have a drop-in replacement that does not depend on how your layer is actually implemented. In Opacus, this is used for DPLSTM, where our implementation leverages submodules and requires alignment to the state_dict of nn.LSTM. """ def __init__(self, rename_map: 'Dict[str, str]'): """ Initializes internal state. Subclass this instead of ``torch.nn.Module`` whenever you need to rename your model's state. Args: rename_map: mapping from old name -> new name for each parameter you want renamed. Note that this must be a 1:1 mapping! """ super().__init__() self.old_to_new = rename_map self.new_to_old = {v: k for k, v in rename_map.items()} self._register_state_dict_hook(filter_out_old_keys) def _register_renamed_parameters(self): """ Internal function. This function simply registers parameters under their new name. They will automatically mask their duplicates coming from submodules. This trick works because self.parameters() proceeds recursively from the top, going into submodules after processing items at the current level, and will not return duplicates. """ for old_name, param in super().named_parameters(): if old_name in self.old_to_new: new_name = self.old_to_new[old_name] self.register_parameter(new_name, param) def __setattr__(self, name: 'str', value: 'Union[Tensor, nn.Module]' ) ->None: """ Whenever you set an attribute, eg `self.linear`, this is called to actually register it in any nn.Module. We rely on the masking trick explained in the docs for ``_register_renamed_parameters`` to make sure we replace things only once. If a new parameter in the rename list is detected, we rename and mask it so next time this is called we will no longer find it. """ super().__setattr__(name, value) try: self._register_renamed_parameters() except AttributeError: pass def load_state_dict(self, state_dict: 'Dict[str, Tensor]', strict: 'bool'=True): """ Identical to ``torch.nn.Module.load_state_dict()`` but handles the renamed keys. """ missing_keys, unexpected_keys = super().load_state_dict(state_dict, strict=False) missing_keys = [k for k in missing_keys if k not in self.old_to_new] if strict: error_msgs = [] if len(unexpected_keys) > 0: error_msgs.insert(0, 'Unexpected key(s) in state_dict: {}. '.format(', '. join('"{}"'.format(k) for k in unexpected_keys))) if len(missing_keys) > 0: error_msgs.insert(0, 'Missing key(s) in state_dict: {}. '. format(', '.join('"{}"'.format(k) for k in missing_keys))) if len(error_msgs) > 0: raise RuntimeError( 'Error(s) in loading state_dict for {}:\n\t{}'.format( self.__class__.__name__, '\n\t'.join(error_msgs))) return _IncompatibleKeys(missing_keys, unexpected_keys) class DPLSTM(ParamRenamedModule): """ DP-friendly drop-in replacement of the ``torch.nn.LSTM`` module. Its state_dict matches that of nn.LSTM exactly, so that after training it can be exported and loaded by an nn.LSTM for inference. Refer to nn.LSTM's documentation for all parameters and inputs. """ def __init__(self, input_size: 'int', hidden_size: 'int', num_layers: 'int'=1, bias: 'bool'=True, batch_first: 'bool'=False, dropout: 'float'=0, bidirectional: 'bool'=False): rename_dict = self._make_rename_dict(num_layers, bias, bidirectional) super().__init__(rename_dict) self.input_size = input_size self.hidden_size = hidden_size self.num_layers = num_layers self.bias = bias self.batch_first = batch_first self.dropout = dropout self.bidirectional = bidirectional self.num_directions = 2 if self.bidirectional else 1 LayerClass = BidirectionalDPLSTMLayer if bidirectional else DPLSTMLayer self.layers = nn.ModuleList([LayerClass(input_size=self.input_size if i == 0 else self.hidden_size * self.num_directions, hidden_size =self.hidden_size, bias=self.bias, dropout=self.dropout if i < self.num_layers - 1 else 0) for i in range(num_layers)]) def forward(self, x: 'torch.Tensor', state_init: 'Optional[Tuple[torch.Tensor, torch.Tensor]]'=None) ->Tuple[torch. Tensor, Tuple[torch.Tensor, torch.Tensor]]: """ Implements the forward pass of the DPLSTM when a sequence is input. Dimensions as follows: - B: Batch size - T: Sequence length - D: LSTM input hidden size (eg from a word embedding) - H: LSTM output hidden size - L: number of layers in the LSTM - P: number of directions (2 if bidirectional, else 1) Args: x: Input sequence to the DPLSTM of shape ``[T, B, D]`` state_init: Initial state of the LSTM as a tuple ``(h_0, c_0)``, where: - h_0 of shape ``[L*P, B, H] contains the initial hidden state - c_0 of shape ``[L*P, B, H] contains the initial cell state This argument can be (and defaults to) None, in which case zero tensors will be used. Returns: ``output, (h_n, c_n)`` where: - ``output`` is of shape ``[T, B, H * P]`` and is a tensor containing the output features (``h_t``) from the last layer of the DPLSTM for each timestep ``t``. - ``h_n`` is of shape ``[L * P, B, H]`` and contains the hidden state for ``t = T``. - ``c_n`` is of shape ``[L * P, B, H]`` and contains the cell state for ``t = T``. """ x = self._rearrange_batch_dim(x) _T, B, _D = x.shape L = self.num_layers P = 2 if self.bidirectional else 1 H = self.hidden_size h_0s, c_0s = state_init or (None, None) if h_0s is None: h_0s = torch.zeros(L, P, B, self.hidden_size, dtype=x[0].dtype, device=x[0].device) else: h_0s = h_0s.reshape([L, P, B, H]) if c_0s is None: c_0s = torch.zeros(L, P, B, self.hidden_size, dtype=x[0].dtype, device=x[0].device) else: c_0s = c_0s.reshape([L, P, B, H]) hs: 'List[torch.Tensor]' = [] cs: 'List[torch.Tensor]' = [] for layer, h0, c0 in zip(self.layers, h_0s, c_0s): if not self.bidirectional: h0 = h0.squeeze(0) c0 = c0.squeeze(0) x, (h, c) = layer(x, (h0, c0)) if not self.bidirectional: h = h.unsqueeze(0) c = c.unsqueeze(0) hs.append(h) cs.append(c) hs = torch.cat(hs, dim=0) cs = torch.cat(cs, dim=0) out = self._rearrange_batch_dim(x) return out, (hs, cs) def _rearrange_batch_dim(self, x: 'torch.Tensor') ->torch.Tensor: if self.batch_first: x = x.transpose(0, 1) return x def __repr__(self): s = f'DPLSTM({self.input_size}, {self.hidden_size}, bias={self.bias}' if self.batch_first: s += f', batch_first={self.batch_first}' if self.num_layers > 1: s += f', num_layers={self.num_layers}' if self.dropout: s += f', dropout={self.dropout}' if self.bidirectional: s += f', bidirectional={self.bidirectional}' return s def _make_rename_dict(self, num_layers, bias, bidirectional): """ Programmatically constructs a dictionary old_name -> new_name to align with the param names used in ``torch.nn.LSTM``. """ d = {} components = ['weight'] + ['bias' if bias else []] matrices = ['ih', 'hh'] for i in range(num_layers): for c in components: for m in matrices: nn_name = f'{c}_{m}_l{i}' if bidirectional: d[f'layers.{i}.forward_layer.cell.{m}.{c}'] = nn_name d[f'layers.{i}.reverse_layer.cell.{m}.{c}' ] = nn_name + '_reverse' else: d[f'layers.{i}.cell.{m}.{c}'] = nn_name return d class DPSLTMAdapterNew(nn.Module): """ Adapter for DPLSTM. LSTM returns a tuple, but our testing tools need the model to return a single tensor in output. We do this adaption here. """ def __init__(self, *args, **kwargs): super().__init__() self.dplstm = DPLSTM(*args, **kwargs) def forward(self, input_0): primals_2 = self.dplstm.weight_ih_l0 primals_3 = self.dplstm.bias_ih_l0 primals_4 = self.dplstm.weight_hh_l0 primals_5 = self.dplstm.bias_hh_l0 primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
adriansarstedt/opacus
DPSLTMAdapter
false
12,097
[ "Apache-2.0" ]
0
a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
https://github.com/adriansarstedt/opacus/tree/a6c89e3d6a3a4e3e4b82bc8c68d53265a9a7cba1
FCNet
import torch import torch.nn as nn import torch.nn.functional as F class FCNet(nn.Module): """ fully-connected neural network """ def __init__(self): super(FCNet, self).__init__() self.fc1 = nn.Linear(784, 400) self.fc2 = nn.Linear(400, 200) self.fc3 = nn.Linear(200, 100) self.fc4 = nn.Linear(100, 10) def forward(self, x): x = x.view(-1, 784) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) x = self.fc4(x) return F.log_softmax(x, dim=1) def get_inputs(): return [torch.rand([4, 784])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 400 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 800 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 200 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 100 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_per_fused__log_softmax_3(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 rnumel = 10 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(rmask & xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(rmask & xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tl_math.log(tmp10) tmp12 = tmp5 - tmp11 tl.store(out_ptr2 + (r1 + 10 * x0), tmp12, rmask & xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 784), (784, 1)) assert_size_stride(primals_2, (400, 784), (784, 1)) assert_size_stride(primals_3, (400,), (1,)) assert_size_stride(primals_4, (200, 400), (400, 1)) assert_size_stride(primals_5, (200,), (1,)) assert_size_stride(primals_6, (100, 200), (200, 1)) assert_size_stride(primals_7, (100,), (1,)) assert_size_stride(primals_8, (10, 100), (100, 1)) assert_size_stride(primals_9, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 400), (400, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (784, 400), (1, 784), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(1600)](buf1, primals_3, 1600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 200), (200, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (400, 200), ( 1, 400), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(800)](buf3, primals_5, 800, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 100), (100, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_6, (200, 100), ( 1, 200), 0), out=buf4) buf5 = buf4 del buf4 triton_poi_fused_relu_2[grid(400)](buf5, primals_7, 400, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_9, buf5, reinterpret_tensor(primals_8, (100, 10), (1, 100), 0), alpha=1, beta=1, out=buf6) del primals_9 buf9 = empty_strided_cuda((4, 10), (10, 1), torch.float32) triton_per_fused__log_softmax_3[grid(4)](buf6, buf9, 4, 10, XBLOCK= 1, num_warps=2, num_stages=1) del buf6 return (buf9, primals_1, buf1, buf3, buf5, buf9, primals_8, primals_6, primals_4) class FCNetNew(nn.Module): """ fully-connected neural network """ def __init__(self): super(FCNetNew, self).__init__() self.fc1 = nn.Linear(784, 400) self.fc2 = nn.Linear(400, 200) self.fc3 = nn.Linear(200, 100) self.fc4 = nn.Linear(100, 10) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_8 = self.fc4.weight primals_9 = self.fc4.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
animeshbchowdhury/robust-pnr-time
FCNet
false
12,098
[ "BSD-3-Clause" ]
0
301c5d973b8c024a85fdab915986ecf257e7698b
https://github.com/animeshbchowdhury/robust-pnr-time/tree/301c5d973b8c024a85fdab915986ecf257e7698b
StendLoss
import torch from itertools import chain as chain import torch.utils.data import torch.nn as nn from torch.nn.modules.loss import _Loss class StendLoss(_Loss): def __init__(self, size_average=None, reduce=None, reduction='mean'): super(StendLoss, self).__init__() self.reduction = reduction def forward(self, output, target): start_pred = output[:, 0] end_pred = output[:, 1] start_target = target[0] end_target = target[1] start_loss = nn.BCEWithLogitsLoss(reduction=self.reduction) end_loss = nn.BCEWithLogitsLoss(reduction=self.reduction) start_comp = start_loss(start_pred, start_target) end_comp = end_loss(end_pred, end_target) return start_comp + end_comp 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 itertools import chain as chain import torch.utils.data from torch.nn.modules.loss import _Loss assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_binary_cross_entropy_with_logits_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) r2 = rindex r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + r2, None) tmp3 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp16 = tl.load(in_ptr0 + (64 + r2), None) tmp18 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp2 * tmp3 tmp5 = 0.0 tmp6 = triton_helpers.minimum(tmp5, tmp3) tmp7 = tl_math.abs(tmp3) tmp8 = -tmp7 tmp9 = tl_math.exp(tmp8) tmp10 = libdevice.log1p(tmp9) tmp11 = tmp6 - tmp10 tmp12 = tmp4 - tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.sum(tmp13, 1)[:, None] tmp17 = tmp1 - tmp16 tmp19 = tmp17 * tmp18 tmp20 = triton_helpers.minimum(tmp5, tmp18) tmp21 = tl_math.abs(tmp18) tmp22 = -tmp21 tmp23 = tl_math.exp(tmp22) tmp24 = libdevice.log1p(tmp23) tmp25 = tmp20 - tmp24 tmp26 = tmp19 - tmp25 tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK]) tmp29 = tl.sum(tmp27, 1)[:, None] tmp30 = 64.0 tmp31 = tmp15 / tmp30 tmp32 = tmp29 / tmp30 tmp33 = tmp31 + tmp32 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp33, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_binary_cross_entropy_with_logits_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 StendLossNew(_Loss): def __init__(self, size_average=None, reduce=None, reduction='mean'): super(StendLossNew, self).__init__() self.reduction = reduction def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
anton-br/SlowFast
StendLoss
false
12,099
[ "Apache-2.0" ]
0
6e8d68bc6f3191886a57f819db1c766c6ca32d21
https://github.com/anton-br/SlowFast/tree/6e8d68bc6f3191886a57f819db1c766c6ca32d21
ZeroLayer
import torch import torch.nn as nn import torch.utils.data class ZeroLayer(nn.Module): def __init__(self, stride): super(ZeroLayer, self).__init__() self.stride = stride def forward(self, x): """n, c, h, w = x.size() h //= self.stride w //= self.stride device = x.get_device() if x.is_cuda else torch.device('cpu') # noinspection PyUnresolvedReferences padding = torch.zeros(n, c, h, w, device=device, requires_grad=False) return padding""" return x * 0 @staticmethod def is_zero_layer(): return True def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'stride': 1}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.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_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.0 tmp2 = 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_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class ZeroLayerNew(nn.Module): def __init__(self, stride): super(ZeroLayerNew, self).__init__() self.stride = stride @staticmethod def is_zero_layer(): return True def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
airglow/nni
ZeroLayer
false
12,100
[ "MIT" ]
0
751065b788f66a6b53446620293095b1fe1b1c65
https://github.com/airglow/nni/tree/751065b788f66a6b53446620293095b1fe1b1c65
SpaceToDepth
import torch from torchvision import datasets as datasets import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed class SpaceToDepth(nn.Module): def __init__(self, block_size=4): super().__init__() assert block_size == 4 self.bs = block_size def forward(self, x): N, C, H, W = x.size() x = x.view(N, C, H // self.bs, self.bs, W // self.bs, self.bs) x = x.permute(0, 3, 5, 1, 2, 4).contiguous() x = x.view(N, C * self.bs ** 2, H // self.bs, W // self.bs) 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 torchvision import datasets as datasets import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel 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): 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, 1, 1), (64, 16, 4, 1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64, 4)](arg0_1, buf0, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 64, 1, 1), (64, 1, 1, 1), 0), class SpaceToDepthNew(nn.Module): def __init__(self, block_size=4): super().__init__() assert block_size == 4 self.bs = block_size def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
adam-dziedzic/ASL
SpaceToDepth
false
12,101
[ "MIT" ]
0
cc063f5e7eda1498544ad2c3b224985203b0774a
https://github.com/adam-dziedzic/ASL/tree/cc063f5e7eda1498544ad2c3b224985203b0774a
HSwish
import torch import torch.nn as nn import torch.nn.functional import torch.nn.parallel import torch.utils.data.distributed class HSwish(nn.Module): """ Applies the Hard-Swish function element-wise. `"Searching for MobileNetV3" <https://arxiv.org/pdf/1905.02244.pdf>`_ Examples: >>> m = Mish() >>> x = torch.randn(2) >>> output = m(x) """ @staticmethod def forward(x: 'torch.Tensor') ->torch.Tensor: out = x * torch.nn.functional.relu6(x + 3, inplace=True) / 6.0 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.nn.functional import torch.nn.parallel 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=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class HSwishNew(nn.Module): """ Applies the Hard-Swish function element-wise. `"Searching for MobileNetV3" <https://arxiv.org/pdf/1905.02244.pdf>`_ Examples: >>> m = Mish() >>> x = torch.randn(2) >>> output = m(x) """ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ardianumam/Vanilla-GAN
HSwish
false
12,102
[ "Apache-2.0" ]
0
3fce9b60dca4609aad1d4e5eb834a2cc72cf07b3
https://github.com/ardianumam/Vanilla-GAN/tree/3fce9b60dca4609aad1d4e5eb834a2cc72cf07b3
SpatialAttentionGate
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class SpatialAttentionGate(nn.Module): def __init__(self, channel, reduction=16): super(SpatialAttentionGate, self).__init__() self.fc1 = nn.Conv2d(channel, reduction, kernel_size=1, padding=0) self.fc2 = nn.Conv2d(reduction, 1, kernel_size=1, padding=0) def forward(self, x): x = self.fc1(x) x = F.relu(x, inplace=True) x = self.fc2(x) x = torch.sigmoid(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channel': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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 @triton.jit def triton_poi_fused_convolution_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 x3 = xindex x1 = xindex // 16 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (16, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_5, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 4, 4), (256, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1024)](buf1, primals_2, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 4, 4), (16, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_sigmoid_1[grid(64)](buf3, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1, buf3 class SpatialAttentionGateNew(nn.Module): def __init__(self, channel, reduction=16): super(SpatialAttentionGateNew, self).__init__() self.fc1 = nn.Conv2d(channel, reduction, kernel_size=1, padding=0) self.fc2 = nn.Conv2d(reduction, 1, kernel_size=1, padding=0) 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]
airglow/nni
SpatialAttentionGate
false
12,103
[ "MIT" ]
0
751065b788f66a6b53446620293095b1fe1b1c65
https://github.com/airglow/nni/tree/751065b788f66a6b53446620293095b1fe1b1c65
HSigmoid
import torch import torch.nn as nn import torch.nn.functional import torch.nn.parallel import torch.utils.data.distributed class HSigmoid(nn.Module): """ Applies the Hard-Sigmoid function element-wise. `"Searching for MobileNetV3" <https://arxiv.org/pdf/1905.02244.pdf>`_ Examples: >>> m = Mish() >>> x = torch.randn(2) >>> output = m(x) """ @staticmethod def forward(x: 'torch.Tensor') ->torch.Tensor: out = torch.nn.functional.relu6(x + 3, inplace=True) / 6.0 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.nn.functional import torch.nn.parallel 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): """ Applies the Hard-Sigmoid function element-wise. `"Searching for MobileNetV3" <https://arxiv.org/pdf/1905.02244.pdf>`_ Examples: >>> m = Mish() >>> x = torch.randn(2) >>> output = m(x) """ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ardianumam/Vanilla-GAN
HSigmoid
false
12,104
[ "Apache-2.0" ]
0
3fce9b60dca4609aad1d4e5eb834a2cc72cf07b3
https://github.com/ardianumam/Vanilla-GAN/tree/3fce9b60dca4609aad1d4e5eb834a2cc72cf07b3
_AddNorm
import torch import torch.nn as nn import torch.nn.functional as F class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNorm(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'): if self.input_size != self.skip_size: skip = self.resample(skip) if self.trainable_add: skip = skip * self.gate(self.mask) * 2.0 output = self.norm(x + skip) return output def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_native_layer_norm_sigmoid_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp9 = 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' ) tmp11 = tl.load(in_ptr2 + 1) tmp12 = tl.broadcast_to(tmp11, [XBLOCK]) tmp18 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr2 + 2) tmp21 = tl.broadcast_to(tmp20, [XBLOCK]) tmp27 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp28 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp29 = tl.load(in_ptr2 + 3) tmp30 = tl.broadcast_to(tmp29, [XBLOCK]) tmp4 = tl.sigmoid(tmp3) tmp5 = tmp1 * tmp4 tmp6 = 2.0 tmp7 = tmp5 * tmp6 tmp8 = tmp0 + tmp7 tmp13 = tl.sigmoid(tmp12) tmp14 = tmp10 * tmp13 tmp15 = tmp14 * tmp6 tmp16 = tmp9 + tmp15 tmp17 = tmp8 + tmp16 tmp22 = tl.sigmoid(tmp21) tmp23 = tmp19 * tmp22 tmp24 = tmp23 * tmp6 tmp25 = tmp18 + tmp24 tmp26 = tmp17 + tmp25 tmp31 = tl.sigmoid(tmp30) tmp32 = tmp28 * tmp31 tmp33 = tmp32 * tmp6 tmp34 = tmp27 + tmp33 tmp35 = tmp26 + tmp34 tmp36 = 4.0 tmp37 = tmp35 / tmp36 tmp38 = tmp8 - tmp37 tmp39 = tmp38 * tmp38 tmp40 = tmp16 - tmp37 tmp41 = tmp40 * tmp40 tmp42 = tmp39 + tmp41 tmp43 = tmp25 - tmp37 tmp44 = tmp43 * tmp43 tmp45 = tmp42 + tmp44 tmp46 = tmp34 - tmp37 tmp47 = tmp46 * tmp46 tmp48 = tmp45 + tmp47 tmp49 = tmp48 / tmp36 tl.store(out_ptr0 + x0, tmp37, xmask) tl.store(out_ptr1 + x0, tmp49, xmask) @triton.jit def triton_poi_fused_add_mul_native_layer_norm_sigmoid_1(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 x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr6 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.sigmoid(tmp2) tmp4 = tmp1 * tmp3 tmp5 = 2.0 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + tmp6 tmp9 = tmp7 - tmp8 tmp11 = 1e-05 tmp12 = tmp10 + tmp11 tmp13 = libdevice.rsqrt(tmp12) tmp14 = tmp9 * tmp13 tmp16 = tmp14 * tmp15 tmp18 = tmp16 + tmp17 tl.store(out_ptr0 + x2, tmp18, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_native_layer_norm_sigmoid_0[grid(64)]( primals_3, primals_2, primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_native_layer_norm_sigmoid_1[grid(256)]( primals_3, primals_2, primals_1, buf0, buf1, primals_4, primals_5, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del buf1 del primals_5 return buf2, primals_1, primals_2, primals_3, primals_4 class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNormNew(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, input_0, input_1): primals_1 = self.mask primals_4 = self.norm.weight primals_5 = self.norm.bias primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
amadejkocbek/darts
_AddNorm
false
12,105
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
_ScaledDotProductAttention
import torch import torch.nn as nn class _ScaledDotProductAttention(nn.Module): def __init__(self, dropout: 'float'=None, scale: 'bool'=True): super(_ScaledDotProductAttention, self).__init__() if dropout is not None: self.dropout = nn.Dropout(p=dropout) else: self.dropout = dropout self.softmax = nn.Softmax(dim=2) self.scale = scale def forward(self, q, k, v, mask=None): attn = torch.bmm(q, k.permute(0, 2, 1)) if self.scale: dimension = torch.sqrt(torch.tensor(k.shape[-1])) attn = attn / dimension if mask is not None: attn = attn.masked_fill(mask, -1000000000.0) attn = self.softmax(attn) if self.dropout is not None: attn = self.dropout(attn) output = torch.bmm(attn, v) return output, attn def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math 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_sqrt_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp8 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 2.0 tmp2 = 0.0 tmp3 = tmp1 >= tmp2 tmp4 = 1.0 tmp5 = -1.0 tmp6 = tl.where(tmp3, tmp4, tmp5) tmp7 = tmp0 * tmp6 tmp9 = tmp8 * tmp6 tmp11 = tmp10 * tmp6 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp14 = tmp13 * tmp6 tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp17 = tmp16 * tmp6 tmp18 = triton_helpers.maximum(tmp15, tmp17) tmp19 = tmp7 - tmp18 tmp20 = tmp6 * tmp1 tmp21 = tmp19 / tmp20 tmp22 = tl_math.exp(tmp21) tl.store(out_ptr0 + x2, tmp22, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), ( 16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_sqrt_0[grid(64)](buf0, buf1, 64, XBLOCK= 64, num_warps=1, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf1 del buf1 extern_kernels.bmm(buf2, arg2_1, out=buf3) del arg2_1 return buf3, buf2 class _ScaledDotProductAttentionNew(nn.Module): def __init__(self, dropout: 'float'=None, scale: 'bool'=True): super(_ScaledDotProductAttentionNew, self).__init__() if dropout is not None: self.dropout = nn.Dropout(p=dropout) else: self.dropout = dropout self.softmax = nn.Softmax(dim=2) self.scale = scale def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0], output[1]
amadejkocbek/darts
_ScaledDotProductAttention
false
12,106
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
_ResampleNorm
import torch import torch.nn as nn import torch.nn.functional as F class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _ResampleNorm(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size if self.input_size != self.output_size: self.resample = _TimeDistributedInterpolation(self.output_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.output_size) def forward(self, x: 'torch.Tensor') ->torch.Tensor: if self.input_size != self.output_size: x = self.resample(x) if self.trainable_add: x = x * self.gate(self.mask) * 2.0 output = self.norm(x) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_native_layer_norm_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + 1) tmp9 = tl.broadcast_to(tmp8, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + 2) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp21 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr1 + 3) tmp23 = tl.broadcast_to(tmp22, [XBLOCK]) tmp3 = tl.sigmoid(tmp2) tmp4 = tmp0 * tmp3 tmp5 = 2.0 tmp6 = tmp4 * tmp5 tmp10 = tl.sigmoid(tmp9) tmp11 = tmp7 * tmp10 tmp12 = tmp11 * tmp5 tmp13 = tmp6 + tmp12 tmp17 = tl.sigmoid(tmp16) tmp18 = tmp14 * tmp17 tmp19 = tmp18 * tmp5 tmp20 = tmp13 + tmp19 tmp24 = tl.sigmoid(tmp23) tmp25 = tmp21 * tmp24 tmp26 = tmp25 * tmp5 tmp27 = tmp20 + tmp26 tmp28 = 4.0 tmp29 = tmp27 / tmp28 tmp30 = tmp6 - tmp29 tmp31 = tmp30 * tmp30 tmp32 = tmp12 - tmp29 tmp33 = tmp32 * tmp32 tmp34 = tmp31 + tmp33 tmp35 = tmp19 - tmp29 tmp36 = tmp35 * tmp35 tmp37 = tmp34 + tmp36 tmp38 = tmp26 - tmp29 tmp39 = tmp38 * tmp38 tmp40 = tmp37 + tmp39 tmp41 = tmp40 / tmp28 tl.store(out_ptr0 + x0, tmp29, xmask) tl.store(out_ptr1 + x0, tmp41, xmask) @triton.jit def triton_poi_fused_mul_native_layer_norm_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = 2.0 tmp5 = tmp3 * tmp4 tmp7 = tmp5 - tmp6 tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = libdevice.rsqrt(tmp10) tmp12 = tmp7 * tmp11 tmp14 = tmp12 * tmp13 tmp16 = tmp14 + tmp15 tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_mul_native_layer_norm_sigmoid_0[grid(64)](primals_2, primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_native_layer_norm_sigmoid_1[grid(256)](primals_2, primals_1, buf0, buf1, primals_3, primals_4, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del buf0 del buf1 del primals_4 return buf2, primals_1, primals_2, primals_3 class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _ResampleNormNew(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size if self.input_size != self.output_size: self.resample = _TimeDistributedInterpolation(self.output_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.output_size) def forward(self, input_0): primals_1 = self.mask primals_3 = self.norm.weight primals_4 = self.norm.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
amadejkocbek/darts
_ResampleNorm
false
12,107
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
_GateAddNorm
import torch import torch.nn as nn import torch.nn.functional as F class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNorm(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'): if self.input_size != self.skip_size: skip = self.resample(skip) if self.trainable_add: skip = skip * self.gate(self.mask) * 2.0 output = self.norm(x + skip) return output class _GatedLinearUnit(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x): if self.dropout is not None: x = self.dropout(x) x = self.fc(x) x = F.glu(x, dim=-1) return x class _GateAddNorm(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int'=None, skip_size: 'int'=None, trainable_add: 'bool'=False, dropout: 'float'=None): super().__init__() self.input_size = input_size self.hidden_size = hidden_size or input_size self.skip_size = skip_size or self.hidden_size self.dropout = dropout self.glu = _GatedLinearUnit(self.input_size, hidden_size=self. hidden_size, dropout=self.dropout) self.add_norm = _AddNorm(self.hidden_size, skip_size=self.skip_size, trainable_add=trainable_add) def forward(self, x, skip): output = self.glu(x) output = self.add_norm(output, skip) return output def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_glu_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp4 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_2(in_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, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 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, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (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_glu_0[grid(256)](buf0, primals_4, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) 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=256, 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 ), reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0), buf1 class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNorm(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'): if self.input_size != self.skip_size: skip = self.resample(skip) if self.trainable_add: skip = skip * self.gate(self.mask) * 2.0 output = self.norm(x + skip) return output class _GatedLinearUnit(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x): if self.dropout is not None: x = self.dropout(x) x = self.fc(x) x = F.glu(x, dim=-1) return x class _GateAddNormNew(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int'=None, skip_size: 'int'=None, trainable_add: 'bool'=False, dropout: 'float'=None): super().__init__() self.input_size = input_size self.hidden_size = hidden_size or input_size self.skip_size = skip_size or self.hidden_size self.dropout = dropout self.glu = _GatedLinearUnit(self.input_size, hidden_size=self. hidden_size, dropout=self.dropout) self.add_norm = _AddNorm(self.hidden_size, skip_size=self.skip_size, trainable_add=trainable_add) def forward(self, input_0, input_1): primals_1 = self.glu.fc.weight primals_2 = self.glu.fc.bias primals_5 = self.add_norm.norm.weight primals_6 = self.add_norm.norm.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]
amadejkocbek/darts
_GateAddNorm
false
12,108
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
_GatedLinearUnit
import torch import torch.nn as nn import torch.nn.functional as F class _GatedLinearUnit(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x): if self.dropout is not None: x = self.dropout(x) x = self.fc(x) x = F.glu(x, dim=-1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn 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_glu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (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_glu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0) class _GatedLinearUnitNew(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) 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]
amadejkocbek/darts
_GatedLinearUnit
false
12,109
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
TReLU
import torch import torch.nn as nn import torch.nn.functional as F class TReLU(nn.Module): def __init__(self): super(TReLU, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, x): x = F.relu(x - self.alpha) + self.alpha return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_relu_sub_threshold_backward_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 - tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = tmp5 + tmp2 tmp7 = 0.0 tmp8 = tmp5 <= tmp7 tl.store(out_ptr0 + x0, tmp6, xmask) tl.store(out_ptr1 + x0, tmp8, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_relu_sub_threshold_backward_0[grid(256)](primals_2 , primals_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_1 del primals_2 return buf0, buf1 class TReLUNew(nn.Module): def __init__(self): super(TReLUNew, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, input_0): primals_1 = self.alpha primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
archiroid003/ICCV2019-LearningToPaint
TReLU
false
12,110
[ "MIT" ]
0
4b5fc263e4843c159a61e5956956b3f7812693f8
https://github.com/archiroid003/ICCV2019-LearningToPaint/tree/4b5fc263e4843c159a61e5956956b3f7812693f8
MLP
from _paritybench_helpers import _mock_config import math import torch import torch.nn as nn def gelu(x): return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) class SharedDropout(torch.nn.Module): def __init__(self, p): super(SharedDropout, self).__init__() self.p = p def forward(self, x): if self.training: mask = torch.rand_like(x[0:1]) > self.p return mask.type(x.type()) * x / (1 - self.p) else: return x class Conv1D(nn.Module): def __init__(self, nf, nx): """ Conv1D layer as defined by Radford et al. for OpenAI GPT (and also used in GPT-2) Basically works like a Linear layer but the weights are transposed """ super().__init__() self.nf = nf w = torch.empty(nx, nf) nn.init.normal_(w, std=0.02) self.weight = nn.Parameter(w) self.bias = nn.Parameter(torch.zeros(nf)) def forward(self, x): size_out = x.size()[:-1] + (self.nf,) x = torch.addmm(self.bias, x.view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class MLP(nn.Module): def __init__(self, n_state, config): super().__init__() nx = config.n_embd self.c_fc = Conv1D(n_state, nx) self.c_proj = Conv1D(nx, n_state) self.act = gelu self.dropout = SharedDropout(config.resid_pdrop) def forward(self, x): h = self.act(self.c_fc(x)) h2 = self.c_proj(h) return self.dropout(h2) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_state': 4, 'config': _mock_config(n_embd=4, resid_pdrop=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_mul_pow_tanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = tmp0 * tmp0 tmp4 = tmp3 * tmp0 tmp5 = 0.044715 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + tmp6 tmp8 = 0.7978845608028654 tmp9 = tmp7 * tmp8 tmp10 = libdevice.tanh(tmp9) tmp11 = 1.0 tmp12 = tmp10 + tmp11 tmp13 = tmp2 * tmp12 tl.store(out_ptr0 + x0, tmp13, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), primals_3, alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_pow_tanh_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), primals_5, alpha=1, beta=1, out=buf2) del primals_4 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), buf0, reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), reinterpret_tensor(buf1, (4, 64), (1, 4), 0), reinterpret_tensor( primals_1, (4, 64), (1, 4), 0) def gelu(x): return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) class SharedDropout(torch.nn.Module): def __init__(self, p): super(SharedDropout, self).__init__() self.p = p def forward(self, x): if self.training: mask = torch.rand_like(x[0:1]) > self.p return mask.type(x.type()) * x / (1 - self.p) else: return x class Conv1D(nn.Module): def __init__(self, nf, nx): """ Conv1D layer as defined by Radford et al. for OpenAI GPT (and also used in GPT-2) Basically works like a Linear layer but the weights are transposed """ super().__init__() self.nf = nf w = torch.empty(nx, nf) nn.init.normal_(w, std=0.02) self.weight = nn.Parameter(w) self.bias = nn.Parameter(torch.zeros(nf)) def forward(self, x): size_out = x.size()[:-1] + (self.nf,) x = torch.addmm(self.bias, x.view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class MLPNew(nn.Module): def __init__(self, n_state, config): super().__init__() nx = config.n_embd self.c_fc = Conv1D(n_state, nx) self.c_proj = Conv1D(nx, n_state) self.act = gelu self.dropout = SharedDropout(config.resid_pdrop) def forward(self, input_0): primals_3 = self.c_fc.weight primals_2 = self.c_fc.bias primals_5 = self.c_proj.weight primals_4 = self.c_proj.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
albertkx/GeDi
MLP
false
12,111
[ "BSD-3-Clause" ]
0
27532eb6ac5dd42d817d25a905401504e916f9fb
https://github.com/albertkx/GeDi/tree/27532eb6ac5dd42d817d25a905401504e916f9fb
_GatedResidualNetwork
import torch import torch.nn as nn import torch.nn.functional as F class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNorm(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'): if self.input_size != self.skip_size: skip = self.resample(skip) if self.trainable_add: skip = skip * self.gate(self.mask) * 2.0 output = self.norm(x + skip) return output class _GatedLinearUnit(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x): if self.dropout is not None: x = self.dropout(x) x = self.fc(x) x = F.glu(x, dim=-1) return x class _GateAddNorm(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int'=None, skip_size: 'int'=None, trainable_add: 'bool'=False, dropout: 'float'=None): super().__init__() self.input_size = input_size self.hidden_size = hidden_size or input_size self.skip_size = skip_size or self.hidden_size self.dropout = dropout self.glu = _GatedLinearUnit(self.input_size, hidden_size=self. hidden_size, dropout=self.dropout) self.add_norm = _AddNorm(self.hidden_size, skip_size=self.skip_size, trainable_add=trainable_add) def forward(self, x, skip): output = self.glu(x) output = self.add_norm(output, skip) return output class _ResampleNorm(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size if self.input_size != self.output_size: self.resample = _TimeDistributedInterpolation(self.output_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.output_size) def forward(self, x: 'torch.Tensor') ->torch.Tensor: if self.input_size != self.output_size: x = self.resample(x) if self.trainable_add: x = x * self.gate(self.mask) * 2.0 output = self.norm(x) return output class _GatedResidualNetwork(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int', output_size: 'int', dropout: 'float'=0.1, context_size: 'int'=None, residual: 'bool'=False): super().__init__() self.input_size = input_size self.output_size = output_size self.context_size = context_size self.hidden_size = hidden_size self.dropout = dropout self.residual = residual if self.input_size != self.output_size and not self.residual: residual_size = self.input_size else: residual_size = self.output_size if self.output_size != residual_size: self.resample_norm = _ResampleNorm(residual_size, self.output_size) self.fc1 = nn.Linear(self.input_size, self.hidden_size) self.elu = nn.ELU() if self.context_size is not None: self.context = nn.Linear(self.context_size, self.hidden_size, bias=False) self.fc2 = nn.Linear(self.hidden_size, self.hidden_size) self.init_weights() self.gate_norm = _GateAddNorm(input_size=self.hidden_size, skip_size=self.output_size, hidden_size=self.output_size, dropout=self.dropout, trainable_add=False) def init_weights(self): for name, p in self.named_parameters(): if 'bias' in name: torch.nn.init.zeros_(p) elif 'fc1' in name or 'fc2' in name: torch.nn.init.kaiming_normal_(p, a=0, mode='fan_in', nonlinearity='leaky_relu') elif 'context' in name: torch.nn.init.xavier_uniform_(p) def forward(self, x, context=None, residual=None): if residual is None: residual = x if self.input_size != self.output_size and not self.residual: residual = self.resample_norm(residual) x = self.fc1(x) if context is not None: context = self.context(context) x = x + context x = self.elu(x) x = self.fc2(x) x = self.gate_norm(x, residual) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_glu_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_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 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_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex 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) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (8, 4), (4, 1)) assert_size_stride(primals_7, (8,), (1,)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_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 buf3 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_7, buf2, reinterpret_tensor(primals_6, (4, 8), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_7 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_glu_1[grid(256)](buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_native_layer_norm_2[grid(64)](buf4, primals_1, buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_3[grid(256)](buf4, primals_1, buf5, buf6, primals_8, primals_9, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf5 del buf6 del primals_9 return buf7, primals_1, primals_8, buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), buf2, reinterpret_tensor(buf3, (4, 4, 4, 8), (128, 32, 8, 1), 0), buf4, primals_6, primals_4 class _TimeDistributedInterpolation(nn.Module): def __init__(self, output_size: 'int', batch_first: 'bool'=False, trainable: 'bool'=False): super().__init__() self.output_size = output_size self.batch_first = batch_first self.trainable = trainable if self.trainable: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float32)) self.gate = nn.Sigmoid() def interpolate(self, x): upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode= 'linear', align_corners=True).squeeze(1) if self.trainable: upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0 return upsampled def forward(self, x): if len(x.size()) <= 2: return self.interpolate(x) x_reshape = x.contiguous().view(-1, x.size(-1)) y = self.interpolate(x_reshape) if self.batch_first: y = y.contiguous().view(x.size(0), -1, y.size(-1)) else: y = y.view(-1, x.size(1), y.size(-1)) return y class _AddNorm(nn.Module): def __init__(self, input_size: 'int', skip_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.skip_size = skip_size or input_size if self.input_size != self.skip_size: self.resample = _TimeDistributedInterpolation(self.input_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.input_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.input_size) def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'): if self.input_size != self.skip_size: skip = self.resample(skip) if self.trainable_add: skip = skip * self.gate(self.mask) * 2.0 output = self.norm(x + skip) return output class _GatedLinearUnit(nn.Module): """Gated Linear Unit""" def __init__(self, input_size: 'int', hidden_size: 'int'=None, dropout: 'float'=None): super().__init__() if dropout is not None: self.dropout = nn.Dropout(dropout) else: self.dropout = dropout self.hidden_size = hidden_size or input_size self.fc = nn.Linear(input_size, self.hidden_size * 2) self.init_weights() def init_weights(self): for n, p in self.named_parameters(): if 'bias' in n: torch.nn.init.zeros_(p) elif 'fc' in n: torch.nn.init.xavier_uniform_(p) def forward(self, x): if self.dropout is not None: x = self.dropout(x) x = self.fc(x) x = F.glu(x, dim=-1) return x class _GateAddNorm(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int'=None, skip_size: 'int'=None, trainable_add: 'bool'=False, dropout: 'float'=None): super().__init__() self.input_size = input_size self.hidden_size = hidden_size or input_size self.skip_size = skip_size or self.hidden_size self.dropout = dropout self.glu = _GatedLinearUnit(self.input_size, hidden_size=self. hidden_size, dropout=self.dropout) self.add_norm = _AddNorm(self.hidden_size, skip_size=self.skip_size, trainable_add=trainable_add) def forward(self, x, skip): output = self.glu(x) output = self.add_norm(output, skip) return output class _ResampleNorm(nn.Module): def __init__(self, input_size: 'int', output_size: 'int'=None, trainable_add: 'bool'=True): super().__init__() self.input_size = input_size self.trainable_add = trainable_add self.output_size = output_size or input_size if self.input_size != self.output_size: self.resample = _TimeDistributedInterpolation(self.output_size, batch_first=True, trainable=False) if self.trainable_add: self.mask = nn.Parameter(torch.zeros(self.output_size, dtype= torch.float)) self.gate = nn.Sigmoid() self.norm = nn.LayerNorm(self.output_size) def forward(self, x: 'torch.Tensor') ->torch.Tensor: if self.input_size != self.output_size: x = self.resample(x) if self.trainable_add: x = x * self.gate(self.mask) * 2.0 output = self.norm(x) return output class _GatedResidualNetworkNew(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int', output_size: 'int', dropout: 'float'=0.1, context_size: 'int'=None, residual: 'bool'=False): super().__init__() self.input_size = input_size self.output_size = output_size self.context_size = context_size self.hidden_size = hidden_size self.dropout = dropout self.residual = residual if self.input_size != self.output_size and not self.residual: residual_size = self.input_size else: residual_size = self.output_size if self.output_size != residual_size: self.resample_norm = _ResampleNorm(residual_size, self.output_size) self.fc1 = nn.Linear(self.input_size, self.hidden_size) self.elu = nn.ELU() if self.context_size is not None: self.context = nn.Linear(self.context_size, self.hidden_size, bias=False) self.fc2 = nn.Linear(self.hidden_size, self.hidden_size) self.init_weights() self.gate_norm = _GateAddNorm(input_size=self.hidden_size, skip_size=self.output_size, hidden_size=self.output_size, dropout=self.dropout, trainable_add=False) def init_weights(self): for name, p in self.named_parameters(): if 'bias' in name: torch.nn.init.zeros_(p) elif 'fc1' in name or 'fc2' in name: torch.nn.init.kaiming_normal_(p, a=0, mode='fan_in', nonlinearity='leaky_relu') elif 'context' in name: torch.nn.init.xavier_uniform_(p) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.gate_norm.glu.fc.weight primals_7 = self.gate_norm.glu.fc.bias primals_8 = self.gate_norm.add_norm.norm.weight primals_9 = self.gate_norm.add_norm.norm.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
amadejkocbek/darts
_GatedResidualNetwork
false
12,112
[ "Apache-2.0" ]
0
074be2a76eee11258da066878c564badf40834e9
https://github.com/amadejkocbek/darts/tree/074be2a76eee11258da066878c564badf40834e9
SEModule
import torch from torchvision import datasets as datasets import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed class FastAvgPool2d(nn.Module): def __init__(self, flatten=False): super(FastAvgPool2d, self).__init__() self.flatten = flatten def forward(self, x): if self.flatten: in_size = x.size() return x.view((in_size[0], in_size[1], -1)).mean(dim=2) else: return x.view(x.size(0), x.size(1), -1).mean(-1).view(x.size(0), x.size(1), 1, 1) class SEModule(nn.Module): def __init__(self, channels, reduction_channels, inplace=True): super(SEModule, self).__init__() self.avg_pool = FastAvgPool2d() self.fc1 = nn.Conv2d(channels, reduction_channels, kernel_size=1, padding=0, bias=True) self.relu = nn.ReLU(inplace=inplace) self.fc2 = nn.Conv2d(reduction_channels, channels, kernel_size=1, padding=0, bias=True) self.activation = nn.Sigmoid() def forward(self, x): x_se = self.avg_pool(x) x_se2 = self.fc1(x_se) x_se2 = self.relu(x_se2) x_se = self.fc2(x_se2) x_se = self.activation(x_se) return x * x_se def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4, 'reduction_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torchvision import datasets as datasets import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 0, 0), 0), primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(16)](buf5, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf5, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf6, primals_1, primals_2, primals_4, reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0), buf3, buf5 class FastAvgPool2d(nn.Module): def __init__(self, flatten=False): super(FastAvgPool2d, self).__init__() self.flatten = flatten def forward(self, x): if self.flatten: in_size = x.size() return x.view((in_size[0], in_size[1], -1)).mean(dim=2) else: return x.view(x.size(0), x.size(1), -1).mean(-1).view(x.size(0), x.size(1), 1, 1) class SEModuleNew(nn.Module): def __init__(self, channels, reduction_channels, inplace=True): super(SEModuleNew, self).__init__() self.avg_pool = FastAvgPool2d() self.fc1 = nn.Conv2d(channels, reduction_channels, kernel_size=1, padding=0, bias=True) self.relu = nn.ReLU(inplace=inplace) self.fc2 = nn.Conv2d(reduction_channels, channels, kernel_size=1, padding=0, bias=True) self.activation = nn.Sigmoid() def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
adam-dziedzic/ASL
SEModule
false
12,113
[ "MIT" ]
0
cc063f5e7eda1498544ad2c3b224985203b0774a
https://github.com/adam-dziedzic/ASL/tree/cc063f5e7eda1498544ad2c3b224985203b0774a
PreActBlockNoBN
import torch import torch.nn as nn import torch.nn.functional as F class PreActBlockNoBN(nn.Module): """Pre-activation version of the BasicBlock.""" expansion = 1 def __init__(self, in_planes, planes, stride=1): super(PreActBlockNoBN, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride= stride, padding=1) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1) if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential(nn.Conv2d(in_planes, self. expansion * planes, kernel_size=1, stride=stride)) def forward(self, x): out = F.relu(x) shortcut = self.shortcut(out) if hasattr(self, 'shortcut') else x out = self.conv1(out) out = F.relu(out) out = self.conv2(out) out += shortcut return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_planes': 4, 'planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_add_convolution_2[grid(256)](buf4, primals_5, primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf4, primals_2, primals_4, buf0, buf2 class PreActBlockNoBNNew(nn.Module): """Pre-activation version of the BasicBlock.""" expansion = 1 def __init__(self, in_planes, planes, stride=1): super(PreActBlockNoBNNew, self).__init__() self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride= stride, padding=1) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1) if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential(nn.Conv2d(in_planes, self. expansion * planes, kernel_size=1, stride=stride)) 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]
arhik/LoCo
PreActBlockNoBN
false
12,114
[ "MIT" ]
0
de3792a8c5650ee1efa0682ad494a3b1b1be3dd0
https://github.com/arhik/LoCo/tree/de3792a8c5650ee1efa0682ad494a3b1b1be3dd0
up
import torch from torch import nn import torch.nn.functional as F class up(nn.Module): def __init__(self, in_ch, out_ch): super(up, self).__init__() self.up_scale = nn.ConvTranspose2d(in_ch, out_ch, 2, stride=2) def forward(self, x1, x2): x2 = self.up_scale(x2) diffY = x1.size()[2] - x2.size()[2] diffX = x1.size()[3] - x2.size()[3] x2 = F.pad(x2, [diffX // 2, diffX - diffX // 2, diffY // 2, diffY - diffY // 2]) x = torch.cat([x2, x1], dim=1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_ch': 4, 'out_ch': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 % 8 x1 = xindex // 4 % 4 x0 = xindex % 4 x3 = xindex // 128 x6 = xindex % 16 x7 = xindex tmp0 = x2 tmp1 = tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = 2 + x1 tmp6 = tmp5 >= tmp1 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp5 < tmp7 tmp9 = 2 + x0 tmp10 = tmp9 >= tmp1 tmp11 = tmp9 < tmp7 tmp12 = tmp6 & tmp8 tmp13 = tmp12 & tmp10 tmp14 = tmp13 & tmp11 tmp15 = tmp14 & tmp4 tmp16 = tl.load(in_ptr0 + (18 + x0 + 8 * x1 + 64 * x2 + 256 * x3), tmp15 & xmask, other=0.0) tmp17 = tl.load(in_ptr1 + x2, tmp15 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 + tmp17 tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp15, tmp18, tmp19) tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype) tmp22 = tl.where(tmp4, tmp20, tmp21) tmp23 = tmp0 >= tmp3 tmp25 = tl.load(in_ptr2 + (x6 + 16 * (-4 + x2) + 64 * x3), tmp23 & xmask, other=0.0) tmp26 = tl.where(tmp4, tmp22, tmp25) tl.store(out_ptr0 + x7, tmp26, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 2, 2), (16, 4, 2, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 8, 8), (256, 64, 8, 1)) buf1 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](buf0, primals_2, primals_4, buf1, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 del primals_4 return buf1, primals_1, primals_3 class upNew(nn.Module): def __init__(self, in_ch, out_ch): super(upNew, self).__init__() self.up_scale = nn.ConvTranspose2d(in_ch, out_ch, 2, stride=2) def forward(self, input_0, input_1): primals_1 = self.up_scale.weight primals_2 = self.up_scale.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
aribryan/segmentation_revisit
up
false
12,115
[ "MIT" ]
0
a37747cfa7bfa7bfd4c0c01983421f632cd719ba
https://github.com/aribryan/segmentation_revisit/tree/a37747cfa7bfa7bfd4c0c01983421f632cd719ba
ResnetBlock
import torch from torch import nn from torch.nn import functional as F import torch.utils.data import torch.utils.data.distributed def actvn(x): out = F.leaky_relu(x, 0.2) return out class ResnetBlock(nn.Module): def __init__(self, fin, fout, fhidden=None, is_bias=True): super().__init__() self.is_bias = is_bias self.learned_shortcut = fin != fout self.fin = fin self.fout = fout if fhidden is None: self.fhidden = min(fin, fout) else: self.fhidden = fhidden self.conv_0 = nn.Conv2d(self.fin, self.fhidden, 3, stride=1, padding=1) self.conv_1 = nn.Conv2d(self.fhidden, self.fout, 3, stride=1, padding=1, bias=is_bias) if self.learned_shortcut: self.conv_s = nn.Conv2d(self.fin, self.fout, 1, stride=1, padding=0, bias=False) def forward(self, x): x_s = self._shortcut(x) dx = self.conv_0(actvn(x)) dx = self.conv_1(actvn(dx)) out = x_s + 0.1 * dx return out def _shortcut(self, x): if self.learned_shortcut: x_s = self.conv_s(x) else: x_s = x return x_s 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 import nn from torch.nn import functional as F import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) @triton.jit def triton_poi_fused_add_convolution_mul_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 = 0.1 tmp5 = tmp3 * tmp4 tmp6 = tmp0 + tmp5 tl.store(in_out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf1, primals_3, buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_add_convolution_mul_2[grid(256)](buf5, primals_1, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf5, primals_2, primals_4, buf0, buf2, buf3 def actvn(x): out = F.leaky_relu(x, 0.2) return out class ResnetBlockNew(nn.Module): def __init__(self, fin, fout, fhidden=None, is_bias=True): super().__init__() self.is_bias = is_bias self.learned_shortcut = fin != fout self.fin = fin self.fout = fout if fhidden is None: self.fhidden = min(fin, fout) else: self.fhidden = fhidden self.conv_0 = nn.Conv2d(self.fin, self.fhidden, 3, stride=1, padding=1) self.conv_1 = nn.Conv2d(self.fhidden, self.fout, 3, stride=1, padding=1, bias=is_bias) if self.learned_shortcut: self.conv_s = nn.Conv2d(self.fin, self.fout, 1, stride=1, padding=0, bias=False) def _shortcut(self, x): if self.learned_shortcut: x_s = self.conv_s(x) else: x_s = x return x_s def forward(self, input_0): primals_2 = self.conv_0.weight primals_3 = self.conv_0.bias primals_4 = self.conv_1.weight primals_5 = self.conv_1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
arnabgho/GAN_stability
ResnetBlock
false
12,116
[ "MIT" ]
0
5037d1d856be58818d1c825cd415e0d90d90aff2
https://github.com/arnabgho/GAN_stability/tree/5037d1d856be58818d1c825cd415e0d90d90aff2
ContrastiveDistanceLoss
import torch import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastiveDistanceLoss(nn.Module): """ Contrastive distance loss """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveDistanceLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, distance_pred, distance_true): """ Forward propagation method for the contrastive loss. Args: distance_pred: predicted distances distance_true: true distances Returns: loss """ bs = len(distance_true) margin_distance = self.margin - distance_pred margin_distance_ = torch.clamp(margin_distance, min=0.0) loss = (1 - distance_true) * torch.pow(distance_pred, 2 ) + distance_true * torch.pow(margin_distance_, 2) if self.reduction == 'mean': loss = torch.sum(loss) / 2.0 / bs elif self.reduction == 'sum': loss = torch.sum(loss) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_clamp_div_mul_pow_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp3 * tmp3 tmp5 = tmp2 * tmp4 tmp6 = tmp1 - tmp3 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8 * tmp8 tmp10 = tmp0 * tmp9 tmp11 = tmp5 + tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = 0.25 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_clamp_div_mul_pow_rsub_sum_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class ContrastiveDistanceLossNew(nn.Module): """ Contrastive distance loss """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveDistanceLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
asmekal/catalyst
ContrastiveDistanceLoss
false
12,117
[ "MIT" ]
0
e11365c0a9812649ceaef14e53061cd5117d8684
https://github.com/asmekal/catalyst/tree/e11365c0a9812649ceaef14e53061cd5117d8684
ContrastivePairwiseEmbeddingLoss
import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastivePairwiseEmbeddingLoss(nn.Module): """ ContrastivePairwiseEmbeddingLoss – proof of concept criterion. Still work in progress. """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastivePairwiseEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, embeddings_pred, embeddings_true): """ Work in progress. Args: embeddings_pred: predicted embeddings embeddings_true: true embeddings Returns: loss """ device = embeddings_pred.device pairwise_similarity = torch.einsum('se,ae->sa', embeddings_pred, embeddings_true) bs = embeddings_pred.shape[0] batch_idx = torch.arange(bs, device=device) loss = F.cross_entropy(pairwise_similarity, batch_idx, reduction= self.reduction) return loss def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_per_fused_arange_nll_loss_forward_1(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp6 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp0 = r0 tmp1 = tl.full([1, 1], -100, tl.int64) tmp2 = tmp0 != tmp1 tmp3 = tl.full([1, 1], 0, tl.int64) tmp4 = tl.where(tmp2, tmp0, tmp3) tmp5 = tl.load(in_ptr0 + (tmp4 + 4 * r0), None, eviction_policy= 'evict_last') tmp7 = tl_math.exp(tmp6) tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp12 = tl_math.exp(tmp11) tmp13 = tmp10 + tmp12 tmp15 = tl_math.exp(tmp14) tmp16 = tmp13 + tmp15 tmp17 = tl_math.log(tmp16) tmp18 = tmp5 - tmp17 tmp19 = -tmp18 tmp20 = 0.0 tmp21 = tl.where(tmp2, tmp19, tmp20) tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp24 = tl.sum(tmp22, 1)[:, None] tmp25 = tmp2.to(tl.int64) tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK]) tmp28 = tl.sum(tmp26, 1)[:, None] tmp29 = tmp28.to(tl.float32) tmp30 = tmp24 / tmp29 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp30, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (1, 4, 4), (16, 4, 1), 0), reinterpret_tensor(arg1_1, (1, 4, 4), (0, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 buf2 = empty_strided_cuda((), (), torch.float32) buf4 = buf2 del buf2 triton_per_fused_arange_nll_loss_forward_1[grid(1)](buf4, buf1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf1 return buf4, class ContrastivePairwiseEmbeddingLossNew(nn.Module): """ ContrastivePairwiseEmbeddingLoss – proof of concept criterion. Still work in progress. """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastivePairwiseEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
asmekal/catalyst
ContrastivePairwiseEmbeddingLoss
false
12,118
[ "MIT" ]
0
e11365c0a9812649ceaef14e53061cd5117d8684
https://github.com/asmekal/catalyst/tree/e11365c0a9812649ceaef14e53061cd5117d8684
BasicBlock
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.utils.weight_norm as weightNorm def conv3x3(in_planes, out_planes, stride=1): return weightNorm(nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)) class TReLU(nn.Module): def __init__(self): super(TReLU, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, x): x = F.relu(x - self.alpha) + self.alpha return x class BasicBlock(nn.Module): expansion = 1 def __init__(self, in_planes, planes, stride=1): super(BasicBlock, self).__init__() self.conv1 = conv3x3(in_planes, planes, stride) self.conv2 = conv3x3(planes, planes) self.shortcut = nn.Sequential() if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential(weightNorm(nn.Conv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias =True))) self.relu_1 = TReLU() self.relu_2 = TReLU() def forward(self, x): out = self.relu_1(self.conv1(x)) out = self.conv2(out) out += self.shortcut(x) out = self.relu_2(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_planes': 4, 'planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F import torch.nn.utils.weight_norm as weightNorm 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__weight_norm_interface_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 rnumel = 36 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 r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 36 * x0), rmask & xmask, other=0.0) tmp7 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(rmask & xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = libdevice.sqrt(tmp5) tmp8 = tmp7 / tmp6 tmp9 = tmp0 * tmp8 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) tl.store(out_ptr0 + (r1 + 36 * x0), tmp9, rmask & xmask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 - tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = tmp7 + tmp4 tmp9 = 0.0 tmp10 = tmp7 <= tmp9 tl.store(out_ptr0 + x3, tmp8, xmask) tl.store(out_ptr1 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x3, xmask) tmp5 = tl.load(in_ptr3 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp7 = tmp4 - tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tmp9 + tmp6 tmp11 = 0.0 tmp12 = tmp9 <= tmp11 tl.store(out_ptr0 + x3, tmp10, xmask) tl.store(out_ptr1 + x3, tmp12, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 1, 1, 1), (1, 1, 1, 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, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_7, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf0 buf2 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32) get_raw_stream(0) triton_per_fused__weight_norm_interface_0[grid(4)](buf1, primals_2, primals_1, buf2, 4, 36, XBLOCK=1, num_warps=2, num_stages=1) buf3 = extern_kernels.convolution(primals_4, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_1[grid (256)](buf3, primals_3, primals_5, buf4, buf11, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 del primals_5 buf5 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf6 = reinterpret_tensor(buf5, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf5 buf7 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32) triton_per_fused__weight_norm_interface_0[grid(4)](buf6, primals_7, primals_6, buf7, 4, 36, XBLOCK=1, num_warps=2, num_stages=1) buf8 = extern_kernels.convolution(buf4, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 4, 4, 4), (64, 16, 4, 1)) buf9 = buf3 del buf3 buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_2[grid (256)](buf8, primals_8, primals_4, primals_9, buf9, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf8 del primals_8 del primals_9 return (buf9, buf2, buf7, primals_1, primals_2, primals_4, primals_6, primals_7, buf1, buf2, buf4, buf6, buf7, buf10, buf11) def conv3x3(in_planes, out_planes, stride=1): return weightNorm(nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)) class TReLU(nn.Module): def __init__(self): super(TReLU, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, x): x = F.relu(x - self.alpha) + self.alpha return x class BasicBlockNew(nn.Module): expansion = 1 def __init__(self, in_planes, planes, stride=1): super(BasicBlockNew, self).__init__() self.conv1 = conv3x3(in_planes, planes, stride) self.conv2 = conv3x3(planes, planes) self.shortcut = nn.Sequential() if stride != 1 or in_planes != self.expansion * planes: self.shortcut = nn.Sequential(weightNorm(nn.Conv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias =True))) self.relu_1 = TReLU() self.relu_2 = TReLU() def forward(self, input_0): primals_3 = self.conv1.bias primals_1 = self.conv1.weight_g primals_2 = self.conv1.weight_v primals_8 = self.conv2.bias primals_6 = self.conv2.weight_g primals_7 = self.conv2.weight_v primals_5 = self.relu_1.alpha primals_9 = self.relu_2.alpha primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
archiroid003/ICCV2019-LearningToPaint
BasicBlock
false
12,119
[ "MIT" ]
0
4b5fc263e4843c159a61e5956956b3f7812693f8
https://github.com/archiroid003/ICCV2019-LearningToPaint/tree/4b5fc263e4843c159a61e5956956b3f7812693f8
DecoderBlock
import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ConvRelu(nn.Module): """3x3 convolution followed by ReLU activation building block. """ def __init__(self, num_in, num_out): """Creates a `ConvReLU` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1, bias=False) def forward(self, x): """ The networks forward pass for which autograd synthesizes the backwards pass. Args: x: the input tensor Returns: The networks output tensor. """ return F.relu(self.block(x), inplace=True) class DecoderBlock(nn.Module): """Decoder building block upsampling resolution by a factor of two. """ def __init__(self, num_in, num_out): """Creates a `DecoderBlock` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = ConvRelu(num_in, num_out) def forward(self, x): """ The networks forward pass for which autograd synthesizes the backwards pass. Args: x: the input tensor Returns: The networks output tensor. """ return self.block(F.interpolate(x, scale_factor=2, mode='nearest')) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in': 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 import torch.nn.functional as F from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.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__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_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 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 = 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = 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, 8, 8), (256, 64, 8, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(1024)](buf2, buf3, 1024, XBLOCK=256, num_warps=4, num_stages=1) return buf2, primals_2, buf0, buf3 class ConvRelu(nn.Module): """3x3 convolution followed by ReLU activation building block. """ def __init__(self, num_in, num_out): """Creates a `ConvReLU` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1, bias=False) def forward(self, x): """ The networks forward pass for which autograd synthesizes the backwards pass. Args: x: the input tensor Returns: The networks output tensor. """ return F.relu(self.block(x), inplace=True) class DecoderBlockNew(nn.Module): """Decoder building block upsampling resolution by a factor of two. """ def __init__(self, num_in, num_out): """Creates a `DecoderBlock` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = ConvRelu(num_in, num_out) def forward(self, input_0): primals_2 = self.block.block.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
asmekal/catalyst
DecoderBlock
false
12,120
[ "MIT" ]
0
e11365c0a9812649ceaef14e53061cd5117d8684
https://github.com/asmekal/catalyst/tree/e11365c0a9812649ceaef14e53061cd5117d8684
Actor
import torch import numpy as np import torch.nn.functional as F import torch.nn as nn def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class Actor(nn.Module): def __init__(self, state_size, action_size, seed, fc1_units=512, fc2_units=256): super(Actor, self).__init__() self.seed = torch.manual_seed(seed) self.fc1 = nn.Linear(state_size, fc1_units) self.fc2 = nn.Linear(fc1_units, fc2_units) self.fc3 = nn.Linear(fc2_units, action_size) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, state): x = F.relu(self.fc1(state)) x = F.relu(self.fc2(x)) return F.tanh(self.fc3(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4, 'seed': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_tanh_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, (512, 4), (4, 1)) assert_size_stride(primals_2, (512,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 512), (512, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (4, 256), (256, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 512), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 512), (8192, 2048, 512, 1), 0 ) del buf0 buf7 = empty_strided_cuda((4, 4, 4, 512), (8192, 2048, 512, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(32768)](buf1, primals_2, buf7, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 512), (512, 1), 0), reinterpret_tensor(primals_4, (512, 256), (1, 512), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf2 buf6 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(16384)](buf3, primals_5, buf6, 16384, 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, 256), (256, 1), 0), reinterpret_tensor(primals_6, (256, 4), (1, 256), 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 ), reinterpret_tensor(buf1, (64, 512), (512, 1), 0 ), reinterpret_tensor(buf3, (64, 256), (256, 1), 0 ), buf5, primals_6, buf6, primals_4, buf7 def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class ActorNew(nn.Module): def __init__(self, state_size, action_size, seed, fc1_units=512, fc2_units=256): super(ActorNew, self).__init__() self.seed = torch.manual_seed(seed) self.fc1 = nn.Linear(state_size, fc1_units) self.fc2 = nn.Linear(fc1_units, fc2_units) self.fc3 = nn.Linear(fc2_units, action_size) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
asiliskender/deep-reinforcement-learning
Actor
false
12,121
[ "MIT" ]
0
dbf96d67477aa9242128b78b081474193e1e4538
https://github.com/asiliskender/deep-reinforcement-learning/tree/dbf96d67477aa9242128b78b081474193e1e4538
ConvRelu
import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ConvRelu(nn.Module): """3x3 convolution followed by ReLU activation building block. """ def __init__(self, num_in, num_out): """Creates a `ConvReLU` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1, bias=False) def forward(self, x): """ The networks forward pass for which autograd synthesizes the backwards pass. Args: x: the input tensor Returns: The networks output tensor. """ return F.relu(self.block(x), inplace=True) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in': 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 from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.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_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 = 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)) 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 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, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf1, primals_1, primals_2, buf2 class ConvReluNew(nn.Module): """3x3 convolution followed by ReLU activation building block. """ def __init__(self, num_in, num_out): """Creates a `ConvReLU` building block. Args: num_in: number of input feature maps num_out: number of output feature maps """ super().__init__() self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1, bias=False) def forward(self, input_0): primals_1 = self.block.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
asmekal/catalyst
ConvRelu
false
12,122
[ "MIT" ]
0
e11365c0a9812649ceaef14e53061cd5117d8684
https://github.com/asmekal/catalyst/tree/e11365c0a9812649ceaef14e53061cd5117d8684
ContrastiveEmbeddingLoss
import torch import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastiveEmbeddingLoss(nn.Module): """ Contrastive embedding loss paper: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, embeddings_left, embeddings_right, distance_true): """ Forward propagation method for the contrastive loss. Args: embeddings_left: left objects embeddings embeddings_right: right objects embeddings distance_true: true distances Returns: loss """ diff = embeddings_left - embeddings_right distance_pred = torch.sqrt(torch.sum(torch.pow(diff, 2), 1)) bs = len(distance_true) margin_distance = self.margin - distance_pred margin_distance_ = torch.clamp(margin_distance, min=0.0) loss = (1 - distance_true) * torch.pow(distance_pred, 2 ) + distance_true * torch.pow(margin_distance_, 2) if self.reduction == 'mean': loss = torch.sum(loss) / 2.0 / bs elif self.reduction == 'sum': loss = torch.sum(loss) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.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_pow_sqrt_sub_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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask) tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask) tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask) tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp16 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = libdevice.sqrt(tmp18) tl.store(out_ptr0 + x2, tmp19, xmask) @triton.jit def triton_per_fused_add_clamp_div_mul_pow_rsub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex r0 = rindex % 64 tmp0 = tl.load(in_ptr0 + r2, None) tmp3 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp3 * tmp3 tmp5 = tmp2 * tmp4 tmp6 = tmp1 - tmp3 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8 * tmp8 tmp10 = tmp0 * tmp9 tmp11 = tmp5 + tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = 0.25 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1, 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), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_pow_sqrt_sub_sum_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_add_clamp_div_mul_pow_rsub_sum_1[grid(1)](buf2, arg2_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg2_1 del buf0 return buf2, class ContrastiveEmbeddingLossNew(nn.Module): """ Contrastive embedding loss paper: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' 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]
asmekal/catalyst
ContrastiveEmbeddingLoss
false
12,123
[ "MIT" ]
0
e11365c0a9812649ceaef14e53061cd5117d8684
https://github.com/asmekal/catalyst/tree/e11365c0a9812649ceaef14e53061cd5117d8684
SingleHiddenLayer
import torch class SingleHiddenLayer(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(SingleHiddenLayer, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, z): z = self.linear1(z) z = torch.relu(z) z = self.linear2(z) z = z.view(*z.shape[:-1], self.hidden_channels, self.input_channels) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (128, 4), (4, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 128), (128, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1, primals_2, buf3, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 16), (1, 128), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 128), (128, 1), 0), primals_4, buf3 class SingleHiddenLayerNew(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(SingleHiddenLayerNew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
athon-millane/NeuralCDE
SingleHiddenLayer
false
12,124
[ "Apache-2.0" ]
0
4196890fe5bf7a69925a12ff35e86f212963be71
https://github.com/athon-millane/NeuralCDE/tree/4196890fe5bf7a69925a12ff35e86f212963be71
FinalTanh
import torch class FinalTanh(torch.nn.Module): def __init__(self, input_channels, hidden_channels, hidden_hidden_channels, num_hidden_layers): super(FinalTanh, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.hidden_hidden_channels = hidden_hidden_channels self.num_hidden_layers = num_hidden_layers self.linear_in = torch.nn.Linear(hidden_channels, hidden_hidden_channels) self.linears = torch.nn.ModuleList(torch.nn.Linear( hidden_hidden_channels, hidden_hidden_channels) for _ in range( num_hidden_layers - 1)) self.linear_out = torch.nn.Linear(hidden_hidden_channels, input_channels * hidden_channels) def extra_repr(self): return ( 'input_channels: {}, hidden_channels: {}, hidden_hidden_channels: {}, num_hidden_layers: {}' .format(self.input_channels, self.hidden_channels, self. hidden_hidden_channels, self.num_hidden_layers)) def forward(self, z): z = self.linear_in(z) z = z.relu() for linear in self.linears: z = linear(z) z = z.relu() z = self.linear_out(z).view(*z.shape[:-1], self.hidden_channels, self.input_channels) z = z.tanh() return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4, 'hidden_hidden_channels': 4, 'num_hidden_layers': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 4), (4, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_2, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 16), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ) del buf2 triton_poi_fused_tanh_1[grid(1024)](buf3, primals_5, 1024, XBLOCK= 256, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), buf3, primals_4, buf4 class FinalTanhNew(torch.nn.Module): def __init__(self, input_channels, hidden_channels, hidden_hidden_channels, num_hidden_layers): super(FinalTanhNew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.hidden_hidden_channels = hidden_hidden_channels self.num_hidden_layers = num_hidden_layers self.linear_in = torch.nn.Linear(hidden_channels, hidden_hidden_channels) self.linears = torch.nn.ModuleList(torch.nn.Linear( hidden_hidden_channels, hidden_hidden_channels) for _ in range( num_hidden_layers - 1)) self.linear_out = torch.nn.Linear(hidden_hidden_channels, input_channels * hidden_channels) def extra_repr(self): return ( 'input_channels: {}, hidden_channels: {}, hidden_hidden_channels: {}, num_hidden_layers: {}' .format(self.input_channels, self.hidden_channels, self. hidden_hidden_channels, self.num_hidden_layers)) def forward(self, input_0): primals_1 = self.linear_in.weight primals_2 = self.linear_in.bias primals_4 = self.linear_out.weight primals_5 = self.linear_out.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
athon-millane/NeuralCDE
FinalTanh
false
12,125
[ "Apache-2.0" ]
0
4196890fe5bf7a69925a12ff35e86f212963be71
https://github.com/athon-millane/NeuralCDE/tree/4196890fe5bf7a69925a12ff35e86f212963be71
_GRU_ODE
import torch class _GRU_ODE(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(_GRU_ODE, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.W_r = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_z = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_h = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.U_r = torch.nn.Linear(hidden_channels, hidden_channels) self.U_z = torch.nn.Linear(hidden_channels, hidden_channels) self.U_h = torch.nn.Linear(hidden_channels, hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, x, h): r = self.W_r(x) + self.U_r(h) r = r.sigmoid() z = self.W_z(x) + self.U_z(h) z = z.sigmoid() g = self.W_h(x) + self.U_h(r * h) g = g.tanh() return (1 - z) * (g - h) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_sigmoid_sigmoid_backward_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x2, xmask) tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp5 = tl.sigmoid(tmp4) tmp7 = tmp5 * tmp6 tmp8 = 1.0 tmp9 = tmp8 - tmp5 tmp10 = tmp5 * tmp9 tl.store(out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr1 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_sigmoid_sub_tanh_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr1 + x2, xmask) tmp7 = tl.load(in_ptr2 + x2, xmask) tmp8 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x2, xmask) tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp5 = tl.sigmoid(tmp4) tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp11 = libdevice.tanh(tmp10) tmp12 = 1.0 tmp13 = tmp12 - tmp5 tmp15 = tmp11 - tmp14 tmp16 = tmp13 * tmp15 tl.store(in_out_ptr0 + x2, tmp5, xmask) tl.store(in_out_ptr1 + x2, tmp11, xmask) tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4, 4), (4, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) del primals_6 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf3) del primals_7 buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf5) del primals_9 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sigmoid_sigmoid_backward_0[grid(256)](buf0, buf1, primals_4, primals_5, buf6, buf10, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_4 buf7 = buf1 del buf1 extern_kernels.mm(reinterpret_tensor(buf6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf7) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf8 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 buf9 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused_add_mul_rsub_sigmoid_sub_tanh_1[grid(256)](buf4, buf8, buf3, primals_8, buf7, primals_11, primals_5, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del buf7 del primals_11 del primals_8 return buf9, primals_5, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), buf4, reinterpret_tensor(buf6, (64, 4), (4, 1), 0 ), buf8, primals_10, buf10 class _GRU_ODENew(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(_GRU_ODENew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.W_r = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_z = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.W_h = torch.nn.Linear(input_channels, hidden_channels, bias=False) self.U_r = torch.nn.Linear(hidden_channels, hidden_channels) self.U_z = torch.nn.Linear(hidden_channels, hidden_channels) self.U_h = torch.nn.Linear(hidden_channels, hidden_channels) def extra_repr(self): return 'input_channels: {}, hidden_channels: {}'.format(self. input_channels, self.hidden_channels) def forward(self, input_0, input_1): primals_1 = self.W_r.weight primals_3 = self.W_z.weight primals_6 = self.W_h.weight primals_7 = self.U_r.weight primals_4 = self.U_r.bias primals_9 = self.U_z.weight primals_8 = self.U_z.bias primals_10 = self.U_h.weight primals_11 = self.U_h.bias primals_2 = input_0 primals_5 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
athon-millane/NeuralCDE
_GRU_ODE
false
12,126
[ "Apache-2.0" ]
0
4196890fe5bf7a69925a12ff35e86f212963be71
https://github.com/athon-millane/NeuralCDE/tree/4196890fe5bf7a69925a12ff35e86f212963be71
CDEFunc
import torch class CDEFunc(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(CDEFunc, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) self.l1 = None self.l2 = None def forward(self, z): z = self.linear1(z) self.l1 = z z = z.relu() z = self.linear2(z) z = z.tanh() self.l2 = z z = z.view(*z.shape[:-1], self.hidden_channels, self.input_channels) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'hidden_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_ptr0 + x0, None) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(out_ptr0 + x0, tmp2, None) tl.store(out_ptr1 + x0, tmp4, None) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (128, 4), (4, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 128), (128, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf0, buf1, buf4, 8192, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 16), (1, 128), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf2 triton_poi_fused_tanh_1[grid(1024)](buf3, primals_5, 1024, XBLOCK= 256, num_warps=4, num_stages=1) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ), buf3, reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 128), (128, 1), 0 ), buf3, primals_4, buf4 class CDEFuncNew(torch.nn.Module): def __init__(self, input_channels, hidden_channels): super(CDEFuncNew, self).__init__() self.input_channels = input_channels self.hidden_channels = hidden_channels self.linear1 = torch.nn.Linear(hidden_channels, 128) self.linear2 = torch.nn.Linear(128, input_channels * hidden_channels) self.l1 = None self.l2 = None def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
athon-millane/NeuralCDE
CDEFunc
false
12,127
[ "Apache-2.0" ]
0
4196890fe5bf7a69925a12ff35e86f212963be71
https://github.com/athon-millane/NeuralCDE/tree/4196890fe5bf7a69925a12ff35e86f212963be71
Critic
import torch import numpy as np import torch.nn.functional as F import torch.nn as nn def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class Critic(nn.Module): """Critic (Value) Model.""" def __init__(self, state_size, action_size, seed, fcs1_units=400, fc2_units=300, num_atoms=51, vmin=-1, vmax=1): """Initialize parameters and build model. Params ====== state_size (int): Dimension of each state action_size (int): Dimension of each action seed (int): Random seed fcs1_units (int): Number of nodes in the first hidden layer fc2_units (int): Number of nodes in the second hidden layer """ super(Critic, self).__init__() self.seed = torch.manual_seed(seed) self.fcs1 = nn.Linear(state_size, fcs1_units) self.fc2 = nn.Linear(fcs1_units + action_size, fc2_units) self.fc3 = nn.Linear(fc2_units, num_atoms) delta = (vmax - vmin) / (num_atoms - 1) self.register_buffer('supports', torch.arange(vmin, vmax + delta, delta)) self.reset_parameters() def reset_parameters(self): self.fcs1.weight.data.uniform_(*hidden_init(self.fcs1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, state, action): """Build a critic (value) network that maps (state, action) pairs -> Q-values.""" xs = F.leaky_relu(self.fcs1(state)) x = torch.cat((xs, action), dim=1) x = F.leaky_relu(self.fc2(x)) return self.fc3(x) def distr_to_q(self, distr): weights = F.softmax(distr, dim=1) * self.supports res = weights.sum(dim=1) return res.unsqueeze(dim=-1) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4, 'seed': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import numpy as np import torch.nn.functional as F import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 400 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1616 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 404 x1 = xindex // 404 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 400, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (400 * x1 + x0), tmp4 & xmask, eviction_policy ='evict_last', other=0.0).to(tl.int1) tmp6 = tl.load(in_ptr1 + (400 * x1 + x0), tmp4 & xmask, eviction_policy ='evict_last', other=0.0) tmp7 = tl.load(in_ptr2 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 + tmp7 tmp9 = 0.01 tmp10 = tmp8 * tmp9 tmp11 = tl.where(tmp5, tmp8, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 404, tl.int64) tmp17 = tl.load(in_ptr3 + (4 * x1 + (-400 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tl.where(tmp4, tmp13, tmp17) tl.store(out_ptr0 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 300 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (400, 4), (4, 1)) assert_size_stride(primals_2, (400,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (300, 404), (404, 1)) assert_size_stride(primals_6, (300,), (1,)) assert_size_stride(primals_7, (51, 300), (300, 1)) assert_size_stride(primals_8, (51,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 400), (400, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 400), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 400), (400, 1), torch.bool) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(1600)](buf0, primals_2, buf1, 1600, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((4, 404), (404, 1), torch.float32) triton_poi_fused_cat_1[grid(1616)](buf1, buf0, primals_2, primals_4, buf2, 1616, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 del primals_4 buf3 = empty_strided_cuda((4, 300), (300, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (404, 300), ( 1, 404), 0), out=buf3) buf4 = empty_strided_cuda((4, 300), (300, 1), torch.bool) buf5 = empty_strided_cuda((4, 300), (300, 1), torch.float32) triton_poi_fused_leaky_relu_2[grid(1200)](buf3, primals_6, buf4, buf5, 1200, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del primals_6 buf6 = empty_strided_cuda((4, 51), (51, 1), torch.float32) extern_kernels.addmm(primals_8, buf5, reinterpret_tensor(primals_7, (300, 51), (1, 300), 0), alpha=1, beta=1, out=buf6) del primals_8 return buf6, primals_3, buf1, buf2, buf4, buf5, primals_7, primals_5 def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class CriticNew(nn.Module): """Critic (Value) Model.""" def __init__(self, state_size, action_size, seed, fcs1_units=400, fc2_units=300, num_atoms=51, vmin=-1, vmax=1): """Initialize parameters and build model. Params ====== state_size (int): Dimension of each state action_size (int): Dimension of each action seed (int): Random seed fcs1_units (int): Number of nodes in the first hidden layer fc2_units (int): Number of nodes in the second hidden layer """ super(CriticNew, self).__init__() self.seed = torch.manual_seed(seed) self.fcs1 = nn.Linear(state_size, fcs1_units) self.fc2 = nn.Linear(fcs1_units + action_size, fc2_units) self.fc3 = nn.Linear(fc2_units, num_atoms) delta = (vmax - vmin) / (num_atoms - 1) self.register_buffer('supports', torch.arange(vmin, vmax + delta, delta)) self.reset_parameters() def reset_parameters(self): self.fcs1.weight.data.uniform_(*hidden_init(self.fcs1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def distr_to_q(self, distr): weights = F.softmax(distr, dim=1) * self.supports res = weights.sum(dim=1) return res.unsqueeze(dim=-1) def forward(self, input_0, input_1): primals_1 = self.fcs1.weight primals_2 = self.fcs1.bias primals_5 = self.fc2.weight primals_6 = self.fc2.bias primals_7 = self.fc3.weight primals_8 = self.fc3.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
arpradha/deep-reinforcement-learning
Critic
false
12,128
[ "MIT" ]
0
01cfc7ab19453285886900d9c6332c8cb435df51
https://github.com/arpradha/deep-reinforcement-learning/tree/01cfc7ab19453285886900d9c6332c8cb435df51
SilogLoss
import torch import torch.nn as nn class SilogLoss(nn.Module): def __init__(self, ratio=10, ratio2=0.85): super().__init__() self.ratio = ratio self.ratio2 = ratio2 def forward(self, pred, gt): log_diff = torch.log(pred * self.ratio) - torch.log(gt * self.ratio) silog1 = torch.mean(log_diff ** 2) silog2 = self.ratio2 * log_diff.mean() ** 2 silog_loss = torch.sqrt(silog1 - silog2) * self.ratio return silog_loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_log_mean_mul_pow_sqrt_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) tmp4 = tl.load(in_ptr1 + r0, None) tmp1 = 10.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.log(tmp2) tmp5 = tmp4 * tmp1 tmp6 = tl_math.log(tmp5) tmp7 = tmp3 - tmp6 tmp8 = tmp7 * tmp7 tmp9 = tl.broadcast_to(tmp8, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = tl.broadcast_to(tmp7, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 256.0 tmp16 = tmp11 / tmp15 tmp17 = tmp14 / tmp15 tmp18 = tmp17 * tmp17 tmp19 = 0.85 tmp20 = tmp18 * tmp19 tmp21 = tmp16 - tmp20 tmp22 = libdevice.sqrt(tmp21) tmp23 = tmp22 * tmp1 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp23, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_log_mean_mul_pow_sqrt_sub_0[grid(1)](buf2, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class SilogLossNew(nn.Module): def __init__(self, ratio=10, ratio2=0.85): super().__init__() self.ratio = ratio self.ratio2 = ratio2 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
aycatakmaz/packnet-sfm
SilogLoss
false
12,130
[ "MIT" ]
0
d89cae81290133f136f6a1d1e288affc67eed1f7
https://github.com/aycatakmaz/packnet-sfm/tree/d89cae81290133f136f6a1d1e288affc67eed1f7
MatrixTree
import torch import torch.nn as nn import torch.cuda import torch.distributed class MatrixTree(nn.Module): """Implementation of the matrix-tree theorem for computing marginals of non-projective dependency parsing. This attention layer is used in the paper "Learning Structured Text Representations" :cite:`DBLP:journals/corr/LiuL17d`. """ def __init__(self, eps=1e-05): self.eps = eps super(MatrixTree, self).__init__() def forward(self, input): laplacian = input.exp() + self.eps output = input.clone() for b in range(input.size(0)): lap = laplacian[b].masked_fill(torch.eye(input.size(1), device= input.device).ne(0), 0) lap = -lap + torch.diag(lap.sum(0)) lap[0] = input[b].diag().exp() inv_laplacian = lap.inverse() factor = inv_laplacian.diag().unsqueeze(1).expand_as(input[b] ).transpose(0, 1) term1 = input[b].exp().mul(factor).clone() term2 = input[b].exp().mul(inv_laplacian.transpose(0, 1)).clone() term1[:, 0] = 0 term2[0] = 0 output[b] = term1 - term2 roots_output = input[b].diag().exp().mul(inv_laplacian. transpose(0, 1)[0]) output[b] = output[b] + torch.diag(roots_output) return output def get_inputs(): return [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.triton_helpers import math as tl_math import torch.nn as nn import torch.cuda import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_eye_masked_fill_ne_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp7 = tl.load(in_ptr0 + x0, xmask) tmp16 = tl.load(in_ptr0 + (4 + x0), xmask) tmp25 = tl.load(in_ptr0 + (8 + x0), xmask) tmp34 = tl.load(in_ptr0 + (12 + x0), xmask) tmp0 = tl.full([1], 0, tl.int64) tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = tmp5 != tmp4 tmp8 = tl_math.exp(tmp7) tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = tl.where(tmp6, tmp4, tmp10) tmp12 = tl.full([1], 1, tl.int64) tmp13 = tmp12 == tmp1 tmp14 = tl.where(tmp13, tmp3, tmp4) tmp15 = tmp14 != tmp4 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 + tmp9 tmp19 = tl.where(tmp15, tmp4, tmp18) tmp20 = tmp11 + tmp19 tmp21 = tl.full([1], 2, tl.int64) tmp22 = tmp21 == tmp1 tmp23 = tl.where(tmp22, tmp3, tmp4) tmp24 = tmp23 != tmp4 tmp26 = tl_math.exp(tmp25) tmp27 = tmp26 + tmp9 tmp28 = tl.where(tmp24, tmp4, tmp27) tmp29 = tmp20 + tmp28 tmp30 = tl.full([1], 3, tl.int64) tmp31 = tmp30 == tmp1 tmp32 = tl.where(tmp31, tmp3, tmp4) tmp33 = tmp32 != tmp4 tmp35 = tl_math.exp(tmp34) tmp36 = tmp35 + tmp9 tmp37 = tl.where(tmp33, tmp4, tmp36) tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_1( in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + 5 * x0, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + x2, xmask) tmp18 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl_math.exp(tmp3) tmp5 = x0 tmp6 = tmp0 == tmp5 tmp7 = 1.0 tmp8 = 0.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = tmp9 != tmp8 tmp12 = tl_math.exp(tmp11) tmp13 = 1e-05 tmp14 = tmp12 + tmp13 tmp15 = tl.where(tmp10, tmp8, tmp14) tmp16 = -tmp15 tmp17 = tmp5 == tmp0 tmp19 = tl.where(tmp17, tmp18, tmp8) tmp20 = tmp16 + tmp19 tmp21 = tl.where(tmp2, tmp4, tmp20) tl.store(out_ptr0 + x2, tmp21, xmask) @triton.jit def triton_poi_fused_eye_masked_fill_ne_sum_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp7 = tl.load(in_ptr0 + (16 + x0), xmask) tmp16 = tl.load(in_ptr0 + (20 + x0), xmask) tmp25 = tl.load(in_ptr0 + (24 + x0), xmask) tmp34 = tl.load(in_ptr0 + (28 + x0), xmask) tmp0 = tl.full([1], 0, tl.int64) tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = tmp5 != tmp4 tmp8 = tl_math.exp(tmp7) tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = tl.where(tmp6, tmp4, tmp10) tmp12 = tl.full([1], 1, tl.int64) tmp13 = tmp12 == tmp1 tmp14 = tl.where(tmp13, tmp3, tmp4) tmp15 = tmp14 != tmp4 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 + tmp9 tmp19 = tl.where(tmp15, tmp4, tmp18) tmp20 = tmp11 + tmp19 tmp21 = tl.full([1], 2, tl.int64) tmp22 = tmp21 == tmp1 tmp23 = tl.where(tmp22, tmp3, tmp4) tmp24 = tmp23 != tmp4 tmp26 = tl_math.exp(tmp25) tmp27 = tmp26 + tmp9 tmp28 = tl.where(tmp24, tmp4, tmp27) tmp29 = tmp20 + tmp28 tmp30 = tl.full([1], 3, tl.int64) tmp31 = tmp30 == tmp1 tmp32 = tl.where(tmp31, tmp3, tmp4) tmp33 = tmp32 != tmp4 tmp35 = tl_math.exp(tmp34) tmp36 = tmp35 + tmp9 tmp37 = tl.where(tmp33, tmp4, tmp36) tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_3( in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (16 + 5 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (16 + x2), xmask) tmp18 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl_math.exp(tmp3) tmp5 = x0 tmp6 = tmp0 == tmp5 tmp7 = 1.0 tmp8 = 0.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = tmp9 != tmp8 tmp12 = tl_math.exp(tmp11) tmp13 = 1e-05 tmp14 = tmp12 + tmp13 tmp15 = tl.where(tmp10, tmp8, tmp14) tmp16 = -tmp15 tmp17 = tmp5 == tmp0 tmp19 = tl.where(tmp17, tmp18, tmp8) tmp20 = tmp16 + tmp19 tmp21 = tl.where(tmp2, tmp4, tmp20) tl.store(out_ptr0 + x2, tmp21, xmask) @triton.jit def triton_poi_fused_add_diag_embed_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp4 = tl.load(in_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr1 + 5 * x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + x2, xmask) tmp18 = tl.load(in_ptr0 + 5 * x0, xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = tl.full([1], 0, tl.int32) tmp1 = tmp0 == tmp0 tmp2 = x0 tmp3 = tmp2 == tmp0 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 * tmp6 tmp8 = 0.0 tmp9 = tl.where(tmp3, tmp8, tmp7) tmp10 = x1 tmp11 = tmp10 == tmp0 tmp13 = tmp5 * tmp12 tmp14 = tl.where(tmp11, tmp8, tmp13) tmp15 = tmp9 - tmp14 tmp16 = tl.where(tmp1, tmp15, tmp4) tmp17 = tmp2 == tmp10 tmp19 = tl_math.exp(tmp18) tmp21 = tmp19 * tmp20 tmp22 = tl.where(tmp17, tmp21, tmp8) tmp23 = tmp16 + tmp22 tl.store(out_ptr0 + x2, tmp23, xmask) @triton.jit def triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_5(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 x2 = xindex // 16 x3 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x5 = xindex tmp3 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr2 + 5 * x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr1 + x5, xmask) tmp0 = x2 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = x0 tmp5 = tmp4 == tmp1 tmp7 = tl_math.exp(tmp6) tmp9 = tmp7 * tmp8 tmp10 = 0.0 tmp11 = tl.where(tmp5, tmp10, tmp9) tmp12 = x1 tmp13 = tmp12 == tmp1 tmp15 = tmp7 * tmp14 tmp16 = tl.where(tmp13, tmp10, tmp15) tmp17 = tmp11 - tmp16 tmp19 = tl.where(tmp2, tmp17, tmp18) tmp20 = tl.where(tmp2, tmp3, tmp19) tl.store(out_ptr0 + x5, tmp20, xmask) @triton.jit def triton_poi_fused_eye_masked_fill_ne_sum_6(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 tmp7 = tl.load(in_ptr0 + (32 + x0), xmask) tmp16 = tl.load(in_ptr0 + (36 + x0), xmask) tmp25 = tl.load(in_ptr0 + (40 + x0), xmask) tmp34 = tl.load(in_ptr0 + (44 + x0), xmask) tmp0 = tl.full([1], 0, tl.int64) tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = tmp5 != tmp4 tmp8 = tl_math.exp(tmp7) tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = tl.where(tmp6, tmp4, tmp10) tmp12 = tl.full([1], 1, tl.int64) tmp13 = tmp12 == tmp1 tmp14 = tl.where(tmp13, tmp3, tmp4) tmp15 = tmp14 != tmp4 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 + tmp9 tmp19 = tl.where(tmp15, tmp4, tmp18) tmp20 = tmp11 + tmp19 tmp21 = tl.full([1], 2, tl.int64) tmp22 = tmp21 == tmp1 tmp23 = tl.where(tmp22, tmp3, tmp4) tmp24 = tmp23 != tmp4 tmp26 = tl_math.exp(tmp25) tmp27 = tmp26 + tmp9 tmp28 = tl.where(tmp24, tmp4, tmp27) tmp29 = tmp20 + tmp28 tmp30 = tl.full([1], 3, tl.int64) tmp31 = tmp30 == tmp1 tmp32 = tl.where(tmp31, tmp3, tmp4) tmp33 = tmp32 != tmp4 tmp35 = tl_math.exp(tmp34) tmp36 = tmp35 + tmp9 tmp37 = tl.where(tmp33, tmp4, tmp36) tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_7( in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (32 + 5 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (32 + x2), xmask) tmp18 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl_math.exp(tmp3) tmp5 = x0 tmp6 = tmp0 == tmp5 tmp7 = 1.0 tmp8 = 0.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = tmp9 != tmp8 tmp12 = tl_math.exp(tmp11) tmp13 = 1e-05 tmp14 = tmp12 + tmp13 tmp15 = tl.where(tmp10, tmp8, tmp14) tmp16 = -tmp15 tmp17 = tmp5 == tmp0 tmp19 = tl.where(tmp17, tmp18, tmp8) tmp20 = tmp16 + tmp19 tmp21 = tl.where(tmp2, tmp4, tmp20) tl.store(out_ptr0 + x2, tmp21, xmask) @triton.jit def triton_poi_fused_add_diag_embed_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp5 = tl.load(in_ptr0 + (16 + x2), xmask) tmp7 = tl.load(in_ptr1 + 5 * x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + x2, xmask) tmp17 = tl.load(in_ptr2 + (16 + x2), xmask) tmp20 = tl.load(in_ptr0 + (16 + 5 * x0), xmask, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = tl.full([1], 1, tl.int32) tmp1 = tmp0 == tmp0 tmp2 = x0 tmp3 = tl.full([1], 0, tl.int32) tmp4 = tmp2 == tmp3 tmp6 = tl_math.exp(tmp5) tmp8 = tmp6 * tmp7 tmp9 = 0.0 tmp10 = tl.where(tmp4, tmp9, tmp8) tmp11 = x1 tmp12 = tmp11 == tmp3 tmp14 = tmp6 * tmp13 tmp15 = tl.where(tmp12, tmp9, tmp14) tmp16 = tmp10 - tmp15 tmp18 = tl.where(tmp1, tmp16, tmp17) tmp19 = tmp2 == tmp11 tmp21 = tl_math.exp(tmp20) tmp23 = tmp21 * tmp22 tmp24 = tl.where(tmp19, tmp23, tmp9) tmp25 = tmp18 + tmp24 tl.store(out_ptr0 + x2, tmp25, xmask) @triton.jit def triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_9(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 // 16 x3 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x5 = xindex tmp3 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (16 + x3), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + 5 * x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp19 = tl.load(in_out_ptr0 + x5, xmask) tmp0 = x2 tmp1 = tl.full([1], 1, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = x0 tmp5 = tl.full([1], 0, tl.int32) tmp6 = tmp4 == tmp5 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 * tmp9 tmp11 = 0.0 tmp12 = tl.where(tmp6, tmp11, tmp10) tmp13 = x1 tmp14 = tmp13 == tmp5 tmp16 = tmp8 * tmp15 tmp17 = tl.where(tmp14, tmp11, tmp16) tmp18 = tmp12 - tmp17 tmp20 = tl.where(tmp2, tmp18, tmp19) tmp21 = tl.where(tmp2, tmp3, tmp20) tl.store(in_out_ptr0 + x5, tmp21, xmask) @triton.jit def triton_poi_fused_eye_masked_fill_ne_sum_10(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 tmp7 = tl.load(in_ptr0 + (48 + x0), xmask) tmp16 = tl.load(in_ptr0 + (52 + x0), xmask) tmp25 = tl.load(in_ptr0 + (56 + x0), xmask) tmp34 = tl.load(in_ptr0 + (60 + x0), xmask) tmp0 = tl.full([1], 0, tl.int64) tmp1 = x0 tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = tmp5 != tmp4 tmp8 = tl_math.exp(tmp7) tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = tl.where(tmp6, tmp4, tmp10) tmp12 = tl.full([1], 1, tl.int64) tmp13 = tmp12 == tmp1 tmp14 = tl.where(tmp13, tmp3, tmp4) tmp15 = tmp14 != tmp4 tmp17 = tl_math.exp(tmp16) tmp18 = tmp17 + tmp9 tmp19 = tl.where(tmp15, tmp4, tmp18) tmp20 = tmp11 + tmp19 tmp21 = tl.full([1], 2, tl.int64) tmp22 = tmp21 == tmp1 tmp23 = tl.where(tmp22, tmp3, tmp4) tmp24 = tmp23 != tmp4 tmp26 = tl_math.exp(tmp25) tmp27 = tmp26 + tmp9 tmp28 = tl.where(tmp24, tmp4, tmp27) tmp29 = tmp20 + tmp28 tmp30 = tl.full([1], 3, tl.int64) tmp31 = tmp30 == tmp1 tmp32 = tl.where(tmp31, tmp3, tmp4) tmp33 = tmp32 != tmp4 tmp35 = tl_math.exp(tmp34) tmp36 = tmp35 + tmp9 tmp37 = tl.where(tmp33, tmp4, tmp36) tmp38 = tmp29 + tmp37 tl.store(out_ptr0 + x0, tmp38, xmask) @triton.jit def triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_11( in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x0 = xindex % 4 x2 = xindex tmp3 = tl.load(in_ptr0 + (48 + 5 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (48 + x2), xmask) tmp18 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = x1 tmp1 = tl.full([1], 0, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = tl_math.exp(tmp3) tmp5 = x0 tmp6 = tmp0 == tmp5 tmp7 = 1.0 tmp8 = 0.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = tmp9 != tmp8 tmp12 = tl_math.exp(tmp11) tmp13 = 1e-05 tmp14 = tmp12 + tmp13 tmp15 = tl.where(tmp10, tmp8, tmp14) tmp16 = -tmp15 tmp17 = tmp5 == tmp0 tmp19 = tl.where(tmp17, tmp18, tmp8) tmp20 = tmp16 + tmp19 tmp21 = tl.where(tmp2, tmp4, tmp20) tl.store(out_ptr0 + x2, tmp21, xmask) @triton.jit def triton_poi_fused_add_diag_embed_12(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp5 = tl.load(in_ptr0 + (32 + x2), xmask) tmp7 = tl.load(in_ptr1 + 5 * x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + x2, xmask) tmp17 = tl.load(in_ptr2 + (32 + x2), xmask) tmp20 = tl.load(in_ptr0 + (32 + 5 * x0), xmask, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = tl.full([1], 2, tl.int32) tmp1 = tmp0 == tmp0 tmp2 = x0 tmp3 = tl.full([1], 0, tl.int32) tmp4 = tmp2 == tmp3 tmp6 = tl_math.exp(tmp5) tmp8 = tmp6 * tmp7 tmp9 = 0.0 tmp10 = tl.where(tmp4, tmp9, tmp8) tmp11 = x1 tmp12 = tmp11 == tmp3 tmp14 = tmp6 * tmp13 tmp15 = tl.where(tmp12, tmp9, tmp14) tmp16 = tmp10 - tmp15 tmp18 = tl.where(tmp1, tmp16, tmp17) tmp19 = tmp2 == tmp11 tmp21 = tl_math.exp(tmp20) tmp23 = tmp21 * tmp22 tmp24 = tl.where(tmp19, tmp23, tmp9) tmp25 = tmp18 + tmp24 tl.store(out_ptr0 + x2, tmp25, xmask) @triton.jit def triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_13(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 // 16 x3 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x5 = xindex tmp3 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (32 + x3), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + 5 * x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp19 = tl.load(in_out_ptr0 + x5, xmask) tmp0 = x2 tmp1 = tl.full([1], 2, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = x0 tmp5 = tl.full([1], 0, tl.int32) tmp6 = tmp4 == tmp5 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 * tmp9 tmp11 = 0.0 tmp12 = tl.where(tmp6, tmp11, tmp10) tmp13 = x1 tmp14 = tmp13 == tmp5 tmp16 = tmp8 * tmp15 tmp17 = tl.where(tmp14, tmp11, tmp16) tmp18 = tmp12 - tmp17 tmp20 = tl.where(tmp2, tmp18, tmp19) tmp21 = tl.where(tmp2, tmp3, tmp20) tl.store(in_out_ptr0 + x5, tmp21, xmask) @triton.jit def triton_poi_fused_add_diag_embed_14(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp5 = tl.load(in_ptr0 + (48 + x2), xmask) tmp7 = tl.load(in_ptr1 + 5 * x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + x2, xmask) tmp17 = tl.load(in_ptr2 + (48 + x2), xmask) tmp20 = tl.load(in_ptr0 + (48 + 5 * x0), xmask, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp0 = tl.full([1], 3, tl.int32) tmp1 = tmp0 == tmp0 tmp2 = x0 tmp3 = tl.full([1], 0, tl.int32) tmp4 = tmp2 == tmp3 tmp6 = tl_math.exp(tmp5) tmp8 = tmp6 * tmp7 tmp9 = 0.0 tmp10 = tl.where(tmp4, tmp9, tmp8) tmp11 = x1 tmp12 = tmp11 == tmp3 tmp14 = tmp6 * tmp13 tmp15 = tl.where(tmp12, tmp9, tmp14) tmp16 = tmp10 - tmp15 tmp18 = tl.where(tmp1, tmp16, tmp17) tmp19 = tmp2 == tmp11 tmp21 = tl_math.exp(tmp20) tmp23 = tmp21 * tmp22 tmp24 = tl.where(tmp19, tmp23, tmp9) tmp25 = tmp18 + tmp24 tl.store(out_ptr0 + x2, tmp25, xmask) @triton.jit def triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_15(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 // 16 x3 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x5 = xindex tmp3 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (48 + x3), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + 5 * x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp19 = tl.load(in_out_ptr0 + x5, xmask) tmp0 = x2 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp4 = x0 tmp5 = tl.full([1], 0, tl.int32) tmp6 = tmp4 == tmp5 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 * tmp9 tmp11 = 0.0 tmp12 = tl.where(tmp6, tmp11, tmp10) tmp13 = x1 tmp14 = tmp13 == tmp5 tmp16 = tmp8 * tmp15 tmp17 = tl.where(tmp14, tmp11, tmp16) tmp18 = tmp12 - tmp17 tmp20 = tl.where(tmp2, tmp18, tmp19) tmp21 = tl.where(tmp2, tmp3, tmp20) tl.store(in_out_ptr0 + x5, tmp21, 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,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_eye_masked_fill_ne_sum_0[grid(4)](arg0_1, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_1[ grid(16)](arg0_1, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = torch.ops.aten.linalg_inv_ex.default(buf1) buf3 = buf2[0] del buf2 buf5 = buf0 del buf0 triton_poi_fused_eye_masked_fill_ne_sum_2[grid(4)](arg0_1, buf5, 4, XBLOCK=4, num_warps=1, num_stages=1) buf6 = buf1 del buf1 triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_3[ grid(16)](arg0_1, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = torch.ops.aten.linalg_inv_ex.default(buf6) buf8 = buf7[0] del buf7 buf10 = buf6 del buf6 triton_poi_fused_add_diag_embed_4[grid(16)](arg0_1, buf3, buf10, 16, XBLOCK=16, num_warps=1, num_stages=1) buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_5[grid(64) ](buf10, arg0_1, buf3, buf11, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf10 buf12 = buf5 del buf5 triton_poi_fused_eye_masked_fill_ne_sum_6[grid(4)](arg0_1, buf12, 4, XBLOCK=4, num_warps=1, num_stages=1) buf13 = reinterpret_tensor(buf3, (4, 4), (4, 1), 0) del buf3 triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_7[ grid(16)](arg0_1, buf12, buf13, 16, XBLOCK=16, num_warps=1, num_stages=1) buf14 = torch.ops.aten.linalg_inv_ex.default(buf13) buf15 = buf14[0] del buf14 buf17 = buf13 del buf13 triton_poi_fused_add_diag_embed_8[grid(16)](arg0_1, buf8, buf11, buf17, 16, XBLOCK=16, num_warps=1, num_stages=1) buf18 = buf11 del buf11 triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_9[grid(64) ](buf18, buf17, arg0_1, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf17 buf19 = buf12 del buf12 triton_poi_fused_eye_masked_fill_ne_sum_10[grid(4)](arg0_1, buf19, 4, XBLOCK=4, num_warps=1, num_stages=1) buf20 = reinterpret_tensor(buf8, (4, 4), (4, 1), 0) del buf8 triton_poi_fused_add_diag_embed_diagonal_copy_exp_eye_masked_fill_ne_neg_11[ grid(16)](arg0_1, buf19, buf20, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf19 buf21 = torch.ops.aten.linalg_inv_ex.default(buf20) buf22 = buf21[0] del buf21 buf24 = buf20 del buf20 triton_poi_fused_add_diag_embed_12[grid(16)](arg0_1, buf15, buf18, buf24, 16, XBLOCK=16, num_warps=1, num_stages=1) buf25 = buf18 del buf18 triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_13[grid(64) ](buf25, buf24, arg0_1, buf15, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf15 buf26 = buf24 del buf24 triton_poi_fused_add_diag_embed_14[grid(16)](arg0_1, buf22, buf25, buf26, 16, XBLOCK=16, num_warps=1, num_stages=1) buf27 = buf25 del buf25 triton_poi_fused_add_diag_embed_exp_fill_lift_fresh_mul_sub_15[grid(64) ](buf27, buf26, arg0_1, buf22, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del buf22 del buf26 return buf27, class MatrixTreeNew(nn.Module): """Implementation of the matrix-tree theorem for computing marginals of non-projective dependency parsing. This attention layer is used in the paper "Learning Structured Text Representations" :cite:`DBLP:journals/corr/LiuL17d`. """ def __init__(self, eps=1e-05): self.eps = eps super(MatrixTreeNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Zer0-dev115/OpenNMT-py
MatrixTree
false
12,131
[ "MIT" ]
0
028c76b34779223ee6b3eb224b99617552987100
https://github.com/Zer0-dev115/OpenNMT-py/tree/028c76b34779223ee6b3eb224b99617552987100
Critic
import torch import numpy as np import torch.nn.functional as F import torch.nn as nn def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class Critic(nn.Module): def __init__(self, state_size, action_size, seed, fcs1_units=512, fc2_units=256): super(Critic, self).__init__() self.seed = torch.manual_seed(seed) self.fcs1 = nn.Linear(state_size, fcs1_units) self.fc2 = nn.Linear(fcs1_units + action_size, fc2_units) self.fc3 = nn.Linear(fc2_units, 1) self.reset_parameters() def reset_parameters(self): self.fcs1.weight.data.uniform_(*hidden_init(self.fcs1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, state, action): xs = F.relu(self.fcs1(state)) x = torch.cat((xs, action), dim=1) x = F.relu(self.fc2(x)) return self.fc3(x) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4, 'seed': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import numpy as np import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 2064 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 516 x1 = xindex // 516 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 512, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (512 * x1 + x0), tmp4 & xmask, eviction_policy ='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 516, tl.int64) tmp15 = tl.load(in_ptr2 + (4 * x1 + (-512 + x0)), tmp12 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.where(tmp4, tmp11, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (512, 4), (4, 1)) assert_size_stride(primals_2, (512,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (256, 516), (516, 1)) assert_size_stride(primals_6, (256,), (1,)) assert_size_stride(primals_7, (1, 256), (256, 1)) assert_size_stride(primals_8, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 512), (512, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 512), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 516), (516, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(2064)](buf0, primals_2, primals_4, buf1, 2064, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((4, 256), (256, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_5, (516, 256), ( 1, 516), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(1024)](buf3, primals_6, 1024, XBLOCK= 256, num_warps=4, num_stages=1) del primals_6 buf5 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, buf3, reinterpret_tensor(primals_7, (256, 1), (1, 256), 0), alpha=1, beta=1, out=buf5) del primals_8 buf6 = empty_strided_cuda((4, 512), (512, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(2048)](buf0, primals_2, buf6, 2048, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_2 return buf5, primals_3, buf1, buf3, primals_7, primals_5, buf6 def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class CriticNew(nn.Module): def __init__(self, state_size, action_size, seed, fcs1_units=512, fc2_units=256): super(CriticNew, self).__init__() self.seed = torch.manual_seed(seed) self.fcs1 = nn.Linear(state_size, fcs1_units) self.fc2 = nn.Linear(fcs1_units + action_size, fc2_units) self.fc3 = nn.Linear(fc2_units, 1) self.reset_parameters() def reset_parameters(self): self.fcs1.weight.data.uniform_(*hidden_init(self.fcs1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, input_0, input_1): primals_1 = self.fcs1.weight primals_2 = self.fcs1.bias primals_5 = self.fc2.weight primals_6 = self.fc2.bias primals_7 = self.fc3.weight primals_8 = self.fc3.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
asiliskender/deep-reinforcement-learning
Critic
false
12,132
[ "MIT" ]
0
dbf96d67477aa9242128b78b081474193e1e4538
https://github.com/asiliskender/deep-reinforcement-learning/tree/dbf96d67477aa9242128b78b081474193e1e4538
CNNCifar
from _paritybench_helpers import _mock_config import torch from torch import nn import torch.nn.functional as F class CNNCifar(nn.Module): def __init__(self, args): super(CNNCifar, self).__init__() self.conv1 = nn.Conv2d(3, 6, 5) self.pool = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(6, 16, 5) self.fc1 = nn.Linear(16 * 5 * 5, 120) self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, args.num_classes) def forward(self, x): x = self.pool(F.relu(self.conv1(x))) x = self.pool(F.relu(self.conv2(x))) x = x.view(-1, 16 * 5 * 5) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) return F.log_softmax(x, dim=1) def get_inputs(): return [torch.rand([4, 3, 32, 32])] def get_init_inputs(): return [[], {'args': _mock_config(num_classes=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18816 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 6 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4704 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 14 x3 = xindex // 14 x2 = xindex // 1176 x4 = xindex % 1176 tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x3), xmask, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x4 + 1184 * x2), tmp6, xmask) tl.store(out_ptr1 + (x4 + 1280 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 100 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 20 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 20 * x1), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (10 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (11 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x2, tmp15, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 480 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 120 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 = 336 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 84 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__log_softmax_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') 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, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (6, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_2, (6,), (1,)) assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1)) assert_size_stride(primals_4, (16, 6, 5, 5), (150, 25, 5, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (120, 400), (400, 1)) assert_size_stride(primals_7, (120,), (1,)) assert_size_stride(primals_8, (84, 120), (120, 1)) assert_size_stride(primals_9, (84,), (1,)) assert_size_stride(primals_10, (4, 84), (84, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 6, 28, 28), (4704, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(18816)](buf1, primals_2, 18816, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 6, 14, 14), (1184, 196, 14, 1), torch .float32) buf3 = empty_strided_cuda((4, 6, 14, 14), (1280, 196, 14, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_1[grid(4704)](buf1, buf2, buf3, 4704, XBLOCK=256, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 16, 10, 10), (1600, 100, 10, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(6400)](buf5, primals_5, 6400, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.int8) buf7 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.float32 ) triton_poi_fused_max_pool2d_with_indices_3[grid(1600)](buf5, buf6, buf7, 1600, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 120), (120, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (4, 400), (400, 1), 0), reinterpret_tensor(primals_6, (400, 120), (1, 400), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_4[grid(480)](buf9, primals_7, 480, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 84), (84, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_8, (120, 84), (1, 120), 0), out=buf10) buf11 = buf10 del buf10 triton_poi_fused_relu_5[grid(336)](buf11, primals_9, 336, XBLOCK= 128, num_warps=4, num_stages=1) del primals_9 buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_11, buf11, reinterpret_tensor( primals_10, (84, 4), (1, 84), 0), alpha=1, beta=1, out=buf12) del primals_11 buf13 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_6[grid(16)](buf12, buf13, 16, XBLOCK= 16, num_warps=1, num_stages=1) buf14 = buf12 del buf12 triton_poi_fused__log_softmax_7[grid(16)](buf13, buf14, 16, XBLOCK= 16, num_warps=1, num_stages=1) del buf13 return (buf14, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 400), (400, 1), 0), buf9, buf11, buf14, primals_10, primals_8, primals_6) class CNNCifarNew(nn.Module): def __init__(self, args): super(CNNCifarNew, self).__init__() self.conv1 = nn.Conv2d(3, 6, 5) self.pool = nn.MaxPool2d(2, 2) self.conv2 = nn.Conv2d(6, 16, 5) self.fc1 = nn.Linear(16 * 5 * 5, 120) self.fc2 = nn.Linear(120, 84) self.fc3 = nn.Linear(84, args.num_classes) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_10 = self.fc3.weight primals_11 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
ataML/Federated-Learning-PyTorch
CNNCifar
false
12,133
[ "MIT" ]
0
1c28f3e4a2ce2fd4e56d249e358a69408f76e34b
https://github.com/ataML/Federated-Learning-PyTorch/tree/1c28f3e4a2ce2fd4e56d249e358a69408f76e34b
Discriminator
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.utils.weight_norm as weightNorm class TReLU(nn.Module): def __init__(self): super(TReLU, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, x): x = F.relu(x - self.alpha) + self.alpha return x class Discriminator(nn.Module): def __init__(self): super(Discriminator, self).__init__() self.conv0 = weightNorm(nn.Conv2d(6, 16, 5, 2, 2)) self.conv1 = weightNorm(nn.Conv2d(16, 32, 5, 2, 2)) self.conv2 = weightNorm(nn.Conv2d(32, 64, 5, 2, 2)) self.conv3 = weightNorm(nn.Conv2d(64, 128, 5, 2, 2)) self.conv4 = weightNorm(nn.Conv2d(128, 1, 1, 1, 0)) self.relu0 = TReLU() self.relu1 = TReLU() self.relu2 = TReLU() self.relu3 = TReLU() def forward(self, x): x = self.conv0(x) x = self.relu0(x) x = self.conv1(x) x = self.relu1(x) x = self.conv2(x) x = self.relu2(x) x = self.conv3(x) x = self.relu3(x) x = self.conv4(x) x = x.view(-1, 64) return x def get_inputs(): return [torch.rand([4, 6, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F import torch.nn.utils.weight_norm as weightNorm 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 = 96 xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 6 y1 = yindex // 6 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 6 * x2 + 150 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 24 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 % 6 y1 = yindex // 6 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 6 * x2 + 24576 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 512 xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 16 y1 = yindex // 16 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 16 * x2 + 400 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 32 * x2 + 800 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 64 * x2 + 1600 * y1), tmp0, xmask) @triton.jit def triton_per_fused__weight_norm_interface_5(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 rnumel = 150 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 + 150 * x0), rmask & xmask, other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(rmask & xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = libdevice.sqrt(tmp5) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused__weight_norm_interface_convolution_6(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 96 xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 6 y1 = yindex // 6 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 6 * x2 + 150 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y1, ymask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + y1, ymask, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + (x2 + 25 * y3), tmp4, xmask & ymask) tl.store(out_ptr1 + (y0 + 6 * x2 + 150 * y1), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_7(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) x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 - tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = tmp7 + tmp4 tmp9 = 0.0 tmp10 = tmp7 <= tmp9 tl.store(out_ptr0 + x2, tmp8, None) tl.store(out_ptr1 + x2, tmp10, None) @triton.jit def triton_per_fused__weight_norm_interface_8(in_out_ptr0, in_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 rnumel = 400 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)[:] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 400 * x0), rmask, other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = tl.where(rmask, tmp2, 0) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp6 = libdevice.sqrt(tmp5) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, None) @triton.jit def triton_poi_fused__weight_norm_interface_convolution_9(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 512 xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 16 y1 = yindex // 16 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 400 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y1, ymask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + y1, ymask, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + (x2 + 25 * y3), tmp4, xmask & ymask) tl.store(out_ptr1 + (y0 + 16 * x2 + 400 * y1), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_10(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) x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 - tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = tmp7 + tmp4 tmp9 = 0.0 tmp10 = tmp7 <= tmp9 tl.store(out_ptr0 + x2, tmp8, None) tl.store(out_ptr1 + x2, tmp10, None) @triton.jit def triton_per_fused__weight_norm_interface_11(in_out_ptr0, in_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 rnumel = 800 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)[:] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 800 * x0), rmask, other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = tl.where(rmask, tmp2, 0) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp6 = libdevice.sqrt(tmp5) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, None) @triton.jit def triton_poi_fused__weight_norm_interface_convolution_12(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 32 y1 = yindex // 32 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 32 * x2 + 800 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + y1, None, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + (x2 + 25 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 32 * x2 + 800 * y1), tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_13(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) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 - tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = tmp7 + tmp4 tmp9 = 0.0 tmp10 = tmp7 <= tmp9 tl.store(out_ptr0 + x2, tmp8, None) tl.store(out_ptr1 + x2, tmp10, None) @triton.jit def triton_red_fused__weight_norm_interface_14(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 128 rnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex _tmp3 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 1600 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = _tmp3 + tmp2 _tmp3 = tl.where(rmask & xmask, tmp4, _tmp3) tmp3 = tl.sum(_tmp3, 1)[:, None] tmp5 = libdevice.sqrt(tmp3) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused__weight_norm_interface_convolution_15(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 64 y1 = yindex // 64 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 64 * x2 + 1600 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + y1, None, eviction_policy='evict_last') tmp3 = tmp1 / tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + (x2 + 25 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 64 * x2 + 1600 * y1), tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_sub_threshold_backward_16(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) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + 0) tmp4 = tl.broadcast_to(tmp3, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp2 - tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = tmp7 + tmp4 tmp9 = 0.0 tmp10 = tmp7 <= tmp9 tl.store(out_ptr0 + x2, tmp8, None) tl.store(out_ptr1 + x2, tmp10, None) @triton.jit def triton_per_fused__weight_norm_interface_17(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 128 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex 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_convolution_18(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20) = args args.clear() assert_size_stride(primals_1, (16, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_2, (16, 6, 5, 5), (150, 25, 5, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (4, 6, 64, 64), (24576, 4096, 64, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (32, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_7, (32, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_8, (32,), (1,)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (64, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_11, (64, 32, 5, 5), (800, 25, 5, 1)) assert_size_stride(primals_12, (64,), (1,)) assert_size_stride(primals_13, (1,), (1,)) assert_size_stride(primals_14, (128, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_15, (128, 64, 5, 5), (1600, 25, 5, 1)) assert_size_stride(primals_16, (128,), (1,)) assert_size_stride(primals_17, (1,), (1,)) assert_size_stride(primals_18, (1, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_19, (1, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_20, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 6, 5, 5), (150, 1, 30, 6), torch.float32 ) get_raw_stream(0) triton_poi_fused_0[grid(96, 25)](primals_2, buf0, 96, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((4, 6, 64, 64), (24576, 1, 384, 6), torch .float32) triton_poi_fused_1[grid(24, 4096)](primals_4, buf1, 24, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((32, 16, 5, 5), (400, 1, 80, 16), torch. float32) triton_poi_fused_2[grid(512, 25)](primals_7, buf2, 512, 25, XBLOCK= 32, YBLOCK=32, num_warps=4, num_stages=1) del primals_7 buf3 = empty_strided_cuda((64, 32, 5, 5), (800, 1, 160, 32), torch. float32) triton_poi_fused_3[grid(2048, 25)](primals_11, buf3, 2048, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_11 buf4 = empty_strided_cuda((128, 64, 5, 5), (1600, 1, 320, 64), torch.float32) triton_poi_fused_4[grid(8192, 25)](primals_15, buf4, 8192, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_15 buf5 = empty_strided_cuda((16, 1, 1, 1), (1, 16, 16, 16), torch.float32 ) buf6 = reinterpret_tensor(buf5, (16, 1, 1, 1), (1, 1, 1, 1), 0) del buf5 triton_per_fused__weight_norm_interface_5[grid(16)](buf6, buf0, 16, 150, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((16, 6, 5, 5), (150, 25, 5, 1), torch.float32 ) buf8 = empty_strided_cuda((16, 6, 5, 5), (150, 1, 30, 6), torch.float32 ) triton_poi_fused__weight_norm_interface_convolution_6[grid(96, 25)]( buf0, primals_1, buf6, buf7, buf8, 96, 25, XBLOCK=32, YBLOCK=8, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf1, buf8, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 16, 32, 32), (16384, 1, 512, 16)) del buf8 buf10 = empty_strided_cuda((4, 16, 32, 32), (16384, 1, 512, 16), torch.float32) buf37 = empty_strided_cuda((4, 16, 32, 32), (16384, 1, 512, 16), torch.bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_7[grid (65536)](buf9, primals_3, primals_5, buf10, buf37, 65536, XBLOCK=512, num_warps=4, num_stages=1) del buf9 del primals_3 del primals_5 buf11 = empty_strided_cuda((32, 1, 1, 1), (1, 32, 32, 32), torch. float32) buf12 = reinterpret_tensor(buf11, (32, 1, 1, 1), (1, 1, 1, 1), 0) del buf11 triton_per_fused__weight_norm_interface_8[grid(32)](buf12, buf2, 32, 400, num_warps=4, num_stages=1) buf13 = empty_strided_cuda((32, 16, 5, 5), (400, 25, 5, 1), torch. float32) buf14 = empty_strided_cuda((32, 16, 5, 5), (400, 1, 80, 16), torch. float32) triton_poi_fused__weight_norm_interface_convolution_9[grid(512, 25)]( buf2, primals_6, buf12, buf13, buf14, 512, 25, XBLOCK=1, YBLOCK =256, num_warps=4, num_stages=1) buf15 = extern_kernels.convolution(buf10, buf14, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 32, 16, 16), (8192, 1, 512, 32)) del buf14 buf16 = empty_strided_cuda((4, 32, 16, 16), (8192, 1, 512, 32), torch.float32) buf36 = empty_strided_cuda((4, 32, 16, 16), (8192, 1, 512, 32), torch.bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_10[grid (32768)](buf15, primals_8, primals_9, buf16, buf36, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf15 del primals_8 del primals_9 buf17 = empty_strided_cuda((64, 1, 1, 1), (1, 64, 64, 64), torch. float32) buf18 = reinterpret_tensor(buf17, (64, 1, 1, 1), (1, 1, 1, 1), 0) del buf17 triton_per_fused__weight_norm_interface_11[grid(64)](buf18, buf3, 64, 800, num_warps=8, num_stages=1) buf19 = empty_strided_cuda((64, 32, 5, 5), (800, 25, 5, 1), torch. float32) buf20 = empty_strided_cuda((64, 32, 5, 5), (800, 1, 160, 32), torch .float32) triton_poi_fused__weight_norm_interface_convolution_12[grid(2048, 25)]( buf3, primals_10, buf18, buf19, buf20, 2048, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) buf21 = extern_kernels.convolution(buf16, buf20, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf21, (4, 64, 8, 8), (4096, 1, 512, 64)) del buf20 buf22 = empty_strided_cuda((4, 64, 8, 8), (4096, 1, 512, 64), torch .float32) buf35 = empty_strided_cuda((4, 64, 8, 8), (4096, 1, 512, 64), torch .bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_13[grid (16384)](buf21, primals_12, primals_13, buf22, buf35, 16384, XBLOCK=128, num_warps=4, num_stages=1) del buf21 del primals_12 del primals_13 buf23 = empty_strided_cuda((128, 1, 1, 1), (1, 128, 128, 128), torch.float32) buf24 = reinterpret_tensor(buf23, (128, 1, 1, 1), (1, 1, 1, 1), 0) del buf23 triton_red_fused__weight_norm_interface_14[grid(128)](buf24, buf4, 128, 1600, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf25 = empty_strided_cuda((128, 64, 5, 5), (1600, 25, 5, 1), torch .float32) buf26 = empty_strided_cuda((128, 64, 5, 5), (1600, 1, 320, 64), torch.float32) triton_poi_fused__weight_norm_interface_convolution_15[grid(8192, 25)]( buf4, primals_14, buf24, buf25, buf26, 8192, 25, XBLOCK=32, YBLOCK=128, num_warps=8, num_stages=1) buf27 = extern_kernels.convolution(buf22, buf26, stride=(2, 2), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 128, 4, 4), (2048, 1, 512, 128)) del buf26 buf28 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.float32) buf34 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.bool) triton_poi_fused_add_convolution_relu_sub_threshold_backward_16[grid (8192)](buf27, primals_16, primals_17, buf28, buf34, 8192, XBLOCK=256, num_warps=4, num_stages=1) del buf27 del primals_16 del primals_17 buf29 = empty_strided_cuda((1, 1, 1, 1), (1, 1, 1, 1), torch.float32) buf30 = buf29 del buf29 buf31 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 1, 1), torch. float32) triton_per_fused__weight_norm_interface_17[grid(1)](buf30, primals_19, primals_18, buf31, 1, 128, XBLOCK=1, num_warps=2, num_stages=1) buf32 = extern_kernels.convolution(buf28, buf31, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 1, 4, 4), (16, 1, 4, 1)) buf33 = buf32 del buf32 triton_poi_fused_convolution_18[grid(64)](buf33, primals_20, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_20 return (reinterpret_tensor(buf33, (1, 64), (64, 1), 0), buf7, buf13, buf19, buf25, buf31, primals_1, buf0, buf1, primals_6, buf2, primals_10, buf3, primals_14, buf4, primals_18, primals_19, buf6, buf7, buf10, buf12, buf13, buf16, buf18, buf19, buf22, buf24, buf25, buf28, buf30, buf31, buf34, buf35, buf36, buf37) class TReLU(nn.Module): def __init__(self): super(TReLU, self).__init__() self.alpha = nn.Parameter(torch.FloatTensor(1), requires_grad=True) self.alpha.data.fill_(0) def forward(self, x): x = F.relu(x - self.alpha) + self.alpha return x class DiscriminatorNew(nn.Module): def __init__(self): super(DiscriminatorNew, self).__init__() self.conv0 = weightNorm(nn.Conv2d(6, 16, 5, 2, 2)) self.conv1 = weightNorm(nn.Conv2d(16, 32, 5, 2, 2)) self.conv2 = weightNorm(nn.Conv2d(32, 64, 5, 2, 2)) self.conv3 = weightNorm(nn.Conv2d(64, 128, 5, 2, 2)) self.conv4 = weightNorm(nn.Conv2d(128, 1, 1, 1, 0)) self.relu0 = TReLU() self.relu1 = TReLU() self.relu2 = TReLU() self.relu3 = TReLU() def forward(self, input_0): primals_3 = self.conv0.bias primals_1 = self.conv0.weight_g primals_2 = self.conv0.weight_v primals_8 = self.conv1.bias primals_6 = self.conv1.weight_g primals_7 = self.conv1.weight_v primals_12 = self.conv2.bias primals_10 = self.conv2.weight_g primals_11 = self.conv2.weight_v primals_16 = self.conv3.bias primals_14 = self.conv3.weight_g primals_15 = self.conv3.weight_v primals_5 = self.conv4.bias primals_18 = self.conv4.weight_g primals_19 = self.conv4.weight_v primals_9 = self.relu0.alpha primals_13 = self.relu1.alpha primals_17 = self.relu2.alpha primals_20 = self.relu3.alpha primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20]) return output[0]
archiroid003/ICCV2019-LearningToPaint
Discriminator
false
12,134
[ "MIT" ]
0
4b5fc263e4843c159a61e5956956b3f7812693f8
https://github.com/archiroid003/ICCV2019-LearningToPaint/tree/4b5fc263e4843c159a61e5956956b3f7812693f8
LayerNorm
import torch import torch.nn as nn from torch.nn import Parameter class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x 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 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_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-08 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-08, affine=True): super(LayerNormNew, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, 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]
autocomic/deepfillv2
LayerNorm
false
12,135
[ "MIT" ]
0
4b0f565accbf20ee90093a4504b1cff0099d9cb9
https://github.com/autocomic/deepfillv2/tree/4b0f565accbf20ee90093a4504b1cff0099d9cb9
GatedConv2d
import torch import torch.nn as nn from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x 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, math as tl_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 @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + x0) + -4 * tl_math .abs(-3 + x1) + 16 * x2), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_elu_mul_sigmoid_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x2, xmask) tmp4 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.0 tmp7 = tmp2 > tmp6 tmp8 = 1.0 tmp9 = tmp2 * tmp8 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp8 tmp12 = tl.where(tmp7, tmp9, tmp11) tmp13 = tl.sigmoid(tmp5) tmp14 = tmp12 * tmp13 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(in_out_ptr1 + x2, tmp5, xmask) tl.store(out_ptr0 + x2, tmp14, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = extern_kernels.convolution(buf0, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 1, 1), (4, 1, 1, 1)) buf2 = buf1 del buf1 buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_convolution_elu_mul_sigmoid_1[grid(16)](buf2, buf4, primals_3, primals_5, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 del primals_5 return buf5, primals_2, primals_4, buf0, buf2, buf4 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2dNew, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = self.mask_conv2d.weight primals_5 = self.mask_conv2d.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
autocomic/deepfillv2
GatedConv2d
false
12,136
[ "MIT" ]
0
4b0f565accbf20ee90093a4504b1cff0099d9cb9
https://github.com/autocomic/deepfillv2/tree/4b0f565accbf20ee90093a4504b1cff0099d9cb9
Conv2dLayer
import torch import torch.nn as nn from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(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_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_elu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x2, tmp9, 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=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 1, 1), (4, 1, 1, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_elu_0[grid(16)](buf1, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf1 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayerNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayerNew, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
autocomic/deepfillv2
Conv2dLayer
false
12,137
[ "MIT" ]
0
4b0f565accbf20ee90093a4504b1cff0099d9cb9
https://github.com/autocomic/deepfillv2/tree/4b0f565accbf20ee90093a4504b1cff0099d9cb9
InvDepth
import torch import torch.nn as nn class InvDepth(nn.Module): """Inverse depth layer""" def __init__(self, in_channels, out_channels=1, min_depth=0.5): """ Initializes an InvDepth object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels min_depth : float Minimum depth value to calculate """ super().__init__() self.min_depth = min_depth self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1) self.pad = nn.ConstantPad2d([1] * 4, value=0) self.activ = nn.Sigmoid() def forward(self, x): """Runs the InvDepth layer.""" x = self.conv1(self.pad(x)) return self.activ(x) / self.min_depth def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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 = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 6 % 6 x0 = xindex % 6 x2 = xindex // 36 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp11, xmask) @triton.jit def triton_poi_fused_convolution_div_sigmoid_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 x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tmp5 = 2.0 tmp6 = tmp4 * tmp5 tl.store(in_out_ptr0 + x0, tmp3, xmask) tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (1,), (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_constant_pad_nd_0[grid(576)](primals_1, buf0, 576, XBLOCK=256, 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, 1, 4, 4), (16, 16, 4, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) triton_poi_fused_convolution_div_sigmoid_1[grid(64)](buf2, primals_3, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf3, primals_2, buf0, buf2 class InvDepthNew(nn.Module): """Inverse depth layer""" def __init__(self, in_channels, out_channels=1, min_depth=0.5): """ Initializes an InvDepth object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels min_depth : float Minimum depth value to calculate """ super().__init__() self.min_depth = min_depth self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1) self.pad = nn.ConstantPad2d([1] * 4, value=0) self.activ = nn.Sigmoid() def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
aycatakmaz/packnet-sfm
InvDepth
false
12,138
[ "MIT" ]
0
d89cae81290133f136f6a1d1e288affc67eed1f7
https://github.com/aycatakmaz/packnet-sfm/tree/d89cae81290133f136f6a1d1e288affc67eed1f7
BBoxTransform
import torch from torch import nn class BBoxTransform(nn.Module): def forward(self, anchors, regression): """ decode_box_outputs adapted from https://github.com/google/automl/blob/master/efficientdet/anchors.py Args: anchors: [batchsize, boxes, (y1, x1, y2, x2)] regression: [batchsize, boxes, (dy, dx, dh, dw)] Returns: """ y_centers_a = (anchors[..., 0] + anchors[..., 2]) / 2 x_centers_a = (anchors[..., 1] + anchors[..., 3]) / 2 ha = anchors[..., 2] - anchors[..., 0] wa = anchors[..., 3] - anchors[..., 1] w = regression[..., 3].exp() * wa h = regression[..., 2].exp() * ha y_centers = regression[..., 0] * ha + y_centers_a x_centers = regression[..., 1] * wa + x_centers_a ymin = y_centers - h / 2.0 xmin = x_centers - w / 2.0 ymax = y_centers + h / 2.0 xmax = x_centers + w / 2.0 return torch.stack([xmin, ymin, xmax, ymax], dim=2) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import 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_stack_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (1 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 - tmp7 tmp9 = tmp5 * tmp8 tmp10 = tmp7 + tmp6 tmp11 = 0.5 tmp12 = tmp10 * tmp11 tmp13 = tmp9 + tmp12 tmp14 = tl.load(in_ptr0 + (3 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl_math.exp(tmp14) tmp16 = tmp15 * tmp8 tmp17 = tmp16 * tmp11 tmp18 = tmp13 - tmp17 tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp4, tmp18, tmp19) tmp21 = tmp0 >= tmp3 tmp22 = tl.full([1], 8, tl.int64) tmp23 = tmp0 < tmp22 tmp24 = tmp21 & tmp23 tmp25 = tl.load(in_ptr0 + (4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp26 = tl.load(in_ptr1 + (2 + 4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr1 + (4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tmp26 - tmp27 tmp29 = tmp25 * tmp28 tmp30 = tmp27 + tmp26 tmp31 = tmp30 * tmp11 tmp32 = tmp29 + tmp31 tmp33 = tl.load(in_ptr0 + (2 + 4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp34 = tl_math.exp(tmp33) tmp35 = tmp34 * tmp28 tmp36 = tmp35 * tmp11 tmp37 = tmp32 - tmp36 tmp38 = tl.full(tmp37.shape, 0.0, tmp37.dtype) tmp39 = tl.where(tmp24, tmp37, tmp38) tmp40 = tmp0 >= tmp22 tmp41 = tl.full([1], 12, tl.int64) tmp42 = tmp0 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tl.load(in_ptr0 + (1 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp45 = tl.load(in_ptr1 + (3 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp46 = tl.load(in_ptr1 + (1 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp47 = tmp45 - tmp46 tmp48 = tmp44 * tmp47 tmp49 = tmp46 + tmp45 tmp50 = tmp49 * tmp11 tmp51 = tmp48 + tmp50 tmp52 = tl.load(in_ptr0 + (3 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp53 = tl_math.exp(tmp52) tmp54 = tmp53 * tmp47 tmp55 = tmp54 * tmp11 tmp56 = tmp51 + tmp55 tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype) tmp58 = tl.where(tmp43, tmp56, tmp57) tmp59 = tmp0 >= tmp41 tl.full([1], 16, tl.int64) tmp62 = tl.load(in_ptr0 + (4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp63 = tl.load(in_ptr1 + (2 + 4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp64 = tl.load(in_ptr1 + (4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp65 = tmp63 - tmp64 tmp66 = tmp62 * tmp65 tmp67 = tmp64 + tmp63 tmp68 = tmp67 * tmp11 tmp69 = tmp66 + tmp68 tmp70 = tl.load(in_ptr0 + (2 + 4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp71 = tl_math.exp(tmp70) tmp72 = tmp71 * tmp65 tmp73 = tmp72 * tmp11 tmp74 = tmp69 + tmp73 tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype) tmp76 = tl.where(tmp59, tmp74, tmp75) tmp77 = tl.where(tmp43, tmp58, tmp76) tmp78 = tl.where(tmp24, tmp39, tmp77) tmp79 = tl.where(tmp4, tmp20, tmp78) tl.store(out_ptr0 + x2, tmp79, 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, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0), class BBoxTransformNew(nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
awesome-amy/efficientmask
BBoxTransform
false
12,139
[ "MIT" ]
0
2456d52af92f765de771fbb6bd27fe2b9f19533b
https://github.com/awesome-amy/efficientmask/tree/2456d52af92f765de771fbb6bd27fe2b9f19533b
TransposeConv2dLayer
import torch import torch.nn as nn from torch.nn import functional as F from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class TransposeConv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=False, scale_factor=2): super(TransposeConv2dLayer, self).__init__() self.scale_factor = scale_factor self.conv2d = Conv2dLayer(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest', recompute_scale_factor=False) x = self.conv2d(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x3, tmp7, xmask) tl.store(out_ptr0 + x3, 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, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_1[grid(400) ](buf2, primals_3, buf3, 400, XBLOCK=256, num_warps=4, num_stages=1 ) del primals_3 return buf2, primals_2, buf0, buf3 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class TransposeConv2dLayerNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=False, scale_factor=2): super(TransposeConv2dLayerNew, self).__init__() self.scale_factor = scale_factor self.conv2d = Conv2dLayer(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, input_0): primals_1 = self.conv2d.conv2d.weight primals_3 = self.conv2d.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
autocomic/deepfillv2
TransposeConv2dLayer
false
12,140
[ "MIT" ]
0
4b0f565accbf20ee90093a4504b1cff0099d9cb9
https://github.com/autocomic/deepfillv2/tree/4b0f565accbf20ee90093a4504b1cff0099d9cb9
AverageRC
import torch import torch.nn as nn class AverageRC(nn.Module): def __init__(self): super(AverageRC, self).__init__() def forward(self, input): input = input[:int(input.shape[0] / 2)] / 2 + input[int(input.shape [0] / 2):] / 2 return input def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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 = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr0 + (128 + x0), xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp5 = tmp2 + tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((2, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_0[grid(128)](arg0_1, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class AverageRCNew(nn.Module): def __init__(self): super(AverageRCNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
banwang27/models
AverageRC
false
12,141
[ "MIT" ]
0
59db29e46f76b630b78c864fb607388dd927b93c
https://github.com/banwang27/models/tree/59db29e46f76b630b78c864fb607388dd927b93c
OscBase
import torch import numpy as np import torch.nn as nn def init(module, weight_init, bias_init, gain=1): weight_init(module.weight.data, gain=gain) bias_init(module.bias.data) return module class NNBase(nn.Module): def __init__(self, recurrent, recurrent_input_size, hidden_size): super(NNBase, self).__init__() self._hidden_size = hidden_size self._recurrent = recurrent if recurrent: self.gru = nn.GRU(recurrent_input_size, hidden_size) for name, param in self.gru.named_parameters(): if 'bias' in name: nn.init.constant_(param, 0) elif 'weight' in name: nn.init.orthogonal_(param) @property def is_recurrent(self): return self._recurrent @property def recurrent_hidden_state_size(self): if self._recurrent: return self._hidden_size return 1 @property def output_size(self): return self._hidden_size def _forward_gru(self, x, hxs, masks): if x.size(0) == hxs.size(0): x, hxs = self.gru(x.unsqueeze(0), (hxs * masks).unsqueeze(0)) x = x.squeeze(0) hxs = hxs.squeeze(0) else: N = hxs.size(0) T = int(x.size(0) / N) x = x.view(T, N, x.size(1)) masks = masks.view(T, N) has_zeros = (masks[1:] == 0.0).any(dim=-1).nonzero().squeeze().cpu( ) if has_zeros.dim() == 0: has_zeros = [has_zeros.item() + 1] else: has_zeros = (has_zeros + 1).numpy().tolist() has_zeros = [0] + has_zeros + [T] hxs = hxs.unsqueeze(0) outputs = [] for i in range(len(has_zeros) - 1): start_idx = has_zeros[i] end_idx = has_zeros[i + 1] rnn_scores, hxs = self.gru(x[start_idx:end_idx], hxs * masks[start_idx].view(1, -1, 1)) outputs.append(rnn_scores) x = torch.cat(outputs, dim=0) x = x.view(T * N, -1) hxs = hxs.squeeze(0) return x, hxs class OscBase(NNBase): def __init__(self, num_inputs, recurrent=False, hidden_size=64): super(OscBase, self).__init__(recurrent, num_inputs, hidden_size) def init_(m): return init(m, nn.init.orthogonal_, lambda x: nn.init.constant_ (x, 0), np.sqrt(2)) self.time_idx = num_inputs // 2 - 1 self.osc_fanout1 = nn.Linear(1, 12) self.osc_fanout2 = nn.Linear(12, 12) self.layer1 = nn.Linear(num_inputs, hidden_size) self.layer2 = nn.Linear(hidden_size, hidden_size * 2) self.layerA1 = nn.Linear(hidden_size * 2 + 12, hidden_size) self.layerA2 = nn.Linear(hidden_size, hidden_size) self.layerC1 = nn.Linear(hidden_size * 2 + 12, hidden_size) self.layerC2 = init_(nn.Linear(hidden_size, 1)) self.train() def forward(self, inputs): x = inputs phase = torch.sin(0.004125 * 2 * 3.14159 / 0.4 * x[:, self.time_idx]) phase = phase.unsqueeze(1) x[:, self.time_idx] = 0 x[:, -1] = 0 o = torch.tanh(self.osc_fanout1(phase)) o = torch.tanh(self.osc_fanout2(o)) x = torch.tanh(self.layer1(x)) x = torch.tanh(self.layer2(x)) xo = torch.cat((x, o), 1) x_a = torch.tanh(self.layerA1(xo)) x_a = torch.tanh(self.layerA2(x_a)) x_c = torch.tanh(self.layerC1(xo)) x_c = self.layerC2(x_c) return x_c, x_a def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_inputs': 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 numpy as np import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sin_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp1 = 0.06479529375 tmp2 = tmp0 * tmp1 tmp3 = tl_math.sin(tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_fill_lift_fresh_1(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 % 4 x2 = xindex tmp5 = tl.load(in_ptr0 + x2, xmask) tmp0 = x0 tmp1 = tl.full([1], 3, tl.int32) tmp2 = tmp0 == tmp1 tmp3 = tl.full([1], 1, tl.int32) tmp4 = tmp0 == tmp3 tmp6 = 0.0 tmp7 = tl.where(tmp4, tmp6, tmp5) tmp8 = tl.where(tmp2, tmp6, tmp7) tl.store(out_ptr0 + x2, tmp8, xmask) tl.store(out_ptr1 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 48 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 12 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_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_cat_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 560 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 140 x1 = xindex // 140 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (128 * x1 + x0), tmp4 & xmask, eviction_policy ='evict_last', other=0.0) tmp6 = libdevice.tanh(tmp5) tmp7 = tl.full(tmp6.shape, 0.0, tmp6.dtype) tmp8 = tl.where(tmp4, tmp6, tmp7) tmp9 = tmp0 >= tmp3 tl.full([1], 140, tl.int64) tmp12 = tl.load(in_ptr1 + (12 * x1 + (-128 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp13 = libdevice.tanh(tmp12) tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp9, tmp13, tmp14) tmp16 = tl.where(tmp4, tmp8, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (12, 1), (1, 1)) assert_size_stride(primals_3, (12,), (1,)) assert_size_stride(primals_4, (12, 12), (12, 1)) assert_size_stride(primals_5, (12,), (1,)) assert_size_stride(primals_6, (64, 4), (4, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (128, 64), (64, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (64, 140), (140, 1)) assert_size_stride(primals_11, (64,), (1,)) assert_size_stride(primals_12, (64, 64), (64, 1)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (64, 140), (140, 1)) assert_size_stride(primals_15, (64,), (1,)) assert_size_stride(primals_16, (1, 64), (64, 1)) assert_size_stride(primals_17, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sin_0[grid(4)](primals_1, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_fill_lift_fresh_1[grid(16)](primals_1, buf1, primals_1, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf2 = empty_strided_cuda((4, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (4, 1), (1, 0), 0), reinterpret_tensor(primals_2, (1, 12), (1, 1), 0), out=buf2) del primals_2 buf3 = buf2 del buf2 triton_poi_fused_tanh_2[grid(48)](buf3, primals_3, 48, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((4, 12), (12, 1), torch.float32) extern_kernels.addmm(primals_5, buf3, reinterpret_tensor(primals_4, (12, 12), (1, 12), 0), alpha=1, beta=1, out=buf4) del primals_5 buf5 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_6, (4, 64), (1, 4), 0), out=buf5) del primals_6 buf6 = buf5 del buf5 triton_poi_fused_tanh_3[grid(256)](buf6, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf7 = empty_strided_cuda((4, 128), (128, 1), torch.float32) extern_kernels.addmm(primals_9, buf6, reinterpret_tensor(primals_8, (64, 128), (1, 64), 0), alpha=1, beta=1, out=buf7) del primals_9 buf8 = empty_strided_cuda((4, 140), (140, 1), torch.float32) triton_poi_fused_cat_4[grid(560)](buf7, buf4, buf8, 560, XBLOCK=128, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_10, (140, 64), ( 1, 140), 0), out=buf9) buf10 = buf9 del buf9 triton_poi_fused_tanh_3[grid(256)](buf10, primals_11, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_11 buf11 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf10, reinterpret_tensor(primals_12, (64, 64), ( 1, 64), 0), out=buf11) buf12 = buf11 del buf11 triton_poi_fused_tanh_3[grid(256)](buf12, primals_13, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_13 buf13 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_14, (140, 64), ( 1, 140), 0), out=buf13) buf14 = buf13 del buf13 triton_poi_fused_tanh_3[grid(256)](buf14, primals_15, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_15 buf16 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_17, buf14, reinterpret_tensor( primals_16, (64, 1), (1, 64), 0), alpha=1, beta=1, out=buf16) del primals_17 return (buf16, buf12, reinterpret_tensor(buf0, (4, 1), (1, 1), 0), buf1, buf3, buf4, buf6, buf7, buf8, buf10, buf12, buf14, primals_16, primals_14, primals_12, primals_10, primals_8, primals_4) def init(module, weight_init, bias_init, gain=1): weight_init(module.weight.data, gain=gain) bias_init(module.bias.data) return module class NNBase(nn.Module): def __init__(self, recurrent, recurrent_input_size, hidden_size): super(NNBase, self).__init__() self._hidden_size = hidden_size self._recurrent = recurrent if recurrent: self.gru = nn.GRU(recurrent_input_size, hidden_size) for name, param in self.gru.named_parameters(): if 'bias' in name: nn.init.constant_(param, 0) elif 'weight' in name: nn.init.orthogonal_(param) @property def is_recurrent(self): return self._recurrent @property def recurrent_hidden_state_size(self): if self._recurrent: return self._hidden_size return 1 @property def output_size(self): return self._hidden_size def _forward_gru(self, x, hxs, masks): if x.size(0) == hxs.size(0): x, hxs = self.gru(x.unsqueeze(0), (hxs * masks).unsqueeze(0)) x = x.squeeze(0) hxs = hxs.squeeze(0) else: N = hxs.size(0) T = int(x.size(0) / N) x = x.view(T, N, x.size(1)) masks = masks.view(T, N) has_zeros = (masks[1:] == 0.0).any(dim=-1).nonzero().squeeze().cpu( ) if has_zeros.dim() == 0: has_zeros = [has_zeros.item() + 1] else: has_zeros = (has_zeros + 1).numpy().tolist() has_zeros = [0] + has_zeros + [T] hxs = hxs.unsqueeze(0) outputs = [] for i in range(len(has_zeros) - 1): start_idx = has_zeros[i] end_idx = has_zeros[i + 1] rnn_scores, hxs = self.gru(x[start_idx:end_idx], hxs * masks[start_idx].view(1, -1, 1)) outputs.append(rnn_scores) x = torch.cat(outputs, dim=0) x = x.view(T * N, -1) hxs = hxs.squeeze(0) return x, hxs class OscBaseNew(NNBase): def __init__(self, num_inputs, recurrent=False, hidden_size=64): super(OscBaseNew, self).__init__(recurrent, num_inputs, hidden_size) def init_(m): return init(m, nn.init.orthogonal_, lambda x: nn.init.constant_ (x, 0), np.sqrt(2)) self.time_idx = num_inputs // 2 - 1 self.osc_fanout1 = nn.Linear(1, 12) self.osc_fanout2 = nn.Linear(12, 12) self.layer1 = nn.Linear(num_inputs, hidden_size) self.layer2 = nn.Linear(hidden_size, hidden_size * 2) self.layerA1 = nn.Linear(hidden_size * 2 + 12, hidden_size) self.layerA2 = nn.Linear(hidden_size, hidden_size) self.layerC1 = nn.Linear(hidden_size * 2 + 12, hidden_size) self.layerC2 = init_(nn.Linear(hidden_size, 1)) self.train() def forward(self, input_0): primals_2 = self.osc_fanout1.weight primals_3 = self.osc_fanout1.bias primals_4 = self.osc_fanout2.weight primals_5 = self.osc_fanout2.bias primals_6 = self.layer1.weight primals_7 = self.layer1.bias primals_8 = self.layer2.weight primals_9 = self.layer2.bias primals_10 = self.layerA1.weight primals_11 = self.layerA1.bias primals_12 = self.layerA2.weight primals_13 = self.layerA2.bias primals_14 = self.layerC1.weight primals_15 = self.layerC1.bias primals_16 = self.layerC2.weight primals_17 = self.layerC2.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, primals_16, primals_17]) return output[0], output[1]
aupilot/a2c
OscBase
false
12,142
[ "MIT" ]
0
cd7e8892f91ce0c8b4c221eb6be31ebbee81d663
https://github.com/aupilot/a2c/tree/cd7e8892f91ce0c8b4c221eb6be31ebbee81d663
CNN
import torch from torch import nn import torch.nn.functional as F class CNN(torch.nn.Module): """Basic CNN architecture.""" def __init__(self, in_channels=1): super(CNN, self).__init__() self.conv1 = nn.Conv2d(in_channels, 64, 8, 1) self.conv2 = nn.Conv2d(64, 128, 6, 2) self.conv3 = nn.Conv2d(128, 128, 5, 1) self.fc1 = nn.Linear(128 * 4 * 4, 128) self.fc2 = nn.Linear(128, 10) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = F.relu(self.conv3(x)) x = x.view(-1, 128 * 4 * 4) x = self.fc1(x) x = self.fc2(x) return x def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 36 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 36 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 64 * x2 + 2304 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 25 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 128 * x2 + 3200 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 256 xnumel = 3249 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 % 64 y1 = yindex // 64 tmp0 = tl.load(in_ptr0 + (x2 + 3249 * y3), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (y0 + 64 * x2 + 207936 * y1), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl. constexpr): ynumel = 512 xnumel = 484 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 128 y1 = yindex // 128 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 128 * x2 + 61952 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 484 * y3), tmp4, xmask & ymask) tl.store(out_ptr1 + (y0 + 128 * x2 + 61952 * y1), tmp6, 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, (64, 1, 8, 8), (64, 64, 8, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (128, 64, 6, 6), (2304, 36, 6, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (128, 128, 5, 5), (3200, 25, 5, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 2048), (2048, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (10, 128), (128, 1)) assert_size_stride(primals_11, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((128, 64, 6, 6), (2304, 1, 384, 64), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(8192, 36)](primals_4, buf0, 8192, 36, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_4 buf1 = empty_strided_cuda((128, 128, 5, 5), (3200, 1, 640, 128), torch.float32) triton_poi_fused_1[grid(16384, 25)](primals_6, buf1, 16384, 25, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_6 buf2 = 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(buf2, (4, 64, 57, 57), (207936, 3249, 57, 1)) buf3 = empty_strided_cuda((4, 64, 57, 57), (207936, 1, 3648, 64), torch.float32) triton_poi_fused_convolution_relu_2[grid(256, 3249)](buf2, primals_2, buf3, 256, 3249, XBLOCK=256, YBLOCK=16, num_warps=8, num_stages=1) del buf2 del primals_2 buf4 = extern_kernels.convolution(buf3, buf0, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 128, 26, 26), (86528, 1, 3328, 128)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_3[grid(346112)](buf5, primals_5, 346112, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf6 = extern_kernels.convolution(buf5, buf1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 22, 22), (61952, 1, 2816, 128)) buf7 = empty_strided_cuda((4, 128, 22, 22), (61952, 484, 22, 1), torch.float32) buf10 = empty_strided_cuda((4, 128, 22, 22), (61952, 1, 2816, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_4[grid(512, 484)]( buf6, primals_7, buf7, buf10, 512, 484, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf6 del primals_7 buf8 = empty_strided_cuda((121, 128), (128, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf7, (121, 2048 ), (2048, 1), 0), reinterpret_tensor(primals_8, (2048, 128), (1, 2048), 0), alpha=1, beta=1, out=buf8) del primals_9 buf9 = empty_strided_cuda((121, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_11, buf8, reinterpret_tensor( primals_10, (128, 10), (1, 128), 0), alpha=1, beta=1, out=buf9) del primals_11 return (buf9, primals_1, primals_3, buf0, buf1, buf3, buf5, reinterpret_tensor(buf7, (121, 2048), (2048, 1), 0), buf8, primals_10, primals_8, buf10) class CNNNew(torch.nn.Module): """Basic CNN architecture.""" def __init__(self, in_channels=1): super(CNNNew, self).__init__() self.conv1 = nn.Conv2d(in_channels, 64, 8, 1) self.conv2 = nn.Conv2d(64, 128, 6, 2) self.conv3 = nn.Conv2d(128, 128, 5, 1) self.fc1 = nn.Linear(128 * 4 * 4, 128) self.fc2 = nn.Linear(128, 10) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.fc1.weight primals_9 = self.fc1.bias primals_10 = self.fc2.weight primals_11 = self.fc2.bias primals_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]
austereantelope/cleverhans
CNN
false
12,143
[ "MIT" ]
0
5d68d538c89257693f9a7491994bb5586d3ec310
https://github.com/austereantelope/cleverhans/tree/5d68d538c89257693f9a7491994bb5586d3ec310
UnpackLayerConv2d
import torch import torch.nn as nn class Conv2D(nn.Module): """ 2D convolution with GroupNorm and ELU Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size stride : int Stride """ def __init__(self, in_channels, out_channels, kernel_size, stride): super().__init__() self.kernel_size = kernel_size self.conv_base = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride) self.pad = nn.ConstantPad2d([kernel_size // 2] * 4, value=0) self.normalize = torch.nn.GroupNorm(16, out_channels) self.activ = nn.ELU(inplace=True) def forward(self, x): """Runs the Conv2D layer.""" x = self.conv_base(self.pad(x)) return self.activ(self.normalize(x)) class UnpackLayerConv2d(nn.Module): """ Unpacking layer with 2d convolutions. Takes a [B,C,H,W] tensor, convolves it to produce [B,(r^2)C,H,W] and then unpacks it to produce [B,C,rH,rW]. """ def __init__(self, in_channels, out_channels, kernel_size, r=2): """ Initializes a UnpackLayerConv2d object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size r : int Packing ratio """ super().__init__() self.conv = Conv2D(in_channels, out_channels * r ** 2, kernel_size, 1) self.unpack = nn.PixelShuffle(r) def forward(self, x): """Runs the UnpackLayerConv2d layer.""" x = self.conv(x) x = self.unpack(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = -2 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -2 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-10 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp11, xmask) @triton.jit def triton_per_fused_convolution_native_group_norm_pixel_shuffle_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 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 r2 = rindex x3 = xindex x0 = xindex % 16 r7 = rindex % 5 r8 = rindex // 5 x4 = xindex % 2 x5 = xindex // 2 % 2 x6 = xindex // 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 25 * x3), rmask & xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp26 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(rmask & xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(rmask & xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 25, 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(rmask & xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 25.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp2 - tmp12 tmp25 = tmp24 * tmp23 tmp27 = tmp25 * tmp26 tmp29 = tmp27 + tmp28 tmp30 = 0.0 tmp31 = tmp29 > tmp30 tmp32 = 1.0 tmp33 = tmp29 * tmp32 tmp34 = libdevice.expm1(tmp33) tmp35 = tmp34 * tmp32 tmp36 = tl.where(tmp31, tmp33, tmp35) tl.store(in_out_ptr0 + (r2 + 25 * x3), tmp2, rmask & xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp23, xmask) tl.store(out_ptr2 + (x4 + 2 * r7 + 10 * x5 + 20 * r8 + 100 * x6), tmp36, rmask & xmask) tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (16, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (16,), (1,)) assert_size_stride(primals_5, (16,), (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_constant_pad_nd_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, 16, 5, 5), (400, 25, 5, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) buf4 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 64, 64), torch.float32 ) buf6 = reinterpret_tensor(buf4, (4, 16, 1, 1), (16, 1, 1, 1), 0) del buf4 buf8 = empty_strided_cuda((4, 4, 5, 2, 5, 2), (400, 100, 20, 10, 2, 1), torch.float32) triton_per_fused_convolution_native_group_norm_pixel_shuffle_1[grid(64) ](buf2, buf6, primals_3, primals_4, primals_5, buf3, buf8, 64, 25, XBLOCK=8, num_warps=2, num_stages=1) del primals_3 return reinterpret_tensor(buf8, (4, 4, 10, 10), (400, 100, 10, 1), 0 ), primals_2, primals_4, primals_5, buf0, buf2, buf3, buf6 class Conv2D(nn.Module): """ 2D convolution with GroupNorm and ELU Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size stride : int Stride """ def __init__(self, in_channels, out_channels, kernel_size, stride): super().__init__() self.kernel_size = kernel_size self.conv_base = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride) self.pad = nn.ConstantPad2d([kernel_size // 2] * 4, value=0) self.normalize = torch.nn.GroupNorm(16, out_channels) self.activ = nn.ELU(inplace=True) def forward(self, x): """Runs the Conv2D layer.""" x = self.conv_base(self.pad(x)) return self.activ(self.normalize(x)) class UnpackLayerConv2dNew(nn.Module): """ Unpacking layer with 2d convolutions. Takes a [B,C,H,W] tensor, convolves it to produce [B,(r^2)C,H,W] and then unpacks it to produce [B,C,rH,rW]. """ def __init__(self, in_channels, out_channels, kernel_size, r=2): """ Initializes a UnpackLayerConv2d object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size r : int Packing ratio """ super().__init__() self.conv = Conv2D(in_channels, out_channels * r ** 2, kernel_size, 1) self.unpack = nn.PixelShuffle(r) def forward(self, input_0): primals_2 = self.conv.conv_base.weight primals_3 = self.conv.conv_base.bias primals_4 = self.conv.normalize.weight primals_5 = self.conv.normalize.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
aycatakmaz/packnet-sfm
UnpackLayerConv2d
false
12,144
[ "MIT" ]
0
d89cae81290133f136f6a1d1e288affc67eed1f7
https://github.com/aycatakmaz/packnet-sfm/tree/d89cae81290133f136f6a1d1e288affc67eed1f7
ReCodeAlphabet
import torch import torch.nn as nn class ReCodeAlphabet(nn.Module): def __init__(self): super(ReCodeAlphabet, self).__init__() def forward(self, input): input_reordered = [input[:, i, ...] for i in [0, 2, 1, 3]] input = torch.stack(input_reordered, dim=1) return input def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_stack_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 16 x0 = xindex % 4 x2 = xindex // 64 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr0 + (32 + x0 + 4 * (-4 + x1) + 64 * x2), tmp9 & xmask, other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + (16 + x0 + 4 * (-8 + x1) + 64 * x2), tmp14 & xmask, other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp19 = tl.load(in_ptr0 + (48 + x0 + 4 * (-12 + x1) + 64 * x2), tmp16 & xmask, other=0.0) tmp20 = tl.where(tmp14, tmp15, tmp19) tmp21 = tl.where(tmp9, tmp10, tmp20) tmp22 = tl.where(tmp4, tmp5, tmp21) tl.store(out_ptr0 + x3, tmp22, xmask) 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, 16, 4), (64, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0), class ReCodeAlphabetNew(nn.Module): def __init__(self): super(ReCodeAlphabetNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
banwang27/models
ReCodeAlphabet
false
12,145
[ "MIT" ]
0
59db29e46f76b630b78c864fb607388dd927b93c
https://github.com/banwang27/models/tree/59db29e46f76b630b78c864fb607388dd927b93c
SuperSimpleSemSegNet
import torch import torch.nn as nn class SuperSimpleSemSegNet(nn.Module): def __init__(self, in_channel, out_channel): super().__init__() self.conv1 = torch.nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1, stride=1) self.ReLU = torch.nn.ReLU() self.softmax = torch.nn.LogSoftmax(dim=1) def forward(self, x): x = self.conv1(x) x = self.ReLU(x) x = self.softmax(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channel': 4, 'out_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 math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_convolution_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp7 = tl.load(in_ptr1 + 1) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp12 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp13 = tl.load(in_ptr1 + 2) tmp14 = tl.broadcast_to(tmp13, [XBLOCK]) tmp18 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp19 = tl.load(in_ptr1 + 3) tmp20 = tl.broadcast_to(tmp19, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp9 = tmp6 + tmp8 tmp10 = triton_helpers.maximum(tmp4, tmp9) tmp11 = triton_helpers.maximum(tmp5, tmp10) tmp15 = tmp12 + tmp14 tmp16 = triton_helpers.maximum(tmp4, tmp15) tmp17 = triton_helpers.maximum(tmp11, tmp16) tmp21 = tmp18 + tmp20 tmp22 = triton_helpers.maximum(tmp4, tmp21) tmp23 = triton_helpers.maximum(tmp17, tmp22) tmp24 = tmp5 - tmp23 tmp25 = tl_math.exp(tmp24) tmp26 = tmp10 - tmp23 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tmp16 - tmp23 tmp30 = tl_math.exp(tmp29) tmp31 = tmp28 + tmp30 tmp32 = tmp22 - tmp23 tmp33 = tl_math.exp(tmp32) tmp34 = tmp31 + tmp33 tl.store(out_ptr0 + x2, tmp23, xmask) tl.store(out_ptr1 + x2, tmp34, xmask) @triton.jit def triton_poi_fused__log_softmax_convolution_relu_threshold_backward_1(in_ptr0 , in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr3 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp4 - tmp5 tmp8 = tl_math.log(tmp7) tmp9 = tmp6 - tmp8 tmp10 = 0.0 tmp11 = tmp4 <= tmp10 tl.store(out_ptr0 + x3, tmp9, xmask) tl.store(out_ptr1 + x3, tmp11, 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, 1, 4, 4), (16, 64, 4, 1), torch.float32) buf2 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_convolution_relu_0[grid(64)](buf0, primals_2, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused__log_softmax_convolution_relu_threshold_backward_1[ grid(256)](buf0, primals_2, buf1, buf2, buf3, buf4, 256, XBLOCK =256, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 del primals_2 return buf3, primals_1, primals_3, buf3, buf4 class SuperSimpleSemSegNetNew(nn.Module): def __init__(self, in_channel, out_channel): super().__init__() self.conv1 = torch.nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1, stride=1) self.ReLU = torch.nn.ReLU() self.softmax = torch.nn.LogSoftmax(dim=1) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
benkoger/kasanka
SuperSimpleSemSegNet
false
12,146
[ "Apache-2.0" ]
0
d5b1d32b7abf54845af0832da577137397089001
https://github.com/benkoger/kasanka/tree/d5b1d32b7abf54845af0832da577137397089001
TransposeGatedConv2d
import torch import torch.nn as nn from torch.nn import functional as F from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2d, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest', recompute_scale_factor=False) x = self.gated_conv2d(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_mv_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.load(in_ptr0 + (64 + r0), None) tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp9 = tl.load(in_ptr0 + (128 + r0), None) tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp14 = tl.load(in_ptr0 + (192 + r0), None) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp3 = tmp0 * tmp2 tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp12 = tmp9 * tmp11 tmp13 = tmp8 + tmp12 tmp17 = tmp14 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = tmp18 * tmp18 tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK]) tmp22 = tl.sum(tmp20, 1)[:, None] tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-12 tmp25 = tmp23 + tmp24 tmp26 = tmp18 / tmp25 tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp18, None) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp25, None) tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp26, None) @triton.jit def triton_per_fused_div_mv_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp4 = tmp1 / tmp3 tmp5 = tmp0 * tmp4 tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tl.store(out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_3(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tmp5 = libdevice.sqrt(tmp4) tmp6 = 1e-12 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp8, None) @triton.jit def triton_per_fused_dot_4(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.sum(tmp3, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None) @triton.jit def triton_poi_fused_div_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 / tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.0 tmp7 = tmp2 > tmp6 tmp8 = 0.2 tmp9 = tmp2 * tmp8 tmp10 = tl.where(tmp7, tmp2, tmp9) tmp11 = tl.sigmoid(tmp5) tmp12 = tmp10 * tmp11 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(in_out_ptr1 + x3, tmp5, xmask) tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64,), (1,), torch.float32) buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 buf27 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf3, primals_4, primals_2, buf1, buf27, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_div_mv_2[grid(4)](primals_4, buf1, buf3, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf6 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf4, buf6, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf6, buf4, buf7, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_4, buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf0, buf8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 4, 5, 5), (100, 25, 5, 1)) buf11 = empty_strided_cuda((64,), (1,), torch.float32) buf12 = empty_strided_cuda((), (), torch.float32) buf13 = buf12 del buf12 buf36 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf13, primals_8, primals_6, buf11, buf36, 1, 64, XBLOCK=1, num_warps= 2, num_stages=1) buf14 = buf4 del buf4 triton_per_fused_div_mv_2[grid(4)](primals_8, buf11, buf13, buf14, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf16 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf14, buf16, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf17 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf16, buf14, buf17, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf14 buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_8, buf17, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1) buf19 = extern_kernels.convolution(buf0, buf18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 4, 5, 5), (100, 25, 5, 1)) buf10 = buf9 del buf9 buf20 = buf19 del buf19 buf21 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.float32 ) triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6[grid(400)](buf10, buf20, primals_5, primals_9, buf21, 400, XBLOCK=256, num_warps= 4, num_stages=1) del primals_5 del primals_9 buf22 = torch.ops.aten.set_.source_Tensor(primals_2, buf6) assert_size_stride(buf22, (4,), (1,)) del buf1 buf28 = torch.ops.aten.set_.source_Tensor(primals_3, buf27) assert_size_stride(buf28, (64,), (1,)) del primals_3 buf31 = torch.ops.aten.set_.source_Tensor(primals_6, buf16) assert_size_stride(buf31, (4,), (1,)) del buf11 buf37 = torch.ops.aten.set_.source_Tensor(primals_7, buf36) assert_size_stride(buf37, (64,), (1,)) del primals_7 return (buf21, buf8, buf18, primals_2, primals_4, primals_6, primals_8, buf0, buf3, buf6, buf7, buf8, buf10, buf13, buf16, buf17, buf18, buf20) def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2dNew, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, input_0): primals_2 = self.gated_conv2d.conv2d.module.bias primals_5 = self.gated_conv2d.conv2d.module.weight_u primals_3 = self.gated_conv2d.conv2d.module.weight_v primals_1 = self.gated_conv2d.conv2d.module.weight_bar primals_6 = self.gated_conv2d.mask_conv2d.module.bias primals_9 = self.gated_conv2d.mask_conv2d.module.weight_u primals_7 = self.gated_conv2d.mask_conv2d.module.weight_v primals_4 = self.gated_conv2d.mask_conv2d.module.weight_bar primals_8 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
autocomic/deepfillv2
TransposeGatedConv2d
false
12,147
[ "MIT" ]
0
4b0f565accbf20ee90093a4504b1cff0099d9cb9
https://github.com/autocomic/deepfillv2/tree/4b0f565accbf20ee90093a4504b1cff0099d9cb9
Attention
import math import torch from torch.nn import functional as F import torch.nn as nn class Attention(nn.Module): def __init__(self, hidden_size): super(Attention, self).__init__() self.hidden_size = hidden_size self.attn = nn.Linear(self.hidden_size * 2, hidden_size) self.v = nn.Parameter(torch.rand(hidden_size)) stdv = 1.0 / math.sqrt(self.v.size(0)) self.v.data.uniform_(-stdv, stdv) def forward(self, hidden, encoder_outputs): timestep = encoder_outputs.size(0) h = hidden.repeat(timestep, 1, 1).transpose(0, 1) encoder_outputs = encoder_outputs.transpose(0, 1) attn_energies = self.score(h, encoder_outputs) return F.softmax(attn_energies, dim=1).unsqueeze(1) def score(self, hidden, encoder_outputs): energy = F.relu(self.attn(torch.cat([hidden, encoder_outputs], 2))) energy = energy.transpose(1, 2) v = self.v.repeat(encoder_outputs.size(0), 1).unsqueeze(1) energy = torch.bmm(v, energy) return energy.squeeze(1) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import math from torch.nn import functional as F import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x2 = xindex // 32 x1 = xindex // 8 % 4 x3 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x2 + 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 * x2 + 16 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_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) @triton.jit def triton_poi_fused_repeat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = 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, 8), (8, 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), (32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_2, primals_1, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf1) del primals_3 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(64)](buf2, primals_4, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_repeat_2[grid(16)](primals_5, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (4, 1, 4), (4, 0, 1), 0 ), reinterpret_tensor(buf2, (4, 4, 4), (16, 1, 4), 0), out=buf4) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_3[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4), (4, 1), 0) del buf4 triton_poi_fused__softmax_4[grid(16)](buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf5 return reinterpret_tensor(buf6, (4, 1, 4), (4, 4, 1), 0 ), reinterpret_tensor(buf0, (16, 8), (8, 1), 0 ), buf6, reinterpret_tensor(buf3, (4, 4, 1), (4, 1, 4), 0), buf2, buf7 class AttentionNew(nn.Module): def __init__(self, hidden_size): super(AttentionNew, self).__init__() self.hidden_size = hidden_size self.attn = nn.Linear(self.hidden_size * 2, hidden_size) self.v = nn.Parameter(torch.rand(hidden_size)) stdv = 1.0 / math.sqrt(self.v.size(0)) self.v.data.uniform_(-stdv, stdv) def score(self, hidden, encoder_outputs): energy = F.relu(self.attn(torch.cat([hidden, encoder_outputs], 2))) energy = energy.transpose(1, 2) v = self.v.repeat(encoder_outputs.size(0), 1).unsqueeze(1) energy = torch.bmm(v, energy) return energy.squeeze(1) def forward(self, input_0, input_1): primals_4 = self.v primals_3 = self.attn.weight primals_5 = self.attn.bias primals_2 = input_0 primals_1 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
baduncan/Pytorch-seq2seq-Beam-Search
Attention
false
12,148
[ "MIT" ]
0
82e2f12563d4db520a9a9089e7205f398ca53699
https://github.com/baduncan/Pytorch-seq2seq-Beam-Search/tree/82e2f12563d4db520a9a9089e7205f398ca53699
L1Norm
import torch import torch.nn as nn class L1Norm(nn.Module): def __init__(self): super(L1Norm, self).__init__() self.eps = 1e-10 def forward(self, x): norm = torch.sum(torch.abs(x), dim=1) + self.eps x = x / norm.expand_as(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn 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 x3 = xindex x0 = xindex % 16 x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp2 = tl_math.abs(tmp1) tmp4 = tl_math.abs(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.abs(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.abs(tmp9) tmp11 = tmp8 + tmp10 tmp12 = 1e-10 tmp13 = tmp11 + tmp12 tmp14 = tmp0 / tmp13 tl.store(out_ptr0 + x3, tmp14, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class L1NormNew(nn.Module): def __init__(self): super(L1NormNew, self).__init__() self.eps = 1e-10 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
bankbiz/Key.Net
L1Norm
false
12,149
[ "BSD-3-Clause-Clear" ]
0
5ba46614821e94be1b36d97721bd6c2e5fff9e20
https://github.com/bankbiz/Key.Net/tree/5ba46614821e94be1b36d97721bd6c2e5fff9e20
L2Norm
import torch import torch.nn as nn class L2Norm(nn.Module): def __init__(self): super(L2Norm, self).__init__() self.eps = 1e-10 def forward(self, x): norm = torch.sqrt(torch.sum(x * x, dim=1) + self.eps) x = x / norm.unsqueeze(-1).expand_as(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x1 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x1 + 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 = 1e-10 tmp13 = tmp11 + tmp12 tmp14 = libdevice.sqrt(tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x3, 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 L2NormNew(nn.Module): def __init__(self): super(L2NormNew, self).__init__() self.eps = 1e-10 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
bankbiz/Key.Net
L2Norm
false
12,150
[ "BSD-3-Clause-Clear" ]
0
5ba46614821e94be1b36d97721bd6c2e5fff9e20
https://github.com/bankbiz/Key.Net/tree/5ba46614821e94be1b36d97721bd6c2e5fff9e20
Swish
import torch from torch.functional import F class Swish(torch.nn.Module): def __init__(self): super().__init__() def forward(self, x): return F.sigmoid(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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_sigmoid_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp2 = tmp1 * tmp0 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](arg0_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SwishNew(torch.nn.Module): def __init__(self): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
bglick13/multi-agent-emergence-environments
Swish
false
12,151
[ "MIT" ]
0
e02d66f0734d95470d15a4508ff369a75fa093a4
https://github.com/bglick13/multi-agent-emergence-environments/tree/e02d66f0734d95470d15a4508ff369a75fa093a4
LinearLR
import torch import torch.nn as nn import torch.utils.checkpoint class LinearLR(nn.Module): """[u * v + res] version of torch.nn.Linear""" def __init__(self, in_features, out_features, rank_ratio=0.25, bias= True, device=None, dtype=None): super().__init__() sliced_rank = int(min(in_features, out_features) * rank_ratio) self.u = nn.Linear(sliced_rank, out_features, bias=bias, device= device, dtype=dtype) self.v = nn.Linear(in_features, sliced_rank, bias=False, device= device, dtype=dtype) self.res = nn.Linear(in_features, out_features, bias=False, device= device, dtype=dtype) def freeze(self): for param in self.res.parameters(): param.requires_grad = False def unfreeze(self): for param in self.res.parameters(): param.requires_grad = True def forward(self, input): return self.u(self.v(input)) + self.res(input) 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 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_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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 1), (1, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (1, 4), (1, 1 ), 0), out=buf1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf2) del primals_5 buf3 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf3, primals_4, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf2 del primals_4 return buf3, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0 ), buf0, primals_3 class LinearLRNew(nn.Module): """[u * v + res] version of torch.nn.Linear""" def __init__(self, in_features, out_features, rank_ratio=0.25, bias= True, device=None, dtype=None): super().__init__() sliced_rank = int(min(in_features, out_features) * rank_ratio) self.u = nn.Linear(sliced_rank, out_features, bias=bias, device= device, dtype=dtype) self.v = nn.Linear(in_features, sliced_rank, bias=False, device= device, dtype=dtype) self.res = nn.Linear(in_features, out_features, bias=False, device= device, dtype=dtype) def freeze(self): for param in self.res.parameters(): param.requires_grad = False def unfreeze(self): for param in self.res.parameters(): param.requires_grad = True def forward(self, input_0): primals_3 = self.u.weight primals_4 = self.u.bias primals_1 = self.v.weight primals_5 = self.res.weight primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
bahducoup/factorized_training
LinearLR
false
12,152
[ "MIT" ]
0
0af38f16338a9bcfcc11091b1a6b75befd67f234
https://github.com/bahducoup/factorized_training/tree/0af38f16338a9bcfcc11091b1a6b75befd67f234
LowRankResidualPositionwiseFeedForward
import torch import torch.nn as nn import torch.utils.checkpoint import torch.nn.functional as F from torch.cuda.amp import autocast class LowRankResidualPositionwiseFeedForward(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1_u = nn.Linear(int(d_in / 4), d_hid, bias=False) self.w_1_v = nn.Linear(d_in, int(d_in / 4), bias=False) self.w_1_res = nn.Linear(d_in, d_hid) self.w_2_u = nn.Linear(int(d_in / 4), d_in, bias=False) self.w_2_v = nn.Linear(d_hid, int(d_in / 4), bias=False) self.w_2_res = nn.Linear(d_hid, d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) @autocast() def forward(self, x): residual = x x = F.relu(self.w_1_u(self.w_1_v(x)) + self.w_1_res(x)) x = self.w_2_u(self.w_2_v(x)) + self.w_2_res(x) x = self.dropout(x) x += residual x = self.layer_norm(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_in': 4, 'd_hid': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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__to_copy_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused__to_copy_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused__to_copy_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_add_relu_threshold_backward_3(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask).to(tl.float32) tmp1 = tl.load(in_ptr0 + x2, xmask).to(tl.float32) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp2.to(tl.float32) tmp4 = tmp1 + tmp3 tmp5 = tmp0 + tmp4 tmp6 = tl.full([1], 0, tl.int32) tmp7 = triton_helpers.maximum(tmp6, tmp5) tmp8 = 0.0 tmp9 = tmp7 <= tmp8 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_add_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask).to(tl.float32) tmp1 = tl.load(in_ptr1 + x2, xmask).to(tl.float32) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr3 + x2, xmask) tmp3 = tmp2.to(tl.float32) tmp4 = tmp1 + tmp3 tmp5 = tmp0 + tmp4 tmp6 = tmp5.to(tl.float32) tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_native_layer_norm_5(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-06 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, 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, (1, 4), (4, 1)) assert_size_stride(primals_3, (4, 1), (1, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (1, 4), (4, 1)) assert_size_stride(primals_7, (4, 1), (1, 1)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float16) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(256)](primals_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((1, 4), (4, 1), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_2, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (4, 1), (1, 0), 0), out=buf2) buf3 = buf1 del buf1 triton_poi_fused__to_copy_1[grid(4)](primals_3, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float16) extern_kernels.mm(buf2, buf3, out=buf4) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float16) triton_poi_fused__to_copy_2[grid(16)](primals_4, buf5, 16, XBLOCK= 16, num_warps=1, num_stages=1) del primals_4 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(buf5, (4, 4), (1, 4), 0), out=buf6) buf7 = empty_strided_cuda((4, 1), (1, 4), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_6, buf7, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_6 buf8 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_relu_threshold_backward_3[grid(256)](buf8, buf6, primals_5, buf18, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf9 = empty_strided_cuda((64, 1), (1, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf8, (64, 4), (4, 1), 0), buf7, out=buf9) buf10 = empty_strided_cuda((1, 4), (4, 1), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_7, buf10, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_7 buf11 = buf6 del buf6 extern_kernels.mm(buf9, buf10, out=buf11) buf12 = reinterpret_tensor(buf5, (4, 4), (1, 4), 0) del buf5 triton_poi_fused__to_copy_2[grid(16)](primals_8, buf12, 16, XBLOCK= 16, num_warps=1, num_stages=1) del primals_8 buf13 = empty_strided_cuda((64, 4), (4, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf8, (64, 4), (4, 1), 0), buf12, out=buf13) buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_4[grid(256)](buf11, buf13, primals_9, primals_1, buf14, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf11 del buf13 del primals_1 del primals_9 buf15 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf16 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_native_layer_norm_5[grid(64)](buf14, buf15, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_6[grid(256)](buf14, buf15, buf16, primals_10, primals_11, buf17, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf15 del buf16 del primals_11 return buf17, primals_10, reinterpret_tensor(buf0, (64, 4), (4, 1), 0 ), buf2, reinterpret_tensor(buf8, (64, 4), (4, 1), 0 ), buf9, buf14, reinterpret_tensor(buf12, (4, 4), (4, 1), 0 ), reinterpret_tensor(buf10, (4, 1), (1, 1), 0), reinterpret_tensor( buf7, (1, 4), (4, 1), 0), buf18, reinterpret_tensor(buf3, (4, 1), ( 1, 1), 0) class LowRankResidualPositionwiseFeedForwardNew(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1_u = nn.Linear(int(d_in / 4), d_hid, bias=False) self.w_1_v = nn.Linear(d_in, int(d_in / 4), bias=False) self.w_1_res = nn.Linear(d_in, d_hid) self.w_2_u = nn.Linear(int(d_in / 4), d_in, bias=False) self.w_2_v = nn.Linear(d_hid, int(d_in / 4), bias=False) self.w_2_res = nn.Linear(d_hid, d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) def forward(self, input_0): primals_3 = self.w_1_u.weight primals_2 = self.w_1_v.weight primals_4 = self.w_1_res.weight primals_5 = self.w_1_res.bias primals_7 = self.w_2_u.weight primals_6 = self.w_2_v.weight primals_8 = self.w_2_res.weight primals_9 = self.w_2_res.bias primals_10 = self.layer_norm.weight primals_11 = self.layer_norm.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
bahducoup/factorized_training
LowRankResidualPositionwiseFeedForward
false
12,153
[ "MIT" ]
0
0af38f16338a9bcfcc11091b1a6b75befd67f234
https://github.com/bahducoup/factorized_training/tree/0af38f16338a9bcfcc11091b1a6b75befd67f234
PyramidModule
import torch import torch.nn as nn from torchvision.transforms import * class ConvBlock(nn.Module): def __init__(self, input_size, output_size, kernel_size=3, stride=1, padding=1, bias=True, activation='prelu', norm=None): super(ConvBlock, self).__init__() self.conv = nn.Conv2d(input_size, output_size, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(output_size) elif self.norm == 'instance': self.bn = nn.InstanceNorm2d(output_size) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): if self.norm is not None: out = self.bn(self.conv(x)) else: out = self.conv(x) if self.activation is not None: return self.act(out) else: return out class DeconvBlock(nn.Module): def __init__(self, input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='prelu', norm=None): super(DeconvBlock, self).__init__() self.deconv = nn.ConvTranspose2d(input_size, output_size, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(output_size) elif self.norm == 'instance': self.bn = nn.InstanceNorm2d(output_size) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): if self.norm is not None: out = self.bn(self.deconv(x)) else: out = self.deconv(x) if self.activation is not None: return self.act(out) else: return out class ResnetBlock(nn.Module): def __init__(self, num_filter, kernel_size=3, stride=1, padding=1, bias =True, activation='prelu', norm='batch'): super(ResnetBlock, self).__init__() self.conv1 = nn.Conv2d(num_filter, num_filter, kernel_size, stride, padding, bias=bias) self.conv2 = nn.Conv2d(num_filter, num_filter, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(num_filter) elif norm == 'instance': self.bn = nn.InstanceNorm2d(num_filter) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): residual = x if self.norm is not None: out = self.bn(self.conv1(x)) else: out = self.conv1(x) if self.activation is not None: out = self.act(out) if self.norm is not None: out = self.bn(self.conv2(out)) else: out = self.conv2(out) out = torch.add(out, residual) if self.activation is not None: out = self.act(out) return out class PyramidModule(nn.Module): def __init__(self, num_inchannels, activation='prelu'): super(PyramidModule, self).__init__() self.l1_1 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_2 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_3 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_4 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_5 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_1 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_2 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_3 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_4 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_1 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_2 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_3 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.down1 = ConvBlock(num_inchannels, num_inchannels * 2, 4, 2, 1, bias=True, activation=activation, norm=None) self.down2 = ConvBlock(num_inchannels * 2, num_inchannels * 4, 4, 2, 1, bias=True, activation=activation, norm=None) self.up1 = DeconvBlock(num_inchannels * 2, num_inchannels, 4, 2, 1, bias=True, activation=activation, norm=None) self.up2 = DeconvBlock(num_inchannels * 4, num_inchannels * 2, 4, 2, 1, bias=True, activation=activation, norm=None) self.final = ConvBlock(num_inchannels, num_inchannels, 3, 1, 1, bias=True, activation=activation, norm=None) def forward(self, x): out1_1 = self.l1_1(x) out2_1 = self.l2_1(self.down1(out1_1)) out3_1 = self.l3_1(self.down2(out2_1)) out1_2 = self.l1_2(out1_1 + self.up1(out2_1)) out2_2 = self.l2_2(out2_1 + self.down1(out1_2) + self.up2(out3_1)) out3_2 = self.l3_2(out3_1 + self.down2(out2_2)) out1_3 = self.l1_3(out1_2 + self.up1(out2_2)) out2_3 = self.l2_3(out2_2 + self.down1(out1_3) + self.up2(out3_2)) out3_3 = self.l3_3(out3_2 + self.down2(out2_3)) out1_4 = self.l1_4(out1_3 + self.up1(out2_3)) out2_4 = self.l2_4(out2_3 + self.down1(out1_4) + self.up2(out3_3)) out1_5 = self.l1_5(out1_4 + self.up1(out2_4)) final = self.final(out1_5) return final def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_inchannels': 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 from torchvision.transforms 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__prelu_kernel_convolution_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp7 = tmp6 * tmp2 tmp8 = tl.where(tmp4, tmp2, tmp7) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp9 = tmp8 * tmp4 tmp10 = tl.where(tmp6, tmp4, tmp9) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__prelu_kernel_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp7 = tmp6 * tmp2 tmp8 = tl.where(tmp4, tmp2, tmp7) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_3(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp9 = tmp8 * tmp4 tmp10 = tl.where(tmp6, tmp4, tmp9) tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__prelu_kernel_convolution_4(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp7 = tmp6 * tmp2 tmp8 = tl.where(tmp4, tmp2, tmp7) tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_5(in_out_ptr0, 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 x2 = xindex x0 = xindex % 16 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) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp9 = tmp8 * tmp4 tmp10 = tl.where(tmp6, tmp4, tmp9) tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp6 = tl.load(in_ptr2 + 0) tmp7 = tl.broadcast_to(tmp6, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = 0.0 tmp5 = tmp2 > tmp4 tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp5, tmp2, tmp8) tmp10 = tmp3 + tmp9 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_7(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp7 = tl.load(in_ptr2 + 0) tmp8 = tl.broadcast_to(tmp7, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = tmp4 > tmp5 tmp9 = tmp8 * tmp4 tmp10 = tl.where(tmp6, tmp4, tmp9) tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_8(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x3, xmask) tmp9 = tl.load(in_ptr3 + 0) tmp10 = tl.broadcast_to(tmp9, [XBLOCK]) tmp15 = tl.load(in_ptr4 + 0) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = 0.0 tmp8 = tmp2 > tmp7 tmp11 = tmp10 * tmp2 tmp12 = tl.where(tmp8, tmp2, tmp11) tmp13 = tmp6 + tmp12 tmp14 = tmp5 > tmp7 tmp17 = tmp16 * tmp5 tmp18 = tl.where(tmp14, tmp5, tmp17) tmp19 = tmp13 + tmp18 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(in_out_ptr1 + x3, tmp5, xmask) tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_poi_fused__prelu_kernel_add_convolution_9(in_out_ptr0, 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 x2 = xindex x0 = xindex % 16 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) tmp6 = tl.load(in_ptr2 + 0) tmp7 = tl.broadcast_to(tmp6, [XBLOCK]) tmp2 = tmp0 + tmp1 tmp4 = 0.0 tmp5 = tmp2 > tmp4 tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp5, tmp2, tmp8) tmp10 = tmp3 + tmp9 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp10, 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) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (1,), (1,)) assert_size_stride(primals_5, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (8, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_8, (8,), (1,)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_11, (8,), (1,)) assert_size_stride(primals_12, (1,), (1,)) assert_size_stride(primals_13, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_14, (8,), (1,)) assert_size_stride(primals_15, (16, 8, 4, 4), (128, 16, 4, 1)) assert_size_stride(primals_16, (16,), (1,)) assert_size_stride(primals_17, (1,), (1,)) assert_size_stride(primals_18, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_19, (16,), (1,)) assert_size_stride(primals_20, (1,), (1,)) assert_size_stride(primals_21, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_22, (16,), (1,)) assert_size_stride(primals_23, (8, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_24, (4,), (1,)) assert_size_stride(primals_25, (1,), (1,)) assert_size_stride(primals_26, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_27, (4,), (1,)) assert_size_stride(primals_28, (1,), (1,)) assert_size_stride(primals_29, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_30, (4,), (1,)) assert_size_stride(primals_31, (16, 8, 4, 4), (128, 16, 4, 1)) assert_size_stride(primals_32, (8,), (1,)) assert_size_stride(primals_33, (1,), (1,)) assert_size_stride(primals_34, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_35, (8,), (1,)) assert_size_stride(primals_36, (1,), (1,)) assert_size_stride(primals_37, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_38, (8,), (1,)) assert_size_stride(primals_39, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_40, (16,), (1,)) assert_size_stride(primals_41, (1,), (1,)) assert_size_stride(primals_42, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_43, (16,), (1,)) assert_size_stride(primals_44, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_45, (4,), (1,)) assert_size_stride(primals_46, (1,), (1,)) assert_size_stride(primals_47, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_48, (4,), (1,)) assert_size_stride(primals_49, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_50, (8,), (1,)) assert_size_stride(primals_51, (1,), (1,)) assert_size_stride(primals_52, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_53, (8,), (1,)) assert_size_stride(primals_54, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_55, (16,), (1,)) assert_size_stride(primals_56, (1,), (1,)) assert_size_stride(primals_57, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_58, (16,), (1,)) assert_size_stride(primals_59, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_60, (4,), (1,)) assert_size_stride(primals_61, (1,), (1,)) assert_size_stride(primals_62, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_63, (4,), (1,)) assert_size_stride(primals_64, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_65, (8,), (1,)) assert_size_stride(primals_66, (1,), (1,)) assert_size_stride(primals_67, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_68, (8,), (1,)) assert_size_stride(primals_69, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_70, (4,), (1,)) assert_size_stride(primals_71, (1,), (1,)) assert_size_stride(primals_72, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_73, (4,), (1,)) assert_size_stride(primals_74, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_75, (4,), (1,)) assert_size_stride(primals_76, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf1, primals_3, primals_4, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_1[grid(256)](buf4, primals_6, primals_1, primals_4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_6 buf6 = extern_kernels.convolution(buf5, primals_7, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 8, 2, 2), (32, 4, 2, 1)) buf7 = buf6 del buf6 buf8 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(128)](buf7, primals_8, primals_9, buf8, 128, XBLOCK=128, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf8, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 8, 2, 2), (32, 4, 2, 1)) buf10 = buf9 del buf9 buf11 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(128)](buf10, primals_11, primals_12, buf11, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_11 buf12 = extern_kernels.convolution(buf11, primals_13, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 8, 2, 2), (32, 4, 2, 1)) buf13 = buf12 del buf12 buf14 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_3[grid(128)](buf13, primals_14, buf8, primals_12, buf14, 128, XBLOCK=128, num_warps =4, num_stages=1) del primals_14 buf15 = extern_kernels.convolution(buf14, primals_15, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 16, 1, 1), (16, 1, 1, 1)) buf16 = buf15 del buf15 buf17 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_4[grid(64)](buf16, primals_16, primals_17, buf17, 64, XBLOCK=64, num_warps=1, num_stages=1) buf18 = extern_kernels.convolution(buf17, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 16, 1, 1), (16, 1, 1, 1)) buf19 = buf18 del buf18 buf20 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_4[grid(64)](buf19, primals_19, primals_20, buf20, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_19 buf21 = extern_kernels.convolution(buf20, primals_21, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf21, (4, 16, 1, 1), (16, 1, 1, 1)) buf22 = buf21 del buf21 buf23 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_5[grid(64)](buf22, primals_22, buf17, primals_20, buf23, 64, XBLOCK=64, num_warps= 1, num_stages=1) del primals_22 buf24 = extern_kernels.convolution(buf14, primals_23, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 4, 4, 4), (64, 16, 4, 1)) buf25 = buf24 del buf24 buf26 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_6[grid(256)](buf25, primals_24, buf5, primals_25, buf26, 256, XBLOCK=128, num_warps =4, num_stages=1) buf27 = extern_kernels.convolution(buf26, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 4, 4, 4), (64, 16, 4, 1)) buf28 = buf27 del buf27 buf29 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf28, primals_27, primals_28, buf29, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_27 buf30 = extern_kernels.convolution(buf29, primals_29, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 4, 4, 4), (64, 16, 4, 1)) buf31 = buf30 del buf30 buf32 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_7[grid(256)](buf31, primals_30, buf26, primals_28, buf32, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_30 buf33 = extern_kernels.convolution(buf32, primals_7, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf33, (4, 8, 2, 2), (32, 4, 2, 1)) buf35 = extern_kernels.convolution(buf23, primals_31, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf35, (4, 8, 2, 2), (32, 4, 2, 1)) buf34 = buf33 del buf33 buf36 = buf35 del buf35 buf37 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_8[grid(128)](buf34, buf36, primals_8, primals_32, buf14, primals_9, primals_33, buf37, 128, XBLOCK=128, num_warps=4, num_stages=1) buf38 = extern_kernels.convolution(buf37, primals_34, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 8, 2, 2), (32, 4, 2, 1)) buf39 = buf38 del buf38 buf40 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(128)](buf39, primals_35, primals_36, buf40, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_35 buf41 = extern_kernels.convolution(buf40, primals_37, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf41, (4, 8, 2, 2), (32, 4, 2, 1)) buf42 = buf41 del buf41 buf43 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_3[grid(128)](buf42, primals_38, buf37, primals_36, buf43, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_38 buf44 = extern_kernels.convolution(buf43, primals_15, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 16, 1, 1), (16, 1, 1, 1)) buf45 = buf44 del buf44 buf46 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_9[grid(64)](buf45, primals_16, buf23, primals_17, buf46, 64, XBLOCK=64, num_warps= 1, num_stages=1) buf47 = extern_kernels.convolution(buf46, primals_39, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf47, (4, 16, 1, 1), (16, 1, 1, 1)) buf48 = buf47 del buf47 buf49 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_4[grid(64)](buf48, primals_40, primals_41, buf49, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_40 buf50 = extern_kernels.convolution(buf49, primals_42, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf50, (4, 16, 1, 1), (16, 1, 1, 1)) buf51 = buf50 del buf50 buf52 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_5[grid(64)](buf51, primals_43, buf46, primals_41, buf52, 64, XBLOCK=64, num_warps= 1, num_stages=1) del primals_43 buf53 = extern_kernels.convolution(buf43, primals_23, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf53, (4, 4, 4, 4), (64, 16, 4, 1)) buf54 = buf53 del buf53 buf55 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_6[grid(256)](buf54, primals_24, buf32, primals_25, buf55, 256, XBLOCK=128, num_warps=4, num_stages=1) buf56 = extern_kernels.convolution(buf55, primals_44, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 4, 4, 4), (64, 16, 4, 1)) buf57 = buf56 del buf56 buf58 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf57, primals_45, primals_46, buf58, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_45 buf59 = extern_kernels.convolution(buf58, primals_47, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf59, (4, 4, 4, 4), (64, 16, 4, 1)) buf60 = buf59 del buf59 buf61 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_7[grid(256)](buf60, primals_48, buf55, primals_46, buf61, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_48 buf62 = extern_kernels.convolution(buf61, primals_7, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 8, 2, 2), (32, 4, 2, 1)) buf64 = extern_kernels.convolution(buf52, primals_31, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 8, 2, 2), (32, 4, 2, 1)) buf63 = buf62 del buf62 buf65 = buf64 del buf64 buf66 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_8[grid(128)](buf63, buf65, primals_8, primals_32, buf43, primals_9, primals_33, buf66, 128, XBLOCK=128, num_warps=4, num_stages=1) buf67 = extern_kernels.convolution(buf66, primals_49, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf67, (4, 8, 2, 2), (32, 4, 2, 1)) buf68 = buf67 del buf67 buf69 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(128)](buf68, primals_50, primals_51, buf69, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_50 buf70 = extern_kernels.convolution(buf69, primals_52, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 8, 2, 2), (32, 4, 2, 1)) buf71 = buf70 del buf70 buf72 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_3[grid(128)](buf71, primals_53, buf66, primals_51, buf72, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_53 buf73 = extern_kernels.convolution(buf72, primals_15, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf73, (4, 16, 1, 1), (16, 1, 1, 1)) buf74 = buf73 del buf73 buf75 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_9[grid(64)](buf74, primals_16, buf52, primals_17, buf75, 64, XBLOCK=64, num_warps= 1, num_stages=1) del primals_16 buf76 = extern_kernels.convolution(buf75, primals_54, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf76, (4, 16, 1, 1), (16, 1, 1, 1)) buf77 = buf76 del buf76 buf78 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_4[grid(64)](buf77, primals_55, primals_56, buf78, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_55 buf79 = extern_kernels.convolution(buf78, primals_57, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf79, (4, 16, 1, 1), (16, 1, 1, 1)) buf80 = buf79 del buf79 buf81 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_5[grid(64)](buf80, primals_58, buf75, primals_56, buf81, 64, XBLOCK=64, num_warps= 1, num_stages=1) del primals_58 buf82 = extern_kernels.convolution(buf72, primals_23, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf82, (4, 4, 4, 4), (64, 16, 4, 1)) buf83 = buf82 del buf82 buf84 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_6[grid(256)](buf83, primals_24, buf61, primals_25, buf84, 256, XBLOCK=128, num_warps=4, num_stages=1) buf85 = extern_kernels.convolution(buf84, primals_59, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf85, (4, 4, 4, 4), (64, 16, 4, 1)) buf86 = buf85 del buf85 buf87 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf86, primals_60, primals_61, buf87, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_60 buf88 = extern_kernels.convolution(buf87, primals_62, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf88, (4, 4, 4, 4), (64, 16, 4, 1)) buf89 = buf88 del buf88 buf90 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_7[grid(256)](buf89, primals_63, buf84, primals_61, buf90, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_63 buf91 = extern_kernels.convolution(buf90, primals_7, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf91, (4, 8, 2, 2), (32, 4, 2, 1)) buf93 = extern_kernels.convolution(buf81, primals_31, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf93, (4, 8, 2, 2), (32, 4, 2, 1)) buf92 = buf91 del buf91 buf94 = buf93 del buf93 buf95 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_8[grid(128)](buf92, buf94, primals_8, primals_32, buf72, primals_9, primals_33, buf95, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_32 del primals_8 buf96 = extern_kernels.convolution(buf95, primals_64, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf96, (4, 8, 2, 2), (32, 4, 2, 1)) buf97 = buf96 del buf96 buf98 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(128)](buf97, primals_65, primals_66, buf98, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_65 buf99 = extern_kernels.convolution(buf98, primals_67, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf99, (4, 8, 2, 2), (32, 4, 2, 1)) buf100 = buf99 del buf99 buf101 = empty_strided_cuda((4, 8, 2, 2), (32, 4, 2, 1), torch.float32) triton_poi_fused__prelu_kernel_add_convolution_3[grid(128)](buf100, primals_68, buf95, primals_66, buf101, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_68 buf102 = extern_kernels.convolution(buf101, primals_23, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf102, (4, 4, 4, 4), (64, 16, 4, 1)) buf103 = buf102 del buf102 buf104 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32 ) triton_poi_fused__prelu_kernel_add_convolution_6[grid(256)](buf103, primals_24, buf90, primals_25, buf104, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_24 buf105 = extern_kernels.convolution(buf104, primals_69, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf105, (4, 4, 4, 4), (64, 16, 4, 1)) buf106 = buf105 del buf105 buf107 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32 ) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf106, primals_70, primals_71, buf107, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_70 buf108 = extern_kernels.convolution(buf107, primals_72, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf108, (4, 4, 4, 4), (64, 16, 4, 1)) buf109 = buf108 del buf108 buf110 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32 ) triton_poi_fused__prelu_kernel_add_convolution_7[grid(256)](buf109, primals_73, buf104, primals_71, buf110, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_73 buf111 = extern_kernels.convolution(buf110, primals_74, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf111, (4, 4, 4, 4), (64, 16, 4, 1)) buf112 = buf111 del buf111 buf113 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32 ) triton_poi_fused__prelu_kernel_convolution_0[grid(256)](buf112, primals_75, primals_76, buf113, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_75 return (buf113, primals_1, primals_2, primals_4, primals_5, primals_7, primals_9, primals_10, primals_12, primals_13, primals_15, primals_17, primals_18, primals_20, primals_21, primals_23, primals_25, primals_26, primals_28, primals_29, primals_31, primals_33, primals_34, primals_36, primals_37, primals_39, primals_41, primals_42, primals_44, primals_46, primals_47, primals_49, primals_51, primals_52, primals_54, primals_56, primals_57, primals_59, primals_61, primals_62, primals_64, primals_66, primals_67, primals_69, primals_71, primals_72, primals_74, primals_76, buf1, buf2, buf4, buf5, buf7, buf8, buf10, buf11, buf13, buf14, buf16, buf17, buf19, buf20, buf22, buf23, buf25, buf26, buf28, buf29, buf31, buf32, buf34, buf36, buf37, buf39, buf40, buf42, buf43, buf45, buf46, buf48, buf49, buf51, buf52, buf54, buf55, buf57, buf58, buf60, buf61, buf63, buf65, buf66, buf68, buf69, buf71, buf72, buf74, buf75, buf77, buf78, buf80, buf81, buf83, buf84, buf86, buf87, buf89, buf90, buf92, buf94, buf95, buf97, buf98, buf100, buf101, buf103, buf104, buf106, buf107, buf109, buf110, buf112) class ConvBlock(nn.Module): def __init__(self, input_size, output_size, kernel_size=3, stride=1, padding=1, bias=True, activation='prelu', norm=None): super(ConvBlock, self).__init__() self.conv = nn.Conv2d(input_size, output_size, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(output_size) elif self.norm == 'instance': self.bn = nn.InstanceNorm2d(output_size) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): if self.norm is not None: out = self.bn(self.conv(x)) else: out = self.conv(x) if self.activation is not None: return self.act(out) else: return out class DeconvBlock(nn.Module): def __init__(self, input_size, output_size, kernel_size=4, stride=2, padding=1, bias=True, activation='prelu', norm=None): super(DeconvBlock, self).__init__() self.deconv = nn.ConvTranspose2d(input_size, output_size, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(output_size) elif self.norm == 'instance': self.bn = nn.InstanceNorm2d(output_size) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): if self.norm is not None: out = self.bn(self.deconv(x)) else: out = self.deconv(x) if self.activation is not None: return self.act(out) else: return out class ResnetBlock(nn.Module): def __init__(self, num_filter, kernel_size=3, stride=1, padding=1, bias =True, activation='prelu', norm='batch'): super(ResnetBlock, self).__init__() self.conv1 = nn.Conv2d(num_filter, num_filter, kernel_size, stride, padding, bias=bias) self.conv2 = nn.Conv2d(num_filter, num_filter, kernel_size, stride, padding, bias=bias) self.norm = norm if self.norm == 'batch': self.bn = nn.BatchNorm2d(num_filter) elif norm == 'instance': self.bn = nn.InstanceNorm2d(num_filter) self.activation = activation if self.activation == 'relu': self.act = nn.ReLU(True) elif self.activation == 'prelu': self.act = nn.PReLU() elif self.activation == 'lrelu': self.act = nn.LeakyReLU(0.1, True) elif self.activation == 'tanh': self.act = nn.Tanh() elif self.activation == 'sigmoid': self.act = nn.Sigmoid() def forward(self, x): residual = x if self.norm is not None: out = self.bn(self.conv1(x)) else: out = self.conv1(x) if self.activation is not None: out = self.act(out) if self.norm is not None: out = self.bn(self.conv2(out)) else: out = self.conv2(out) out = torch.add(out, residual) if self.activation is not None: out = self.act(out) return out class PyramidModuleNew(nn.Module): def __init__(self, num_inchannels, activation='prelu'): super(PyramidModuleNew, self).__init__() self.l1_1 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_2 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_3 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_4 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l1_5 = ResnetBlock(num_inchannels, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_1 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_2 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_3 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l2_4 = ResnetBlock(num_inchannels * 2, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_1 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_2 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.l3_3 = ResnetBlock(num_inchannels * 4, kernel_size=3, stride=1, padding=1, bias=True, activation=activation, norm=None) self.down1 = ConvBlock(num_inchannels, num_inchannels * 2, 4, 2, 1, bias=True, activation=activation, norm=None) self.down2 = ConvBlock(num_inchannels * 2, num_inchannels * 4, 4, 2, 1, bias=True, activation=activation, norm=None) self.up1 = DeconvBlock(num_inchannels * 2, num_inchannels, 4, 2, 1, bias=True, activation=activation, norm=None) self.up2 = DeconvBlock(num_inchannels * 4, num_inchannels * 2, 4, 2, 1, bias=True, activation=activation, norm=None) self.final = ConvBlock(num_inchannels, num_inchannels, 3, 1, 1, bias=True, activation=activation, norm=None) def forward(self, input_0): primals_2 = self.l1_1.conv1.weight primals_3 = self.l1_1.conv1.bias primals_5 = self.l1_1.conv2.weight primals_6 = self.l1_1.conv2.bias primals_4 = self.l1_1.act.weight primals_26 = self.l1_2.conv1.weight primals_24 = self.l1_2.conv1.bias primals_29 = self.l1_2.conv2.weight primals_27 = self.l1_2.conv2.bias primals_9 = self.l1_2.act.weight primals_44 = self.l1_3.conv1.weight primals_30 = self.l1_3.conv1.bias primals_47 = self.l1_3.conv2.weight primals_45 = self.l1_3.conv2.bias primals_12 = self.l1_3.act.weight primals_59 = self.l1_4.conv1.weight primals_48 = self.l1_4.conv1.bias primals_62 = self.l1_4.conv2.weight primals_60 = self.l1_4.conv2.bias primals_17 = self.l1_4.act.weight primals_69 = self.l1_5.conv1.weight primals_63 = self.l1_5.conv1.bias primals_72 = self.l1_5.conv2.weight primals_70 = self.l1_5.conv2.bias primals_20 = self.l1_5.act.weight primals_10 = self.l2_1.conv1.weight primals_8 = self.l2_1.conv1.bias primals_13 = self.l2_1.conv2.weight primals_11 = self.l2_1.conv2.bias primals_25 = self.l2_1.act.weight primals_34 = self.l2_2.conv1.weight primals_14 = self.l2_2.conv1.bias primals_37 = self.l2_2.conv2.weight primals_32 = self.l2_2.conv2.bias primals_28 = self.l2_2.act.weight primals_49 = self.l2_3.conv1.weight primals_35 = self.l2_3.conv1.bias primals_52 = self.l2_3.conv2.weight primals_38 = self.l2_3.conv2.bias primals_33 = self.l2_3.act.weight primals_64 = self.l2_4.conv1.weight primals_50 = self.l2_4.conv1.bias primals_67 = self.l2_4.conv2.weight primals_53 = self.l2_4.conv2.bias primals_36 = self.l2_4.act.weight primals_18 = self.l3_1.conv1.weight primals_16 = self.l3_1.conv1.bias primals_21 = self.l3_1.conv2.weight primals_19 = self.l3_1.conv2.bias primals_41 = self.l3_1.act.weight primals_39 = self.l3_2.conv1.weight primals_22 = self.l3_2.conv1.bias primals_42 = self.l3_2.conv2.weight primals_40 = self.l3_2.conv2.bias primals_46 = self.l3_2.act.weight primals_54 = self.l3_3.conv1.weight primals_43 = self.l3_3.conv1.bias primals_57 = self.l3_3.conv2.weight primals_55 = self.l3_3.conv2.bias primals_51 = self.l3_3.act.weight primals_7 = self.down1.conv.weight primals_65 = self.down1.conv.bias primals_56 = self.down1.act.weight primals_15 = self.down2.conv.weight primals_58 = self.down2.conv.bias primals_61 = self.down2.act.weight primals_23 = self.up1.deconv.weight primals_73 = self.up1.deconv.bias primals_66 = self.up1.act.weight primals_31 = self.up2.deconv.weight primals_68 = self.up2.deconv.bias primals_71 = self.up2.act.weight primals_74 = self.final.conv.weight primals_75 = self.final.conv.bias primals_76 = self.final.act.weight 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, 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]) return output[0]
arnon-weinberg/Upscale-interpolate-STARnet
PyramidModule
false
12,154
[ "MIT" ]
0
d898d38364a36f4633cfba8f914db20d9b900217
https://github.com/arnon-weinberg/Upscale-interpolate-STARnet/tree/d898d38364a36f4633cfba8f914db20d9b900217
LowRankPositionwiseFeedForward
import torch import torch.nn as nn import torch.utils.checkpoint import torch.nn.functional as F from torch.cuda.amp import autocast class LowRankPositionwiseFeedForward(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1_u = nn.Linear(d_in, int(d_in / 4), bias=False) self.w_1_v = nn.Linear(int(d_in / 4), d_hid) self.w_2_u = nn.Linear(d_hid, int(d_in / 4), bias=False) self.w_2_v = nn.Linear(int(d_in / 4), d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) @autocast() def forward(self, x): residual = x x = self.w_2_v(self.w_2_u(F.relu(self.w_1_v(self.w_1_u(x))))) x = self.dropout(x) x += residual x = self.layer_norm(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_in': 4, 'd_hid': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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__to_copy_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused__to_copy_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.float32) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask).to(tl.float32) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp1.to(tl.float32) 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 + x2, tmp5, xmask) tl.store(out_ptr0 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last').to(tl .float32) tmp2 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.float32) tmp6 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.float32) tmp11 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ).to(tl.float32) tmp16 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = tmp0.to(tl.float32) tmp3 = tmp1 + tmp2 tmp5 = tmp4.to(tl.float32) tmp7 = tmp5 + tmp6 tmp8 = tmp3 + tmp7 tmp10 = tmp9.to(tl.float32) tmp12 = tmp10 + tmp11 tmp13 = tmp8 + tmp12 tmp15 = tmp14.to(tl.float32) tmp17 = tmp15 + tmp16 tmp18 = tmp13 + tmp17 tmp19 = 4.0 tmp20 = tmp18 / tmp19 tmp21 = tmp3 - tmp20 tmp22 = tmp21 * tmp21 tmp23 = tmp7 - tmp20 tmp24 = tmp23 * tmp23 tmp25 = tmp22 + tmp24 tmp26 = tmp12 - tmp20 tmp27 = tmp26 * tmp26 tmp28 = tmp25 + tmp27 tmp29 = tmp17 - tmp20 tmp30 = tmp29 * tmp29 tmp31 = tmp28 + tmp30 tmp32 = tmp31 / tmp19 tl.store(out_ptr0 + x0, tmp20, xmask) tl.store(out_ptr1 + x0, tmp32, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask).to(tl.float32) tmp2 = tl.load(in_ptr1 + x2, xmask) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp1 = tmp0.to(tl.float32) tmp3 = tmp1 + tmp2 tmp5 = tmp3 - tmp4 tmp7 = 1e-06 tmp8 = tmp6 + tmp7 tmp9 = libdevice.rsqrt(tmp8) tmp10 = tmp5 * tmp9 tmp12 = tmp10 * tmp11 tmp14 = tmp12 + tmp13 tl.store(out_ptr0 + x2, tmp14, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4), (4, 1)) assert_size_stride(primals_3, (4, 1), (1, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (1, 4), (4, 1)) assert_size_stride(primals_6, (4, 1), (1, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float16) get_raw_stream(0) triton_poi_fused__to_copy_0[grid(256)](primals_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((1, 4), (4, 1), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_2, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (4, 1), (1, 0), 0), out=buf2) buf3 = buf1 del buf1 triton_poi_fused__to_copy_1[grid(4)](primals_3, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float16) extern_kernels.mm(buf2, buf3, out=buf4) buf5 = empty_strided_cuda((4, 1), (1, 4), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_5, buf5, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_5 buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(256)](buf6, primals_4, buf14, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf7 = empty_strided_cuda((64, 1), (1, 1), torch.float16) extern_kernels.mm(reinterpret_tensor(buf6, (64, 4), (4, 1), 0), buf5, out=buf7) buf8 = empty_strided_cuda((4, 1), (1, 1), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_6, buf8, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_6 buf9 = empty_strided_cuda((4,), (1,), torch.float16) triton_poi_fused__to_copy_1[grid(4)](primals_7, buf9, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_7 buf10 = empty_strided_cuda((64, 4), (4, 1), torch.float16) extern_kernels.addmm(buf9, buf7, reinterpret_tensor(buf8, (1, 4), ( 0, 1), 0), alpha=1, beta=1, out=buf10) del buf9 buf11 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf12 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_native_layer_norm_3[grid(64)](buf10, primals_1, buf11, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_4[grid(256)](buf10, primals_1, buf11, buf12, primals_8, primals_9, buf13, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf11 del buf12 del primals_9 return buf13, primals_1, primals_8, reinterpret_tensor(buf0, (64, 4), ( 4, 1), 0), buf2, reinterpret_tensor(buf6, (64, 4), (4, 1), 0 ), buf7, buf10, buf8, reinterpret_tensor(buf5, (1, 4), (4, 1), 0 ), buf14, reinterpret_tensor(buf3, (4, 1), (1, 1), 0) class LowRankPositionwiseFeedForwardNew(nn.Module): """ A two-feed-forward-layer module """ def __init__(self, d_in, d_hid, dropout=0.1): super().__init__() self.w_1_u = nn.Linear(d_in, int(d_in / 4), bias=False) self.w_1_v = nn.Linear(int(d_in / 4), d_hid) self.w_2_u = nn.Linear(d_hid, int(d_in / 4), bias=False) self.w_2_v = nn.Linear(int(d_in / 4), d_in) self.layer_norm = nn.LayerNorm(d_in, eps=1e-06) self.dropout = nn.Dropout(dropout) def forward(self, input_0): primals_2 = self.w_1_u.weight primals_3 = self.w_1_v.weight primals_4 = self.w_1_v.bias primals_5 = self.w_2_u.weight primals_6 = self.w_2_v.weight primals_7 = self.w_2_v.bias primals_8 = self.layer_norm.weight primals_9 = self.layer_norm.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
bahducoup/factorized_training
LowRankPositionwiseFeedForward
false
12,155
[ "MIT" ]
0
0af38f16338a9bcfcc11091b1a6b75befd67f234
https://github.com/bahducoup/factorized_training/tree/0af38f16338a9bcfcc11091b1a6b75befd67f234