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
Mix
import torch import torch.nn as nn class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer() self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x class Mix(nn.Module): def __init__(self, dim, y_dim, num_heads, mlp_ratio=4.0, y_mlp_ratio= 4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn.GELU, norm_layer=nn.LayerNorm): super().__init__() self.norm1 = norm_layer(y_dim) y_mlp_hidden_dim = int(y_dim / y_mlp_ratio) self.channel_mlp = Mlp(in_features=y_dim, hidden_features= y_mlp_hidden_dim, act_layer=act_layer, drop=drop) self.drop_path = DropPath(drop_path ) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) def forward(self, x): x = x + self.drop_path(self.channel_mlp(self.norm1(x.transpose(1, 2 ).contiguous())).transpose(1, 2).contiguous()) x = x + self.drop_path(self.mlp(self.norm2(x))) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4, 'y_dim': 4, 'num_heads': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import 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_clone_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_clone_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x5 = xindex // 4 x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + x5, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x5, 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 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp8, xmask) @triton.jit def triton_poi_fused_gelu_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865476 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_clone_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 x3 = xindex x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (4 * x1 + 16 * x0 + 64 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x1 + 16 * x0 + 64 * x2), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x1 + 16 * x0 + 64 * x2), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x1 + 16 * x0 + 64 * x2), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 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 + x3, tmp16, xmask) tl.store(out_ptr1 + x3, tmp28, xmask) @triton.jit def triton_poi_fused_add_clone_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 x4 = xindex x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x5 = xindex // 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tmp3 = tl.load(in_ptr2 + x5, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x5, 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 + x4, tmp13, xmask) @triton.jit def triton_poi_fused_gelu_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865476 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_clone_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tmp3 = tl.load(in_out_ptr0 + x4, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tl.store(in_out_ptr0 + x4, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (1, 4), (4, 1)) assert_size_stride(primals_5, (1,), (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,)) assert_size_stride(primals_10, (16, 4), (4, 1)) assert_size_stride(primals_11, (16,), (1,)) assert_size_stride(primals_12, (4, 16), (16, 1)) assert_size_stride(primals_13, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) get_raw_stream(0) triton_poi_fused_clone_native_layer_norm_0[grid(64)](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_clone_native_layer_norm_1[grid(256)](primals_1, buf0, buf1, primals_2, primals_3, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 del primals_3 buf4 = reinterpret_tensor(buf1, (64, 1), (1, 1), 0) del buf1 extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_5 buf5 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 triton_poi_fused_gelu_2[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf5, (64, 1), ( 1, 0), 0), reinterpret_tensor(primals_6, (1, 4), (1, 1), 0), alpha=1, beta=1, out=buf6) del primals_7 buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_add_clone_native_layer_norm_3[grid(64)](primals_1, buf6, buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_clone_native_layer_norm_4[grid(256)](primals_1, buf6, buf7, buf8, primals_8, primals_9, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf7 del buf8 del primals_9 buf10 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf9, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf10) del primals_11 buf11 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch. float32) triton_poi_fused_gelu_5[grid(1024)](buf10, buf11, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf12 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf11, (64, 16), (16, 1), 0), reinterpret_tensor(primals_12, (16, 4), (1, 16), 0), out=buf12) buf13 = reinterpret_tensor(buf12, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf12 triton_poi_fused_add_clone_6[grid(256)](buf13, primals_1, buf6, primals_13, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_13 return buf13, primals_1, primals_8, reinterpret_tensor(buf2, (64, 4), ( 4, 1), 0), buf4, reinterpret_tensor(buf5, (64, 1), (1, 1), 0 ), buf6, reinterpret_tensor(buf9, (64, 4), (4, 1), 0 ), buf10, reinterpret_tensor(buf11, (64, 16), (16, 1), 0 ), primals_12, primals_10, primals_6, primals_4 class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer() self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x class MixNew(nn.Module): def __init__(self, dim, y_dim, num_heads, mlp_ratio=4.0, y_mlp_ratio= 4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn.GELU, norm_layer=nn.LayerNorm): super().__init__() self.norm1 = norm_layer(y_dim) y_mlp_hidden_dim = int(y_dim / y_mlp_ratio) self.channel_mlp = Mlp(in_features=y_dim, hidden_features= y_mlp_hidden_dim, act_layer=act_layer, drop=drop) self.drop_path = DropPath(drop_path ) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) def forward(self, input_0): primals_2 = self.norm1.weight primals_3 = self.norm1.bias primals_4 = self.channel_mlp.fc1.weight primals_5 = self.channel_mlp.fc1.bias primals_6 = self.channel_mlp.fc2.weight primals_7 = self.channel_mlp.fc2.bias primals_8 = self.norm2.weight primals_9 = self.norm2.bias primals_10 = self.mlp.fc1.weight primals_11 = self.mlp.fc1.bias primals_12 = self.mlp.fc2.weight primals_13 = self.mlp.fc2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0]
gaopengcuhk/deit
Mix
false
3,516
[ "Apache-2.0" ]
0
de7db8f3a12c35e5e554b385030c574b7c78aaa6
https://github.com/gaopengcuhk/deit/tree/de7db8f3a12c35e5e554b385030c574b7c78aaa6
CQAttention
import torch import torch.nn as nn import torch.nn.functional as F def mask_logits(target, mask): mask = mask.type(torch.float32) return target * mask + (1 - mask) * -1e+30 class CQAttention(nn.Module): def __init__(self, d_model, dropout=0.1): super().__init__() w4C = torch.empty(d_model, 1) w4Q = torch.empty(d_model, 1) w4mlu = torch.empty(1, 1, d_model) nn.init.xavier_uniform_(w4C) nn.init.xavier_uniform_(w4Q) nn.init.xavier_uniform_(w4mlu) self.w4C = nn.Parameter(w4C) self.w4Q = nn.Parameter(w4Q) self.w4mlu = nn.Parameter(w4mlu) bias = torch.empty(1) nn.init.constant_(bias, 0) self.bias = nn.Parameter(bias) self.dropout = dropout def forward(self, C, Q, Cmask, Qmask): C = C.transpose(1, 2) Q = Q.transpose(1, 2) batch_size_c = C.size()[0] _batch_size, Lc, _d_model = C.shape _batch_size, Lq, _d_model = Q.shape S = self.trilinear_for_attention(C, Q) Cmask = Cmask.view(batch_size_c, Lc, 1) Qmask = Qmask.view(batch_size_c, 1, Lq) S1 = F.softmax(mask_logits(S, Qmask), dim=2) S2 = F.softmax(mask_logits(S, Cmask), dim=1) A = torch.bmm(S1, Q) B = torch.bmm(torch.bmm(S1, S2.transpose(1, 2)), C) out = torch.cat([C, A, torch.mul(C, A), torch.mul(C, B)], dim=2) return out.transpose(1, 2) def trilinear_for_attention(self, C, Q): _batch_size, Lc, _d_model = C.shape _batch_size, Lq, _d_model = Q.shape dropout = self.dropout C = F.dropout(C, p=dropout, training=self.training) Q = F.dropout(Q, p=dropout, training=self.training) subres0 = torch.matmul(C, self.w4C).expand([-1, -1, Lq]) subres1 = torch.matmul(Q, self.w4Q).transpose(1, 2).expand([-1, Lc, -1] ) subres2 = torch.matmul(C * self.w4mlu, Q.transpose(1, 2)) res = subres0 + subres1 + subres2 res += self.bias return res def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 1]), torch.rand([4, 1, 4])] def get_init_inputs(): return [[], {'d_model': 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 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__unsafe_view_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (4 * x1 + 16 * (y0 // 4) + y0 % 4), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr2 + x4, xmask) tmp5 = tl.load(in_ptr3 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp8 = tl.load(in_ptr4 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr5 + x3, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp7 = tmp4 + tmp6 tmp9 = tmp7 * tmp8 tmp10 = 1.0 tmp11 = tmp10 - tmp8 tmp12 = -1e+30 tmp13 = tmp11 * tmp12 tmp14 = tmp9 + tmp13 tmp16 = tmp7 * tmp15 tmp17 = tmp10 - tmp15 tmp18 = tmp17 * tmp12 tmp19 = tmp16 + tmp18 tl.store(out_ptr0 + x4, tmp14, xmask) tl.store(out_ptr1 + x4, tmp19, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 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 = 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) @triton.jit def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_cat_7(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex // 16 x4 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x1 + 4 * x0 + 16 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (4 * x3 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + (x1 + 4 * (-8 + x0) + 16 * x2), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.load(in_ptr1 + (4 * x3 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tmp15 * tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp14, tmp17, tmp18) tmp20 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp23 = tl.load(in_ptr0 + (x1 + 4 * (-12 + x0) + 16 * x2), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tl.load(in_ptr2 + (4 * x3 + (-12 + x0)), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = tmp23 * tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp20, tmp25, tmp26) tmp28 = tl.where(tmp14, tmp19, tmp27) tmp29 = tl.where(tmp9, tmp10, tmp28) tmp30 = tl.where(tmp4, tmp5, tmp29) tl.store(out_ptr0 + x4, tmp30, 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), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 1), (1, 1)) assert_size_stride(primals_4, (4, 1), (1, 1)) assert_size_stride(primals_5, (1, 1, 4), (4, 4, 1)) assert_size_stride(primals_6, (1,), (1,)) assert_size_stride(primals_7, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_8, (4, 1, 4), (4, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_view_clone_0[grid(16, 4)](primals_1, buf0, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.mm(buf0, primals_3, out=buf1) del primals_3 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) triton_poi_fused__unsafe_view_clone_0[grid(16, 4)](primals_2, buf2, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.mm(buf2, primals_4, out=buf3) del primals_4 buf4 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) triton_poi_fused_mul_1[grid(64)](primals_1, primals_5, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf4, primals_2, out=buf5) buf6 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0) del buf4 buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_rsub_2[grid(64)](buf1, buf3, buf5, primals_6, primals_8, primals_7, buf6, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 del buf3 del primals_6 buf7 = buf5 del buf5 triton_poi_fused__softmax_3[grid(64)](buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = buf6 del buf6 triton_poi_fused__softmax_4[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf10 = buf7 del buf7 triton_poi_fused__softmax_5[grid(64)](buf9, buf10, 64, XBLOCK=64, num_warps=1, num_stages=1) buf11 = buf9 del buf9 triton_poi_fused__softmax_6[grid(64)](buf10, buf11, 64, XBLOCK=64, num_warps=1, num_stages=1) buf12 = buf10 del buf10 extern_kernels.bmm(buf8, reinterpret_tensor(primals_2, (4, 4, 4), ( 16, 1, 4), 0), out=buf12) buf13 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf8, reinterpret_tensor(buf11, (4, 4, 4), (16, 1, 4), 0), out=buf13) buf14 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf13, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), out=buf14) del buf13 buf15 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_cat_7[grid(256)](primals_1, buf12, buf14, buf15, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf12 del buf14 return reinterpret_tensor(buf15, (4, 16, 4), (64, 1, 16), 0 ), primals_7, primals_8, reinterpret_tensor(primals_1, (4, 4, 4), ( 16, 1, 4), 0), primals_2, buf8, buf11, reinterpret_tensor(buf2, (4, 16), (1, 4), 0), reinterpret_tensor(buf0, (4, 16), (1, 4), 0) def mask_logits(target, mask): mask = mask.type(torch.float32) return target * mask + (1 - mask) * -1e+30 class CQAttentionNew(nn.Module): def __init__(self, d_model, dropout=0.1): super().__init__() w4C = torch.empty(d_model, 1) w4Q = torch.empty(d_model, 1) w4mlu = torch.empty(1, 1, d_model) nn.init.xavier_uniform_(w4C) nn.init.xavier_uniform_(w4Q) nn.init.xavier_uniform_(w4mlu) self.w4C = nn.Parameter(w4C) self.w4Q = nn.Parameter(w4Q) self.w4mlu = nn.Parameter(w4mlu) bias = torch.empty(1) nn.init.constant_(bias, 0) self.bias = nn.Parameter(bias) self.dropout = dropout def trilinear_for_attention(self, C, Q): _batch_size, Lc, _d_model = C.shape _batch_size, Lq, _d_model = Q.shape dropout = self.dropout C = F.dropout(C, p=dropout, training=self.training) Q = F.dropout(Q, p=dropout, training=self.training) subres0 = torch.matmul(C, self.w4C).expand([-1, -1, Lq]) subres1 = torch.matmul(Q, self.w4Q).transpose(1, 2).expand([-1, Lc, -1] ) subres2 = torch.matmul(C * self.w4mlu, Q.transpose(1, 2)) res = subres0 + subres1 + subres2 res += self.bias return res def forward(self, input_0, input_1, input_2, input_3): primals_3 = self.w4C primals_4 = self.w4Q primals_5 = self.w4mlu primals_6 = self.bias primals_1 = input_0 primals_2 = input_1 primals_7 = input_2 primals_8 = input_3 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
dcy2018/QANA
CQAttention
false
3,517
[ "MIT" ]
0
69d1e4ff408a56317479e22ecc854c91fc0f420f
https://github.com/dcy2018/QANA/tree/69d1e4ff408a56317479e22ecc854c91fc0f420f
CMlp
import torch import torch.nn as nn class CMlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Conv2d(in_features, hidden_features, 1) self.act = act_layer() self.fc2 = nn.Conv2d(hidden_features, out_features, 1) self.drop = nn.Dropout(drop) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import 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_gelu_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 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 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = 0.7071067811865476 tmp6 = tmp2 * tmp5 tmp7 = libdevice.erf(tmp6) tmp8 = 1.0 tmp9 = tmp7 + tmp8 tmp10 = tmp4 * tmp9 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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, 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_convolution_gelu_0[grid(256)](buf1, primals_2, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 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_convolution_1[grid(256)](buf4, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf4, primals_1, primals_3, primals_4, buf1, buf2 class CMlpNew(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Conv2d(in_features, hidden_features, 1) self.act = act_layer() self.fc2 = nn.Conv2d(hidden_features, out_features, 1) self.drop = nn.Dropout(drop) 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]
gaopengcuhk/deit
CMlp
false
3,518
[ "Apache-2.0" ]
0
de7db8f3a12c35e5e554b385030c574b7c78aaa6
https://github.com/gaopengcuhk/deit/tree/de7db8f3a12c35e5e554b385030c574b7c78aaa6
GCN
from torch.nn import Module import math import torch import torch.nn.functional as F import torch.nn as nn class GraphConvolution(Module): """ A Graph Convolution Layer (GCN) """ def __init__(self, in_features, out_features, bias=True): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.W = nn.Linear(in_features, out_features, bias=bias) self.init() def init(self): stdv = 1.0 / math.sqrt(self.W.weight.size(1)) self.W.weight.data.uniform_(-stdv, stdv) def forward(self, input, adj): support = self.W(input) output = torch.spmm(adj, support) return output class GCN(nn.Module): """ A Two-layer GCN. """ def __init__(self, nfeat, nhid, nclass, dropout): super(GCN, self).__init__() self.gc1 = GraphConvolution(nfeat, nhid) self.gc2 = GraphConvolution(nhid, 1024) self.gc3 = GraphConvolution(1024, nclass) self.dropout = dropout def forward(self, x, adj, use_relu=True): x = self.gc1(x, adj) if use_relu: x = F.relu(x) x = F.dropout(x, self.dropout, training=self.training) x = self.gc2(x, adj) if use_relu: x = F.relu(x) x = F.dropout(x, self.dropout, training=self.training) x = self.gc3(x, adj) return x def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'nfeat': 4, 'nhid': 4, 'nclass': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch.nn import Module 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_relu_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, None) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(in_out_ptr0 + x0, tmp2, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (1024, 4), (4, 1)) assert_size_stride(primals_6, (1024,), (1,)) assert_size_stride(primals_7, (4, 1024), (1024, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, primals_3, reinterpret_tensor( primals_1, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_4, buf0, out=buf1) buf2 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_relu_0[grid(16)](buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32) extern_kernels.addmm(primals_6, buf2, reinterpret_tensor(primals_5, (4, 1024), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_6 buf4 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32) extern_kernels.mm(primals_4, buf3, out=buf4) del buf3 buf5 = buf4 del buf4 triton_poi_fused_relu_1[grid(4096)](buf5, 4096, XBLOCK=256, num_warps=4, num_stages=1) buf6 = buf0 del buf0 extern_kernels.addmm(primals_8, buf5, reinterpret_tensor(primals_7, (1024, 4), (1, 1024), 0), alpha=1, beta=1, out=buf6) del primals_8 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_4, buf6, out=buf7) del buf6 return buf7, primals_3, buf2, buf5, reinterpret_tensor(primals_4, (4, 4 ), (1, 4), 0), primals_7, primals_5 class GraphConvolution(Module): """ A Graph Convolution Layer (GCN) """ def __init__(self, in_features, out_features, bias=True): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.W = nn.Linear(in_features, out_features, bias=bias) self.init() def init(self): stdv = 1.0 / math.sqrt(self.W.weight.size(1)) self.W.weight.data.uniform_(-stdv, stdv) def forward(self, input, adj): support = self.W(input) output = torch.spmm(adj, support) return output class GCNNew(nn.Module): """ A Two-layer GCN. """ def __init__(self, nfeat, nhid, nclass, dropout): super(GCNNew, self).__init__() self.gc1 = GraphConvolution(nfeat, nhid) self.gc2 = GraphConvolution(nhid, 1024) self.gc3 = GraphConvolution(1024, nclass) self.dropout = dropout def forward(self, input_0, input_1): primals_1 = self.gc1.W.weight primals_2 = self.gc1.W.bias primals_5 = self.gc2.W.weight primals_6 = self.gc2.W.bias primals_7 = self.gc3.W.weight primals_8 = self.gc3.W.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]
duzhizhai/HGNN
GCN
false
3,519
[ "MIT" ]
0
1d219f9eb773e0d2f585295d6fc13c2eb093d908
https://github.com/duzhizhai/HGNN/tree/1d219f9eb773e0d2f585295d6fc13c2eb093d908
Attention
import torch import numpy as np import torch as th import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): def __init__(self, model_dim, n_heads=1): super(Attention, self).__init__() self.model_dim = model_dim self.dim_per_head = model_dim // n_heads self.n_heads = n_heads self.fcq = nn.Linear(model_dim, self.dim_per_head * n_heads) self.fck = nn.Linear(model_dim, self.dim_per_head * n_heads) self.fcv = nn.Linear(model_dim, self.dim_per_head * n_heads) self.layer_norm = nn.LayerNorm(model_dim) def forward(self, queries, keys, values): """ queries: batch * model_dim keys: batch * ? * model_dim values: batch * ? * model_dim """ residual = queries batch_size = queries.size(0) q = self.fcq(queries).view(batch_size * self.n_heads, 1, self. dim_per_head) k = self.fck(keys).view(batch_size, -1, self.n_heads, self.dim_per_head ).transpose(1, 2).reshape(batch_size * self.n_heads, -1, self. dim_per_head) v = self.fcv(values).view(batch_size, -1, self.n_heads, self. dim_per_head).transpose(1, 2).reshape(batch_size * self.n_heads, -1, self.dim_per_head) weight = th.bmm(q, k.transpose(1, 2)) / np.sqrt(self.dim_per_head) attn = th.bmm(F.softmax(weight, dim=-1), v) attn = attn.view(batch_size, self.n_heads * self.dim_per_head) return self.layer_norm(attn + residual) def get_inputs(): return [torch.rand([4, 1, 4]), torch.rand([4, 4, 4, 4]), torch.rand([4, 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 from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__softmax_sqrt_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.full([1, 1], 2.0, tl.float64) tmp2 = tl.full([1, 1], 0.0, tl.float64) tmp3 = tmp1 >= tmp2 tmp4 = 1.0 tmp5 = -1.0 tmp6 = tl.where(tmp3, tmp4, tmp5) tmp7 = tmp0 * tmp6 tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = tl.where(xmask, tmp8, float('-inf')) tmp11 = triton_helpers.max2(tmp10, 1)[:, None] tmp12 = tmp7 - tmp11 tmp13 = tmp6.to(tl.float64) tmp14 = tmp13 * tmp1 tmp15 = tmp14.to(tl.float32) tmp16 = tmp12 / tmp15 tmp17 = tl_math.exp(tmp16) tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK]) tmp20 = tl.where(xmask, tmp18, 0) tmp21 = tl.sum(tmp20, 1)[:, None] tmp22 = tmp17 / tmp21 tl.store(out_ptr2 + (r1 + 16 * x0), tmp22, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x1, 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 * x1), 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 * x1), 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 * x1), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 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 + x2, tmp16, xmask) tl.store(out_ptr1 + x2, tmp28, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex % 16 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex // 4 x5 = xindex tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x4, 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 + x5, 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, (4, 1, 4), (4, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_10, (4,), (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, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (4, 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((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_8, reinterpret_tensor(primals_9, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf2) del primals_7 del primals_8 buf3 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (4, 1, 4), (4, 4, 1), 0 ), reinterpret_tensor(buf1, (4, 4, 16), (64, 1, 4), 0), out=buf3) buf6 = empty_strided_cuda((4, 1, 16), (16, 16, 1), torch.float32) get_raw_stream(0) triton_per_fused__softmax_sqrt_0[grid(4)](buf3, buf6, 4, 16, XBLOCK =1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((4, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(buf6, reinterpret_tensor(buf2, (4, 16, 4), (64, 4, 1), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf9 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_add_native_layer_norm_1[grid(16)](buf7, primals_1, buf8, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1) buf10 = reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0) del buf3 triton_poi_fused_add_native_layer_norm_2[grid(64)](buf7, primals_1, buf8, buf9, primals_10, primals_11, buf10, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf8 del buf9 del primals_11 return buf10, primals_1, primals_10, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0 ), buf6, buf7, reinterpret_tensor(buf2, (4, 4, 16), (64, 1, 4), 0 ), reinterpret_tensor(buf0, (4, 4, 1), (4, 1, 4), 0 ), reinterpret_tensor(buf1, (4, 16, 4), (64, 4, 1), 0) class AttentionNew(nn.Module): def __init__(self, model_dim, n_heads=1): super(AttentionNew, self).__init__() self.model_dim = model_dim self.dim_per_head = model_dim // n_heads self.n_heads = n_heads self.fcq = nn.Linear(model_dim, self.dim_per_head * n_heads) self.fck = nn.Linear(model_dim, self.dim_per_head * n_heads) self.fcv = nn.Linear(model_dim, self.dim_per_head * n_heads) self.layer_norm = nn.LayerNorm(model_dim) def forward(self, input_0, input_1, input_2): primals_2 = self.fcq.weight primals_3 = self.fcq.bias primals_4 = self.fck.weight primals_5 = self.fck.bias primals_7 = self.fcv.weight primals_8 = self.fcv.bias primals_10 = self.layer_norm.weight primals_11 = self.layer_norm.bias primals_1 = input_0 primals_6 = input_1 primals_9 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
footoredo/pymarl
Attention
false
3,520
[ "Apache-2.0" ]
0
9c62dda7a7ed984e020f2cafab93601342305af2
https://github.com/footoredo/pymarl/tree/9c62dda7a7ed984e020f2cafab93601342305af2
MaskedMSELoss
import torch import torch.nn as nn class MaskedMSELoss(nn.Module): def __init__(self): super(MaskedMSELoss, self).__init__() self.loss = nn.MSELoss(reduction='sum') def forward(self, pred, target, mask): """ pred -> batch*seq_len target -> batch*seq_len mask -> batch*seq_len """ loss = self.loss(pred * mask, target) / torch.sum(mask) 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_div_mse_loss_mul_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp3 = tl.load(in_ptr2 + r0, None) tmp2 = tmp0 * tmp1 tmp4 = tmp2 - tmp3 tmp5 = tmp4 * tmp4 tmp6 = tl.broadcast_to(tmp5, [RBLOCK]) tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0)) tmp9 = tl.broadcast_to(tmp1, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = tmp8 / tmp11 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp12, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_div_mse_loss_mul_sum_0[grid(1)](buf2, arg0_1, arg1_1, arg2_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class MaskedMSELossNew(nn.Module): def __init__(self): super(MaskedMSELossNew, self).__init__() self.loss = nn.MSELoss(reduction='sum') 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]
filkar/CASTLE
MaskedMSELoss
false
3,521
[ "MIT" ]
0
128b316d24503875bcc298301c17b003e6d4599d
https://github.com/filkar/CASTLE/tree/128b316d24503875bcc298301c17b003e6d4599d
Net16
import torch import torch.nn as nn import torch.nn.functional as F class Net16(nn.Module): def __init__(self, input_dim, output_dim): super(Net16, self).__init__() self.linear1 = nn.Linear(input_dim, 16) self.linear2 = nn.Linear(16, output_dim) def forward(self, x): x = F.relu(self.linear1(x)) x = self.linear2(x) return 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 import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (16, 4), (4, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 16), (16, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(1024)](buf1, primals_2, buf3, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 16), (16, 1), 0), reinterpret_tensor(primals_4, (16, 4), (1, 16), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 16), (16, 1), 0), primals_4, buf3 class Net16New(nn.Module): def __init__(self, input_dim, output_dim): super(Net16New, self).__init__() self.linear1 = nn.Linear(input_dim, 16) self.linear2 = nn.Linear(16, output_dim) 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]
gautam-sharma1/Imitation-Learning
Net16
false
3,522
[ "MIT" ]
0
20b6fcd2a8d6de8eb95e6831f5b379a083306361
https://github.com/gautam-sharma1/Imitation-Learning/tree/20b6fcd2a8d6de8eb95e6831f5b379a083306361
LearnablePositionalEncoding
import torch import torch.nn as nn class LearnablePositionalEncoding(nn.Module): def __init__(self, d_model, dropout=0.1, max_len=1024): super(LearnablePositionalEncoding, self).__init__() self.dropout = nn.Dropout(p=dropout) self.pe = nn.Parameter(torch.empty(max_len, 1, d_model)) nn.init.uniform_(self.pe, -0.02, 0.02) def forward(self, x): """Inputs of forward function Args: x: the sequence fed to the positional encoder model (required). Shape: x: [sequence length, batch size, embed dim] output: [sequence length, batch size, embed dim] """ x = x + self.pe[:x.size(0), :] return self.dropout(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_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 x4 = xindex x0 = xindex % 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x4, tmp2, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1024, 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((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](primals_2, primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, class LearnablePositionalEncodingNew(nn.Module): def __init__(self, d_model, dropout=0.1, max_len=1024): super(LearnablePositionalEncodingNew, self).__init__() self.dropout = nn.Dropout(p=dropout) self.pe = nn.Parameter(torch.empty(max_len, 1, d_model)) nn.init.uniform_(self.pe, -0.02, 0.02) def forward(self, input_0): primals_1 = self.pe primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
gaowanting/paper_code0
LearnablePositionalEncoding
false
3,523
[ "MIT" ]
0
15568fc9989b26df7c582b92163d2f262654712e
https://github.com/gaowanting/paper_code0/tree/15568fc9989b26df7c582b92163d2f262654712e
SBlock
import torch import torch.nn as nn class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer() self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x class Attention(nn.Module): def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads self.scale = qk_scale or head_dim ** -0.5 self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias) self.attn_drop = nn.Dropout(attn_drop) self.proj = nn.Linear(dim, dim) self.proj_drop = nn.Dropout(proj_drop) def forward(self, x): B, N, C = x.shape qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads ).permute(2, 0, 3, 1, 4) q, k, v = qkv[0], qkv[1], qkv[2] attn = q @ k.transpose(-2, -1) * self.scale attn = attn.softmax(dim=-1) attn = self.attn_drop(attn) x = (attn @ v).transpose(1, 2).reshape(B, N, C) x = self.proj(x) x = self.proj_drop(x) return x class SBlock(nn.Module): def __init__(self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn .GELU, norm_layer=nn.LayerNorm, block=-1): super().__init__() self.norm1 = norm_layer(dim) self.attn = Attention(dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop) self.drop_path = DropPath(drop_path ) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) self.block = block def forward(self, x): B, L, C = x.shape if self.block != -1: x = x + self.drop_path(self.attn(self.norm1(x).reshape(-1, self .block, C))).reshape(B, L, C) else: x = x + self.drop_path(self.attn(self.norm1(x))) x = x + self.drop_path(self.mlp(self.norm2(x))) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4, 'num_heads': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused__softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = tmp14 * tmp1 tmp16 = tl_math.exp(tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused__softmax_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_clone_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_clone_7(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr2 + 1) tmp9 = tl.broadcast_to(tmp8, [XBLOCK]) tmp13 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr2 + 2) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp20 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp21 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp22 = tl.load(in_ptr2 + 3) tmp23 = tl.broadcast_to(tmp22, [XBLOCK]) tmp4 = tmp1 + tmp3 tmp5 = tmp0 + tmp4 tmp10 = tmp7 + tmp9 tmp11 = tmp6 + tmp10 tmp12 = tmp5 + tmp11 tmp17 = tmp14 + tmp16 tmp18 = tmp13 + tmp17 tmp19 = tmp12 + tmp18 tmp24 = tmp21 + tmp23 tmp25 = tmp20 + tmp24 tmp26 = tmp19 + tmp25 tmp27 = 4.0 tmp28 = tmp26 / tmp27 tmp29 = tmp5 - tmp28 tmp30 = tmp29 * tmp29 tmp31 = tmp11 - tmp28 tmp32 = tmp31 * tmp31 tmp33 = tmp30 + tmp32 tmp34 = tmp18 - tmp28 tmp35 = tmp34 * tmp34 tmp36 = tmp33 + tmp35 tmp37 = tmp25 - tmp28 tmp38 = tmp37 * tmp37 tmp39 = tmp36 + tmp38 tmp40 = tmp39 / tmp27 tl.store(out_ptr0 + x0, tmp28, xmask) tl.store(out_ptr1 + x0, tmp40, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_9(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr6 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp6 = tmp4 - tmp5 tmp8 = 1e-05 tmp9 = tmp7 + tmp8 tmp10 = libdevice.rsqrt(tmp9) tmp11 = tmp6 * tmp10 tmp13 = tmp11 * tmp12 tmp15 = tmp13 + tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused_gelu_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 * tmp1 tmp3 = 0.7071067811865476 tmp4 = tmp0 * tmp3 tmp5 = libdevice.erf(tmp4) tmp6 = 1.0 tmp7 = tmp5 + tmp6 tmp8 = tmp2 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_11(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_out_ptr0 + x2, xmask) tmp6 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tmp7 = tmp5 + tmp6 tmp8 = tmp4 + tmp7 tl.store(in_out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12 ) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (12, 4), (4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (16, 4), (4, 1)) assert_size_stride(primals_10, (16,), (1,)) assert_size_stride(primals_11, (4, 16), (16, 1)) assert_size_stride(primals_12, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(16)](primals_1, buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](primals_1, buf0, buf1, primals_2, primals_3, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 del primals_3 buf3 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 12), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_2[grid(16, 4)](buf3, buf4, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32) triton_poi_fused_clone_3[grid(16, 4)](buf3, buf5, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_4[grid(256)](buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) buf8 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused__softmax_5[grid(256)](buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_6[grid(16, 4)](buf3, buf9, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del buf3 buf10 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf8, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf9, (16, 4, 1), (4, 1, 0), 0), out=buf10) buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_7[grid(16, 4)](buf10, buf11, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf12 = reinterpret_tensor(buf10, (16, 4), (4, 1), 0) del buf10 extern_kernels.mm(reinterpret_tensor(buf11, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf12) buf13 = buf1 del buf1 buf14 = buf0 del buf0 triton_poi_fused_add_native_layer_norm_8[grid(16)](primals_1, buf12, primals_6, buf13, buf14, 16, XBLOCK=16, num_warps=1, num_stages=1) buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_9[grid(64)](primals_1, buf12, primals_6, buf13, buf14, primals_7, primals_8, buf15, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf13 del buf14 del primals_8 buf16 = reinterpret_tensor(buf7, (16, 16), (16, 1), 0) del buf7 extern_kernels.addmm(primals_10, reinterpret_tensor(buf15, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf16) del primals_10 buf17 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_gelu_10[grid(256)](buf16, buf17, 256, XBLOCK=256, num_warps=4, num_stages=1) buf18 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf17, (16, 16), (16, 1), 0), reinterpret_tensor(primals_11, (16, 4), (1, 16), 0), out=buf18) buf19 = reinterpret_tensor(buf18, (4, 4, 4), (16, 4, 1), 0) del buf18 triton_poi_fused_add_11[grid(64)](buf19, primals_1, buf12, primals_6, primals_12, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_12 return buf19, primals_1, primals_6, primals_7, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), buf8, reinterpret_tensor(buf11, (16, 4), (4, 1), 0 ), buf12, reinterpret_tensor(buf15, (16, 4), (4, 1), 0 ), buf16, reinterpret_tensor(buf17, (16, 16), (16, 1), 0 ), primals_11, primals_9, primals_5, reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0), primals_4 class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer() self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x class Attention(nn.Module): def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads self.scale = qk_scale or head_dim ** -0.5 self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias) self.attn_drop = nn.Dropout(attn_drop) self.proj = nn.Linear(dim, dim) self.proj_drop = nn.Dropout(proj_drop) def forward(self, x): B, N, C = x.shape qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads ).permute(2, 0, 3, 1, 4) q, k, v = qkv[0], qkv[1], qkv[2] attn = q @ k.transpose(-2, -1) * self.scale attn = attn.softmax(dim=-1) attn = self.attn_drop(attn) x = (attn @ v).transpose(1, 2).reshape(B, N, C) x = self.proj(x) x = self.proj_drop(x) return x class SBlockNew(nn.Module): def __init__(self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn .GELU, norm_layer=nn.LayerNorm, block=-1): super().__init__() self.norm1 = norm_layer(dim) self.attn = Attention(dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop) self.drop_path = DropPath(drop_path ) if drop_path > 0.0 else nn.Identity() self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) self.block = block def forward(self, input_0): primals_2 = self.norm1.weight primals_3 = self.norm1.bias primals_4 = self.attn.qkv.weight primals_5 = self.attn.proj.weight primals_6 = self.attn.proj.bias primals_7 = self.norm2.weight primals_8 = self.norm2.bias primals_9 = self.mlp.fc1.weight primals_10 = self.mlp.fc1.bias primals_11 = self.mlp.fc2.weight primals_12 = self.mlp.fc2.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]) return output[0]
gaopengcuhk/deit
SBlock
false
3,524
[ "Apache-2.0" ]
0
de7db8f3a12c35e5e554b385030c574b7c78aaa6
https://github.com/gaopengcuhk/deit/tree/de7db8f3a12c35e5e554b385030c574b7c78aaa6
PNet
import torch import torch.nn as nn from collections import OrderedDict class PNet(nn.Module): def __init__(self): super().__init__() self.features = nn.Sequential(OrderedDict([('conv1', nn.Conv2d(3, 10, 3, 1)), ('prelu1', nn.PReLU(10)), ('pool1', nn.MaxPool2d(2, 2, ceil_mode=True)), ('conv2', nn.Conv2d(10, 16, 3, 1)), ( 'prelu2', nn.PReLU(16)), ('conv3', nn.Conv2d(16, 32, 3, 1)), ( 'prelu3', nn.PReLU(32))])) self.conv4_1 = nn.Conv2d(32, 2, 1, 1) self.conv4_2 = nn.Conv2d(32, 4, 1, 1) self.softmax = nn.Softmax(dim=-1) def forward(self, x): x = self.features(x) a = self.conv4_1(x) b = self.conv4_2(x) a = self.softmax(a) return b, a 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._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn from collections import OrderedDict 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 = 153760 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3844 % 10 x0 = xindex % 3844 x4 = xindex // 3844 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp6 = tmp5 * tmp2 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + (x0 + 3872 * x4), tmp7, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 38440 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 31 x1 = xindex // 31 % 31 x4 = xindex // 961 x3 = xindex // 9610 x5 = xindex % 9610 tmp0 = tl.load(in_ptr0 + (2 * x0 + 124 * x1 + 3872 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 124 * x1 + 3872 * x4), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (62 + 2 * x0 + 124 * x1 + 3872 * x4), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (63 + 2 * x0 + 124 * x1 + 3872 * x4), 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 + (x5 + 9632 * x3), tmp6, xmask) tl.store(out_ptr1 + (x5 + 9728 * x3), tmp16, 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 = 53824 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 841 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp6 = tmp5 * tmp2 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp7, xmask) @triton.jit def triton_poi_fused__prelu_kernel_convolution_3(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 93312 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 729 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp6 = tmp5 * tmp2 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp7, xmask) @triton.jit def triton_poi_fused_convolution_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 11664 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 729 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_per_fused__softmax_convolution_5(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 216 rnumel = 27 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 r3 = rindex x4 = xindex x1 = xindex // 27 % 2 tmp0 = tl.load(in_ptr0 + (r3 + 27 * x4), rmask & xmask, other=0.0) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.where(rmask & xmask, tmp3, float('-inf')) tmp6 = triton_helpers.max2(tmp5, 1)[:, None] tmp7 = tmp2 - tmp6 tmp8 = tl_math.exp(tmp7) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.where(rmask & xmask, tmp9, 0) tmp12 = tl.sum(tmp11, 1)[:, None] tmp13 = tmp8 / tmp12 tl.store(out_ptr2 + (r3 + 27 * x4), tmp13, rmask & 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, (10, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (10,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (10,), (1,)) assert_size_stride(primals_5, (16, 10, 3, 3), (90, 9, 3, 1)) assert_size_stride(primals_6, (16,), (1,)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (32, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_9, (32,), (1,)) assert_size_stride(primals_10, (32,), (1,)) assert_size_stride(primals_11, (2, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_12, (2,), (1,)) assert_size_stride(primals_13, (4, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_14, (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, 10, 62, 62), (38440, 3844, 62, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 10, 62, 62), (38720, 3872, 62, 1), torch.float32) get_raw_stream(0) triton_poi_fused__prelu_kernel_convolution_0[grid(153760)](buf1, primals_2, primals_4, buf2, 153760, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf3 = empty_strided_cuda((4, 10, 31, 31), (9632, 961, 31, 1), torch.float32) buf4 = empty_strided_cuda((4, 10, 31, 31), (9728, 961, 31, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(38440)](buf2, buf3, buf4, 38440, XBLOCK=512, num_warps=4, num_stages=1) buf5 = extern_kernels.convolution(buf3, primals_5, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 16, 29, 29), (13456, 841, 29, 1)) buf6 = buf5 del buf5 buf7 = empty_strided_cuda((4, 16, 29, 29), (13456, 841, 29, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_2[grid(53824)](buf6, primals_6, primals_7, buf7, 53824, XBLOCK=512, num_warps=4, num_stages=1) del primals_6 buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 32, 27, 27), (23328, 729, 27, 1)) buf9 = buf8 del buf8 buf10 = empty_strided_cuda((4, 32, 27, 27), (23328, 729, 27, 1), torch.float32) triton_poi_fused__prelu_kernel_convolution_3[grid(93312)](buf9, primals_9, primals_10, buf10, 93312, XBLOCK=512, num_warps=8, num_stages=1) del primals_9 buf11 = extern_kernels.convolution(buf10, primals_11, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 2, 27, 27), (1458, 729, 27, 1)) buf12 = extern_kernels.convolution(buf10, primals_13, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 4, 27, 27), (2916, 729, 27, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_4[grid(11664)](buf13, primals_14, 11664, XBLOCK=256, num_warps=4, num_stages=1) del primals_14 buf16 = empty_strided_cuda((4, 2, 27, 27), (1458, 729, 27, 1), torch.float32) triton_per_fused__softmax_convolution_5[grid(216)](buf11, primals_12, buf16, 216, 27, XBLOCK=1, num_warps=2, num_stages=1) del buf11 del primals_12 return (buf13, buf16, primals_1, primals_3, primals_4, primals_5, primals_7, primals_8, primals_10, primals_11, primals_13, buf1, buf2, buf3, buf4, buf6, buf7, buf9, buf10, buf16) class PNetNew(nn.Module): def __init__(self): super().__init__() self.features = nn.Sequential(OrderedDict([('conv1', nn.Conv2d(3, 10, 3, 1)), ('prelu1', nn.PReLU(10)), ('pool1', nn.MaxPool2d(2, 2, ceil_mode=True)), ('conv2', nn.Conv2d(10, 16, 3, 1)), ( 'prelu2', nn.PReLU(16)), ('conv3', nn.Conv2d(16, 32, 3, 1)), ( 'prelu3', nn.PReLU(32))])) self.conv4_1 = nn.Conv2d(32, 2, 1, 1) self.conv4_2 = nn.Conv2d(32, 4, 1, 1) self.softmax = nn.Softmax(dim=-1) def forward(self, input_0): primals_1 = self.features.conv1.weight primals_2 = self.features.conv1.bias primals_4 = self.features.prelu1.weight primals_5 = self.features.conv2.weight primals_6 = self.features.conv2.bias primals_7 = self.features.prelu2.weight primals_8 = self.features.conv3.weight primals_9 = self.features.conv3.bias primals_10 = self.features.prelu3.weight primals_11 = self.conv4_1.weight primals_12 = self.conv4_1.bias primals_13 = self.conv4_2.weight primals_14 = self.conv4_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14]) return output[0], output[1]
galbiati/mtcnn
PNet
false
3,525
[ "MIT" ]
0
6caa8e47ee6c7a01f6f990193129964a2d7e4b52
https://github.com/galbiati/mtcnn/tree/6caa8e47ee6c7a01f6f990193129964a2d7e4b52
FocusLayer
import torch import torch.nn as nn class FocusLayer(nn.Module): def __init__(self, c1, c2, k=1): super().__init__() def forward(self, x): return torch.cat([x[..., ::2], x[..., 1::2]], dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'c1': 4, 'c2': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 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 + (2 * x0 + 16 * x1 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr0 + (1 + 2 * x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8, 4, 2), (64, 8, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class FocusLayerNew(nn.Module): def __init__(self, c1, c2, k=1): super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
gdevos010/Informer2020
FocusLayer
false
3,526
[ "Apache-2.0" ]
0
607a1981ff8b8009eda3570a1ea4c9617289c9f2
https://github.com/gdevos010/Informer2020/tree/607a1981ff8b8009eda3570a1ea4c9617289c9f2
NNet
import torch import torch.nn as nn import torch.nn.functional as F class NNet(nn.Module): def __init__(self, input_dim, output_dim): super(NNet, self).__init__() self.linear1 = nn.Linear(input_dim, 64) self.linear2 = nn.Linear(64, 256) self.linear3 = nn.Linear(256, output_dim) def forward(self, x): x = F.relu(self.linear1(x)) x = F.relu(self.linear2(x)) x = self.linear3(x) return 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 import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @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) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 64), (64, 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, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf0 buf6 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf1, primals_2, buf6, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 256), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf2 buf5 = 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, buf5, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 256), (256, 1), 0), reinterpret_tensor(primals_6, (256, 4), (1, 256), 0), alpha=1, beta=1, out=buf4) del primals_7 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor( buf3, (64, 256), (256, 1), 0), primals_6, buf5, primals_4, buf6 class NNetNew(nn.Module): def __init__(self, input_dim, output_dim): super(NNetNew, self).__init__() self.linear1 = nn.Linear(input_dim, 64) self.linear2 = nn.Linear(64, 256) self.linear3 = nn.Linear(256, output_dim) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
gautam-sharma1/Imitation-Learning
NNet
false
3,527
[ "MIT" ]
0
20b6fcd2a8d6de8eb95e6831f5b379a083306361
https://github.com/gautam-sharma1/Imitation-Learning/tree/20b6fcd2a8d6de8eb95e6831f5b379a083306361
Temp
import torch import torch.nn as nn import torch.nn.functional as F class Temp(nn.Module): def __init__(self, input_dim, output_dim): super(Temp, self).__init__() self.linear1 = nn.Linear(input_dim, 256) self.linear2 = nn.Linear(256, 256) self.linear3 = nn.Linear(256, 256) self.linear4 = nn.Linear(256, output_dim) def forward(self, x): x = F.leaky_relu(self.linear1(x)) x = F.sigmoid(self.linear2(x)) x = F.leaky_relu(self.linear3(x)) x = self.linear4(x) return 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, None) tl.store(out_ptr1 + x2, tmp7, None) @triton.jit def triton_poi_fused_sigmoid_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) 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.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, 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, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 256), (256, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (256, 256), (256, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (4, 256), (256, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(16384)](buf0, primals_2, buf1, buf2, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf3 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (64, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 256), (1, 256), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf3 triton_poi_fused_sigmoid_1[grid(16384)](buf4, primals_5, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf4, (64, 256), (256, 1), 0), reinterpret_tensor(primals_6, (256, 256), (1, 256), 0), out=buf5) buf6 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) buf7 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.float32) triton_poi_fused_leaky_relu_0[grid(16384)](buf5, primals_7, buf6, buf7, 16384, XBLOCK=256, num_warps=4, num_stages=1) del buf5 del primals_7 buf8 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf7, (64, 256), (256, 1), 0), reinterpret_tensor(primals_8, (256, 4), (1, 256), 0), alpha=1, beta=1, out=buf8) del primals_9 return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 256), (256, 1), 0 ), buf4, buf6, reinterpret_tensor(buf7, (64, 256), (256, 1), 0 ), primals_8, primals_6, primals_4 class TempNew(nn.Module): def __init__(self, input_dim, output_dim): super(TempNew, self).__init__() self.linear1 = nn.Linear(input_dim, 256) self.linear2 = nn.Linear(256, 256) self.linear3 = nn.Linear(256, 256) self.linear4 = nn.Linear(256, output_dim) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_8 = self.linear4.weight primals_9 = self.linear4.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]
gautam-sharma1/Imitation-Learning
Temp
false
3,528
[ "MIT" ]
0
20b6fcd2a8d6de8eb95e6831f5b379a083306361
https://github.com/gautam-sharma1/Imitation-Learning/tree/20b6fcd2a8d6de8eb95e6831f5b379a083306361
Netleaky
import torch import torch.nn as nn import torch.nn.functional as F class Netleaky(nn.Module): def __init__(self, input_dim, output_dim): super(Netleaky, self).__init__() self.linear1 = nn.Linear(input_dim, 32) self.linear2 = nn.Linear(32, 32) self.linear3 = nn.Linear(32, 64) self.linear4 = nn.Linear(64, output_dim) def forward(self, x): x = F.relu(self.linear1(x)) x = F.relu(self.linear2(x)) x = F.relu(self.linear3(x)) x = self.linear4(x) return 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 import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 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_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 % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = 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, (64, 32), (32, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (4, 64), (64, 1)) assert_size_stride(primals_9, (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 buf9 = 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, buf9, 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 buf8 = 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, buf8, 2048, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 32), (32, 1), 0), reinterpret_tensor(primals_6, (32, 64), (1, 32), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf4 buf7 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) triton_poi_fused_relu_threshold_backward_1[grid(4096)](buf5, primals_7, buf7, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf5, (64, 64), (64, 1), 0), reinterpret_tensor(primals_8, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf6) del primals_9 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), 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), reinterpret_tensor(buf5, (64, 64), (64, 1), 0), primals_8, buf7, primals_6, buf8, primals_4, buf9 class NetleakyNew(nn.Module): def __init__(self, input_dim, output_dim): super(NetleakyNew, self).__init__() self.linear1 = nn.Linear(input_dim, 32) self.linear2 = nn.Linear(32, 32) self.linear3 = nn.Linear(32, 64) self.linear4 = nn.Linear(64, output_dim) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_8 = self.linear4.weight primals_9 = self.linear4.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]
gautam-sharma1/Imitation-Learning
Netleaky
false
3,529
[ "MIT" ]
0
20b6fcd2a8d6de8eb95e6831f5b379a083306361
https://github.com/gautam-sharma1/Imitation-Learning/tree/20b6fcd2a8d6de8eb95e6831f5b379a083306361
HardSigmoid
import torch from torch import nn import torch.nn.functional as F class HardSigmoid(nn.Module): def __init__(self, slope=0.2, offset=0.5): super().__init__() self.slope = slope self.offset = offset def forward(self, x): x = self.slope * x + self.offset x = F.threshold(-x, -1, -1) x = F.threshold(-x, 0, 0) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_neg_threshold_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.2 tmp2 = tmp0 * tmp1 tmp3 = 0.5 tmp4 = tmp2 + tmp3 tmp5 = -tmp4 tmp6 = -1.0 tmp7 = tmp5 <= tmp6 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = -tmp8 tmp10 = 0.0 tmp11 = tmp9 <= tmp10 tmp12 = tl.where(tmp11, tmp10, tmp9) tl.store(out_ptr0 + x0, tmp12, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_neg_threshold_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class HardSigmoidNew(nn.Module): def __init__(self, slope=0.2, offset=0.5): super().__init__() self.slope = slope self.offset = offset def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
gentlebreeze1/dbnet
HardSigmoid
false
3,530
[ "Apache-2.0" ]
0
be28a7ae835af7d6f8b7c2b636b875adc9fc187c
https://github.com/gentlebreeze1/dbnet/tree/be28a7ae835af7d6f8b7c2b636b875adc9fc187c
ActorNet
from torch.nn import Module import torch from torch.nn import Linear import torch.nn.functional as F class ActorNet(Module): def __init__(self, hidden_size, num_programs): super(ActorNet, self).__init__() self.l1 = Linear(hidden_size, hidden_size // 2) self.l2 = Linear(hidden_size // 2, num_programs) def forward(self, hidden_state): x = F.relu(self.l1(hidden_state)) x = F.softmax(self.l2(x), dim=-1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'num_programs': 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.nn import Module from torch.nn import Linear 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 = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 2 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (2, 4), (4, 1)) assert_size_stride(primals_2, (2,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 2), (2, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 2), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(128)](buf1, primals_2, buf5, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 2), ( 2, 1), 0), reinterpret_tensor(primals_4, (2, 4), (1, 2), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf3 return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 2), (2, 1), 0), buf4, primals_4, buf5 class ActorNetNew(Module): def __init__(self, hidden_size, num_programs): super(ActorNetNew, self).__init__() self.l1 = Linear(hidden_size, hidden_size // 2) self.l2 = Linear(hidden_size // 2, num_programs) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
geektoni/AlphaNPI
ActorNet
false
3,531
[ "MIT" ]
0
ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
https://github.com/geektoni/AlphaNPI/tree/ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
ListEnvEncoder
import torch import torch.nn.functional as F import torch.nn as nn class ListEnvEncoder(nn.Module): """ Implement an encoder (f_enc) specific to the List environment. It encodes observations e_t into vectors s_t of size D = encoding_dim. """ def __init__(self, observation_dim, encoding_dim): super(ListEnvEncoder, self).__init__() self.l1 = nn.Linear(observation_dim, 100) self.l2 = nn.Linear(100, encoding_dim) def forward(self, x): x = F.relu(self.l1(x)) x = torch.tanh(self.l2(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'observation_dim': 4, 'encoding_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 100 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_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 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, (100, 4), (4, 1)) assert_size_stride(primals_2, (100,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 100), (100, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 100), (100, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 100), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 100), (1600, 400, 100, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 4, 4, 100), (1664, 400, 100, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(6400)](buf1, primals_2, buf4, 6400, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 100), (100, 1), 0), reinterpret_tensor(primals_4, (100, 4), (1, 100), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_tanh_1[grid(256)](buf3, primals_5, 256, 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, 100), (100, 1), 0 ), buf3, primals_4, buf4 class ListEnvEncoderNew(nn.Module): """ Implement an encoder (f_enc) specific to the List environment. It encodes observations e_t into vectors s_t of size D = encoding_dim. """ def __init__(self, observation_dim, encoding_dim): super(ListEnvEncoderNew, self).__init__() self.l1 = nn.Linear(observation_dim, 100) self.l2 = nn.Linear(100, encoding_dim) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
geektoni/AlphaNPI
ListEnvEncoder
false
3,532
[ "MIT" ]
0
ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
https://github.com/geektoni/AlphaNPI/tree/ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
MaskL1Loss
import torch from torch import nn class MaskL1Loss(nn.Module): def __init__(self, eps=1e-06): super(MaskL1Loss, self).__init__() self.eps = eps def forward(self, pred: 'torch.Tensor', gt, mask): loss = (torch.abs(pred - gt) * mask).sum() / (mask.sum() + self.eps) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_div_mul_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp4 = tl.load(in_ptr2 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp5 = tmp3 * tmp4 tmp6 = tl.broadcast_to(tmp5, [RBLOCK]) tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0)) tmp9 = tl.broadcast_to(tmp4, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = 1e-06 tmp13 = tmp11 + tmp12 tmp14 = tmp8 / tmp13 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp14, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_div_mul_sub_sum_0[grid(1)](buf2, arg0_1, arg1_1, arg2_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class MaskL1LossNew(nn.Module): def __init__(self, eps=1e-06): super(MaskL1LossNew, self).__init__() self.eps = eps 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]
gentlebreeze1/dbnet
MaskL1Loss
false
3,533
[ "Apache-2.0" ]
0
be28a7ae835af7d6f8b7c2b636b875adc9fc187c
https://github.com/gentlebreeze1/dbnet/tree/be28a7ae835af7d6f8b7c2b636b875adc9fc187c
CriticNet
from torch.nn import Module import torch from torch.nn import Linear import torch.nn.functional as F class CriticNet(Module): def __init__(self, hidden_size): super(CriticNet, self).__init__() self.l1 = Linear(hidden_size, hidden_size // 2) self.l2 = Linear(hidden_size // 2, 1) def forward(self, hidden_state): x = F.relu(self.l1(hidden_state)) x = torch.tanh(self.l2(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch.nn import Module from torch.nn import Linear 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 = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 2 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 = 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 = libdevice.tanh(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, (2, 4), (4, 1)) assert_size_stride(primals_2, (2,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 2), (2, 1)) assert_size_stride(primals_5, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 2), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(128)](buf1, primals_2, buf4, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 2), (2, 1), 0), reinterpret_tensor(primals_4, (2, 1), (1, 2), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf2 triton_poi_fused_tanh_1[grid(64)](buf3, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 2), (2, 1), 0), buf3, primals_4, buf4 class CriticNetNew(Module): def __init__(self, hidden_size): super(CriticNetNew, self).__init__() self.l1 = Linear(hidden_size, hidden_size // 2) self.l2 = Linear(hidden_size // 2, 1) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
geektoni/AlphaNPI
CriticNet
false
3,534
[ "MIT" ]
0
ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
https://github.com/geektoni/AlphaNPI/tree/ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
HanoiEnvEncoder
import torch import torch.nn.functional as F import torch.nn as nn class HanoiEnvEncoder(nn.Module): """ Implement an encoder (f_enc) specific to the List environment. It encodes observations e_t into vectors s_t of size D = encoding_dim. """ def __init__(self, observation_dim, encoding_dim): super(HanoiEnvEncoder, self).__init__() self.l1 = nn.Linear(observation_dim, 100) self.l2 = nn.Linear(100, encoding_dim) def forward(self, x): x = F.relu(self.l1(x)) x = F.relu(self.l2(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'observation_dim': 4, 'encoding_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 100 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_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (100, 4), (4, 1)) assert_size_stride(primals_2, (100,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 100), (100, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 100), (100, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 100), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 100), (1600, 400, 100, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 100), (1664, 400, 100, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(6400)](buf1, primals_2, buf5, 6400, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 100), (100, 1), 0), reinterpret_tensor(primals_4, (100, 4), (1, 100), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf3, primals_5, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 100), (100, 1), 0 ), buf4, primals_4, buf5 class HanoiEnvEncoderNew(nn.Module): """ Implement an encoder (f_enc) specific to the List environment. It encodes observations e_t into vectors s_t of size D = encoding_dim. """ def __init__(self, observation_dim, encoding_dim): super(HanoiEnvEncoderNew, self).__init__() self.l1 = nn.Linear(observation_dim, 100) self.l2 = nn.Linear(100, encoding_dim) 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
geektoni/AlphaNPI
HanoiEnvEncoder
false
3,535
[ "MIT" ]
0
ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
https://github.com/geektoni/AlphaNPI/tree/ab48cb9cfb74f3960e264da4f3eb2d6917bfb9c9
MultiHeadAttention
import torch import torch.nn as nn class MultiHeadAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): return self.attention(x_q, x_kv, x_kv, key_padding_mask=pad_mask, attn_mask=attn_mask)[0] def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_q_channels': 4, 'num_kv_channels': 4, 'num_heads': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_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 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, 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 = 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 = 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) @triton.jit def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (12, 4), (4, 1)) assert_size_stride(primals_4, (12,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf0) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_4, (4,), (1,), 4), primals_2, reinterpret_tensor(primals_3, (4, 4), (1, 4), 16), alpha=1, beta=1, out=buf1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_4, (4,), (1,), 8), primals_2, reinterpret_tensor(primals_3, (4, 4), (1, 4), 32), alpha=1, beta=1, out=buf2) del primals_3 buf3 = reinterpret_tensor(buf0, (4, 4, 1), (1, 4, 16), 0) del buf0 get_raw_stream(0) triton_poi_fused_mul_0[grid(16)](buf3, primals_4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf3, reinterpret_tensor(buf1, (4, 1, 4), (1, 1, 4), 0), out=buf4) buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = buf4 del buf4 triton_poi_fused__softmax_2[grid(64)](buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf5 buf7 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf6, reinterpret_tensor(buf2, (4, 4, 1), (1, 4, 1), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_clone_3[grid(4, 4)](buf7, buf8, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf7, (4, 4), (4, 1), 0) del buf7 extern_kernels.addmm(primals_6, reinterpret_tensor(buf8, (4, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha =1, beta=1, out=buf9) del primals_6 return buf9, primals_1, primals_2, buf6, reinterpret_tensor(buf8, (4, 4 ), (4, 1), 0), primals_5, reinterpret_tensor(buf2, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf3, (4, 1, 4), (1, 1, 4), 0 ), reinterpret_tensor(buf1, (4, 4, 1), (1, 4, 1), 0) class MultiHeadAttentionNew(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, input_0, input_1): primals_3 = self.attention.in_proj_weight primals_4 = self.attention.in_proj_bias primals_1 = self.attention.out_proj.weight primals_6 = self.attention.out_proj.bias primals_2 = input_0 primals_5 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
felixyu7/perceiver-io-1
MultiHeadAttention
false
3,536
[ "Apache-2.0" ]
0
895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
https://github.com/felixyu7/perceiver-io-1/tree/895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
DiceLoss
import torch from torch import nn class DiceLoss(nn.Module): """ Loss function from https://arxiv.org/abs/1707.03237, where iou computation is introduced heatmap manner to measure the diversity bwtween tow heatmaps. """ def __init__(self, eps=1e-06): super(DiceLoss, self).__init__() self.eps = eps def forward(self, pred: 'torch.Tensor', gt, mask, weights=None): """ pred: one or two heatmaps of shape (N, 1, H, W), the losses of tow heatmaps are added together. gt: (N, 1, H, W) mask: (N, H, W) """ return self._compute(pred, gt, mask, weights) def _compute(self, pred, gt, mask, weights): if pred.dim() == 4: pred = pred[:, 0, :, :] gt = gt[:, 0, :, :] assert pred.shape == gt.shape assert pred.shape == mask.shape if weights is not None: assert weights.shape == mask.shape mask = weights * mask intersection = (pred * gt * mask).sum() union = (pred * mask).sum() + (gt * mask).sum() + self.eps loss = 1 - 2.0 * intersection / union assert loss <= 1 return loss def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_div_mul_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp3 = tl.load(in_ptr2 + r0, None) tmp2 = tmp0 * tmp1 tmp4 = tmp2 * tmp3 tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK]) tmp7 = tl.sum(tmp5, 1)[:, None] tmp8 = tmp0 * tmp3 tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.sum(tmp9, 1)[:, None] tmp12 = tmp1 * tmp3 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.sum(tmp13, 1)[:, None] tmp16 = 2.0 tmp17 = tmp7 * tmp16 tmp18 = tmp11 + tmp15 tmp19 = 1e-06 tmp20 = tmp18 + tmp19 tmp21 = tmp17 / tmp20 tmp22 = 1.0 tmp23 = tmp22 - tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp23, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) assert_size_stride(arg2_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf3 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_div_mul_rsub_sum_0[grid(1)](buf3, arg0_1, arg1_1, arg2_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf3, class DiceLossNew(nn.Module): """ Loss function from https://arxiv.org/abs/1707.03237, where iou computation is introduced heatmap manner to measure the diversity bwtween tow heatmaps. """ def __init__(self, eps=1e-06): super(DiceLossNew, self).__init__() self.eps = eps def _compute(self, pred, gt, mask, weights): if pred.dim() == 4: pred = pred[:, 0, :, :] gt = gt[:, 0, :, :] assert pred.shape == gt.shape assert pred.shape == mask.shape if weights is not None: assert weights.shape == mask.shape mask = weights * mask intersection = (pred * gt * mask).sum() union = (pred * mask).sum() + (gt * mask).sum() + self.eps loss = 1 - 2.0 * intersection / union assert loss <= 1 return loss def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
gentlebreeze1/dbnet
DiceLoss
false
3,537
[ "Apache-2.0" ]
0
be28a7ae835af7d6f8b7c2b636b875adc9fc187c
https://github.com/gentlebreeze1/dbnet/tree/be28a7ae835af7d6f8b7c2b636b875adc9fc187c
SEBlock
import torch from torch import nn import torch.nn.functional as F class HardSigmoid(nn.Module): def __init__(self, slope=0.2, offset=0.5): super().__init__() self.slope = slope self.offset = offset def forward(self, x): x = self.slope * x + self.offset x = F.threshold(-x, -1, -1) x = F.threshold(-x, 0, 0) return x class SEBlock(nn.Module): def __init__(self, in_channels, out_channels, ratio=4): super().__init__() num_mid_filter = out_channels // ratio self.pool = nn.AdaptiveAvgPool2d(1) self.conv1 = nn.Conv2d(in_channels=in_channels, out_channels= num_mid_filter, kernel_size=1, bias=True) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(in_channels=num_mid_filter, kernel_size=1, out_channels=out_channels, bias=True) self.relu2 = HardSigmoid() def forward(self, x): attn = self.pool(x) attn = self.conv1(attn) attn = self.relu1(attn) attn = self.conv2(attn) attn = self.relu2(attn) return x * attn 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._inductor.runtime import triton_helpers from torch import nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda 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 = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tl.store(in_out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_add_convolution_mul_neg_threshold_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.2 tmp4 = tmp2 * tmp3 tmp5 = 0.5 tmp6 = tmp4 + tmp5 tmp7 = -tmp6 tmp8 = -1.0 tmp9 = tmp7 <= tmp8 tmp10 = tl.where(tmp9, tmp8, tmp7) tmp11 = -tmp10 tmp12 = 0.0 tmp13 = tmp11 <= tmp12 tl.store(out_ptr0 + x2, tmp9, xmask) tl.store(out_ptr1 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_add_convolution_mul_neg_threshold_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 16 x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last').to(tl .int1) tmp2 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last').to(tl .int1) tmp3 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp5 = tmp3 + tmp4 tmp6 = 0.2 tmp7 = tmp5 * tmp6 tmp8 = 0.5 tmp9 = tmp7 + tmp8 tmp10 = -tmp9 tmp11 = -1.0 tmp12 = tl.where(tmp2, tmp11, tmp10) tmp13 = -tmp12 tmp14 = 0.0 tmp15 = tl.where(tmp1, tmp14, tmp13) tmp16 = tmp0 * tmp15 tl.store(out_ptr0 + x3, tmp16, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (4, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 1, 1), (1, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(4)](buf3, primals_3, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool) buf6 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool) triton_poi_fused_add_convolution_mul_neg_threshold_2[grid(16)](buf4, primals_5, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_mul_neg_threshold_3[grid(256)]( primals_1, buf6, buf5, buf4, primals_5, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf4 del primals_5 return buf7, primals_1, primals_2, primals_4, buf1, buf3, buf5, buf6 class HardSigmoid(nn.Module): def __init__(self, slope=0.2, offset=0.5): super().__init__() self.slope = slope self.offset = offset def forward(self, x): x = self.slope * x + self.offset x = F.threshold(-x, -1, -1) x = F.threshold(-x, 0, 0) return x class SEBlockNew(nn.Module): def __init__(self, in_channels, out_channels, ratio=4): super().__init__() num_mid_filter = out_channels // ratio self.pool = nn.AdaptiveAvgPool2d(1) self.conv1 = nn.Conv2d(in_channels=in_channels, out_channels= num_mid_filter, kernel_size=1, bias=True) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(in_channels=num_mid_filter, kernel_size=1, out_channels=out_channels, bias=True) self.relu2 = HardSigmoid() 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]
gentlebreeze1/dbnet
SEBlock
false
3,538
[ "Apache-2.0" ]
0
be28a7ae835af7d6f8b7c2b636b875adc9fc187c
https://github.com/gentlebreeze1/dbnet/tree/be28a7ae835af7d6f8b7c2b636b875adc9fc187c
L1Linear
import math import torch import warnings from torch import Tensor from torch.nn.parameter import Parameter from torch.nn import functional as F from torch.nn import init class L1Linear(torch.nn.Module): def __init__(self, l1: 'float', in_features: 'int', out_features: 'int', bias: 'bool'=True, init_zero=False, device=None, dtype=None) ->None: """Applies a linear transformation to the incoming data: :math:`y = xW^T + b` where the weights of :math:`W` are l1-penalized, i.e. with the term l1 * ||W||_1 The weights :math:`W` are never actually optimized but rather they are split up into two factors ``self.weight_u`` and ``self.weight_v``. The lweights :math:`W` can be retrieved by ``self.get_weight()``. For further details see Equivalences Between Sparse Models and Neural Networks, Ryan Tibshirani, 2021. This module supports :ref:`TensorFloat32<tf32_on_ampere>`. Args: l1: float, regularization parameter in_features: size of each input sample out_features: size of each output sample bias: If set to ``False``, the layer will not learn an additive bias. The bias is not regularized. Default: ``True`` Shape: - Input: :math:`(*, H_{in})` where :math:`*` means any number of dimensions including none and :math:`H_{in} = ext{in\\_features}`. - Output: :math:`(*, H_{out})` where all but the last dimension are the same shape as the input and :math:`H_{out} = ext{out\\_features}`. Attributes: weight_u: the learnable weights of the module of shape :math:`( ext{out\\_features}, ext{in\\_features})`. The values are initialized to zero. weight_v: the learnable weights of the module of shape :math:`( ext{out\\_features}, ext{in\\_features})`. The values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})`, where :math:`k = rac{1}{ ext{in\\_features}}` bias: the learnable bias of the module of shape :math:`( ext{out\\_features})`. If :attr:`bias` is ``True``, the values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where :math:`k = rac{1}{ ext{in\\_features}}` init_zero: whether to initialize one of the weights at zero. Examples:: TBD """ factory_kwargs = {'device': device, 'dtype': dtype} super(L1Linear, self).__init__() assert l1 >= 0, 'l1 should be non-negative.' if l1 == 0: warnings.warn( 'Choosing l1=0 means no regularization. You should use the standard Pytorch Linear module.' ) self.l1 = l1 self.in_features = in_features self.out_features = out_features self.weight_u = Parameter(torch.zeros((out_features, in_features), **factory_kwargs)) self.weight_v = Parameter(torch.empty((out_features, in_features), **factory_kwargs)) if bias: self.bias = Parameter(torch.empty(out_features, **factory_kwargs)) else: self.register_parameter('bias', None) self.reset_parameters(init_zero) return def forward(self, input: 'Tensor') ->Tensor: return F.linear(input, self.weight_u.mul(self.weight_v), self.bias) def reg(self): """ compute l1 * ||W||_1 = (l1/2)* (||W_u||^2 + ||W_v||^2) """ return self.l1 / 2 * (torch.linalg.norm(self.weight_u) ** 2 + torch .linalg.norm(self.weight_u) ** 2) def get_weight(self): return self.weight_u.mul(self.weight_v) def get_tol(self): """ Stopping criterion for the split, i.e. at the minimizer we have ``abs(self.weight_u) == abs(self.weight_v)`` """ return torch.max(torch.abs(torch.abs(self.weight_u) - torch.abs( self.weight_v))) def reset_parameters(self, init_zero=False) ->None: if not init_zero: init.kaiming_uniform_(self.weight_u, a=math.sqrt(5)) init.kaiming_uniform_(self.weight_v, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight_u) bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0 init.uniform_(self.bias, -bound, bound) def extra_repr(self) ->str: return 'l1={}, in_features={}, out_features={}, bias={}'.format(self .l1, self.in_features, self.out_features, self.bias is not None) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'l1': 4, '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 warnings from torch.nn.parameter import Parameter from torch.nn import init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(16)](primals_1, primals_2, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1) del buf0 del primals_3 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, primals_2, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0) class L1LinearNew(torch.nn.Module): def __init__(self, l1: 'float', in_features: 'int', out_features: 'int', bias: 'bool'=True, init_zero=False, device=None, dtype=None) ->None: """Applies a linear transformation to the incoming data: :math:`y = xW^T + b` where the weights of :math:`W` are l1-penalized, i.e. with the term l1 * ||W||_1 The weights :math:`W` are never actually optimized but rather they are split up into two factors ``self.weight_u`` and ``self.weight_v``. The lweights :math:`W` can be retrieved by ``self.get_weight()``. For further details see Equivalences Between Sparse Models and Neural Networks, Ryan Tibshirani, 2021. This module supports :ref:`TensorFloat32<tf32_on_ampere>`. Args: l1: float, regularization parameter in_features: size of each input sample out_features: size of each output sample bias: If set to ``False``, the layer will not learn an additive bias. The bias is not regularized. Default: ``True`` Shape: - Input: :math:`(*, H_{in})` where :math:`*` means any number of dimensions including none and :math:`H_{in} = ext{in\\_features}`. - Output: :math:`(*, H_{out})` where all but the last dimension are the same shape as the input and :math:`H_{out} = ext{out\\_features}`. Attributes: weight_u: the learnable weights of the module of shape :math:`( ext{out\\_features}, ext{in\\_features})`. The values are initialized to zero. weight_v: the learnable weights of the module of shape :math:`( ext{out\\_features}, ext{in\\_features})`. The values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})`, where :math:`k = rac{1}{ ext{in\\_features}}` bias: the learnable bias of the module of shape :math:`( ext{out\\_features})`. If :attr:`bias` is ``True``, the values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where :math:`k = rac{1}{ ext{in\\_features}}` init_zero: whether to initialize one of the weights at zero. Examples:: TBD """ factory_kwargs = {'device': device, 'dtype': dtype} super(L1LinearNew, self).__init__() assert l1 >= 0, 'l1 should be non-negative.' if l1 == 0: warnings.warn( 'Choosing l1=0 means no regularization. You should use the standard Pytorch Linear module.' ) self.l1 = l1 self.in_features = in_features self.out_features = out_features self.weight_u = Parameter(torch.zeros((out_features, in_features), **factory_kwargs)) self.weight_v = Parameter(torch.empty((out_features, in_features), **factory_kwargs)) if bias: self.bias = Parameter(torch.empty(out_features, **factory_kwargs)) else: self.register_parameter('bias', None) self.reset_parameters(init_zero) return def reg(self): """ compute l1 * ||W||_1 = (l1/2)* (||W_u||^2 + ||W_v||^2) """ return self.l1 / 2 * (torch.linalg.norm(self.weight_u) ** 2 + torch .linalg.norm(self.weight_u) ** 2) def get_weight(self): return self.weight_u.mul(self.weight_v) def get_tol(self): """ Stopping criterion for the split, i.e. at the minimizer we have ``abs(self.weight_u) == abs(self.weight_v)`` """ return torch.max(torch.abs(torch.abs(self.weight_u) - torch.abs( self.weight_v))) def reset_parameters(self, init_zero=False) ->None: if not init_zero: init.kaiming_uniform_(self.weight_u, a=math.sqrt(5)) init.kaiming_uniform_(self.weight_v, a=math.sqrt(5)) if self.bias is not None: fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight_u) bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0 init.uniform_(self.bias, -bound, bound) def extra_repr(self) ->str: return 'l1={}, in_features={}, out_features={}, bias={}'.format(self .l1, self.in_features, self.out_features, self.bias is not None) def forward(self, input_0): primals_1 = self.weight_u primals_2 = self.weight_v primals_3 = self.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
fabian-sp/regular-layers
L1Linear
false
3,539
[ "BSD-3-Clause" ]
0
573b652d1e66c4e44cc740dcc8dc618669af5c96
https://github.com/fabian-sp/regular-layers/tree/573b652d1e66c4e44cc740dcc8dc618669af5c96
SelfAttention
import torch import torch.nn as nn class MultiHeadAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): return self.attention(x_q, x_kv, x_kv, key_padding_mask=pad_mask, attn_mask=attn_mask)[0] class SelfAttention(nn.Module): def __init__(self, num_channels: 'int', num_heads: 'int', dropout: 'float' ): super().__init__() self.norm = nn.LayerNorm(num_channels) self.attention = MultiHeadAttention(num_q_channels=num_channels, num_kv_channels=num_channels, num_heads=num_heads, dropout=dropout) def forward(self, x, pad_mask=None, attn_mask=None): x = self.norm(x) return self.attention(x, x, pad_mask=pad_mask, attn_mask=attn_mask) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_channels': 4, 'num_heads': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 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 = 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) @triton.jit def triton_poi_fused_clone_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (12, 4), (4, 1)) assert_size_stride(primals_5, (12,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(4)](primals_3, buf0, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(16)](primals_3, buf0, buf1, primals_1, primals_2, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 del buf1 del primals_1 del primals_2 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf3) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 4), buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 16), alpha= 1, beta=1, out=buf4) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_5, (4,), (1,), 8), buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 32), alpha= 1, beta=1, out=buf5) buf6 = reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 16), 0) del buf3 triton_poi_fused_mul_2[grid(16)](buf6, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf6, reinterpret_tensor(buf4, (4, 1, 4), (1, 1, 4), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = buf7 del buf7 triton_poi_fused__softmax_4[grid(64)](buf8, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf8 buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf9, reinterpret_tensor(buf5, (4, 4, 1), (1, 4, 1), 0), out=buf10) buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_clone_5[grid(4, 4)](buf10, buf11, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf12 = reinterpret_tensor(buf10, (4, 4), (4, 1), 0) del buf10 extern_kernels.addmm(primals_7, reinterpret_tensor(buf11, (4, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf12) del primals_7 return buf12, primals_3, buf2, buf9, reinterpret_tensor(buf11, (4, 4), (4, 1), 0), primals_6, reinterpret_tensor(buf5, (4, 1, 4), (1, 1, 4), 0 ), reinterpret_tensor(buf6, (4, 1, 4), (1, 1, 4), 0 ), reinterpret_tensor(buf4, (4, 4, 1), (1, 4, 1), 0 ), reinterpret_tensor(primals_4, (4, 4), (4, 1), 32 ), reinterpret_tensor(primals_4, (4, 4), (4, 1), 16 ), reinterpret_tensor(primals_4, (4, 4), (4, 1), 0) class MultiHeadAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): return self.attention(x_q, x_kv, x_kv, key_padding_mask=pad_mask, attn_mask=attn_mask)[0] class SelfAttentionNew(nn.Module): def __init__(self, num_channels: 'int', num_heads: 'int', dropout: 'float' ): super().__init__() self.norm = nn.LayerNorm(num_channels) self.attention = MultiHeadAttention(num_q_channels=num_channels, num_kv_channels=num_channels, num_heads=num_heads, dropout=dropout) def forward(self, input_0): primals_1 = self.norm.weight primals_2 = self.norm.bias primals_4 = self.attention.attention.in_proj_weight primals_5 = self.attention.attention.in_proj_bias primals_3 = self.attention.attention.out_proj.weight primals_7 = self.attention.attention.out_proj.bias primals_6 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
felixyu7/perceiver-io-1
SelfAttention
false
3,540
[ "Apache-2.0" ]
0
895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
https://github.com/felixyu7/perceiver-io-1/tree/895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
CrossAttention
import torch import torch.nn as nn class MultiHeadAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): return self.attention(x_q, x_kv, x_kv, key_padding_mask=pad_mask, attn_mask=attn_mask)[0] class CrossAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.q_norm = nn.LayerNorm(num_q_channels) self.kv_norm = nn.LayerNorm(num_kv_channels) self.attention = MultiHeadAttention(num_q_channels=num_q_channels, num_kv_channels=num_kv_channels, num_heads=num_heads, dropout= dropout) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): x_q = self.q_norm(x_q) x_kv = self.kv_norm(x_kv) return self.attention(x_q, x_kv, pad_mask=pad_mask, attn_mask=attn_mask ) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_q_channels': 4, 'num_kv_channels': 4, 'num_heads': 4, 'dropout': 0.5}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 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 = 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) @triton.jit def triton_poi_fused_clone_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask) tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10) = args args.clear() assert_size_stride(primals_1, (4,), (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,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (12, 4), (4, 1)) assert_size_stride(primals_8, (12,), (1,)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(4)](primals_3, buf0, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf3 = empty_strided_cuda((4, 1), (1, 4), torch.float32) triton_poi_fused_native_layer_norm_0[grid(4)](primals_6, buf2, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(16)](primals_3, buf0, buf1, primals_1, primals_2, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 del buf1 del primals_1 del primals_2 buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf4, reinterpret_tensor(primals_7, (4, 4), (1, 4 ), 0), out=buf5) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(16)](primals_6, buf2, buf3, primals_4, primals_5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf2 del buf3 del primals_4 del primals_5 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_8, (4,), (1,), 4), buf6, reinterpret_tensor(primals_7, (4, 4), (1, 4), 16), alpha= 1, beta=1, out=buf7) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(reinterpret_tensor(primals_8, (4,), (1,), 8), buf6, reinterpret_tensor(primals_7, (4, 4), (1, 4), 32), alpha= 1, beta=1, out=buf8) buf9 = reinterpret_tensor(buf5, (4, 4, 1), (1, 4, 16), 0) del buf5 triton_poi_fused_mul_2[grid(16)](buf9, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_8 buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf9, reinterpret_tensor(buf7, (4, 1, 4), (1, 1, 4), 0), out=buf10) buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_3[grid(64)](buf10, buf11, 64, XBLOCK=64, num_warps=1, num_stages=1) buf12 = buf10 del buf10 triton_poi_fused__softmax_4[grid(64)](buf11, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf11 buf13 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(buf12, reinterpret_tensor(buf8, (4, 4, 1), (1, 4, 1), 0), out=buf13) buf14 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_clone_5[grid(4, 4)](buf13, buf14, 4, 4, XBLOCK=4, YBLOCK=4, num_warps=1, num_stages=1) buf15 = reinterpret_tensor(buf13, (4, 4), (4, 1), 0) del buf13 extern_kernels.addmm(primals_10, reinterpret_tensor(buf14, (4, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf15) del primals_10 return buf15, primals_3, primals_6, buf4, buf6, buf12, reinterpret_tensor( buf14, (4, 4), (4, 1), 0), primals_9, reinterpret_tensor(buf8, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf9, (4, 1, 4), (1, 1, 4), 0 ), reinterpret_tensor(buf7, (4, 4, 1), (1, 4, 1), 0 ), reinterpret_tensor(primals_7, (4, 4), (4, 1), 32 ), reinterpret_tensor(primals_7, (4, 4), (4, 1), 16 ), reinterpret_tensor(primals_7, (4, 4), (4, 1), 0) class MultiHeadAttention(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.attention = nn.MultiheadAttention(embed_dim=num_q_channels, num_heads=num_heads, kdim=num_kv_channels, vdim=num_kv_channels, dropout=dropout, batch_first=True) def forward(self, x_q, x_kv, pad_mask=None, attn_mask=None): return self.attention(x_q, x_kv, x_kv, key_padding_mask=pad_mask, attn_mask=attn_mask)[0] class CrossAttentionNew(nn.Module): def __init__(self, num_q_channels: 'int', num_kv_channels: 'int', num_heads: 'int', dropout: 'float'): super().__init__() self.q_norm = nn.LayerNorm(num_q_channels) self.kv_norm = nn.LayerNorm(num_kv_channels) self.attention = MultiHeadAttention(num_q_channels=num_q_channels, num_kv_channels=num_kv_channels, num_heads=num_heads, dropout= dropout) def forward(self, input_0, input_1): primals_1 = self.q_norm.weight primals_2 = self.q_norm.bias primals_4 = self.kv_norm.weight primals_5 = self.kv_norm.bias primals_7 = self.attention.attention.in_proj_weight primals_8 = self.attention.attention.in_proj_bias primals_3 = self.attention.attention.out_proj.weight primals_10 = self.attention.attention.out_proj.bias primals_6 = input_0 primals_9 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10]) return output[0]
felixyu7/perceiver-io-1
CrossAttention
false
3,541
[ "Apache-2.0" ]
0
895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
https://github.com/felixyu7/perceiver-io-1/tree/895f09e75e5a4b5e90dfef5d3a86ea26c2f48f4e
ReflectionPad3d
import torch import torch.utils.data import torch import torch.nn as nn class ReflectionPad3d(nn.Module): def __init__(self, padding): super(ReflectionPad3d, self).__init__() self.padding = padding if isinstance(padding, int): self.padding = (padding,) * 6 def forward(self, input): """ Arguments :param input: tensor of shape :math:`(N, C_{ ext{in}}, H, [W, D]))` Returns :return: tensor of shape :math:`(N, C_{ ext{in}}, [D + 2 * self.padding[0], H + 2 * self.padding[1]], W + 2 * self.padding[2]))` """ input = torch.cat([input, input.flip([2])[:, :, 0:self.padding[-1]] ], dim=2) input = torch.cat([input.flip([2])[:, :, -self.padding[-2]:], input ], dim=2) if len(self.padding) > 2: input = torch.cat([input, input.flip([3])[:, :, :, 0:self. padding[-3]]], dim=3) input = torch.cat([input.flip([3])[:, :, :, -self.padding[-4]:], input], dim=3) if len(self.padding) > 4: input = torch.cat([input, input.flip([4])[:, :, :, :, 0:self. padding[-5]]], dim=4) input = torch.cat([input.flip([4])[:, :, :, :, -self.padding[-6 ]:], input], dim=4) return input def get_inputs(): return [torch.rand([4, 4, 4, 4, 4])] def get_init_inputs(): return [[], {'padding': 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.utils.data import torch import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 12 x0 = xindex % 16 x2 = xindex // 192 x3 = xindex // 16 tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = 3 + -1 * x1 tmp7 = tmp5 < tmp3 tmp8 = tmp7 & tmp4 tmp9 = tl.load(in_ptr0 + (x0 + 16 * (3 + -1 * x1) + 64 * x2), tmp8 & xmask, other=0.0) tmp10 = tmp5 >= tmp3 tl.full([1], 8, tl.int64) tmp13 = tmp10 & tmp4 tmp14 = tl.load(in_ptr0 + (48 + x0 + -16 * (-1 + -1 * x1) + 64 * x2), tmp13 & xmask, other=0.0) tmp15 = tl.where(tmp7, tmp9, tmp14) tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp4, tmp15, tmp16) tmp18 = tmp0 >= tmp3 tl.full([1], 12, tl.int64) tmp21 = -4 + x1 tmp23 = tmp21 < tmp3 tmp24 = tmp23 & tmp18 tmp25 = tl.load(in_ptr0 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp24 & xmask, other=0.0) tmp26 = tmp21 >= tmp3 tmp28 = tmp26 & tmp18 tmp29 = tl.load(in_ptr0 + (48 + x0 + -16 * (-4 + (-4 + x1)) + 64 * x2), tmp28 & xmask, other=0.0) tmp30 = tl.where(tmp23, tmp25, tmp29) tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype) tmp32 = tl.where(tmp18, tmp30, tmp31) tmp33 = tl.where(tmp4, tmp17, tmp32) tl.store(out_ptr0 + (x0 + 32 * x3), tmp33, xmask) @triton.jit def triton_poi_fused_flip_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex % 16 tmp0 = tl.load(in_ptr0 + (12 + x0 + -4 * x1 + 32 * x2), xmask) tl.store(out_ptr0 + (x3 + 32 * x2), tmp0, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 27648 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 12 x1 = xindex // 12 % 12 x2 = xindex // 144 x4 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = 3 + -1 * x0 tmp7 = tmp5 < tmp3 tmp8 = tmp7 & tmp4 tmp9 = x1 tmp11 = tmp9 < tmp3 tmp12 = tmp11 & tmp8 tmp13 = tl.load(in_ptr0 + (12 + -4 * x1 + 32 * x2 + (3 + -1 * x0)), tmp12 & xmask, eviction_policy='evict_last', other=0.0) tmp14 = tmp9 >= tmp3 tl.full([1], 12, tl.int64) tmp17 = tmp14 & tmp8 tmp18 = tl.load(in_ptr0 + (4 * (-4 + x1) + 32 * x2 + (3 + -1 * x0)), tmp17 & xmask, eviction_policy='evict_last', other=0.0) tmp19 = tl.where(tmp11, tmp13, tmp18) tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype) tmp21 = tl.where(tmp8, tmp19, tmp20) tmp22 = tmp5 >= tmp3 tl.full([1], 8, tl.int64) tmp25 = tmp22 & tmp4 tmp26 = tmp11 & tmp25 tmp27 = tl.load(in_ptr0 + (15 + -1 * (-1 + -1 * x0) + -4 * x1 + 32 * x2 ), tmp26 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tmp14 & tmp25 tmp29 = tl.load(in_ptr0 + (3 + -1 * (-1 + -1 * x0) + 4 * (-4 + x1) + 32 * x2), tmp28 & xmask, eviction_policy='evict_last', other=0.0) tmp30 = tl.where(tmp11, tmp27, tmp29) tmp31 = tl.full(tmp30.shape, 0.0, tmp30.dtype) tmp32 = tl.where(tmp25, tmp30, tmp31) tmp33 = tl.where(tmp7, tmp21, tmp32) tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp4, tmp33, tmp34) tmp36 = tmp0 >= tmp3 tmp38 = -4 + x0 tmp40 = tmp38 < tmp3 tmp41 = tmp40 & tmp36 tmp42 = tmp11 & tmp41 tmp43 = tl.load(in_ptr0 + (12 + -4 * x1 + 32 * x2 + (-4 + x0)), tmp42 & xmask, eviction_policy='evict_last', other=0.0) tmp44 = tmp14 & tmp41 tmp45 = tl.load(in_ptr0 + (4 * (-4 + x1) + 32 * x2 + (-4 + x0)), tmp44 & xmask, eviction_policy='evict_last', other=0.0) tmp46 = tl.where(tmp11, tmp43, tmp45) tmp47 = tl.full(tmp46.shape, 0.0, tmp46.dtype) tmp48 = tl.where(tmp41, tmp46, tmp47) tmp49 = tmp38 >= tmp3 tmp51 = tmp49 & tmp36 tmp52 = tmp11 & tmp51 tmp53 = tl.load(in_ptr0 + (15 + -1 * (-4 + (-4 + x0)) + -4 * x1 + 32 * x2), tmp52 & xmask, eviction_policy='evict_last', other=0.0) tmp54 = tmp14 & tmp51 tmp55 = tl.load(in_ptr0 + (3 + -1 * (-4 + (-4 + x0)) + 4 * (-4 + x1) + 32 * x2), tmp54 & xmask, eviction_policy='evict_last', other=0.0) tmp56 = tl.where(tmp11, tmp53, tmp55) tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype) tmp58 = tl.where(tmp51, tmp56, tmp57) tmp59 = tl.where(tmp40, tmp48, tmp58) tmp60 = tl.full(tmp59.shape, 0.0, tmp59.dtype) tmp61 = tl.where(tmp36, tmp59, tmp60) tmp62 = tl.where(tmp4, tmp35, tmp61) tl.store(out_ptr0 + x4, tmp62, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = empty_strided_cuda((4, 4, 12, 8, 4), (1536, 384, 32, 4, 1), torch.float32) buf0 = reinterpret_tensor(buf2, (4, 4, 12, 4, 4), (1536, 384, 32, 4, 1), 0) get_raw_stream(0) triton_poi_fused_cat_0[grid(3072)](arg0_1, buf0, 3072, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf1 = reinterpret_tensor(buf2, (4, 4, 12, 4, 4), (1536, 384, 32, 4, 1), 16) triton_poi_fused_flip_1[grid(3072)](buf0, buf1, 3072, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 12, 12, 12), (6912, 1728, 144, 12, 1), torch.float32) triton_poi_fused_cat_2[grid(27648)](buf2, buf3, 27648, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf1 del buf2 return buf3, class ReflectionPad3dNew(nn.Module): def __init__(self, padding): super(ReflectionPad3dNew, self).__init__() self.padding = padding if isinstance(padding, int): self.padding = (padding,) * 6 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
giuliabaldini/Pix2PixNIfTI
ReflectionPad3d
false
3,542
[ "BSD-3-Clause" ]
0
59ff825760f682d2734bd5e95503a03f80d32414
https://github.com/giuliabaldini/Pix2PixNIfTI/tree/59ff825760f682d2734bd5e95503a03f80d32414
CNN
import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.utils class CNN(nn.Module): """ Convolutional layer of a character-based convolutional encoder that outputs word embeddings. """ def __init__(self, char_embed_size: 'int', word_embed_size: 'int', kernel_size: 'int'=5, padding: 'int'=1): """ Init CNN @param char_embed_size (int): size of the character embedding vector; in_channels (dimensionality) @param word_embed_size (int): size of the word embedding vector; out_channels (dimensionality) @param kernel_size (int): kernel size of the convolutional layer @param padding (int): padding size for convolutional layer """ super(CNN, self).__init__() self.conv = nn.Conv1d(char_embed_size, word_embed_size, kernel_size =kernel_size, padding=padding) def forward(self, x: 'torch.Tensor') ->torch.Tensor: """ Takes a minibatch of character embeddings of source sentences and computes convolutions in the temporal direction. Then, we take a max-pool over the temporal dimension to get the output. @param x (torch.Tensor): a minibatch of character-level word embeddings; shape (batch_size, char_embed_size, max_word_length) @returns x_conv_out (Tensor): a tensor of the result of convolution & max_pool; shape (batch_size, word_embed_size) """ x_conv = F.relu(self.conv(x)) num_windows = x_conv.shape[-1] x_conv_out = F.max_pool1d(x_conv, kernel_size=num_windows) x_conv_out = x_conv_out.squeeze(-1) return x_conv_out def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'char_embed_size': 4, 'word_embed_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.nn.utils 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 = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 2 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tl.store(out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr1 + x0, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 5), (20, 5, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_1, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 2), (8, 2, 1)) buf1 = reinterpret_tensor(buf0, (4, 2), (2, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 2), (2, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8)](buf1, primals_2, buf4, 8, XBLOCK=8, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.int8) buf3 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_1[grid(4)](buf1, buf2, buf3, 4, XBLOCK=4, num_warps=1, num_stages=1) return reinterpret_tensor(buf3, (4,), (1,), 0 ), primals_1, reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf1, (4, 1, 2), (2, 2, 1), 0), buf2, buf4 class CNNNew(nn.Module): """ Convolutional layer of a character-based convolutional encoder that outputs word embeddings. """ def __init__(self, char_embed_size: 'int', word_embed_size: 'int', kernel_size: 'int'=5, padding: 'int'=1): """ Init CNN @param char_embed_size (int): size of the character embedding vector; in_channels (dimensionality) @param word_embed_size (int): size of the word embedding vector; out_channels (dimensionality) @param kernel_size (int): kernel size of the convolutional layer @param padding (int): padding size for convolutional layer """ super(CNNNew, self).__init__() self.conv = nn.Conv1d(char_embed_size, word_embed_size, kernel_size =kernel_size, padding=padding) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
giwankim/cs224n
CNN
false
3,543
[ "MIT" ]
0
d05d018dd3026aa48810260be50c94cda596dc82
https://github.com/giwankim/cs224n/tree/d05d018dd3026aa48810260be50c94cda596dc82
LinearAdditiveUpsample
import torch import torch.utils.data import torch import torch.nn as nn class LinearAdditiveUpsample(nn.Module): """Bi/Trilinear Additive Upsample Upsampling strategy described in Wojna et al (https://doi.org/10.1007/s11263-019-01170-8) to avoid checkerboard patterns while keeping a better performance for the convolution. Parameters: scale_factor (int) -- the factor for the upsampling operation n_splits (float) -- the channel reduction factor threed (bool) -- 3D (true) or 2D (false) network """ def __init__(self, scale_factor, n_splits, threed): super(LinearAdditiveUpsample, self).__init__() self.scale_factor = scale_factor self.n_splits = n_splits if threed: self.mode = 'trilinear' else: self.mode = 'bilinear' def forward(self, input_tensor): n_channels = input_tensor.shape[1] assert self.n_splits > 0 and n_channels % self.n_splits == 0, 'Number of feature channels should be divisible by n_splits' resizing_layer = nn.functional.interpolate(input_tensor, scale_factor=self.scale_factor, mode=self.mode, align_corners=False ) split = torch.split(resizing_layer, self.n_splits, dim=1) split_tensor = torch.stack(split, dim=1) output_tensor = torch.sum(split_tensor, dim=2) return output_tensor def get_inputs(): return [torch.rand([4, 4, 4, 4, 4])] def get_init_inputs(): return [[], {'scale_factor': 1.0, 'n_splits': 4, 'threed': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.utils.data import torch import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0( in_out_ptr0, in_out_ptr1, in_out_ptr3, 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 // 16 % 4 x1 = xindex // 4 % 4 x0 = xindex % 4 x3 = xindex // 64 x6 = xindex tmp0 = x2 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = x1 tmp11 = tmp10.to(tl.float32) tmp12 = tmp11 + tmp2 tmp13 = tmp12 * tmp4 tmp14 = tmp13 - tmp2 tmp15 = triton_helpers.maximum(tmp14, tmp7) tmp16 = tmp15.to(tl.int32) tmp17 = tl.full([1], 1, tl.int64) tmp18 = tmp16 + tmp17 tmp19 = tl.full([1], 3, tl.int64) tmp20 = triton_helpers.minimum(tmp18, tmp19) tmp21 = x0 tmp22 = tmp21.to(tl.float32) tmp23 = tmp22 + tmp2 tmp24 = tmp23 * tmp4 tmp25 = tmp24 - tmp2 tmp26 = triton_helpers.maximum(tmp25, tmp7) tmp27 = tmp26.to(tl.int32) tmp28 = tmp27 + tmp17 tmp29 = triton_helpers.minimum(tmp28, tmp19) tmp30 = tl.load(in_ptr0 + (tmp29 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask, eviction_policy='evict_last') tmp31 = tl.load(in_ptr0 + (tmp27 + 4 * tmp20 + 16 * tmp9 + 64 * x3), xmask, eviction_policy='evict_last') tmp32 = tmp30 - tmp31 tmp33 = tmp27.to(tl.float32) tmp34 = tmp26 - tmp33 tmp35 = triton_helpers.maximum(tmp34, tmp7) tmp36 = triton_helpers.minimum(tmp35, tmp4) tmp37 = tmp32 * tmp36 tmp38 = tmp31 + tmp37 tmp39 = tl.load(in_ptr0 + (tmp29 + 4 * tmp16 + 16 * tmp9 + 64 * x3), xmask, eviction_policy='evict_last') tmp40 = tl.load(in_ptr0 + (tmp27 + 4 * tmp16 + 16 * tmp9 + 64 * x3), xmask, eviction_policy='evict_last') tmp41 = tmp39 - tmp40 tmp42 = tmp41 * tmp36 tmp43 = tmp40 + tmp42 tmp44 = tmp9 + tmp17 tmp45 = triton_helpers.minimum(tmp44, tmp19) tmp46 = tl.load(in_ptr0 + (tmp29 + 4 * tmp20 + 16 * tmp45 + 64 * x3), xmask, eviction_policy='evict_last') tmp47 = tl.load(in_ptr0 + (tmp27 + 4 * tmp20 + 16 * tmp45 + 64 * x3), xmask, eviction_policy='evict_last') tmp48 = tl.load(in_ptr0 + (tmp29 + 4 * tmp16 + 16 * tmp45 + 64 * x3), xmask, eviction_policy='evict_last') tmp49 = tl.load(in_ptr0 + (tmp27 + 4 * tmp16 + 16 * tmp45 + 64 * x3), xmask, eviction_policy='evict_last') tmp50 = tmp48 - tmp49 tmp51 = tmp50 * tmp36 tmp52 = tmp49 + tmp51 tmp53 = tmp46 - tmp47 tmp54 = tmp53 * tmp36 tmp55 = tmp47 + tmp54 tmp56 = tmp55 - tmp52 tmp57 = tmp16.to(tl.float32) tmp58 = tmp15 - tmp57 tmp59 = triton_helpers.maximum(tmp58, tmp7) tmp60 = triton_helpers.minimum(tmp59, tmp4) tmp61 = tmp56 * tmp60 tmp62 = tmp52 + tmp61 tmp63 = tmp38 - tmp43 tmp64 = tmp63 * tmp60 tmp65 = tmp43 + tmp64 tmp66 = tmp62 - tmp65 tmp67 = tmp9.to(tl.float32) tmp68 = tmp8 - tmp67 tmp69 = triton_helpers.maximum(tmp68, tmp7) tmp70 = triton_helpers.minimum(tmp69, tmp4) tmp71 = tmp66 * tmp70 tl.store(in_out_ptr0 + x6, tmp38, xmask) tl.store(in_out_ptr1 + x6, tmp43, xmask) tl.store(in_out_ptr3 + x6, tmp71, xmask) @triton.jit def triton_poi_fused_sum_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex // 64 x4 = xindex % 64 x1 = xindex // 4 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (x4 + 256 * x3), xmask) tmp1 = tl.load(in_ptr1 + (x4 + 256 * x3), xmask) tmp19 = tl.load(in_ptr2 + (x4 + 256 * x3), xmask) tmp21 = tl.load(in_ptr0 + (64 + x4 + 256 * x3), xmask) tmp22 = tl.load(in_ptr1 + (64 + x4 + 256 * x3), xmask) tmp26 = tl.load(in_ptr2 + (64 + x4 + 256 * x3), xmask) tmp29 = tl.load(in_ptr0 + (128 + x4 + 256 * x3), xmask) tmp30 = tl.load(in_ptr1 + (128 + x4 + 256 * x3), xmask) tmp34 = tl.load(in_ptr2 + (128 + x4 + 256 * x3), xmask) tmp37 = tl.load(in_ptr0 + (192 + x4 + 256 * x3), xmask) tmp38 = tl.load(in_ptr1 + (192 + x4 + 256 * x3), xmask) tmp42 = tl.load(in_ptr2 + (192 + x4 + 256 * x3), xmask) tmp2 = tmp1 - tmp0 tmp3 = x1 tmp4 = tmp3.to(tl.float32) tmp5 = 0.5 tmp6 = tmp4 + tmp5 tmp7 = 1.0 tmp8 = tmp6 * tmp7 tmp9 = tmp8 - tmp5 tmp10 = 0.0 tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp12 = tmp11.to(tl.int32) tmp13 = tmp12.to(tl.float32) tmp14 = tmp11 - tmp13 tmp15 = triton_helpers.maximum(tmp14, tmp10) tmp16 = triton_helpers.minimum(tmp15, tmp7) tmp17 = tmp2 * tmp16 tmp18 = tmp0 + tmp17 tmp20 = tmp18 + tmp19 tmp23 = tmp22 - tmp21 tmp24 = tmp23 * tmp16 tmp25 = tmp21 + tmp24 tmp27 = tmp25 + tmp26 tmp28 = tmp20 + tmp27 tmp31 = tmp30 - tmp29 tmp32 = tmp31 * tmp16 tmp33 = tmp29 + tmp32 tmp35 = tmp33 + tmp34 tmp36 = tmp28 + tmp35 tmp39 = tmp38 - tmp37 tmp40 = tmp39 * tmp16 tmp41 = tmp37 + tmp40 tmp43 = tmp41 + tmp42 tmp44 = tmp36 + tmp43 tl.store(out_ptr0 + x5, tmp44, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf6 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf7 = buf6 del buf6 buf8 = buf7 del buf7 buf9 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf10 = buf9 del buf9 buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf5 = buf0 del buf0 buf11 = buf5 del buf5 get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid (1024)](buf8, buf10, buf11, arg0_1, 1024, XBLOCK=256, num_warps =4, num_stages=1) del arg0_1 buf12 = empty_strided_cuda((4, 1, 4, 4, 4), (64, 64, 16, 4, 1), torch.float32) triton_poi_fused_sum_1[grid(256)](buf10, buf8, buf11, buf12, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf10 del buf11 del buf8 return buf12, class LinearAdditiveUpsampleNew(nn.Module): """Bi/Trilinear Additive Upsample Upsampling strategy described in Wojna et al (https://doi.org/10.1007/s11263-019-01170-8) to avoid checkerboard patterns while keeping a better performance for the convolution. Parameters: scale_factor (int) -- the factor for the upsampling operation n_splits (float) -- the channel reduction factor threed (bool) -- 3D (true) or 2D (false) network """ def __init__(self, scale_factor, n_splits, threed): super(LinearAdditiveUpsampleNew, self).__init__() self.scale_factor = scale_factor self.n_splits = n_splits if threed: self.mode = 'trilinear' else: self.mode = 'bilinear' def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
giuliabaldini/Pix2PixNIfTI
LinearAdditiveUpsample
false
3,544
[ "BSD-3-Clause" ]
0
59ff825760f682d2734bd5e95503a03f80d32414
https://github.com/giuliabaldini/Pix2PixNIfTI/tree/59ff825760f682d2734bd5e95503a03f80d32414
Entmax15
from torch.autograd import Function import torch from torch import nn def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _entmax_threshold_and_support(X, dim=-1, k=None): """Core computation for 1.5-entmax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: Xsrt, _ = torch.sort(X, dim=dim, descending=True) else: Xsrt, _ = torch.topk(X, k=k, dim=dim) rho = _make_ix_like(Xsrt, dim) mean = Xsrt.cumsum(dim) / rho mean_sq = (Xsrt ** 2).cumsum(dim) / rho ss = rho * (mean_sq - mean ** 2) delta = (1 - ss) / rho delta_nz = torch.clamp(delta, 0) tau = mean - torch.sqrt(delta_nz) support_size = (tau <= Xsrt).sum(dim).unsqueeze(dim) tau_star = tau.gather(dim, support_size - 1) if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): X_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _entmax_threshold_and_support(X_, dim=-1, k=2 * k) _roll_last(tau_star, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau_star, support_size def entmax15(X, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return Entmax15Function.apply(X, dim, k) class Entmax15Function(Function): @classmethod def forward(cls, ctx, X, dim=0, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val X = X / 2 tau_star, _ = _entmax_threshold_and_support(X, dim=dim, k=k) Y = torch.clamp(X - tau_star, min=0) ** 2 ctx.save_for_backward(Y) return Y @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y.sqrt() dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None class Entmax15(nn.Module): def __init__(self, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Entmax15, self).__init__() def forward(self, X): return entmax15(X, dim=self.dim, k=self.k) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch.autograd import Function 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_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_div_max_pow_sort_sub_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = 0.5 tmp10 = tmp8 * tmp9 tmp11 = r1 tmp12 = tmp11.to(tl.int16) tmp13 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp14 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15, _tmp16 = triton_helpers.sort_with_index(tmp13, tmp14, None, 1, stable=False, descending=True) tmp17 = tmp15 * tmp15 tmp18 = tmp17.to(tl.float32) tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK]) tmp20, = tl.associative_scan((tmp19,), 1, _triton_helper_fn_add0) tmp21 = tmp15.to(tl.float32) tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp23, = tl.associative_scan((tmp22,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (r1 + 4 * x0), tmp10, xmask) tl.store(out_ptr1 + (r1 + 4 * x0), tmp15, xmask) tl.store(out_ptr2 + (r1 + 4 * x0), tmp20, xmask) tl.store(out_ptr3 + (r1 + 4 * x0), tmp23, xmask) @triton.jit def triton_poi_fused_clamp_div_le_mul_pow_rsub_sqrt_sub_sum_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last') tmp17 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp30 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp34 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp37 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp47 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp51 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp54 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp64 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 / tmp1 tmp4 = tmp3 / tmp1 tmp5 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp1 * tmp6 tmp8 = tmp1 - tmp7 tmp9 = tmp8 / tmp1 tmp10 = 0.0 tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp2 - tmp12 tmp15 = tmp13 <= tmp14 tmp16 = tmp15.to(tl.int64) tmp18 = 2.0 tmp19 = tmp17 / tmp18 tmp21 = tmp20 / tmp18 tmp22 = tmp19 * tmp19 tmp23 = tmp21 - tmp22 tmp24 = tmp18 * tmp23 tmp25 = tmp1 - tmp24 tmp26 = tmp25 / tmp18 tmp27 = triton_helpers.maximum(tmp26, tmp10) tmp28 = libdevice.sqrt(tmp27) tmp29 = tmp19 - tmp28 tmp31 = tmp29 <= tmp30 tmp32 = tmp31.to(tl.int64) tmp33 = tmp16 + tmp32 tmp35 = 3.0 tmp36 = tmp34 / tmp35 tmp38 = tmp37 / tmp35 tmp39 = tmp36 * tmp36 tmp40 = tmp38 - tmp39 tmp41 = tmp35 * tmp40 tmp42 = tmp1 - tmp41 tmp43 = tmp42 / tmp35 tmp44 = triton_helpers.maximum(tmp43, tmp10) tmp45 = libdevice.sqrt(tmp44) tmp46 = tmp36 - tmp45 tmp48 = tmp46 <= tmp47 tmp49 = tmp48.to(tl.int64) tmp50 = tmp33 + tmp49 tmp52 = 4.0 tmp53 = tmp51 / tmp52 tmp55 = tmp54 / tmp52 tmp56 = tmp53 * tmp53 tmp57 = tmp55 - tmp56 tmp58 = tmp52 * tmp57 tmp59 = tmp1 - tmp58 tmp60 = tmp59 / tmp52 tmp61 = triton_helpers.maximum(tmp60, tmp10) tmp62 = libdevice.sqrt(tmp61) tmp63 = tmp53 - tmp62 tmp65 = tmp63 <= tmp64 tmp66 = tmp65.to(tl.int64) tmp67 = tmp50 + tmp66 tl.store(out_ptr0 + x0, tmp67, xmask) @triton.jit def triton_poi_fused_clamp_div_gather_mul_pow_rsub_sqrt_sub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.full([1], 1, tl.int64) tmp3 = tmp1 - tmp2 tmp4 = tl.full([XBLOCK], 4, tl.int32) tmp5 = tmp3 + tmp4 tmp6 = tmp3 < 0 tmp7 = tl.where(tmp6, tmp5, tmp3) tl.device_assert((0 <= tmp7) & (tmp7 < 4) | ~xmask, 'index out of bounds: 0 <= tmp7 < 4') tmp9 = tl.load(in_ptr2 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp10 = 1 + tmp7 tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tl.load(in_ptr3 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp14 = tmp13 / tmp11 tmp15 = tmp12 * tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp11 * tmp16 tmp18 = 1.0 tmp19 = tmp18 - tmp17 tmp20 = tmp19 / tmp11 tmp21 = 0.0 tmp22 = triton_helpers.maximum(tmp20, tmp21) tmp23 = libdevice.sqrt(tmp22) tmp24 = tmp12 - tmp23 tmp25 = tmp0 - tmp24 tmp26 = triton_helpers.maximum(tmp25, tmp21) tmp27 = tmp26 * tmp26 tl.store(out_ptr0 + x2, tmp27, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_cumsum_div_max_pow_sort_sub_0[grid(64)](arg0_1, buf0, buf1, buf3, buf4, 64, 4, XBLOCK=8, num_warps=2, num_stages=1) del arg0_1 buf5 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) triton_poi_fused_clamp_div_le_mul_pow_rsub_sqrt_sub_sum_1[grid(64)]( buf4, buf3, buf1, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = buf1 del buf1 triton_poi_fused_clamp_div_gather_mul_pow_rsub_sqrt_sub_2[grid(256)]( buf0, buf5, buf4, buf3, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del buf3 del buf4 del buf5 return buf6, def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _entmax_threshold_and_support(X, dim=-1, k=None): """Core computation for 1.5-entmax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: Xsrt, _ = torch.sort(X, dim=dim, descending=True) else: Xsrt, _ = torch.topk(X, k=k, dim=dim) rho = _make_ix_like(Xsrt, dim) mean = Xsrt.cumsum(dim) / rho mean_sq = (Xsrt ** 2).cumsum(dim) / rho ss = rho * (mean_sq - mean ** 2) delta = (1 - ss) / rho delta_nz = torch.clamp(delta, 0) tau = mean - torch.sqrt(delta_nz) support_size = (tau <= Xsrt).sum(dim).unsqueeze(dim) tau_star = tau.gather(dim, support_size - 1) if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): X_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _entmax_threshold_and_support(X_, dim=-1, k=2 * k) _roll_last(tau_star, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau_star, support_size def entmax15(X, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return Entmax15Function.apply(X, dim, k) class Entmax15Function(Function): @classmethod def forward(cls, ctx, X, dim=0, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val X = X / 2 tau_star, _ = _entmax_threshold_and_support(X, dim=dim, k=k) Y = torch.clamp(X - tau_star, min=0) ** 2 ctx.save_for_backward(Y) return Y @classmethod def backward(cls, ctx, dY): Y, = ctx.saved_tensors gppr = Y.sqrt() dX = dY * gppr q = dX.sum(ctx.dim) / gppr.sum(ctx.dim) q = q.unsqueeze(ctx.dim) dX -= q * gppr return dX, None, None class Entmax15New(nn.Module): def __init__(self, dim=-1, k=None): """1.5-entmax: normalizing sparse transform (a la softmax). Solves the optimization problem: max_p <x, p> - H_1.5(p) s.t. p >= 0, sum(p) == 1. where H_1.5(p) is the Tsallis alpha-entropy with alpha=1.5. Parameters ---------- dim : int The dimension along which to apply 1.5-entmax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Entmax15New, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
gitlost-murali/awesome-align
Entmax15
false
3,545
[ "BSD-3-Clause" ]
0
39fb45ca85a98e005447bddb52c48e65ce7d399b
https://github.com/gitlost-murali/awesome-align/tree/39fb45ca85a98e005447bddb52c48e65ce7d399b
DoubleSwish
import torch from torch import Tensor class DoubleSwishFunction(torch.autograd.Function): """ double_swish(x) = x * torch.sigmoid(x-1) This is a definition, originally motivated by its close numerical similarity to swish(swish(x)), where swish(x) = x * sigmoid(x). Memory-efficient derivative computation: double_swish(x) = x * s, where s(x) = torch.sigmoid(x-1) double_swish'(x) = d/dx double_swish(x) = x * s'(x) + x' * s(x) = x * s'(x) + s(x). Now, s'(x) = s(x) * (1-s(x)). double_swish'(x) = x * s'(x) + s(x). = x * s(x) * (1-s(x)) + s(x). = double_swish(x) * (1-s(x)) + s(x) ... so we just need to remember s(x) but not x itself. """ @staticmethod def forward(ctx, x: 'Tensor') ->Tensor: x = x.detach() s = torch.sigmoid(x - 1.0) y = x * s ctx.save_for_backward(s, y) return y @staticmethod def backward(ctx, y_grad: 'Tensor') ->Tensor: s, y = ctx.saved_tensors return (y * (1 - s) + s) * y_grad class DoubleSwish(torch.nn.Module): def forward(self, x: 'Tensor') ->Tensor: """Return double-swish activation function which is an approximation to Swish(Swish(x)), that we approximate closely with x * sigmoid(x-1). """ return DoubleSwishFunction.apply(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import Tensor 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_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.0 tmp2 = tmp0 - tmp1 tmp3 = tl.sigmoid(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class DoubleSwishFunction(torch.autograd.Function): """ double_swish(x) = x * torch.sigmoid(x-1) This is a definition, originally motivated by its close numerical similarity to swish(swish(x)), where swish(x) = x * sigmoid(x). Memory-efficient derivative computation: double_swish(x) = x * s, where s(x) = torch.sigmoid(x-1) double_swish'(x) = d/dx double_swish(x) = x * s'(x) + x' * s(x) = x * s'(x) + s(x). Now, s'(x) = s(x) * (1-s(x)). double_swish'(x) = x * s'(x) + s(x). = x * s(x) * (1-s(x)) + s(x). = double_swish(x) * (1-s(x)) + s(x) ... so we just need to remember s(x) but not x itself. """ @staticmethod def forward(ctx, x: 'Tensor') ->Tensor: x = x.detach() s = torch.sigmoid(x - 1.0) y = x * s ctx.save_for_backward(s, y) return y @staticmethod def backward(ctx, y_grad: 'Tensor') ->Tensor: s, y = ctx.saved_tensors return (y * (1 - s) + s) * y_grad class DoubleSwishNew(torch.nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
glynpu/icefall
DoubleSwish
false
3,546
[ "Apache-2.0" ]
0
d766dc5aeea1a8aefab033e581948b07c4ac4bc0
https://github.com/glynpu/icefall/tree/d766dc5aeea1a8aefab033e581948b07c4ac4bc0
UpConv
import torch import torch.nn as nn import torchvision.transforms.functional as TF class UpConv(nn.Module): def __init__(self, in_channels, out_channels): super().__init__() self.tconv = nn.ConvTranspose2d(in_channels=in_channels, out_channels=out_channels, kernel_size=2, stride=2) def forward(self, x, skip_connection): out = self.tconv(x) if out.shape != skip_connection.shape: out = TF.resize(out, size=skip_connection.shape[2:]) out = torch.cat([skip_connection, out], axis=1) return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 8 x0 = xindex % 16 x2 = xindex // 128 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask, other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x3, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = 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 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(1024)](buf1, primals_2, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = torch.ops.aten._upsample_bilinear2d_aa.default(buf1, [4, 4], False) del buf1 buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) triton_poi_fused_cat_1[grid(512)](primals_4, buf3, buf4, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf3 del primals_4 return buf4, primals_1, primals_3 class UpConvNew(nn.Module): def __init__(self, in_channels, out_channels): super().__init__() self.tconv = nn.ConvTranspose2d(in_channels=in_channels, out_channels=out_channels, kernel_size=2, stride=2) def forward(self, input_0, input_1): primals_1 = self.tconv.weight primals_2 = self.tconv.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
gandhisamay/Drone-Cam-Segmentation
UpConv
false
3,547
[ "MIT" ]
0
7e93b6bb65300aea94dd5e35bb8ca3bd1efbe043
https://github.com/gandhisamay/Drone-Cam-Segmentation/tree/7e93b6bb65300aea94dd5e35bb8ca3bd1efbe043
BertPSIHead
from _paritybench_helpers import _mock_config import torch from torch import nn class BertPSIHead(nn.Module): def __init__(self, config): super().__init__() self.transform = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() self.decoder = nn.Linear(config.hidden_size, 2, bias=False) self.bias = nn.Parameter(torch.zeros(2)) self.decoder.bias = self.bias def forward(self, hidden_states): hidden_states = hidden_states[:, 0] hidden_states = self.transform(hidden_states) hidden_states = self.activation(hidden_states) hidden_states = self.decoder(hidden_states) return hidden_states def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (2, 4), (4, 1)) assert_size_stride(primals_5, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_add_tanh_1[grid(64)](buf2, primals_3, 64, XBLOCK= 64, num_warps=1, num_stages=1) del primals_3 buf3 = empty_strided_cuda((16, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 2), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 2), (8, 2, 1), 0 ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf2, primals_4 class BertPSIHeadNew(nn.Module): def __init__(self, config): super().__init__() self.transform = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() self.decoder = nn.Linear(config.hidden_size, 2, bias=False) self.bias = nn.Parameter(torch.zeros(2)) self.decoder.bias = self.bias def forward(self, input_0): primals_5 = self.bias primals_2 = self.transform.weight primals_3 = self.transform.bias primals_4 = self.decoder.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
gitlost-murali/awesome-align
BertPSIHead
false
3,548
[ "BSD-3-Clause" ]
0
39fb45ca85a98e005447bddb52c48e65ce7d399b
https://github.com/gitlost-murali/awesome-align/tree/39fb45ca85a98e005447bddb52c48e65ce7d399b
MultConst
import torch import torch.nn as nn class MultConst(nn.Module): def forward(self, input): return 255 * 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_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 = 255.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 MultConstNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
globz-eu/PyTorch-Multi-Style-Transfer
MultConst
false
3,549
[ "MIT" ]
0
d00ca44ffee6a4eb4b517f3f1a6eabf72db2a3d2
https://github.com/globz-eu/PyTorch-Multi-Style-Transfer/tree/d00ca44ffee6a4eb4b517f3f1a6eabf72db2a3d2
Vgg16
import torch import torch.nn.functional as F from torch import nn from torch.nn import * 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 from torch.nn 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_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=512, num_warps=8, 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=512, num_warps=8, 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=512, num_warps=8, 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=512, num_warps=8, 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]
entc17-fyp-27/GCL
Vgg16
false
3,550
[ "MIT" ]
0
df3964b1ea07a5b825e35720377153f3c143f79b
https://github.com/entc17-fyp-27/GCL/tree/df3964b1ea07a5b825e35720377153f3c143f79b
GramMatrix
import torch import torch.nn as nn class GramMatrix(nn.Module): def forward(self, y): b, ch, h, w = y.size() features = y.view(b, ch, w * h) features_t = features.transpose(1, 2) gram = features.bmm(features_t) / (ch * h * w) return gram def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = 0.015625 tmp2 = tmp0 * tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (4, 4, 16), (64, 16, 1), 0), reinterpret_tensor(arg0_1, (4, 16, 4), (64, 1, 16), 0), out=buf0) del arg0_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_div_0[grid(64)](buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf1, class GramMatrixNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
globz-eu/PyTorch-Multi-Style-Transfer
GramMatrix
false
3,551
[ "MIT" ]
0
d00ca44ffee6a4eb4b517f3f1a6eabf72db2a3d2
https://github.com/globz-eu/PyTorch-Multi-Style-Transfer/tree/d00ca44ffee6a4eb4b517f3f1a6eabf72db2a3d2
ScaledConv2d
import torch from torch import Tensor from torch import nn class ScaledConv2d(nn.Conv2d): def __init__(self, *args, initial_scale: float=1.0, initial_speed: float=1.0, **kwargs): super(ScaledConv2d, self).__init__(*args, **kwargs) initial_scale = torch.tensor(initial_scale).log() self.weight_scale = nn.Parameter(initial_scale.clone().detach()) if self.bias is not None: self.bias_scale = nn.Parameter(initial_scale.clone().detach()) else: self.register_parameter('bias_scale', None) self._reset_parameters(initial_speed) def _reset_parameters(self, initial_speed: 'float'): std = 0.1 / initial_speed a = 3 ** 0.5 * std nn.init.uniform_(self.weight, -a, a) if self.bias is not None: nn.init.constant_(self.bias, 0.0) fan_in = self.weight.shape[1] * self.weight[0][0].numel() scale = fan_in ** -0.5 with torch.no_grad(): self.weight_scale += torch.tensor(scale / std).log() def get_weight(self): return self.weight * self.weight_scale.exp() def get_bias(self): return None if self.bias is None else self.bias * self.bias_scale.exp() def _conv_forward(self, input, weight): F = torch.nn.functional if self.padding_mode != 'zeros': return F.conv2d(F.pad(input, self. _reversed_padding_repeated_twice, mode=self.padding_mode), weight, self.get_bias(), self.stride, _pair(0), self. dilation, self.groups) return F.conv2d(input, weight, self.get_bias(), self.stride, self. padding, self.dilation, self.groups) def forward(self, input: 'Tensor') ->Tensor: return self._conv_forward(input, self.get_weight()) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_exp_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl_math.exp(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_exp_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl_math.exp(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_exp_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (), ()) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (), ()) assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_exp_mul_0[grid(256)](primals_1, primals_2, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_convolution_exp_mul_1[grid(4)](primals_3, primals_4, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = extern_kernels.convolution(primals_5, buf0, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_exp_mul_2[grid(16)](buf3, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf1 return buf3, primals_1, primals_2, primals_3, primals_4, primals_5, buf0 class ScaledConv2dNew(nn.Conv2d): def __init__(self, *args, initial_scale: float=1.0, initial_speed: float=1.0, **kwargs): super(ScaledConv2dNew, self).__init__(*args, **kwargs) initial_scale = torch.tensor(initial_scale).log() self.weight_scale = nn.Parameter(initial_scale.clone().detach()) if self.bias is not None: self.bias_scale = nn.Parameter(initial_scale.clone().detach()) else: self.register_parameter('bias_scale', None) self._reset_parameters(initial_speed) def _reset_parameters(self, initial_speed: 'float'): std = 0.1 / initial_speed a = 3 ** 0.5 * std nn.init.uniform_(self.weight, -a, a) if self.bias is not None: nn.init.constant_(self.bias, 0.0) fan_in = self.weight.shape[1] * self.weight[0][0].numel() scale = fan_in ** -0.5 with torch.no_grad(): self.weight_scale += torch.tensor(scale / std).log() def get_weight(self): return self.weight * self.weight_scale.exp() def get_bias(self): return None if self.bias is None else self.bias * self.bias_scale.exp() def _conv_forward(self, input, weight): F = torch.nn.functional if self.padding_mode != 'zeros': return F.conv2d(F.pad(input, self. _reversed_padding_repeated_twice, mode=self.padding_mode), weight, self.get_bias(), self.stride, _pair(0), self. dilation, self.groups) return F.conv2d(input, weight, self.get_bias(), self.stride, self. padding, self.dilation, self.groups) def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = self.weight_scale primals_4 = self.bias_scale primals_5 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
glynpu/icefall
ScaledConv2d
false
3,552
[ "Apache-2.0" ]
0
d766dc5aeea1a8aefab033e581948b07c4ac4bc0
https://github.com/glynpu/icefall/tree/d766dc5aeea1a8aefab033e581948b07c4ac4bc0
BasicNorm
import torch from torch import Tensor from torch import nn class BasicNorm(torch.nn.Module): """ This is intended to be a simpler, and hopefully cheaper, replacement for LayerNorm. The observation this is based on, is that Transformer-type networks, especially with pre-norm, sometimes seem to set one of the feature dimensions to a large constant value (e.g. 50), which "defeats" the LayerNorm because the output magnitude is then not strongly dependent on the other (useful) features. Presumably the weight and bias of the LayerNorm are required to allow it to do this. So the idea is to introduce this large constant value as an explicit parameter, that takes the role of the "eps" in LayerNorm, so the network doesn't have to do this trick. We make the "eps" learnable. Args: num_channels: the number of channels, e.g. 512. channel_dim: the axis/dimension corresponding to the channel, interprted as an offset from the input's ndim if negative. shis is NOT the num_channels; it should typically be one of {-2, -1, 0, 1, 2, 3}. eps: the initial "epsilon" that we add as ballast in: scale = ((input_vec**2).mean() + epsilon)**-0.5 Note: our epsilon is actually large, but we keep the name to indicate the connection with conventional LayerNorm. learn_eps: if true, we learn epsilon; if false, we keep it at the initial value. """ def __init__(self, num_channels: 'int', channel_dim: 'int'=-1, eps: 'float'=0.25, learn_eps: 'bool'=True) ->None: super(BasicNorm, self).__init__() self.num_channels = num_channels self.channel_dim = channel_dim if learn_eps: self.eps = nn.Parameter(torch.tensor(eps).log().detach()) else: self.register_buffer('eps', torch.tensor(eps).log().detach()) def forward(self, x: 'Tensor') ->Tensor: assert x.shape[self.channel_dim] == self.num_channels scales = (torch.mean(x ** 2, dim=self.channel_dim, keepdim=True) + self.eps.exp()) ** -0.5 return x * scales def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_exp_mean_pow_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') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr1 + 0) tmp14 = tl.broadcast_to(tmp13, [XBLOCK]) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp11 = 4.0 tmp12 = tmp10 / tmp11 tmp15 = tl_math.exp(tmp14) tmp16 = tmp12 + tmp15 tmp17 = -0.5 tmp18 = libdevice.pow(tmp16, tmp17) tl.store(out_ptr0 + x0, tmp18, xmask) @triton.jit def triton_poi_fused_add_exp_mean_mul_pow_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (), ()) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_add_exp_mean_pow_0[grid(64)](primals_1, primals_2, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_exp_mean_mul_pow_1[grid(256)](primals_1, buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 return buf1, primals_1, primals_2 class BasicNormNew(torch.nn.Module): """ This is intended to be a simpler, and hopefully cheaper, replacement for LayerNorm. The observation this is based on, is that Transformer-type networks, especially with pre-norm, sometimes seem to set one of the feature dimensions to a large constant value (e.g. 50), which "defeats" the LayerNorm because the output magnitude is then not strongly dependent on the other (useful) features. Presumably the weight and bias of the LayerNorm are required to allow it to do this. So the idea is to introduce this large constant value as an explicit parameter, that takes the role of the "eps" in LayerNorm, so the network doesn't have to do this trick. We make the "eps" learnable. Args: num_channels: the number of channels, e.g. 512. channel_dim: the axis/dimension corresponding to the channel, interprted as an offset from the input's ndim if negative. shis is NOT the num_channels; it should typically be one of {-2, -1, 0, 1, 2, 3}. eps: the initial "epsilon" that we add as ballast in: scale = ((input_vec**2).mean() + epsilon)**-0.5 Note: our epsilon is actually large, but we keep the name to indicate the connection with conventional LayerNorm. learn_eps: if true, we learn epsilon; if false, we keep it at the initial value. """ def __init__(self, num_channels: 'int', channel_dim: 'int'=-1, eps: 'float'=0.25, learn_eps: 'bool'=True) ->None: super(BasicNormNew, self).__init__() self.num_channels = num_channels self.channel_dim = channel_dim if learn_eps: self.eps = nn.Parameter(torch.tensor(eps).log().detach()) else: self.register_buffer('eps', torch.tensor(eps).log().detach()) def forward(self, input_0): primals_2 = self.eps primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
glynpu/icefall
BasicNorm
false
3,553
[ "Apache-2.0" ]
0
d766dc5aeea1a8aefab033e581948b07c4ac4bc0
https://github.com/glynpu/icefall/tree/d766dc5aeea1a8aefab033e581948b07c4ac4bc0
Sparsemax
from torch.autograd import Function import torch from torch import nn def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _sparsemax_threshold_and_support(X, dim=-1, k=None): """Core computation for sparsemax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: topk, _ = torch.sort(X, dim=dim, descending=True) else: topk, _ = torch.topk(X, k=k, dim=dim) topk_cumsum = topk.cumsum(dim) - 1 rhos = _make_ix_like(topk, dim) support = rhos * topk > topk_cumsum support_size = support.sum(dim=dim).unsqueeze(dim) tau = topk_cumsum.gather(dim, support_size - 1) tau /= support_size if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): in_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _sparsemax_threshold_and_support(in_, dim=-1, k=2 * k) _roll_last(tau, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau, support_size def sparsemax(X, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxFunction.apply(X, dim, k) class SparsemaxFunction(Function): @classmethod def forward(cls, ctx, X, dim=-1, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val tau, supp_size = _sparsemax_threshold_and_support(X, dim=dim, k=k) output = torch.clamp(X - tau, min=0) ctx.save_for_backward(supp_size, output) return output @classmethod def backward(cls, ctx, grad_output): supp_size, output = ctx.saved_tensors dim = ctx.dim grad_input = grad_output.clone() grad_input[output == 0] = 0 v_hat = grad_input.sum(dim=dim) / supp_size.squeeze() v_hat = v_hat.unsqueeze(dim) grad_input = torch.where(output != 0, grad_input - v_hat, grad_input) return grad_input, None, None class Sparsemax(nn.Module): def __init__(self, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(Sparsemax, self).__init__() def forward(self, X): return sparsemax(X, dim=self.dim, k=self.k) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch.autograd import Function 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_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_max_sort_sub_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = r1 tmp10 = tmp9.to(tl.int16) tmp11 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp12 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13, _tmp14 = triton_helpers.sort_with_index(tmp11, tmp12, None, 1, stable=False, descending=True) tmp15 = tmp13.to(tl.float32) tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp17, = tl.associative_scan((tmp16,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (r1 + 4 * x0), tmp8, xmask) tl.store(out_ptr1 + (r1 + 4 * x0), tmp13, xmask) tl.store(out_ptr2 + (r1 + 4 * x0), tmp17, xmask) @triton.jit def triton_poi_fused_gt_mul_sub_sum_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp23 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp26 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp1 * tmp0 tmp4 = tmp3 - tmp1 tmp5 = tmp2 > tmp4 tmp6 = tmp5.to(tl.int64) tmp8 = 2.0 tmp9 = tmp8 * tmp7 tmp11 = tmp10 - tmp1 tmp12 = tmp9 > tmp11 tmp13 = tmp12.to(tl.int64) tmp14 = tmp6 + tmp13 tmp16 = 3.0 tmp17 = tmp16 * tmp15 tmp19 = tmp18 - tmp1 tmp20 = tmp17 > tmp19 tmp21 = tmp20.to(tl.int64) tmp22 = tmp14 + tmp21 tmp24 = 4.0 tmp25 = tmp24 * tmp23 tmp27 = tmp26 - tmp1 tmp28 = tmp25 > tmp27 tmp29 = tmp28.to(tl.int64) tmp30 = tmp22 + tmp29 tl.store(out_ptr0 + x0, tmp30, xmask) @triton.jit def triton_poi_fused_clamp_div_gather_sub_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.full([1], 1, tl.int64) tmp3 = tmp1 - tmp2 tmp4 = tl.full([XBLOCK], 4, tl.int32) tmp5 = tmp3 + tmp4 tmp6 = tmp3 < 0 tmp7 = tl.where(tmp6, tmp5, tmp3) tl.device_assert((0 <= tmp7) & (tmp7 < 4) | ~xmask, 'index out of bounds: 0 <= tmp7 < 4') tmp9 = tl.load(in_ptr2 + (tmp7 + 4 * x1), xmask, eviction_policy= 'evict_last') tmp10 = 1.0 tmp11 = tmp9 - tmp10 tmp12 = tmp1.to(tl.float32) tmp13 = tmp11 / tmp12 tmp14 = tmp0 - tmp13 tmp15 = 0.0 tmp16 = triton_helpers.maximum(tmp14, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_cumsum_max_sort_sub_0[grid(64)](arg0_1, buf0, buf1, buf3, 64, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) triton_poi_fused_gt_mul_sub_sum_1[grid(64)](buf1, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf1 del buf1 triton_poi_fused_clamp_div_gather_sub_2[grid(256)](buf0, buf4, buf3, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del buf3 del buf4 return buf5, def _make_ix_like(X, dim): d = X.size(dim) rho = torch.arange(1, d + 1, device=X.device, dtype=X.dtype) view = [1] * X.dim() view[0] = -1 return rho.view(view).transpose(0, dim) def _roll_last(X, dim): if dim == -1: return X elif dim < 0: dim = X.dim() - dim perm = [i for i in range(X.dim()) if i != dim] + [dim] return X.permute(perm) def _sparsemax_threshold_and_support(X, dim=-1, k=None): """Core computation for sparsemax: optimal threshold and support size. Parameters ---------- X : torch.Tensor The input tensor to compute thresholds over. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- tau : torch.Tensor like `X`, with all but the `dim` dimension intact the threshold value for each vector support_size : torch LongTensor, shape like `tau` the number of nonzeros in each vector. """ if k is None or k >= X.shape[dim]: topk, _ = torch.sort(X, dim=dim, descending=True) else: topk, _ = torch.topk(X, k=k, dim=dim) topk_cumsum = topk.cumsum(dim) - 1 rhos = _make_ix_like(topk, dim) support = rhos * topk > topk_cumsum support_size = support.sum(dim=dim).unsqueeze(dim) tau = topk_cumsum.gather(dim, support_size - 1) tau /= support_size if k is not None and k < X.shape[dim]: unsolved = (support_size == k).squeeze(dim) if torch.any(unsolved): in_ = _roll_last(X, dim)[unsolved] tau_, ss_ = _sparsemax_threshold_and_support(in_, dim=-1, k=2 * k) _roll_last(tau, dim)[unsolved] = tau_ _roll_last(support_size, dim)[unsolved] = ss_ return tau, support_size def sparsemax(X, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- X : torch.Tensor The input tensor. dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. Returns ------- P : torch tensor, same shape as X The projection result, such that P.sum(dim=dim) == 1 elementwise. """ return SparsemaxFunction.apply(X, dim, k) class SparsemaxFunction(Function): @classmethod def forward(cls, ctx, X, dim=-1, k=None): ctx.dim = dim max_val, _ = X.max(dim=dim, keepdim=True) X = X - max_val tau, supp_size = _sparsemax_threshold_and_support(X, dim=dim, k=k) output = torch.clamp(X - tau, min=0) ctx.save_for_backward(supp_size, output) return output @classmethod def backward(cls, ctx, grad_output): supp_size, output = ctx.saved_tensors dim = ctx.dim grad_input = grad_output.clone() grad_input[output == 0] = 0 v_hat = grad_input.sum(dim=dim) / supp_size.squeeze() v_hat = v_hat.unsqueeze(dim) grad_input = torch.where(output != 0, grad_input - v_hat, grad_input) return grad_input, None, None class SparsemaxNew(nn.Module): def __init__(self, dim=-1, k=None): """sparsemax: normalizing sparse transform (a la softmax). Solves the projection: min_p ||x - p||_2 s.t. p >= 0, sum(p) == 1. Parameters ---------- dim : int The dimension along which to apply sparsemax. k : int or None number of largest elements to partial-sort over. For optimal performance, should be slightly bigger than the expected number of nonzeros in the solution. If the solution is more than k-sparse, this function is recursively called with a 2*k schedule. If `None`, full sorting is performed from the beginning. """ self.dim = dim self.k = k super(SparsemaxNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
gitlost-murali/awesome-align
Sparsemax
false
3,554
[ "BSD-3-Clause" ]
0
39fb45ca85a98e005447bddb52c48e65ce7d399b
https://github.com/gitlost-murali/awesome-align/tree/39fb45ca85a98e005447bddb52c48e65ce7d399b
ScaledLinear
import torch from torch import Tensor from torch import nn class ScaledLinear(nn.Linear): """ A modified version of nn.Linear where the parameters are scaled before use, via: weight = self.weight * self.weight_scale.exp() bias = self.bias * self.bias_scale.exp() Args: Accepts the standard args and kwargs that nn.Linear accepts e.g. in_features, out_features, bias=False. initial_scale: you can override this if you want to increase or decrease the initial magnitude of the module's output (affects the initialization of weight_scale and bias_scale). Another option, if you want to do something like this, is to re-initialize the parameters. initial_speed: this affects how fast the parameter will learn near the start of training; you can set it to a value less than one if you suspect that a module is contributing to instability near the start of training. Nnote: regardless of the use of this option, it's best to use schedulers like Noam that have a warm-up period. Alternatively you can set it to more than 1 if you want it to initially train faster. Must be greater than 0. """ def __init__(self, *args, initial_scale: float=1.0, initial_speed: float=1.0, **kwargs): super(ScaledLinear, self).__init__(*args, **kwargs) initial_scale = torch.tensor(initial_scale).log() self.weight_scale = nn.Parameter(initial_scale.clone().detach()) if self.bias is not None: self.bias_scale = nn.Parameter(initial_scale.clone().detach()) else: self.register_parameter('bias_scale', None) self._reset_parameters(initial_speed) def _reset_parameters(self, initial_speed: 'float'): std = 0.1 / initial_speed a = 3 ** 0.5 * std nn.init.uniform_(self.weight, -a, a) if self.bias is not None: nn.init.constant_(self.bias, 0.0) fan_in = self.weight.shape[1] * self.weight[0][0].numel() scale = fan_in ** -0.5 with torch.no_grad(): self.weight_scale += torch.tensor(scale / std).log() def get_weight(self): return self.weight * self.weight_scale.exp() def get_bias(self): return None if self.bias is None else self.bias * self.bias_scale.exp() def forward(self, input: 'Tensor') ->Tensor: return torch.nn.functional.linear(input, self.get_weight(), self. get_bias()) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import 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_exp_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl_math.exp(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_exp_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl_math.exp(tmp2) tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (), ()) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (), ()) assert_size_stride(primals_5, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_exp_mul_0[grid(16)](primals_1, primals_2, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_exp_mul_1[grid(4)](primals_3, primals_4, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(buf1, reinterpret_tensor(primals_5, (64, 4), ( 4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del buf0 del buf1 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, primals_2, primals_3, primals_4, reinterpret_tensor( primals_5, (64, 4), (4, 1), 0) class ScaledLinearNew(nn.Linear): """ A modified version of nn.Linear where the parameters are scaled before use, via: weight = self.weight * self.weight_scale.exp() bias = self.bias * self.bias_scale.exp() Args: Accepts the standard args and kwargs that nn.Linear accepts e.g. in_features, out_features, bias=False. initial_scale: you can override this if you want to increase or decrease the initial magnitude of the module's output (affects the initialization of weight_scale and bias_scale). Another option, if you want to do something like this, is to re-initialize the parameters. initial_speed: this affects how fast the parameter will learn near the start of training; you can set it to a value less than one if you suspect that a module is contributing to instability near the start of training. Nnote: regardless of the use of this option, it's best to use schedulers like Noam that have a warm-up period. Alternatively you can set it to more than 1 if you want it to initially train faster. Must be greater than 0. """ def __init__(self, *args, initial_scale: float=1.0, initial_speed: float=1.0, **kwargs): super(ScaledLinearNew, self).__init__(*args, **kwargs) initial_scale = torch.tensor(initial_scale).log() self.weight_scale = nn.Parameter(initial_scale.clone().detach()) if self.bias is not None: self.bias_scale = nn.Parameter(initial_scale.clone().detach()) else: self.register_parameter('bias_scale', None) self._reset_parameters(initial_speed) def _reset_parameters(self, initial_speed: 'float'): std = 0.1 / initial_speed a = 3 ** 0.5 * std nn.init.uniform_(self.weight, -a, a) if self.bias is not None: nn.init.constant_(self.bias, 0.0) fan_in = self.weight.shape[1] * self.weight[0][0].numel() scale = fan_in ** -0.5 with torch.no_grad(): self.weight_scale += torch.tensor(scale / std).log() def get_weight(self): return self.weight * self.weight_scale.exp() def get_bias(self): return None if self.bias is None else self.bias * self.bias_scale.exp() def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = self.weight_scale primals_4 = self.bias_scale primals_5 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
glynpu/icefall
ScaledLinear
false
3,555
[ "Apache-2.0" ]
0
d766dc5aeea1a8aefab033e581948b07c4ac4bc0
https://github.com/glynpu/icefall/tree/d766dc5aeea1a8aefab033e581948b07c4ac4bc0
BPR
import torch import torch.nn as nn import torch.nn.functional as F class BPR(nn.Module): def __init__(self, user_size, item_size, dim, weight_decay): super().__init__() self.W = nn.Parameter(torch.empty(user_size, dim)) self.H = nn.Parameter(torch.empty(item_size, dim)) nn.init.xavier_normal_(self.W.data) nn.init.xavier_normal_(self.H.data) self.weight_decay = weight_decay def forward(self, u, i, j): """Return loss value. Args: u(torch.LongTensor): tensor stored user indexes. [batch_size,] i(torch.LongTensor): tensor stored item indexes which is prefered by user. [batch_size,] j(torch.LongTensor): tensor stored item indexes which is not prefered by user. [batch_size,] Returns: torch.FloatTensor """ u = self.W[u, :] i = self.H[i, :] j = self.H[j, :] x_ui = torch.mul(u, i).sum(dim=1) x_uj = torch.mul(u, j).sum(dim=1) x_uij = x_ui - x_uj log_prob = F.logsigmoid(x_uij).sum() regularization = self.weight_decay * (u.norm(dim=1).pow(2).sum() + i.norm(dim=1).pow(2).sum() + j.norm(dim=1).pow(2).sum()) return -log_prob + regularization def recommend(self, u): """Return recommended item list given users. Args: u(torch.LongTensor): tensor stored user indexes. [batch_size,] Returns: pred(torch.LongTensor): recommended item list sorted by preference. [batch_size, item_size] """ u = self.W[u, :] x_ui = torch.mm(u, self.H.t()) pred = torch.argsort(x_ui, dim=1) return pred def get_inputs(): return [torch.ones([4], dtype=torch.int64), torch.ones([4], dtype=torch .int64), torch.ones([4], dtype=torch.int64)] def get_init_inputs(): return [[], {'user_size': 4, 'item_size': 4, 'dim': 4, 'weight_decay': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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) tmp7 = tl.load(in_ptr2 + r0, None) tmp26 = tl.load(in_ptr4 + r0, None) tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4), 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + 4 * tmp4, None, eviction_policy='evict_last') tmp8 = tmp7 + tmp1 tmp9 = tmp7 < 0 tmp10 = tl.where(tmp9, tmp8, tmp7) tl.device_assert((0 <= tmp10) & (tmp10 < 4), 'index out of bounds: 0 <= tmp10 < 4') tmp12 = tl.load(in_ptr3 + 4 * tmp10, None, eviction_policy='evict_last') tmp13 = tmp6 * tmp12 tmp14 = tl.load(in_ptr1 + (1 + 4 * tmp4), None, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr3 + (1 + 4 * tmp10), None, eviction_policy= 'evict_last') tmp16 = tmp14 * tmp15 tmp17 = tmp13 + tmp16 tmp18 = tl.load(in_ptr1 + (2 + 4 * tmp4), None, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr3 + (2 + 4 * tmp10), None, eviction_policy= 'evict_last') tmp20 = tmp18 * tmp19 tmp21 = tmp17 + tmp20 tmp22 = tl.load(in_ptr1 + (3 + 4 * tmp4), None, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr3 + (3 + 4 * tmp10), None, eviction_policy= 'evict_last') tmp24 = tmp22 * tmp23 tmp25 = tmp21 + tmp24 tmp27 = tmp26 + tmp1 tmp28 = tmp26 < 0 tmp29 = tl.where(tmp28, tmp27, tmp26) tl.device_assert((0 <= tmp29) & (tmp29 < 4), 'index out of bounds: 0 <= tmp29 < 4') tmp31 = tl.load(in_ptr3 + 4 * tmp29, None, eviction_policy='evict_last') tmp32 = tmp6 * tmp31 tmp33 = tl.load(in_ptr3 + (1 + 4 * tmp29), None, eviction_policy= 'evict_last') tmp34 = tmp14 * tmp33 tmp35 = tmp32 + tmp34 tmp36 = tl.load(in_ptr3 + (2 + 4 * tmp29), None, eviction_policy= 'evict_last') tmp37 = tmp18 * tmp36 tmp38 = tmp35 + tmp37 tmp39 = tl.load(in_ptr3 + (3 + 4 * tmp29), None, eviction_policy= 'evict_last') tmp40 = tmp22 * tmp39 tmp41 = tmp38 + tmp40 tmp42 = tmp6 * tmp6 tmp43 = tmp14 * tmp14 tmp44 = tmp42 + tmp43 tmp45 = tmp18 * tmp18 tmp46 = tmp44 + tmp45 tmp47 = tmp22 * tmp22 tmp48 = tmp46 + tmp47 tmp49 = libdevice.sqrt(tmp48) tmp50 = tmp49 * tmp49 tmp51 = tl.broadcast_to(tmp50, [XBLOCK, RBLOCK]) tmp53 = tl.sum(tmp51, 1)[:, None] tmp54 = tmp12 * tmp12 tmp55 = tmp15 * tmp15 tmp56 = tmp54 + tmp55 tmp57 = tmp19 * tmp19 tmp58 = tmp56 + tmp57 tmp59 = tmp23 * tmp23 tmp60 = tmp58 + tmp59 tmp61 = libdevice.sqrt(tmp60) tmp62 = tmp61 * tmp61 tmp63 = tl.broadcast_to(tmp62, [XBLOCK, RBLOCK]) tmp65 = tl.sum(tmp63, 1)[:, None] tmp66 = tmp31 * tmp31 tmp67 = tmp33 * tmp33 tmp68 = tmp66 + tmp67 tmp69 = tmp36 * tmp36 tmp70 = tmp68 + tmp69 tmp71 = tmp39 * tmp39 tmp72 = tmp70 + tmp71 tmp73 = libdevice.sqrt(tmp72) tmp74 = tmp73 * tmp73 tmp75 = tl.broadcast_to(tmp74, [XBLOCK, RBLOCK]) tmp77 = tl.sum(tmp75, 1)[:, None] tmp78 = tmp25 - tmp41 tmp79 = 0.0 tmp80 = triton_helpers.minimum(tmp79, tmp78) tmp81 = tl_math.abs(tmp78) tmp82 = -tmp81 tmp83 = tl_math.exp(tmp82) tmp84 = libdevice.log1p(tmp83) tmp85 = tmp80 - tmp84 tmp86 = tl.broadcast_to(tmp85, [XBLOCK, RBLOCK]) tmp88 = tl.sum(tmp86, 1)[:, None] tmp89 = -tmp88 tmp90 = tmp53 + tmp65 tmp91 = tmp90 + tmp77 tmp92 = 4.0 tmp93 = tmp91 * tmp92 tmp94 = tmp89 + tmp93 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp94, None) 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, 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) buf2 = empty_strided_cuda((), (), torch.float32) buf6 = buf2 del buf2 get_raw_stream(0) triton_per_fused_add_index_linalg_vector_norm_log_sigmoid_forward_mul_neg_pow_sub_sum_0[ grid(1)](buf6, primals_2, primals_1, primals_4, primals_3, primals_5, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) return buf6, primals_1, primals_2, primals_3, primals_4, primals_5 class BPRNew(nn.Module): def __init__(self, user_size, item_size, dim, weight_decay): super().__init__() self.W = nn.Parameter(torch.empty(user_size, dim)) self.H = nn.Parameter(torch.empty(item_size, dim)) nn.init.xavier_normal_(self.W.data) nn.init.xavier_normal_(self.H.data) self.weight_decay = weight_decay def recommend(self, u): """Return recommended item list given users. Args: u(torch.LongTensor): tensor stored user indexes. [batch_size,] Returns: pred(torch.LongTensor): recommended item list sorted by preference. [batch_size, item_size] """ u = self.W[u, :] x_ui = torch.mm(u, self.H.t()) pred = torch.argsort(x_ui, dim=1) return pred def forward(self, input_0, input_1, input_2): primals_1 = self.W primals_3 = self.H primals_2 = input_0 primals_4 = input_1 primals_5 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
georgezzzh/bpr
BPR
false
3,556
[ "MIT" ]
0
dd2f39d99f7f06ebb305b66363c89c3606a811a1
https://github.com/georgezzzh/bpr/tree/dd2f39d99f7f06ebb305b66363c89c3606a811a1
RegressionModel
import torch import torch.nn as nn class RegressionModel(nn.Module): def __init__(self, num_features_in, num_anchors=5, feature_size=256): super(RegressionModel, self).__init__() self.conv1 = nn.Conv2d(num_features_in, feature_size, kernel_size=3, padding=1) self.act1 = nn.ReLU() self.conv2 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act2 = nn.ReLU() self.conv3 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act3 = nn.ReLU() self.conv4 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act4 = nn.ReLU() self.output = nn.Conv2d(feature_size, num_anchors * 4, kernel_size= 3, padding=1) def forward(self, x): batch_size, _channels, _width, _height = x.shape out = self.conv1(x) out = self.act1(out) out = self.conv2(out) out = self.act2(out) out = self.conv3(out) out = self.act3(out) out = self.conv4(out) out1 = self.act4(out) out = self.output(out1) out = out.permute(0, 2, 3, 1) return out.contiguous().view(batch_size, -1, 4) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features_in': 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): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_clone_view_1(in_out_ptr0, in_ptr0, in_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 20 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 + 320 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.debug_barrier() tl.store(in_out_ptr0 + (x2 + 20 * y3), tmp2, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (256, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (256,), (1,)) assert_size_stride(primals_4, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (20, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_11, (20,), (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, 256, 4, 4), (4096, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(16384)](buf1, primals_3, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 256, 4, 4), (4096, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(16384)](buf3, primals_5, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 256, 4, 4), (4096, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_0[grid(16384)](buf5, primals_7, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 256, 4, 4), (4096, 16, 4, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_0[grid(16384)](buf7, primals_9, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf8 = extern_kernels.convolution(buf7, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 20, 4, 4), (320, 16, 4, 1)) buf9 = empty_strided_cuda((4, 4, 4, 20), (320, 80, 20, 1), torch. float32) buf10 = reinterpret_tensor(buf9, (4, 80, 4), (320, 4, 1), 0) del buf9 triton_poi_fused_clone_view_1[grid(64, 20)](buf10, buf8, primals_11, 64, 20, XBLOCK=32, YBLOCK=8, num_warps=4, num_stages=1) del buf8 del primals_11 return (buf10, primals_1, primals_2, primals_4, primals_6, primals_8, primals_10, buf1, buf3, buf5, buf7) class RegressionModelNew(nn.Module): def __init__(self, num_features_in, num_anchors=5, feature_size=256): super(RegressionModelNew, self).__init__() self.conv1 = nn.Conv2d(num_features_in, feature_size, kernel_size=3, padding=1) self.act1 = nn.ReLU() self.conv2 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act2 = nn.ReLU() self.conv3 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act3 = nn.ReLU() self.conv4 = nn.Conv2d(feature_size, feature_size, kernel_size=3, padding=1) self.act4 = nn.ReLU() self.output = nn.Conv2d(feature_size, num_anchors * 4, kernel_size= 3, padding=1) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.output.weight primals_11 = self.output.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]
glhr/swig
RegressionModel
false
3,557
[ "MIT" ]
0
d6465862ae9adaab6594f79ec8eed211b5d7e4d8
https://github.com/glhr/swig/tree/d6465862ae9adaab6594f79ec8eed211b5d7e4d8
LayerNorm
import torch import torch.nn as nn class LayerNorm(nn.Module): """ Layer Normalization (https://arxiv.org/abs/1607.06450) """ def __init__(self, normalized_shape, eps=1e-05): super(LayerNorm, self).__init__() self.gamma = nn.Parameter(torch.ones(normalized_shape)) self.beta = nn.Parameter(torch.zeros(normalized_shape)) self.eps = eps def forward(self, x): mean = x.mean(-1, keepdim=True) std = x.std(-1, keepdim=True) return self.gamma * (x - mean) / (std + self.eps) + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'normalized_shape': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 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 = tmp0 * tmp11 tmp13 = tmp2 - tmp10 tmp14 = tmp13 * tmp13 tmp15 = tmp3 - tmp10 tmp16 = tmp15 * tmp15 tmp17 = tmp14 + tmp16 tmp18 = tmp5 - tmp10 tmp19 = tmp18 * tmp18 tmp20 = tmp17 + tmp19 tmp21 = tmp7 - tmp10 tmp22 = tmp21 * tmp21 tmp23 = tmp20 + tmp22 tmp24 = 3.0 tmp25 = tmp23 / tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = 1e-05 tmp28 = tmp26 + tmp27 tmp29 = tmp12 / 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, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mean_mul_std_sub_0[grid(256)](primals_2, primals_1, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class LayerNormNew(nn.Module): """ Layer Normalization (https://arxiv.org/abs/1607.06450) """ def __init__(self, normalized_shape, eps=1e-05): super(LayerNormNew, self).__init__() self.gamma = nn.Parameter(torch.ones(normalized_shape)) self.beta = nn.Parameter(torch.zeros(normalized_shape)) self.eps = eps 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]
hamishivi/claf
LayerNorm
false
3,558
[ "MIT" ]
0
8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
https://github.com/hamishivi/claf/tree/8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
Network
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data.distributed import torch class Network(nn.Module): def __init__(self, num_classes): super(Network, self).__init__() self.conv1 = nn.Conv2d(1, 32, kernel_size=3) self.conv2 = nn.Conv2d(32, 64, kernel_size=3) self.drop1 = nn.Dropout2d(p=0.25) self.fc1 = nn.Linear(9216, 128) self.drop2 = nn.Dropout2d(p=0.5) self.fc2 = nn.Linear(128, num_classes) def forward(self, x): x = F.relu(self.conv1(x)) x = F.max_pool2d(F.relu(self.conv2(x)), 2) x = self.drop1(x) x = x.view(-1, 9216) x = F.relu(self.fc1(x)) x = self.drop2(x) x = self.fc2(x) return F.log_softmax(x) def get_inputs(): return [torch.rand([4, 1, 64, 64])] 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 from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils.data.distributed import torch assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 492032 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3844 % 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_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 3600 % 64 x0 = xindex % 3600 x4 = xindex // 3600 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 3616 * x4), tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 230400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 30 x1 = xindex // 30 % 30 x2 = xindex // 900 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (60 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (61 + 2 * x0 + 120 * x1 + 3616 * x2), 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 + x3, tmp15, xmask) tl.store(out_ptr1 + x3, tmp16, xmask) @triton.jit def triton_poi_fused_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 3200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__log_softmax_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 100 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_5(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 100 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) = args args.clear() assert_size_stride(primals_1, (32, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 1, 64, 64), (4096, 4096, 64, 1)) assert_size_stride(primals_4, (64, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 9216), (9216, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (4, 128), (128, 1)) assert_size_stride(primals_9, (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, 32, 62, 62), (123008, 3844, 62, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(492032)](buf1, primals_2, 492032, XBLOCK=1024, 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, 64, 60, 60), (230400, 3600, 60, 1)) buf3 = empty_strided_cuda((4, 64, 60, 60), (231424, 3616, 60, 1), torch.float32) triton_poi_fused_convolution_relu_1[grid(921600)](buf2, primals_5, buf3, 921600, XBLOCK=1024, num_warps=4, num_stages=1) del buf2 del primals_5 buf4 = empty_strided_cuda((4, 64, 30, 30), (57600, 900, 30, 1), torch.int8) buf5 = empty_strided_cuda((4, 64, 30, 30), (57600, 900, 30, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_2[grid(230400)](buf3, buf4, buf5, 230400, XBLOCK=512, num_warps=8, num_stages=1) buf6 = empty_strided_cuda((25, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (25, 9216), (9216, 1), 0 ), reinterpret_tensor(primals_6, (9216, 128), (1, 9216), 0), out=buf6) buf7 = buf6 del buf6 triton_poi_fused_relu_3[grid(3200)](buf7, primals_7, 3200, XBLOCK= 256, num_warps=4, num_stages=1) del primals_7 buf8 = empty_strided_cuda((25, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, buf7, reinterpret_tensor(primals_8, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf8) del primals_9 buf9 = empty_strided_cuda((25, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_4[grid(100)](buf8, buf9, 100, XBLOCK= 128, num_warps=4, num_stages=1) buf10 = buf8 del buf8 triton_poi_fused__log_softmax_5[grid(100)](buf9, buf10, 100, XBLOCK =128, num_warps=4, num_stages=1) del buf9 return (buf10, primals_1, primals_3, primals_4, buf1, buf3, buf4, reinterpret_tensor(buf5, (25, 9216), (9216, 1), 0), buf7, buf10, primals_8, primals_6) class NetworkNew(nn.Module): def __init__(self, num_classes): super(NetworkNew, self).__init__() self.conv1 = nn.Conv2d(1, 32, kernel_size=3) self.conv2 = nn.Conv2d(32, 64, kernel_size=3) self.drop1 = nn.Dropout2d(p=0.25) self.fc1 = nn.Linear(9216, 128) self.drop2 = nn.Dropout2d(p=0.5) self.fc2 = nn.Linear(128, 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_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]
gregmbi/polyaxon
Network
false
3,559
[ "Apache-2.0" ]
0
8f24089fa9cb5df28fc7b70aec27d6d23ee81e8d
https://github.com/gregmbi/polyaxon/tree/8f24089fa9cb5df28fc7b70aec27d6d23ee81e8d
CNN
import torch import torch.nn as nn class CNN(nn.Module): """CNN class - defines model and forward operations""" def __init__(self): super(CNN, self).__init__() self.relu = nn.ReLU() self.pooling = nn.MaxPool2d(kernel_size=2) self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size= 3, stride=1, padding=1) self.conv3 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size =3, stride=1, padding=1) self.conv4 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size =3, stride=1, padding=1) self.fc1 = nn.Linear(64, 128) self.dropout = nn.Dropout(p=0.25) self.fc2 = nn.Linear(128, 10) self.logsoftmax = nn.LogSoftmax(dim=1) def forward(self, x): """ Method override for forward operation """ x = self.conv1(x) x = self.relu(x) x = self.pooling(x) x = self.conv2(x) x = self.relu(x) x = self.pooling(x) x = self.conv3(x) x = self.relu(x) x = self.pooling(x) x = self.conv4(x) x = self.relu(x) x = self.pooling(x) x = x.view(-1, 64) x = self.fc1(x) x = self.relu(x) x = self.dropout(x) x = self.fc2(x) out = self.logsoftmax(x) return out def get_inputs(): return [torch.rand([4, 1, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import 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_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 % 8 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 % 16 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 % 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_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 % 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_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr0 + (8 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp12 = tl.load(in_ptr0 + (9 + 2 * x0 + 16 * x1), None, eviction_policy ='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x2, tmp15, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_relu_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 % 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_per_fused__log_softmax_9(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 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, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (8, 1, 3, 3), (9, 9, 3, 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, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (32, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (64, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (128, 64), (64, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (10, 128), (128, 1)) assert_size_stride(primals_13, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 64, 64), (32768, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(131072)](buf1, primals_2, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 8, 32, 32), (8192, 1024, 32, 1), torch.float32) buf3 = empty_strided_cuda((4, 8, 32, 32), (8192, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(32768)](buf1, buf2, buf3, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf4 = 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(buf4, (4, 16, 32, 32), (16384, 1024, 32, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(65536)](buf5, primals_5, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 16, 16, 16), (4096, 256, 16, 1), torch.float32) buf7 = empty_strided_cuda((4, 16, 16, 16), (4096, 256, 16, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(16384)](buf5, buf6, buf7, 16384, XBLOCK=256, num_warps=4, num_stages=1) buf8 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 32, 16, 16), (8192, 256, 16, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_4[grid(32768)](buf9, primals_7, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 32, 8, 8), (2048, 64, 8, 1), torch. float32) buf11 = empty_strided_cuda((4, 32, 8, 8), (2048, 64, 8, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(8192)](buf9, buf10, buf11, 8192, XBLOCK=128, num_warps=4, num_stages=1) buf12 = extern_kernels.convolution(buf10, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 64, 8, 8), (4096, 64, 8, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_6[grid(16384)](buf13, primals_9, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf14 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.int8) buf15 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch. float32) triton_poi_fused_max_pool2d_with_indices_7[grid(4096)](buf13, buf14, buf15, 4096, XBLOCK=128, num_warps=4, num_stages=1) buf16 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf15, (64, 64), (64, 1), 0), reinterpret_tensor(primals_10, (64, 128), (1, 64), 0), out=buf16) buf17 = buf16 del buf16 triton_poi_fused_relu_8[grid(8192)](buf17, primals_11, 8192, XBLOCK =256, num_warps=4, num_stages=1) del primals_11 buf18 = empty_strided_cuda((64, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_13, buf17, reinterpret_tensor( primals_12, (128, 10), (1, 128), 0), alpha=1, beta=1, out=buf18) del primals_13 buf21 = empty_strided_cuda((64, 10), (10, 1), torch.float32) triton_per_fused__log_softmax_9[grid(64)](buf18, buf21, 64, 10, XBLOCK=8, num_warps=2, num_stages=1) del buf18 return (buf21, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf2, buf3, buf5, buf6, buf7, buf9, buf10, buf11, buf13, buf14, reinterpret_tensor(buf15, (64, 64), (64, 1), 0), buf17, buf21, primals_12, primals_10) class CNNNew(nn.Module): """CNN class - defines model and forward operations""" def __init__(self): super(CNNNew, self).__init__() self.relu = nn.ReLU() self.pooling = nn.MaxPool2d(kernel_size=2) self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=3, stride=1, padding=1) self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size= 3, stride=1, padding=1) self.conv3 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size =3, stride=1, padding=1) self.conv4 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size =3, stride=1, padding=1) self.fc1 = nn.Linear(64, 128) self.dropout = nn.Dropout(p=0.25) self.fc2 = nn.Linear(128, 10) self.logsoftmax = nn.LogSoftmax(dim=1) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.fc1.weight primals_11 = self.fc1.bias primals_12 = self.fc2.weight primals_13 = 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, primals_12, primals_13]) return output[0]
gnzeleven/Hand-Written-Digits-Recognition-Web-App
CNN
false
3,560
[ "Apache-2.0" ]
0
b2c654f8b897273323a4930e3064b843b45cd5c6
https://github.com/gnzeleven/Hand-Written-Digits-Recognition-Web-App/tree/b2c654f8b897273323a4930e3064b843b45cd5c6
SeqAttnMatch
import torch import torch.nn as nn from torch.nn import functional as F class SeqAttnMatch(nn.Module): """ Given sequences X and Y, match sequence Y to each element in X. * o_i = sum(alpha_j * y_j) for i in X * alpha_j = softmax(y_j * x_i) """ def __init__(self, embed_dim, identity=False): super(SeqAttnMatch, self).__init__() if not identity: self.linear = nn.Linear(embed_dim, embed_dim) else: self.linear = None def forward(self, x, y, y_mask): if self.linear: x_proj = self.linear(x.view(-1, x.size(2))).view(x.size()) x_proj = F.relu(x_proj) y_proj = self.linear(y.view(-1, y.size(2))).view(y.size()) y_proj = F.relu(y_proj) else: x_proj = x y_proj = y scores = x_proj.bmm(y_proj.transpose(2, 1)) y_mask = y_mask.unsqueeze(1).expand(scores.size()) scores = scores.masked_fill(y_mask == 0, -1e+30) alpha_flat = F.softmax(scores.view(-1, y.size(1)), -1) alpha = alpha_flat.view(-1, x.size(1), y.size(1)) matched_seq = alpha.bmm(y) return matched_seq def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'embed_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_out_ptr1, 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') tmp5 = tl.load(in_out_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp5 + tmp1 tmp7 = triton_helpers.maximum(tmp3, tmp6) tmp8 = 0.0 tmp9 = tmp7 <= tmp8 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(in_out_ptr1 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * (x0 // 4), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * (x0 // 4)), xmask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * (x0 // 4)), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * (x0 // 4)), xmask, eviction_policy= 'evict_last') tmp18 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1.0000000150474662e+30 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp7 = tmp6 == tmp1 tmp9 = tl.where(tmp7, tmp4, tmp8) tmp10 = triton_helpers.maximum(tmp5, tmp9) tmp12 = tmp11 == tmp1 tmp14 = tl.where(tmp12, tmp4, tmp13) tmp15 = triton_helpers.maximum(tmp10, tmp14) tmp17 = tmp16 == tmp1 tmp19 = tl.where(tmp17, tmp4, tmp18) tmp20 = triton_helpers.maximum(tmp15, tmp19) tmp21 = tmp5 - tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = tmp9 - tmp20 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = tmp14 - tmp20 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tmp19 - tmp20 tmp30 = tl_math.exp(tmp29) tmp31 = tmp28 + tmp30 tl.store(out_ptr0 + x0, tmp20, xmask) tl.store(out_ptr1 + x0, tmp31, xmask) @triton.jit def triton_poi_fused__softmax_2(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 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x1 // 4)), xmask) tmp3 = tl.load(in_ptr1 + x2, xmask) tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 == tmp1 tmp4 = -1.0000000150474662e+30 tmp5 = tl.where(tmp2, tmp4, tmp3) tmp7 = tmp5 - tmp6 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 / tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf2) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0) del buf0 buf3 = reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0) del buf2 buf9 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf1, buf3, primals_3, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf1, reinterpret_tensor(buf3, (4, 4, 4), (16, 1, 4), 0), out=buf4) buf5 = empty_strided_cuda((16, 1), (1, 16), torch.float32) buf6 = empty_strided_cuda((16, 1), (1, 16), torch.float32) triton_poi_fused__softmax_1[grid(16)](primals_5, buf4, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((16, 4), (4, 1), torch.float32) triton_poi_fused__softmax_2[grid(64)](primals_5, buf4, buf5, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf5 del buf6 buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf7, (4, 4, 4), (16, 4, 1), 0), primals_4, out=buf8) del buf7 return buf8, primals_4, primals_5, reinterpret_tensor(primals_1, (16, 4 ), (4, 1), 0), buf1, buf4, buf3, buf9 class SeqAttnMatchNew(nn.Module): """ Given sequences X and Y, match sequence Y to each element in X. * o_i = sum(alpha_j * y_j) for i in X * alpha_j = softmax(y_j * x_i) """ def __init__(self, embed_dim, identity=False): super(SeqAttnMatchNew, self).__init__() if not identity: self.linear = nn.Linear(embed_dim, embed_dim) else: self.linear = None def forward(self, input_0, input_1, input_2): primals_2 = self.linear.weight primals_3 = self.linear.bias primals_1 = input_0 primals_4 = input_1 primals_5 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
hamishivi/claf
SeqAttnMatch
false
3,561
[ "MIT" ]
0
8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
https://github.com/hamishivi/claf/tree/8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
OutputGenerator
import torch import torch.nn as nn class OutputGenerator(nn.Module): def __init__(self, model_dim, tgt_vocab_size): super().__init__() self.tgt_vocab_size = tgt_vocab_size self.linear = nn.Linear(model_dim, tgt_vocab_size, bias=False) self.log_softmax = nn.LogSoftmax(dim=-1) def forward(self, tgt): tgt_log_probs = self.log_softmax(self.linear(tgt)) return tgt_log_probs.reshape(-1, self.tgt_vocab_size) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'model_dim': 4, 'tgt_vocab_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax__log_softmax_backward_data_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') 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 tmp14 = tl_math.exp(tmp13) tl.store(out_ptr0 + x2, tmp13, xmask) tl.store(out_ptr1 + x2, tmp14, 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 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](buf0, buf1, 256, XBLOCK= 256, num_warps=4, num_stages=1) buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax__log_softmax_backward_data_1[grid(256)]( buf1, buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 return reinterpret_tensor(buf2, (64, 4), (4, 1), 0), reinterpret_tensor( primals_2, (64, 4), (4, 1), 0), buf3 class OutputGeneratorNew(nn.Module): def __init__(self, model_dim, tgt_vocab_size): super().__init__() self.tgt_vocab_size = tgt_vocab_size self.linear = nn.Linear(model_dim, tgt_vocab_size, bias=False) self.log_softmax = nn.LogSoftmax(dim=-1) def forward(self, input_0): primals_1 = self.linear.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
guyjacoby/original-transformer-pytorch
OutputGenerator
false
3,562
[ "MIT" ]
0
19e9ab4af3f0ee1ca81f6436eb18c36382bfbc1d
https://github.com/guyjacoby/original-transformer-pytorch/tree/19e9ab4af3f0ee1ca81f6436eb18c36382bfbc1d
PositionwiseFeedForward
import torch import torch.nn as nn from torch.nn import functional as F class PointwiseConv(nn.Module): """ Pointwise Convolution (1x1 Conv) Convolution 1 Dimension (Faster version) (cf. https://github.com/huggingface/pytorch-openai-transformer-lm/blob/ eafc28abdfadfa0732f03a0fc65805c5bfb2ffe7/model_pytorch.py#L45) * Args: input_size: the number of input tensor's dimension num_filters: the number of convolution filter """ def __init__(self, input_size, num_filters): super(PointwiseConv, self).__init__() self.kernel_size = 1 self.num_filters = num_filters weight = torch.empty(input_size, num_filters) nn.init.normal_(weight, std=0.02) self.weight = nn.Parameter(weight) self.bias = nn.Parameter(torch.zeros(num_filters)) def forward(self, x): size_out = x.size()[:-1] + (self.num_filters,) x = torch.addmm(self.bias, x.contiguous().view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class PositionwiseFeedForward(nn.Module): """ Pointwise Feed-Forward Layer * Args: input_size: the number of input size hidden_size: the number of hidden size * Kwargs: dropout: the probability of dropout """ def __init__(self, input_size, hidden_size, dropout=0.1): super(PositionwiseFeedForward, self).__init__() self.pointwise_conv1 = PointwiseConv(input_size=input_size, num_filters=hidden_size) self.pointwise_conv2 = PointwiseConv(input_size=hidden_size, num_filters=input_size) self.activation_fn = F.relu self.dropout = nn.Dropout(p=dropout) def forward(self, x): x = self.pointwise_conv1(x) x = self.activation_fn(x) x = self.pointwise_conv2(x) x = self.dropout(x) return x def get_inputs(): return [torch.rand([4, 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 import triton_helpers import torch.nn as nn from torch.nn import functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = 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.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), primals_3, out=buf0) del primals_3 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_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 ), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), reinterpret_tensor(buf1, (4, 64), (1, 4), 0 ), buf3, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0) class PointwiseConv(nn.Module): """ Pointwise Convolution (1x1 Conv) Convolution 1 Dimension (Faster version) (cf. https://github.com/huggingface/pytorch-openai-transformer-lm/blob/ eafc28abdfadfa0732f03a0fc65805c5bfb2ffe7/model_pytorch.py#L45) * Args: input_size: the number of input tensor's dimension num_filters: the number of convolution filter """ def __init__(self, input_size, num_filters): super(PointwiseConv, self).__init__() self.kernel_size = 1 self.num_filters = num_filters weight = torch.empty(input_size, num_filters) nn.init.normal_(weight, std=0.02) self.weight = nn.Parameter(weight) self.bias = nn.Parameter(torch.zeros(num_filters)) def forward(self, x): size_out = x.size()[:-1] + (self.num_filters,) x = torch.addmm(self.bias, x.contiguous().view(-1, x.size(-1)), self.weight) x = x.view(*size_out) return x class PositionwiseFeedForwardNew(nn.Module): """ Pointwise Feed-Forward Layer * Args: input_size: the number of input size hidden_size: the number of hidden size * Kwargs: dropout: the probability of dropout """ def __init__(self, input_size, hidden_size, dropout=0.1): super(PositionwiseFeedForwardNew, self).__init__() self.pointwise_conv1 = PointwiseConv(input_size=input_size, num_filters=hidden_size) self.pointwise_conv2 = PointwiseConv(input_size=hidden_size, num_filters=input_size) self.activation_fn = F.relu self.dropout = nn.Dropout(p=dropout) def forward(self, input_0): primals_3 = self.pointwise_conv1.weight primals_2 = self.pointwise_conv1.bias primals_5 = self.pointwise_conv2.weight primals_4 = self.pointwise_conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
hamishivi/claf
PositionwiseFeedForward
false
3,563
[ "MIT" ]
0
8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
https://github.com/hamishivi/claf/tree/8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
UNet
import torch import torch.nn as nn import torch.nn.functional as F class UNet(nn.Module): def __init__(self): super().__init__() self.lrelu = nn.LeakyReLU(0.2) self.maxpool = nn.MaxPool2d(2) self.conv1_0 = nn.Conv2d(3, 32, 3, padding=1) self.conv1_1 = nn.Conv2d(32, 32, 3, padding=1) self.conv2_0 = nn.Conv2d(32, 64, 3, padding=1) self.conv2_1 = nn.Conv2d(64, 64, 3, padding=1) self.conv3_0 = nn.Conv2d(64, 128, 3, padding=1) self.conv3_1 = nn.Conv2d(128, 128, 3, padding=1) self.conv4_0 = nn.Conv2d(128, 256, 3, padding=1) self.conv4_1 = nn.Conv2d(256, 256, 3, padding=1) self.conv5_0 = nn.Conv2d(256, 512, 3, padding=1) self.conv5_1 = nn.Conv2d(512, 512, 3, padding=1) self.upconv6_0 = nn.ConvTranspose2d(512, 256, kernel_size=2, stride=2) self.conv6_1 = nn.Conv2d(512, 256, 3, padding=1) self.conv6_2 = nn.Conv2d(256, 256, 3, padding=1) self.upconv7_0 = nn.ConvTranspose2d(256, 128, kernel_size=2, stride=2) self.conv7_1 = nn.Conv2d(256, 128, 3, padding=1) self.conv7_2 = nn.Conv2d(128, 128, 3, padding=1) self.upconv8_0 = nn.ConvTranspose2d(128, 64, kernel_size=2, stride=2) self.conv8_1 = nn.Conv2d(128, 64, 3, padding=1) self.conv8_2 = nn.Conv2d(64, 64, 3, padding=1) self.upconv9_0 = nn.ConvTranspose2d(64, 32, kernel_size=2, stride=2) self.conv9_1 = nn.Conv2d(64, 32, 3, padding=1) self.conv9_2 = nn.Conv2d(32, 32, 3, padding=1) self.conv10 = nn.Conv2d(32, 12, 3, padding=1) def upsample_and_concat(self, x1, x2, upconv_func): upconv = upconv_func(x1) out = torch.cat([x2, upconv], dim=1) return out def forward(self, x): conv1 = self.lrelu(self.conv1_0(x)) conv1 = self.lrelu(self.conv1_1(conv1)) max1 = nn.MaxPool2d(2)(conv1) conv2 = self.lrelu(self.conv2_0(max1)) conv2 = self.lrelu(self.conv2_1(conv2)) max2 = nn.MaxPool2d(2)(conv2) conv3 = self.lrelu(self.conv3_0(max2)) conv3 = self.lrelu(self.conv3_1(conv3)) max3 = nn.MaxPool2d(2)(conv3) conv4 = self.lrelu(self.conv4_0(max3)) conv4 = self.lrelu(self.conv4_1(conv4)) max4 = nn.MaxPool2d(2)(conv4) conv5 = self.lrelu(self.conv5_0(max4)) conv5 = self.lrelu(self.conv5_1(conv5)) upconv6 = self.upsample_and_concat(conv5, conv4, self.upconv6_0) conv6 = self.lrelu(self.conv6_1(upconv6)) conv6 = self.lrelu(self.conv6_2(conv6)) upconv7 = self.upsample_and_concat(conv6, conv3, self.upconv7_0) conv7 = self.lrelu(self.conv7_1(upconv7)) conv7 = self.lrelu(self.conv7_2(conv7)) upconv8 = self.upsample_and_concat(conv7, conv2, self.upconv8_0) conv8 = self.lrelu(self.conv8_1(upconv8)) conv8 = self.lrelu(self.conv8_2(conv8)) upconv9 = self.upsample_and_concat(conv8, conv1, self.upconv9_0) conv9 = self.lrelu(self.conv9_1(upconv9)) conv9 = self.lrelu(self.conv9_2(conv9)) conv10 = self.conv10(conv9) out = F.pixel_shuffle(conv10, 2) return out def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 32 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_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_leaky_relu_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_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_leaky_relu_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_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_leaky_relu_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (8 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr0 + (9 + 2 * x0 + 16 * x1), None, eviction_policy= 'evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_leaky_relu_8(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, None) tl.store(out_ptr1 + x3, tmp7, None) @triton.jit def triton_poi_fused_cat_9(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 64 % 512 x0 = xindex % 64 x2 = xindex // 32768 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x1 + 16384 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 512, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 64 * (-256 + x1) + 16384 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-256 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused_cat_10(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 256 % 256 x0 = xindex % 256 x2 = xindex // 65536 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 256 * x1 + 32768 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 256, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 256 * (-128 + x1) + 32768 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-128 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused_cat_11(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 1024 % 128 x0 = xindex % 1024 x2 = xindex // 131072 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 1024 * x1 + 65536 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 128, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 1024 * (-64 + x1) + 65536 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-64 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused_cat_12(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 4096 % 64 x0 = xindex % 4096 x2 = xindex // 262144 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 4096 * x1 + 131072 * x2), tmp4, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 64, tl.int64) tmp9 = tl.load(in_ptr1 + (x0 + 4096 * (-32 + x1) + 131072 * x2), tmp6, other=0.0) tmp10 = tl.load(in_ptr2 + (-32 + x1), tmp6, eviction_policy= 'evict_last', other=0.0) tmp11 = tmp9 + tmp10 tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp6, tmp11, tmp12) tmp14 = tl.where(tmp4, tmp5, tmp13) tl.store(out_ptr0 + x3, tmp14, None) @triton.jit def triton_poi_fused_pixel_shuffle_13(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 2 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 x5 = xindex y0 = yindex % 64 y1 = yindex // 64 % 2 y2 = yindex // 128 % 64 y6 = yindex // 8192 y3 = yindex // 8192 % 3 y7 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 64 * y2 + 4096 * x5 + 8192 * y1 + 16384 * y6), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x5 + 2 * y1 + 4 * y3), xmask, eviction_policy ='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x5 + 2 * y7), tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47) = args args.clear() assert_size_stride(primals_1, (32, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 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, (64, 32, 3, 3), (288, 9, 3, 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, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_13, (128,), (1,)) assert_size_stride(primals_14, (256, 128, 3, 3), (1152, 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, (512, 256, 2, 2), (1024, 4, 2, 1)) assert_size_stride(primals_23, (256,), (1,)) assert_size_stride(primals_24, (256, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_25, (256,), (1,)) assert_size_stride(primals_26, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_27, (256,), (1,)) assert_size_stride(primals_28, (256, 128, 2, 2), (512, 4, 2, 1)) assert_size_stride(primals_29, (128,), (1,)) assert_size_stride(primals_30, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_31, (128,), (1,)) assert_size_stride(primals_32, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_33, (128,), (1,)) assert_size_stride(primals_34, (128, 64, 2, 2), (256, 4, 2, 1)) assert_size_stride(primals_35, (64,), (1,)) assert_size_stride(primals_36, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_37, (64,), (1,)) assert_size_stride(primals_38, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_39, (64,), (1,)) assert_size_stride(primals_40, (64, 32, 2, 2), (128, 4, 2, 1)) assert_size_stride(primals_41, (32,), (1,)) assert_size_stride(primals_42, (32, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_43, (32,), (1,)) assert_size_stride(primals_44, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_45, (32,), (1,)) assert_size_stride(primals_46, (12, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_47, (12,), (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, 32, 64, 64), (131072, 4096, 64, 1)) buf1 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.bool) buf2 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf0, primals_2, buf1, buf2, 524288, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf4 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.bool) buf5 = buf0 del buf0 triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf3, primals_5, buf4, buf5, 524288, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.float32) buf7 = empty_strided_cuda((4, 32, 32, 32), (32768, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(131072)](buf5, buf6, buf7, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf8 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf9 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) buf10 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf8, primals_7, buf9, buf10, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf11 = extern_kernels.convolution(buf10, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf12 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) buf13 = buf8 del buf8 triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf11, primals_9, buf12, buf13, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf14 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.float32) buf15 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(65536)](buf13, buf14, buf15, 65536, XBLOCK=256, num_warps=4, num_stages=1) buf16 = extern_kernels.convolution(buf14, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 128, 16, 16), (32768, 256, 16, 1)) buf17 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) buf18 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_4[grid(131072)](buf16, primals_11, buf17, buf18, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf19 = extern_kernels.convolution(buf18, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 128, 16, 16), (32768, 256, 16, 1)) buf20 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) buf21 = buf16 del buf16 triton_poi_fused_convolution_leaky_relu_4[grid(131072)](buf19, primals_13, buf20, buf21, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_13 buf22 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch. float32) buf23 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch.int8 ) triton_poi_fused_max_pool2d_with_indices_5[grid(32768)](buf21, buf22, buf23, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf24 = extern_kernels.convolution(buf22, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 256, 8, 8), (16384, 64, 8, 1)) buf25 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .bool) buf26 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .float32) triton_poi_fused_convolution_leaky_relu_6[grid(65536)](buf24, primals_15, buf25, buf26, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_15 buf27 = extern_kernels.convolution(buf26, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 256, 8, 8), (16384, 64, 8, 1)) buf28 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .bool) buf29 = buf24 del buf24 triton_poi_fused_convolution_leaky_relu_6[grid(65536)](buf27, primals_17, buf28, buf29, 65536, XBLOCK=512, num_warps=4, num_stages=1) del buf27 del primals_17 buf30 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch. float32) buf31 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.int8 ) triton_poi_fused_max_pool2d_with_indices_7[grid(16384)](buf29, buf30, buf31, 16384, XBLOCK=256, num_warps=4, num_stages=1) buf32 = extern_kernels.convolution(buf30, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 512, 4, 4), (8192, 16, 4, 1)) buf33 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.bool ) buf34 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch. float32) triton_poi_fused_convolution_leaky_relu_8[grid(32768)](buf32, primals_19, buf33, buf34, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_19 buf35 = extern_kernels.convolution(buf34, primals_20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf35, (4, 512, 4, 4), (8192, 16, 4, 1)) buf36 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.bool ) buf37 = buf32 del buf32 triton_poi_fused_convolution_leaky_relu_8[grid(32768)](buf35, primals_21, buf36, buf37, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf35 del primals_21 buf38 = extern_kernels.convolution(buf37, primals_22, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 256, 8, 8), (16384, 64, 8, 1)) buf39 = reinterpret_tensor(buf19, (4, 512, 8, 8), (32768, 64, 8, 1), 0) del buf19 triton_poi_fused_cat_9[grid(131072)](buf29, buf38, primals_23, buf39, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_23 buf40 = extern_kernels.convolution(buf39, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf40, (4, 256, 8, 8), (16384, 64, 8, 1)) buf41 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .bool) buf42 = buf38 del buf38 triton_poi_fused_convolution_leaky_relu_6[grid(65536)](buf40, primals_25, buf41, buf42, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_25 buf43 = extern_kernels.convolution(buf42, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf43, (4, 256, 8, 8), (16384, 64, 8, 1)) buf44 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .bool) buf45 = buf40 del buf40 triton_poi_fused_convolution_leaky_relu_6[grid(65536)](buf43, primals_27, buf44, buf45, 65536, XBLOCK=512, num_warps=4, num_stages=1) del buf43 del primals_27 buf46 = extern_kernels.convolution(buf45, primals_28, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 128, 16, 16), (32768, 256, 16, 1)) buf47 = reinterpret_tensor(buf11, (4, 256, 16, 16), (65536, 256, 16, 1), 0) del buf11 triton_poi_fused_cat_10[grid(262144)](buf21, buf46, primals_29, buf47, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_29 buf48 = extern_kernels.convolution(buf47, primals_30, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 128, 16, 16), (32768, 256, 16, 1)) buf49 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) buf50 = buf46 del buf46 triton_poi_fused_convolution_leaky_relu_4[grid(131072)](buf48, primals_31, buf49, buf50, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del primals_31 buf51 = extern_kernels.convolution(buf50, primals_32, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf51, (4, 128, 16, 16), (32768, 256, 16, 1)) buf52 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) buf53 = buf48 del buf48 triton_poi_fused_convolution_leaky_relu_4[grid(131072)](buf51, primals_33, buf52, buf53, 131072, XBLOCK=1024, num_warps=4, num_stages=1) del buf51 del primals_33 buf54 = extern_kernels.convolution(buf53, primals_34, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf55 = reinterpret_tensor(buf3, (4, 128, 32, 32), (131072, 1024, 32, 1), 0) del buf3 triton_poi_fused_cat_11[grid(524288)](buf13, buf54, primals_35, buf55, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_35 buf56 = extern_kernels.convolution(buf55, primals_36, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf57 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) buf58 = buf54 del buf54 triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf56, primals_37, buf57, buf58, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_37 buf59 = extern_kernels.convolution(buf58, primals_38, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf59, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf60 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) buf61 = buf56 del buf56 triton_poi_fused_convolution_leaky_relu_2[grid(262144)](buf59, primals_39, buf60, buf61, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf59 del primals_39 buf62 = extern_kernels.convolution(buf61, primals_40, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf63 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) triton_poi_fused_cat_12[grid(1048576)](buf5, buf62, primals_41, buf63, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_41 buf64 = extern_kernels.convolution(buf63, primals_42, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf65 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.bool) buf66 = buf62 del buf62 triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf64, primals_43, buf65, buf66, 524288, XBLOCK=512, num_warps=8, num_stages=1) del primals_43 buf67 = extern_kernels.convolution(buf66, primals_44, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf67, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf68 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1), torch.bool) buf69 = buf64 del buf64 triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf67, primals_45, buf68, buf69, 524288, XBLOCK=512, num_warps=8, num_stages=1) del buf67 del primals_45 buf70 = extern_kernels.convolution(buf69, primals_46, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 12, 64, 64), (49152, 4096, 64, 1)) buf71 = empty_strided_cuda((4, 3, 64, 2, 64, 2), (49152, 16384, 256, 128, 2, 1), torch.float32) triton_poi_fused_pixel_shuffle_13[grid(98304, 2)](buf70, primals_47, buf71, 98304, 2, XBLOCK=2, YBLOCK=512, num_warps=4, num_stages=1) del buf70 del primals_47 return (reinterpret_tensor(buf71, (4, 3, 128, 128), (49152, 16384, 128, 1), 0), 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, buf1, buf2, buf4, buf5, buf6, buf7, buf9, buf10, buf12, buf13, buf14, buf15, buf17, buf18, buf20, buf21, buf22, buf23, buf25, buf26, buf28, buf29, buf30, buf31, buf33, buf34, buf36, buf37, buf39, buf41, buf42, buf44, buf45, buf47, buf49, buf50, buf52, buf53, buf55, buf57, buf58, buf60, buf61, buf63, buf65, buf66, buf68, buf69) class UNetNew(nn.Module): def __init__(self): super().__init__() self.lrelu = nn.LeakyReLU(0.2) self.maxpool = nn.MaxPool2d(2) self.conv1_0 = nn.Conv2d(3, 32, 3, padding=1) self.conv1_1 = nn.Conv2d(32, 32, 3, padding=1) self.conv2_0 = nn.Conv2d(32, 64, 3, padding=1) self.conv2_1 = nn.Conv2d(64, 64, 3, padding=1) self.conv3_0 = nn.Conv2d(64, 128, 3, padding=1) self.conv3_1 = nn.Conv2d(128, 128, 3, padding=1) self.conv4_0 = nn.Conv2d(128, 256, 3, padding=1) self.conv4_1 = nn.Conv2d(256, 256, 3, padding=1) self.conv5_0 = nn.Conv2d(256, 512, 3, padding=1) self.conv5_1 = nn.Conv2d(512, 512, 3, padding=1) self.upconv6_0 = nn.ConvTranspose2d(512, 256, kernel_size=2, stride=2) self.conv6_1 = nn.Conv2d(512, 256, 3, padding=1) self.conv6_2 = nn.Conv2d(256, 256, 3, padding=1) self.upconv7_0 = nn.ConvTranspose2d(256, 128, kernel_size=2, stride=2) self.conv7_1 = nn.Conv2d(256, 128, 3, padding=1) self.conv7_2 = nn.Conv2d(128, 128, 3, padding=1) self.upconv8_0 = nn.ConvTranspose2d(128, 64, kernel_size=2, stride=2) self.conv8_1 = nn.Conv2d(128, 64, 3, padding=1) self.conv8_2 = nn.Conv2d(64, 64, 3, padding=1) self.upconv9_0 = nn.ConvTranspose2d(64, 32, kernel_size=2, stride=2) self.conv9_1 = nn.Conv2d(64, 32, 3, padding=1) self.conv9_2 = nn.Conv2d(32, 32, 3, padding=1) self.conv10 = nn.Conv2d(32, 12, 3, padding=1) def upsample_and_concat(self, x1, x2, upconv_func): upconv = upconv_func(x1) out = torch.cat([x2, upconv], dim=1) return out def forward(self, input_0): primals_1 = self.conv1_0.weight primals_2 = self.conv1_0.bias primals_4 = self.conv1_1.weight primals_5 = self.conv1_1.bias primals_6 = self.conv2_0.weight primals_7 = self.conv2_0.bias primals_8 = self.conv2_1.weight primals_9 = self.conv2_1.bias primals_10 = self.conv3_0.weight primals_11 = self.conv3_0.bias primals_12 = self.conv3_1.weight primals_13 = self.conv3_1.bias primals_14 = self.conv4_0.weight primals_15 = self.conv4_0.bias primals_16 = self.conv4_1.weight primals_17 = self.conv4_1.bias primals_18 = self.conv5_0.weight primals_19 = self.conv5_0.bias primals_20 = self.conv5_1.weight primals_21 = self.conv5_1.bias primals_22 = self.upconv6_0.weight primals_23 = self.upconv6_0.bias primals_24 = self.conv6_1.weight primals_25 = self.conv6_1.bias primals_26 = self.conv6_2.weight primals_27 = self.conv6_2.bias primals_28 = self.upconv7_0.weight primals_29 = self.upconv7_0.bias primals_30 = self.conv7_1.weight primals_31 = self.conv7_1.bias primals_32 = self.conv7_2.weight primals_33 = self.conv7_2.bias primals_34 = self.upconv8_0.weight primals_35 = self.upconv8_0.bias primals_36 = self.conv8_1.weight primals_37 = self.conv8_1.bias primals_38 = self.conv8_2.weight primals_39 = self.conv8_2.bias primals_40 = self.upconv9_0.weight primals_41 = self.upconv9_0.bias primals_42 = self.conv9_1.weight primals_43 = self.conv9_1.bias primals_44 = self.conv9_2.weight primals_45 = self.conv9_2.bias primals_46 = self.conv10.weight primals_47 = self.conv10.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]) return output[0]
frankgu968/learning-to-see-in-the-dark-pytorch
UNet
false
3,564
[ "MIT" ]
0
6a59fc64d1f152a2410b9128a6a51687a9b179d1
https://github.com/frankgu968/learning-to-see-in-the-dark-pytorch/tree/6a59fc64d1f152a2410b9128a6a51687a9b179d1
decoder3
import torch import torch.nn as nn class decoder3(nn.Module): def __init__(self): super(decoder3, self).__init__() self.reflecPad7 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv7 = nn.Conv2d(256, 128, 3, 1, 0) self.relu7 = nn.ReLU(inplace=True) self.unpool = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad8 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv8 = nn.Conv2d(128, 128, 3, 1, 0) self.relu8 = nn.ReLU(inplace=True) self.reflecPad9 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv9 = nn.Conv2d(128, 64, 3, 1, 0) self.relu9 = nn.ReLU(inplace=True) self.unpool2 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad10 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv10 = nn.Conv2d(64, 64, 3, 1, 0) self.relu10 = nn.ReLU(inplace=True) self.reflecPad11 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv11 = nn.Conv2d(64, 3, 3, 1, 0) def forward(self, x): out = self.reflecPad7(x) out = self.conv7(out) out = self.relu7(out) out = self.unpool(out) out = self.reflecPad8(out) out = self.conv8(out) out = self.relu8(out) out = self.reflecPad9(out) out = self.conv9(out) out_relu9 = self.relu9(out) out = self.unpool2(out_relu9) out = self.reflecPad10(out) out = self.conv10(out) out = self.relu10(out) out = self.reflecPad11(out) out = self.conv11(out) return out def get_inputs(): return [torch.rand([4, 256, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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), None, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_1(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 10 % 10 x0 = xindex % 10 x4 = xindex // 100 x2 = xindex // 100 % 128 x7 = xindex tmp0 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x1 ))), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x0 ))), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 4 * tmp4 + 16 * x4), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, None) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 10 x1 = xindex // 10 % 10 x4 = xindex // 100 x2 = xindex // 100 % 128 x5 = xindex tmp0 = tl.load(in_ptr0 + (63 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x0)) + -8 * tl_math.abs(-7 + tl_math.abs(-1 + x1)) + 64 * x4), None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_4(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 18 % 18 x0 = xindex % 18 x4 = xindex // 324 x2 = xindex // 324 % 64 x7 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x1))), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x0))), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 8, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 8 * tmp4 + 64 * x4), xmask, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, xmask) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 82944 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 18 x1 = xindex // 18 % 18 x4 = xindex // 324 x2 = xindex // 324 % 64 x5 = xindex tmp0 = tl.load(in_ptr0 + (255 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x0)) + -16 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 256 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 256 % 3 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_8(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_9(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_10(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_11(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 256, 4, 4), (4096, 16, 4, 1)) assert_size_stride(primals_2, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_3, (128,), (1,)) assert_size_stride(primals_4, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (64, 128, 3, 3), (1152, 9, 3, 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, (3, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_11, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 256, 6, 6), (9216, 36, 6, 1), torch. float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(36864)](primals_1, buf0, 36864, 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, 128, 4, 4), (2048, 16, 4, 1)) buf2 = empty_strided_cuda((8,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_1[grid(8)](buf2, 8, XBLOCK =8, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 128, 10, 10), (12800, 100, 10, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2[grid (51200)](buf2, buf1, primals_3, buf3, 51200, XBLOCK=512, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 128, 8, 8), (8192, 64, 8, 1)) buf5 = empty_strided_cuda((4, 128, 10, 10), (12800, 100, 10, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(51200)](buf4, primals_5, buf5, 51200, XBLOCK=512, num_warps=4, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_6, 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, 8, 8), (4096, 64, 8, 1)) buf7 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_4[grid(16)](buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 64, 18, 18), (20736, 324, 18, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5[grid (82944)](buf7, buf6, primals_7, buf8, 82944, XBLOCK=1024, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 64, 16, 16), (16384, 256, 16, 1)) buf10 = empty_strided_cuda((4, 64, 18, 18), (20736, 324, 18, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_6[grid(82944)](buf9, primals_9, buf10, 82944, XBLOCK=1024, num_warps=4, num_stages=1) buf11 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 3, 16, 16), (768, 256, 16, 1)) buf12 = buf11 del buf11 triton_poi_fused_convolution_7[grid(3072)](buf12, primals_11, 3072, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf13 = empty_strided_cuda((4, 64, 16, 16), (16384, 256, 16, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_8[grid(65536)]( buf9, primals_9, buf13, 65536, XBLOCK=256, num_warps=4, num_stages=1) del buf9 del primals_9 buf14 = empty_strided_cuda((4, 64, 8, 8), (4096, 64, 8, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_9[grid(16384)]( buf6, primals_7, buf14, 16384, XBLOCK=128, num_warps=4, num_stages=1) del buf6 del primals_7 buf15 = empty_strided_cuda((4, 128, 8, 8), (8192, 64, 8, 1), torch.bool ) triton_poi_fused_convolution_relu_threshold_backward_10[grid(32768)]( buf4, primals_5, buf15, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf4 del primals_5 buf16 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.bool ) triton_poi_fused_convolution_relu_threshold_backward_11[grid(8192)]( buf1, primals_3, buf16, 8192, XBLOCK=128, num_warps=4, num_stages=1 ) del buf1 del primals_3 return (buf12, primals_2, primals_4, primals_6, primals_8, primals_10, buf0, buf2, buf3, buf5, buf7, buf8, buf10, buf13, buf14, buf15, buf16) class decoder3New(nn.Module): def __init__(self): super(decoder3New, self).__init__() self.reflecPad7 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv7 = nn.Conv2d(256, 128, 3, 1, 0) self.relu7 = nn.ReLU(inplace=True) self.unpool = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad8 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv8 = nn.Conv2d(128, 128, 3, 1, 0) self.relu8 = nn.ReLU(inplace=True) self.reflecPad9 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv9 = nn.Conv2d(128, 64, 3, 1, 0) self.relu9 = nn.ReLU(inplace=True) self.unpool2 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad10 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv10 = nn.Conv2d(64, 64, 3, 1, 0) self.relu10 = nn.ReLU(inplace=True) self.reflecPad11 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv11 = nn.Conv2d(64, 3, 3, 1, 0) def forward(self, input_0): primals_2 = self.conv7.weight primals_3 = self.conv7.bias primals_4 = self.conv8.weight primals_5 = self.conv8.bias primals_6 = self.conv9.weight primals_7 = self.conv9.bias primals_8 = self.conv10.weight primals_9 = self.conv10.bias primals_10 = self.conv11.weight primals_11 = self.conv11.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]
guswl8033/ARtists
decoder3
false
3,565
[ "Apache-2.0" ]
0
d353195872c1ef1a1aa68659a32fb47779a416fc
https://github.com/guswl8033/ARtists/tree/d353195872c1ef1a1aa68659a32fb47779a416fc
SelfAttention
import torch import torch.nn as nn class SelfAttention(nn.Module): def __init__(self, embed_size, heads): super(SelfAttention, self).__init__() self.embed_size = embed_size self.heads = heads self.head_dim = embed_size // heads assert self.head_dim * self.heads == self.embed_size, 'Embed size need to be div by heads' self.value = nn.Linear(self.head_dim, self.head_dim, bias=False) self.key = nn.Linear(self.head_dim, self.head_dim, bias=False) self.query = nn.Linear(self.head_dim, self.head_dim, bias=False) self.fc_out = nn.Linear(self.heads * self.head_dim, self.embed_size) def forward(self, values, keys, queries, mask): N = queries.shape[0] values_len, keys_len, queries_len = values.shape[1], keys.shape[1 ], queries.shape[1] values = values.reshape(N, values_len, self.heads, self.head_dim) keys = keys.reshape(N, keys_len, self.heads, self.head_dim) queries = queries.reshape(N, queries_len, self.heads, self.head_dim) values = self.value(values) keys = self.key(keys) queries = self.query(queries) energy = torch.einsum('NQHD, NKHD -> NHQK', [queries, keys]) if mask is not None: energy = energy.masked_fill(mask == 0, float(1e-12)) attention = torch.softmax(energy / self.head_dim ** 0.5, dim=3) out = torch.einsum('NVHD, NHQK->NQHD', [values, attention]).reshape(N, queries_len, self.heads * self.head_dim) out = self.fc_out(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 1]), torch.rand([4, 4, 4, 1]), torch.rand( [4, 4, 4, 1]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'embed_size': 4, 'heads': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_eq_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) @triton.jit def triton_poi_fused__softmax_masked_fill_sum_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl. constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (4 * x2 + 16 * y3), xmask & ymask, eviction_policy='evict_last').to(tl.int1) tmp1 = tl.load(in_ptr1 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + (y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * x2 + 16 * y3), xmask & ymask, eviction_policy='evict_last').to(tl.int1) tmp9 = tl.load(in_ptr2 + (4 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (2 + 4 * x2 + 16 * y3), xmask & ymask, eviction_policy='evict_last').to(tl.int1) tmp15 = tl.load(in_ptr2 + (8 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp20 = tl.load(in_ptr0 + (3 + 4 * x2 + 16 * y3), xmask & ymask, eviction_policy='evict_last').to(tl.int1) tmp21 = tl.load(in_ptr2 + (12 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp3 = tmp1 * tmp2 tmp4 = 9.999999960041972e-13 tmp5 = tl.where(tmp0, tmp4, tmp3) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp10 = tmp1 * tmp9 tmp11 = tl.where(tmp8, tmp4, tmp10) tmp12 = tmp11 * tmp6 tmp13 = triton_helpers.maximum(tmp7, tmp12) tmp16 = tmp1 * tmp15 tmp17 = tl.where(tmp14, tmp4, tmp16) tmp18 = tmp17 * tmp6 tmp19 = triton_helpers.maximum(tmp13, tmp18) tmp22 = tmp1 * tmp21 tmp23 = tl.where(tmp20, 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 tmp41 = tmp28 / tmp40 tmp42 = tmp31 / tmp40 tmp43 = tmp41 + tmp42 tmp44 = tmp35 / tmp40 tmp45 = tmp43 + tmp44 tmp46 = tmp39 / tmp40 tmp47 = tmp45 + tmp46 tl.debug_barrier() tl.store(in_out_ptr0 + (x2 + 4 * y3), tmp47, xmask & ymask) @triton.jit def triton_poi_fused_sum_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp3 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp5 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_mul_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y1 = yindex // 4 y0 = yindex % 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (x2 + 4 * y1), xmask & ymask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 1), (16, 4, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 1), (16, 4, 1, 1)) assert_size_stride(primals_3, (4, 4, 4, 1), (16, 4, 1, 1)) assert_size_stride(primals_4, (1, 1), (1, 1)) assert_size_stride(primals_5, (1, 1), (1, 1)) assert_size_stride(primals_6, (1, 1), (1, 1)) assert_size_stride(primals_7, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 1), (1, 1), 0), primals_4, out=buf0) del primals_4 buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 1), (1, 1), 0), primals_5, out=buf1) del primals_5 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 1), (1, 1), 0), primals_6, out=buf2) del primals_6 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_eq_0[grid(256)](primals_7, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf7 = reinterpret_tensor(buf5, (4, 4, 4, 1, 1, 1), (16, 1, 4, 64, 64, 64), 0) del buf5 triton_poi_fused__softmax_masked_fill_sum_1[grid(16, 4)](buf7, buf3, buf2, buf1, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((4, 1, 4, 1, 1, 1), (4, 4, 1, 1, 1, 1), torch.float32) triton_poi_fused_sum_2[grid(16)](buf0, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf8 = reinterpret_tensor(buf0, (4, 4, 4, 1, 1, 1), (16, 4, 1, 1, 1, 1), 0) del buf0 triton_poi_fused_mul_3[grid(16, 4)](buf6, buf7, buf8, 16, 4, XBLOCK =4, YBLOCK=8, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0) del buf7 extern_kernels.addmm(primals_9, reinterpret_tensor(buf8, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf9) del primals_9 return reinterpret_tensor(buf9, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 1), (1, 1), 0 ), reinterpret_tensor(primals_3, (64, 1), (1, 1), 0 ), buf1, reinterpret_tensor(primals_1, (64, 1), (1, 1), 0 ), buf2, buf3, buf6, reinterpret_tensor(buf8, (16, 4), (4, 1), 0 ), primals_8 class SelfAttentionNew(nn.Module): def __init__(self, embed_size, heads): super(SelfAttentionNew, self).__init__() self.embed_size = embed_size self.heads = heads self.head_dim = embed_size // heads assert self.head_dim * self.heads == self.embed_size, 'Embed size need to be div by heads' self.value = nn.Linear(self.head_dim, self.head_dim, bias=False) self.key = nn.Linear(self.head_dim, self.head_dim, bias=False) self.query = nn.Linear(self.head_dim, self.head_dim, bias=False) self.fc_out = nn.Linear(self.heads * self.head_dim, self.embed_size) def forward(self, input_0, input_1, input_2, input_3): primals_4 = self.value.weight primals_5 = self.key.weight primals_6 = self.query.weight primals_8 = self.fc_out.weight primals_9 = self.fc_out.bias primals_1 = input_0 primals_2 = input_1 primals_3 = input_2 primals_7 = input_3 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
h851206/NLP
SelfAttention
false
3,566
[ "MIT" ]
0
f6dd78db78536f203cf9a6748075351df9daeba3
https://github.com/h851206/NLP/tree/f6dd78db78536f203cf9a6748075351df9daeba3
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=128, num_warps=4, num_stages=1) return buf1, primals_2 class GateNew(nn.Module): """Gate Unit g = sigmoid(Wx) x = g * x """ def __init__(self, input_size): 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]
hansd410/mnemonic
Gate
false
3,567
[ "BSD-3-Clause" ]
0
409508d08da7f5d5940ffb56fd9715e6ef1e68a3
https://github.com/hansd410/mnemonic/tree/409508d08da7f5d5940ffb56fd9715e6ef1e68a3
Net
import torch import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self, observations_dim, actions_dim, hidden_dim=500): super(Net, self).__init__() self._input_layer = nn.Linear(observations_dim, hidden_dim) self._hidden1 = nn.Linear(hidden_dim, hidden_dim) self._output_layer = nn.Linear(hidden_dim, actions_dim) def forward(self, x): x = F.relu(self._input_layer(x)) x = F.relu(self._hidden1(x)) x = self._output_layer(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'observations_dim': 4, 'actions_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 32000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 500 x2 = xindex // 2000 x3 = xindex % 2000 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 + 2016 * x2), tmp4, xmask) tl.store(out_ptr1 + (x3 + 2048 * x2), tmp6, xmask) @triton.jit def triton_poi_fused_relu_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 500 x1 = xindex // 500 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 500 * (x1 % 4) + 2016 * (x1 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (500, 4), (4, 1)) assert_size_stride(primals_2, (500,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (500, 500), (500, 1)) assert_size_stride(primals_5, (500,), (1,)) assert_size_stride(primals_6, (4, 500), (500, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 500), (500, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 500), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 500), (8064, 2016, 500, 1), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 500), (8192, 2048, 500, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(32000)](buf0, primals_2, buf1, buf8, 32000, XBLOCK=256, num_warps=4, num_stages=1 ) del primals_2 buf2 = buf0 del buf0 triton_poi_fused_relu_view_1[grid(32000)](buf1, buf2, 32000, XBLOCK =256, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((64, 500), (500, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (500, 500), ( 1, 500), 0), out=buf3) buf4 = buf1 del buf1 buf7 = empty_strided_cuda((4, 4, 4, 500), (8192, 2048, 500, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(32000)](buf3, primals_5, buf4, buf7, 32000, XBLOCK=256, num_warps=4, num_stages=1 ) del primals_5 buf5 = buf3 del buf3 triton_poi_fused_relu_view_1[grid(32000)](buf4, buf5, 32000, XBLOCK =256, num_warps=4, num_stages=1) del buf4 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf5, reinterpret_tensor(primals_6, (500, 4), (1, 500), 0), alpha=1, beta=1, out=buf6) del primals_7 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, buf5, primals_6, buf7, primals_4, buf8 class NetNew(nn.Module): def __init__(self, observations_dim, actions_dim, hidden_dim=500): super(NetNew, self).__init__() self._input_layer = nn.Linear(observations_dim, hidden_dim) self._hidden1 = nn.Linear(hidden_dim, hidden_dim) self._output_layer = nn.Linear(hidden_dim, actions_dim) def forward(self, input_0): primals_1 = self._input_layer.weight primals_2 = self._input_layer.bias primals_4 = self._hidden1.weight primals_5 = self._hidden1.bias primals_6 = self._output_layer.weight primals_7 = self._output_layer.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
hany606/PMLDL-Project
Net
false
3,568
[ "MIT" ]
0
40ccf97720c8fd28ed2a8d8101a0499ff58c2b38
https://github.com/hany606/PMLDL-Project/tree/40ccf97720c8fd28ed2a8d8101a0499ff58c2b38
CAM_Module
import torch import torch.nn as nn class CAM_Module(nn.Module): """ Channel attention module""" def __init__(self, in_dim): super(CAM_Module, self).__init__() self.chanel_in = in_dim self.gamma = nn.Parameter(torch.zeros(1)) self.softmax = nn.Softmax(dim=-1) def forward(self, x): """ inputs : x : input feature maps( B X C X H) returns : out : attention value + input feature attention: B X C X C """ m_batchsize, C, height = x.size() proj_query = x.view(m_batchsize, C, -1) proj_key = x.view(m_batchsize, C, -1).permute(0, 2, 1) energy = torch.bmm(proj_query, proj_key) energy_new = torch.max(energy, -1, keepdim=True)[0].expand_as(energy ) - energy attention = self.softmax(energy_new) proj_value = x.view(m_batchsize, C, -1) out = torch.bmm(attention, proj_value) out = out.view(m_batchsize, C, height) out = self.gamma * out + x return out def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'in_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.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_sub_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 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + x2, xmask) tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp8 = tmp6 - tmp7 tl.store(out_ptr0 + x2, tmp8, 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 = 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 = 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) @triton.jit def triton_poi_fused_add_mul_3(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 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp3 = tmp1 * tmp2 tmp5 = tmp3 + tmp4 tl.store(out_ptr0 + x0, tmp5, 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, (1,), (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(primals_1, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0), out=buf0) buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sub_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 triton_poi_fused__softmax_2[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = buf2 del buf2 extern_kernels.bmm(buf3, primals_1, out=buf4) buf5 = buf3 del buf3 triton_poi_fused_add_mul_3[grid(64)](primals_2, buf4, primals_1, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 del primals_2 return buf5, buf4 class CAM_ModuleNew(nn.Module): """ Channel attention module""" def __init__(self, in_dim): super(CAM_ModuleNew, self).__init__() self.chanel_in = in_dim self.gamma = nn.Parameter(torch.zeros(1)) self.softmax = nn.Softmax(dim=-1) def forward(self, input_0): primals_2 = self.gamma primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
hanhanminnan/Trans-on-BME
CAM_Module
false
3,569
[ "Apache-2.0" ]
0
f4e27c946a30d11a9e9d2bee8f199fd06fe4bef2
https://github.com/hanhanminnan/Trans-on-BME/tree/f4e27c946a30d11a9e9d2bee8f199fd06fe4bef2
encoder3
import torch import torch.nn as nn class encoder3(nn.Module): def __init__(self): super(encoder3, self).__init__() self.conv1 = nn.Conv2d(3, 3, 1, 1, 0) self.reflecPad1 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv2 = nn.Conv2d(3, 64, 3, 1, 0) self.relu2 = nn.ReLU(inplace=True) self.reflecPad3 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv3 = nn.Conv2d(64, 64, 3, 1, 0) self.relu3 = nn.ReLU(inplace=True) self.maxPool = nn.MaxPool2d(kernel_size=2, stride=2, return_indices =True) self.reflecPad4 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv4 = nn.Conv2d(64, 128, 3, 1, 0) self.relu4 = nn.ReLU(inplace=True) self.reflecPad5 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv5 = nn.Conv2d(128, 128, 3, 1, 0) self.relu5 = nn.ReLU(inplace=True) self.maxPool2 = nn.MaxPool2d(kernel_size=2, stride=2, return_indices=True) self.reflecPad6 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv6 = nn.Conv2d(128, 256, 3, 1, 0) self.relu6 = nn.ReLU(inplace=True) def forward(self, x): out = self.conv1(x) out = self.reflecPad1(out) out = self.conv2(out) out = self.relu2(out) out = self.reflecPad3(out) out = self.conv3(out) pool1 = self.relu3(out) out, _pool_idx = self.maxPool(pool1) out = self.reflecPad4(out) out = self.conv4(out) out = self.relu4(out) out = self.reflecPad5(out) out = self.conv5(out) pool2 = self.relu5(out) out, _pool_idx2 = self.maxPool2(pool2) out = self.reflecPad6(out) out = self.conv6(out) out = self.relu6(out) return out 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._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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 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_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_convolution_reflection_pad2d_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 52272 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 3 x1 = xindex // 3 % 66 x2 = xindex // 198 % 66 x3 = xindex // 13068 x4 = xindex tmp0 = tl.load(in_ptr0 + (12285 + x0 + -192 * tl_math.abs(-63 + tl_math .abs(-1 + x2)) + -3 * tl_math.abs(-63 + tl_math.abs(-1 + x1)) + 12288 * x3), xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x4, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_7(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1115136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x1 = xindex // 64 % 66 x2 = xindex // 4224 % 66 x3 = xindex // 278784 x4 = xindex tmp0 = tl.load(in_ptr0 + (262080 + x0 + -4096 * tl_math.abs(-63 + tl_math.abs(-1 + x2)) + -64 * tl_math.abs(-63 + tl_math.abs(-1 + x1 )) + 262144 * x3), 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) tl.store(out_ptr0 + x4, tmp4, xmask) @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 % 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_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 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) tmp7 = tl.load(in_ptr0 + (4096 + x0 + 128 * x1 + 8192 * x2), None) tmp12 = tl.load(in_ptr0 + (4160 + x0 + 128 * x1 + 8192 * x2), None) 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) triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_reflection_pad2d_10(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 295936 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x1 = xindex // 64 % 34 x2 = xindex // 2176 % 34 x3 = xindex // 73984 x4 = xindex tmp0 = tl.load(in_ptr0 + (257920 + x0 + -8192 * tl_math.abs(-31 + tl_math.abs(-1 + x2)) + -128 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 262144 * x3), xmask) tmp1 = tl.load(in_ptr0 + (257984 + x0 + -8192 * tl_math.abs(-31 + tl_math.abs(-1 + x2)) + -128 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 262144 * x3), xmask) tmp3 = tl.load(in_ptr0 + (262016 + x0 + -8192 * tl_math.abs(-31 + tl_math.abs(-1 + x2)) + -128 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 262144 * x3), xmask) tmp5 = tl.load(in_ptr0 + (262080 + x0 + -8192 * tl_math.abs(-31 + tl_math.abs(-1 + x2)) + -128 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 262144 * x3), xmask) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_11(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 % 34 x2 = xindex // 4352 % 34 x3 = xindex // 147968 x4 = xindex tmp0 = tl.load(in_ptr0 + (130944 + x0 + -4096 * tl_math.abs(-31 + tl_math.abs(-1 + x2)) + -128 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 131072 * x3), 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) tl.store(out_ptr0 + x4, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_12(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_13(in_ptr0, out_ptr0, 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) tmp7 = tl.load(in_ptr0 + (4096 + x0 + 256 * x1 + 8192 * x2), None) tmp12 = tl.load(in_ptr0 + (4224 + x0 + 256 * x1 + 8192 * x2), None) 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) triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x3, tmp15, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_reflection_pad2d_14(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 % 18 x2 = xindex // 2304 % 18 x3 = xindex // 41472 x4 = xindex tmp0 = tl.load(in_ptr0 + (126720 + x0 + -8192 * tl_math.abs(-15 + tl_math.abs(-1 + x2)) + -256 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 131072 * x3), None) tmp1 = tl.load(in_ptr0 + (126848 + x0 + -8192 * tl_math.abs(-15 + tl_math.abs(-1 + x2)) + -256 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 131072 * x3), None) tmp3 = tl.load(in_ptr0 + (130816 + x0 + -8192 * tl_math.abs(-15 + tl_math.abs(-1 + x2)) + -256 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 131072 * x3), None) tmp5 = tl.load(in_ptr0 + (130944 + x0 + -8192 * tl_math.abs(-15 + tl_math.abs(-1 + x2)) + -256 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 131072 * x3), None) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tl.store(out_ptr0 + x4, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_15(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 256 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 + 65536 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 256 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 256 * x2 + 65536 * y1), tmp6, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_16(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 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) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_17(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 % 64 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (3, 3, 1, 1), (3, 1, 1, 1)) assert_size_stride(primals_2, (3,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (64, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) get_raw_stream(0) triton_poi_fused_0[grid(12, 4096)](primals_3, buf0, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf1 = empty_strided_cuda((64, 3, 3, 3), (27, 1, 9, 3), torch.float32) triton_poi_fused_1[grid(192, 9)](primals_4, buf1, 192, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((64, 64, 3, 3), (576, 1, 192, 64), torch. float32) triton_poi_fused_2[grid(4096, 9)](primals_6, buf2, 4096, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_6 buf3 = empty_strided_cuda((128, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_3[grid(8192, 9)](primals_8, buf3, 8192, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf4 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_4[grid(16384, 9)](primals_10, buf4, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_10 buf5 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_5[grid(32768, 9)](primals_12, buf5, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf6 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 3, 64, 64), (12288, 1, 192, 3)) buf7 = empty_strided_cuda((4, 3, 66, 66), (13068, 1, 198, 3), torch .float32) triton_poi_fused_convolution_reflection_pad2d_6[grid(52272)](buf6, primals_2, buf7, 52272, XBLOCK=512, num_warps=4, num_stages=1) del buf6 del primals_2 buf8 = extern_kernels.convolution(buf7, buf1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf9 = empty_strided_cuda((4, 64, 66, 66), (278784, 1, 4224, 64), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_7[grid(1115136)]( buf8, primals_5, buf9, 1115136, XBLOCK=1024, num_warps=4, num_stages=1) buf10 = extern_kernels.convolution(buf9, buf2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 64, 64, 64), (262144, 1, 4096, 64)) buf11 = buf10 del buf10 triton_poi_fused_convolution_relu_8[grid(1048576)](buf11, primals_7, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf12 = empty_strided_cuda((4, 64, 32, 32), (65536, 1, 2048, 64), torch.int8) triton_poi_fused_max_pool2d_with_indices_9[grid(262144)](buf11, buf12, 262144, XBLOCK=512, num_warps=8, num_stages=1) buf13 = empty_strided_cuda((4, 64, 34, 34), (73984, 1, 2176, 64), torch.float32) triton_poi_fused_max_pool2d_with_indices_reflection_pad2d_10[grid( 295936)](buf11, buf13, 295936, XBLOCK=1024, num_warps=4, num_stages=1) buf14 = extern_kernels.convolution(buf13, buf3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf15 = empty_strided_cuda((4, 128, 34, 34), (147968, 1, 4352, 128), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_11[grid(591872)]( buf14, primals_9, buf15, 591872, XBLOCK=1024, num_warps=4, num_stages=1) buf16 = extern_kernels.convolution(buf15, buf4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 128, 32, 32), (131072, 1, 4096, 128)) buf17 = buf16 del buf16 triton_poi_fused_convolution_relu_12[grid(524288)](buf17, primals_11, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf18 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.int8) triton_poi_fused_max_pool2d_with_indices_13[grid(131072)](buf17, buf18, 131072, XBLOCK=1024, num_warps=4, num_stages=1) buf19 = empty_strided_cuda((4, 128, 18, 18), (41472, 1, 2304, 128), torch.float32) triton_poi_fused_max_pool2d_with_indices_reflection_pad2d_14[grid( 165888)](buf17, buf19, 165888, XBLOCK=512, num_warps=8, num_stages=1) buf20 = extern_kernels.convolution(buf19, buf5, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf21 = empty_strided_cuda((4, 256, 16, 16), (65536, 256, 16, 1), torch.float32) buf22 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_15[grid(1024, 256) ](buf20, primals_13, buf21, buf22, 1024, 256, XBLOCK=32, YBLOCK =32, num_warps=4, num_stages=1) del buf20 del primals_13 buf23 = empty_strided_cuda((4, 128, 32, 32), (131072, 1, 4096, 128), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_16[grid(524288)]( buf14, primals_9, buf23, 524288, XBLOCK=512, num_warps=8, num_stages=1) del buf14 del primals_9 buf24 = empty_strided_cuda((4, 64, 64, 64), (262144, 1, 4096, 64), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_17[grid(1048576)]( buf8, primals_5, buf24, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf8 del primals_5 return (buf21, primals_1, buf0, buf1, buf2, buf3, buf4, buf5, buf7, buf9, buf11, buf12, buf13, buf15, buf17, buf18, buf19, buf22, buf23, buf24) class encoder3New(nn.Module): def __init__(self): super(encoder3New, self).__init__() self.conv1 = nn.Conv2d(3, 3, 1, 1, 0) self.reflecPad1 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv2 = nn.Conv2d(3, 64, 3, 1, 0) self.relu2 = nn.ReLU(inplace=True) self.reflecPad3 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv3 = nn.Conv2d(64, 64, 3, 1, 0) self.relu3 = nn.ReLU(inplace=True) self.maxPool = nn.MaxPool2d(kernel_size=2, stride=2, return_indices =True) self.reflecPad4 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv4 = nn.Conv2d(64, 128, 3, 1, 0) self.relu4 = nn.ReLU(inplace=True) self.reflecPad5 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv5 = nn.Conv2d(128, 128, 3, 1, 0) self.relu5 = nn.ReLU(inplace=True) self.maxPool2 = nn.MaxPool2d(kernel_size=2, stride=2, return_indices=True) self.reflecPad6 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv6 = nn.Conv2d(128, 256, 3, 1, 0) self.relu6 = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.conv5.weight primals_11 = self.conv5.bias primals_12 = self.conv6.weight primals_13 = self.conv6.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13]) return output[0]
guswl8033/ARtists
encoder3
false
3,570
[ "Apache-2.0" ]
0
d353195872c1ef1a1aa68659a32fb47779a416fc
https://github.com/guswl8033/ARtists/tree/d353195872c1ef1a1aa68659a32fb47779a416fc
Policy
import torch import numpy as np import torch.nn as nn def orthog_layer_init(layer, std=np.sqrt(2), bias_const=0.0): torch.nn.init.orthogonal_(layer.weight, std) torch.nn.init.constant_(layer.bias, bias_const) return layer class Policy(nn.Module): def __init__(self, num_inputs, num_outputs): super(Policy, self).__init__() self.num_outputs = num_outputs self.affine1 = orthog_layer_init(nn.Linear(num_inputs, 64)) self.affine2 = orthog_layer_init(nn.Linear(64, 64)) self.linear3 = orthog_layer_init(nn.Linear(64, num_outputs * 2), std=0.01) def forward(self, x): x = torch.tanh(self.affine1(x)) x = torch.tanh(self.affine2(x)) mu = self.linear3(x)[:, :self.num_outputs] log_std = self.linear3.bias[self.num_outputs:].unsqueeze(0).expand_as( mu) std = torch.exp(log_std) return mu, log_std, std def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'num_inputs': 4, 'num_outputs': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import 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_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 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_exp_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp1 = tl_math.exp(tmp0) tl.store(out_ptr0 + x2, tmp1, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (64, 64), (64, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (8, 64), (64, 1)) assert_size_stride(primals_7, (8,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(256)](buf1, primals_2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (64, 64), (1, 64), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_tanh_0[grid(256)](buf3, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (64, 8), (1, 64), 0), alpha=1, beta=1, out=buf4) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_exp_1[grid(16)](primals_7, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) return reinterpret_tensor(buf4, (4, 4), (8, 1), 0), reinterpret_tensor( primals_7, (4, 4), (0, 1), 4 ), buf5, primals_3, buf1, buf3, buf5, primals_6, primals_4 def orthog_layer_init(layer, std=np.sqrt(2), bias_const=0.0): torch.nn.init.orthogonal_(layer.weight, std) torch.nn.init.constant_(layer.bias, bias_const) return layer class PolicyNew(nn.Module): def __init__(self, num_inputs, num_outputs): super(PolicyNew, self).__init__() self.num_outputs = num_outputs self.affine1 = orthog_layer_init(nn.Linear(num_inputs, 64)) self.affine2 = orthog_layer_init(nn.Linear(64, 64)) self.linear3 = orthog_layer_init(nn.Linear(64, num_outputs * 2), std=0.01) def forward(self, input_0): primals_1 = self.affine1.weight primals_2 = self.affine1.bias primals_4 = self.affine2.weight primals_5 = self.affine2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0], output[1], output[2]
gebob19/natural-policy-gradient-reinforcement-learning
Policy
false
3,571
[ "MIT" ]
0
23faa28d746521d6291034bc87d750c665934ff7
https://github.com/gebob19/natural-policy-gradient-reinforcement-learning/tree/23faa28d746521d6291034bc87d750c665934ff7
ActorNetwork
import torch import torch.nn as nn import torch.nn.functional as F class ActorNetwork(nn.Module): def __init__(self, obs_dim, hidden_size=256): super(ActorNetwork, self).__init__() self._obs_dim = obs_dim self._l1 = nn.Linear(obs_dim, hidden_size) self._l2 = nn.Linear(hidden_size, hidden_size) self._hidden_size = hidden_size def forward(self, x): x = F.relu(self._l1(x)) x = F.relu(self._l2(x)) return x def policy(self, x): pass def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'obs_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 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) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 256), (256, 1)) assert_size_stride(primals_5, (256,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf1, primals_2, buf5, 16384, XBLOCK=128, 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, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 256), (1, 256), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf3, primals_5, buf4, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 256), (256, 1), 0 ), buf4, primals_4, buf5 class ActorNetworkNew(nn.Module): def __init__(self, obs_dim, hidden_size=256): super(ActorNetworkNew, self).__init__() self._obs_dim = obs_dim self._l1 = nn.Linear(obs_dim, hidden_size) self._l2 = nn.Linear(hidden_size, hidden_size) self._hidden_size = hidden_size def policy(self, x): pass 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
harwiltz/sac
ActorNetwork
false
3,572
[ "MIT" ]
0
076e01e63d8933665fbf4038513f163bbfd62800
https://github.com/harwiltz/sac/tree/076e01e63d8933665fbf4038513f163bbfd62800
LogisticRegressionModel
import torch import torch.nn as nn class LogisticRegressionModel(nn.Module): def __init__(self, input_dim, output_dim): super(LogisticRegressionModel, self).__init__() self.linear1 = nn.Linear(input_dim, 1500) self.linear2 = nn.Linear(1500, 1000) self.linear3 = nn.Linear(1000, output_dim) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU() def forward(self, x): out = self.linear1(x) out = self.relu(out) out = self.linear2(out) out = self.relu(out) out = self.linear3(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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 = 96000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 1500 x1 = xindex // 1500 tmp0 = tl.load(in_out_ptr0 + (x0 + 1504 * x1), 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 + (x0 + 1504 * x1), tmp4, xmask) tl.store(out_ptr0 + (x0 + 1536 * x1), tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 1000 x2 = xindex % 4000 x3 = xindex // 4000 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 + 4096 * x3), 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, (1500, 4), (4, 1)) assert_size_stride(primals_2, (1500,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1000, 1500), (1500, 1)) assert_size_stride(primals_5, (1000,), (1,)) assert_size_stride(primals_6, (4, 1000), (1000, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1500), (1504, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1500), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 1500), (24064, 6016, 1504, 1), 0) del buf0 buf6 = empty_strided_cuda((4, 4, 4, 1500), (24576, 6144, 1536, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(96000)](buf1, primals_2, buf6, 96000, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1000), (1000, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 1500), (1504, 1), 0 ), reinterpret_tensor(primals_4, (1500, 1000), (1, 1500), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 1000), (16000, 4000, 1000, 1), 0) del buf2 buf5 = empty_strided_cuda((4, 4, 4, 1000), (16384, 4096, 1000, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(64000)](buf3, primals_5, buf5, 64000, XBLOCK=512, 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, 1000), (1000, 1), 0), reinterpret_tensor(primals_6, (1000, 4), (1, 1000), 0), alpha=1, beta=1, out=buf4) del primals_7 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 1500), (1504, 1), 0 ), reinterpret_tensor(buf3, (64, 1000), (1000, 1), 0 ), primals_6, buf5, primals_4, buf6 class LogisticRegressionModelNew(nn.Module): def __init__(self, input_dim, output_dim): super(LogisticRegressionModelNew, self).__init__() self.linear1 = nn.Linear(input_dim, 1500) self.linear2 = nn.Linear(1500, 1000) self.linear3 = nn.Linear(1000, output_dim) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU() def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
harimaruthachalam/PyTorchNNs
LogisticRegressionModel
false
3,573
[ "MIT" ]
0
94fe173204e18fbe5087643e3da1cd9cdd6bd2ef
https://github.com/harimaruthachalam/PyTorchNNs/tree/94fe173204e18fbe5087643e3da1cd9cdd6bd2ef
ResidualBlock
import torch from torch import nn class ConvRelu(nn.Module): def __init__(self, in_: 'int', out: 'int', activate=True): super(ConvRelu, self).__init__() self.activate = activate self.conv = nn.Conv2d(in_, out, 3, padding=1) self.activation = nn.ReLU(inplace=True) def forward(self, x): x = self.conv(x) if self.activate: x = self.activation(x) return x class ResidualBlock(nn.Module): def __init__(self, in_channels: 'int', num_filters: 'int', batch_activate=False): super(ResidualBlock, self).__init__() self.batch_activate = batch_activate self.activation = nn.ReLU(inplace=True) self.conv_block = ConvRelu(in_channels, num_filters, activate=True) self.conv_block_na = ConvRelu(in_channels, num_filters, activate=False) self.activation = nn.ReLU(inplace=True) def forward(self, inp): x = self.conv_block(inp) x = self.conv_block_na(x) x = x.add(inp) if self.batch_activate: x = self.activation(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'num_filters': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn 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 = 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_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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, 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=128, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_1[grid(256)](buf3, primals_5, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1 class ConvRelu(nn.Module): def __init__(self, in_: 'int', out: 'int', activate=True): super(ConvRelu, self).__init__() self.activate = activate self.conv = nn.Conv2d(in_, out, 3, padding=1) self.activation = nn.ReLU(inplace=True) def forward(self, x): x = self.conv(x) if self.activate: x = self.activation(x) return x class ResidualBlockNew(nn.Module): def __init__(self, in_channels: 'int', num_filters: 'int', batch_activate=False): super(ResidualBlockNew, self).__init__() self.batch_activate = batch_activate self.activation = nn.ReLU(inplace=True) self.conv_block = ConvRelu(in_channels, num_filters, activate=True) self.conv_block_na = ConvRelu(in_channels, num_filters, activate=False) self.activation = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.conv_block.conv.weight primals_2 = self.conv_block.conv.bias primals_4 = self.conv_block_na.conv.weight primals_5 = self.conv_block_na.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
haonguyen1107/style_transfer
ResidualBlock
false
3,574
[ "MIT" ]
0
8df9b20ce8ebc446cf2c0a67393001b3cf318fed
https://github.com/haonguyen1107/style_transfer/tree/8df9b20ce8ebc446cf2c0a67393001b3cf318fed
SQNet
import math import torch import torch.nn as nn import torch.nn.functional as F class Fire(nn.Module): def __init__(self, inplanes, squeeze_planes, expand_planes): super(Fire, self).__init__() self.conv1 = nn.Conv2d(inplanes, squeeze_planes, kernel_size=1, stride=1) self.relu1 = nn.ELU(inplace=True) self.conv2 = nn.Conv2d(squeeze_planes, expand_planes, kernel_size=1, stride=1) self.conv3 = nn.Conv2d(squeeze_planes, expand_planes, kernel_size=3, stride=1, padding=1) self.relu2 = nn.ELU(inplace=True) for m in self.modules(): if isinstance(m, nn.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels m.weight.data.normal_(0, math.sqrt(2.0 / n)) def forward(self, x): x = self.conv1(x) x = self.relu1(x) out1 = self.conv2(x) out2 = self.conv3(x) out = torch.cat([out1, out2], 1) out = self.relu2(out) return out class ParallelDilatedConv(nn.Module): def __init__(self, inplanes, planes): super(ParallelDilatedConv, self).__init__() self.dilated_conv_1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=1, dilation=1) self.dilated_conv_2 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=2, dilation=2) self.dilated_conv_3 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=3, dilation=3) self.dilated_conv_4 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=4, dilation=4) self.relu1 = nn.ELU(inplace=True) self.relu2 = nn.ELU(inplace=True) self.relu3 = nn.ELU(inplace=True) self.relu4 = nn.ELU(inplace=True) def forward(self, x): out1 = self.dilated_conv_1(x) out2 = self.dilated_conv_2(x) out3 = self.dilated_conv_3(x) out4 = self.dilated_conv_4(x) out1 = self.relu1(out1) out2 = self.relu2(out2) out3 = self.relu3(out3) out4 = self.relu4(out4) out = out1 + out2 + out3 + out4 return out class SQNet(nn.Module): def __init__(self, classes): super().__init__() self.num_classes = classes self.conv1 = nn.Conv2d(3, 96, kernel_size=3, stride=2, padding=1) self.relu1 = nn.ELU(inplace=True) self.maxpool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire1_1 = Fire(96, 16, 64) self.fire1_2 = Fire(128, 16, 64) self.maxpool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire2_1 = Fire(128, 32, 128) self.fire2_2 = Fire(256, 32, 128) self.maxpool3 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire3_1 = Fire(256, 64, 256) self.fire3_2 = Fire(512, 64, 256) self.fire3_3 = Fire(512, 64, 256) self.parallel = ParallelDilatedConv(512, 512) self.deconv1 = nn.ConvTranspose2d(512, 256, 3, stride=2, padding=1, output_padding=1) self.relu2 = nn.ELU(inplace=True) self.deconv2 = nn.ConvTranspose2d(512, 128, 3, stride=2, padding=1, output_padding=1) self.relu3 = nn.ELU(inplace=True) self.deconv3 = nn.ConvTranspose2d(256, 96, 3, stride=2, padding=1, output_padding=1) self.relu4 = nn.ELU(inplace=True) self.deconv4 = nn.ConvTranspose2d(192, self.num_classes, 3, stride= 2, padding=1, output_padding=1) self.conv3_1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv3_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv2_1 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) self.conv2_2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv1_1 = nn.Conv2d(96, 96, kernel_size=3, stride=1, padding=1) self.conv1_2 = nn.Conv2d(192, 192, kernel_size=3, stride=1, padding=1) self.relu1_1 = nn.ELU(inplace=True) self.relu1_2 = nn.ELU(inplace=True) self.relu2_1 = nn.ELU(inplace=True) self.relu2_2 = nn.ELU(inplace=True) self.relu3_1 = nn.ELU(inplace=True) self.relu3_2 = nn.ELU(inplace=True) for m in self.modules(): if isinstance(m, nn.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels m.weight.data.normal_(0, math.sqrt(2.0 / n)) elif isinstance(m, nn.BatchNorm2d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, x): x = self.conv1(x) x_1 = self.relu1(x) x = self.maxpool1(x_1) x = self.fire1_1(x) x_2 = self.fire1_2(x) x = self.maxpool2(x_2) x = self.fire2_1(x) x_3 = self.fire2_2(x) x = self.maxpool3(x_3) x = self.fire3_1(x) x = self.fire3_2(x) x = self.fire3_3(x) x = self.parallel(x) y_3 = self.deconv1(x) y_3 = self.relu2(y_3) x_3 = self.conv3_1(x_3) x_3 = self.relu3_1(x_3) x_3 = F.interpolate(x_3, y_3.size()[2:], mode='bilinear', align_corners=True) x = torch.cat([x_3, y_3], 1) x = self.conv3_2(x) x = self.relu3_2(x) y_2 = self.deconv2(x) y_2 = self.relu3(y_2) x_2 = self.conv2_1(x_2) x_2 = self.relu2_1(x_2) y_2 = F.interpolate(y_2, x_2.size()[2:], mode='bilinear', align_corners=True) x = torch.cat([x_2, y_2], 1) x = self.conv2_2(x) x = self.relu2_2(x) y_1 = self.deconv3(x) y_1 = self.relu4(y_1) x_1 = self.conv1_1(x_1) x_1 = self.relu1_1(x_1) x = torch.cat([x_1, y_1], 1) x = self.conv1_2(x) x = self.relu1_2(x) x = self.deconv4(x) return x def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {'classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 288 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 % 16 y1 = yindex // 16 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 16 * x2 + 144 * 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 % 32 y1 = yindex // 32 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 32 * x2 + 288 * 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 % 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_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 512 y1 = yindex // 512 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 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 % 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_9(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_10(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 96 y1 = yindex // 96 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 96 * x2 + 864 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_11(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 % 96 y1 = yindex // 96 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 96 * x2 + 864 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_12(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 % 192 y1 = yindex // 192 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 192 * x2 + 1728 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_13(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 768 xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 4 * x2 + 36 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_elu_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 96 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, 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 + x2, tmp9, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_15(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 96 x1 = xindex // 96 % 16 x2 = xindex // 1536 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 192 * x1 + 6144 * x2), None) tmp1 = tl.load(in_ptr0 + (96 + x0 + 192 * x1 + 6144 * x2), None) tmp3 = tl.load(in_ptr0 + (3072 + x0 + 192 * x1 + 6144 * x2), None) tmp5 = tl.load(in_ptr0 + (3168 + x0 + 192 * x1 + 6144 * 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_elu_16(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, 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 + x2, tmp9, None) @triton.jit def triton_poi_fused_cat_elu_17(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (64 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, 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 tl.full([1], 128, tl.int64) tmp13 = tl.load(in_ptr2 + (64 * x1 + (-64 + x0)), tmp10, eviction_policy='evict_last', other=0.0) tmp14 = tl.load(in_ptr3 + (-64 + x0), tmp10, eviction_policy= 'evict_last', other=0.0) tmp15 = tmp13 + tmp14 tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp10, tmp15, tmp16) tmp18 = tl.where(tmp4, tmp9, tmp17) tmp19 = 0.0 tmp20 = tmp18 > tmp19 tmp21 = 1.0 tmp22 = tmp18 * tmp21 tmp23 = libdevice.expm1(tmp22) tmp24 = tmp23 * tmp21 tmp25 = tl.where(tmp20, tmp22, tmp24) tl.store(out_ptr0 + x2, tmp25, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_18(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 % 8 x2 = xindex // 1024 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 256 * x1 + 4096 * x2), None) tmp1 = tl.load(in_ptr0 + (128 + x0 + 256 * x1 + 4096 * x2), None) tmp3 = tl.load(in_ptr0 + (2048 + x0 + 256 * x1 + 4096 * x2), None) tmp5 = tl.load(in_ptr0 + (2176 + x0 + 256 * x1 + 4096 * 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_elu_19(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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 = 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, None) @triton.jit def triton_poi_fused_cat_elu_20(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 256 x1 = xindex // 256 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, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, 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 tl.full([1], 256, tl.int64) tmp13 = tl.load(in_ptr2 + (128 * x1 + (-128 + x0)), tmp10, eviction_policy='evict_last', other=0.0) tmp14 = tl.load(in_ptr3 + (-128 + x0), tmp10, eviction_policy= 'evict_last', other=0.0) tmp15 = tmp13 + tmp14 tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp10, tmp15, tmp16) tmp18 = tl.where(tmp4, tmp9, tmp17) tmp19 = 0.0 tmp20 = tmp18 > tmp19 tmp21 = 1.0 tmp22 = tmp18 * tmp21 tmp23 = libdevice.expm1(tmp22) tmp24 = tmp23 * tmp21 tmp25 = tl.where(tmp20, tmp22, tmp24) tl.store(out_ptr0 + x2, tmp25, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_21(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 % 4 x2 = xindex // 1024 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 4096 * x2), None) tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 4096 * x2), None) tmp3 = tl.load(in_ptr0 + (2048 + x0 + 512 * x1 + 4096 * x2), None) tmp5 = tl.load(in_ptr0 + (2304 + x0 + 512 * x1 + 4096 * 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_elu_22(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 = 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, None) @triton.jit def triton_poi_fused_cat_elu_23(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 512 x1 = xindex // 512 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (256 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4, 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 tl.full([1], 512, tl.int64) tmp13 = tl.load(in_ptr2 + (256 * x1 + (-256 + x0)), tmp10, eviction_policy='evict_last', other=0.0) tmp14 = tl.load(in_ptr3 + (-256 + x0), tmp10, eviction_policy= 'evict_last', other=0.0) tmp15 = tmp13 + tmp14 tmp16 = tl.full(tmp15.shape, 0.0, tmp15.dtype) tmp17 = tl.where(tmp10, tmp15, tmp16) tmp18 = tl.where(tmp4, tmp9, tmp17) tmp19 = 0.0 tmp20 = tmp18 > tmp19 tmp21 = 1.0 tmp22 = tmp18 * tmp21 tmp23 = libdevice.expm1(tmp22) tmp24 = tmp23 * tmp21 tmp25 = tl.where(tmp20, tmp22, tmp24) tl.store(out_ptr0 + x2, tmp25, None) @triton.jit def triton_poi_fused_add_convolution_elu_24(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x2, None) tmp4 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr2 + x2, None) tmp7 = tl.load(in_ptr2 + x0, None, eviction_policy='evict_last') tmp9 = tl.load(in_out_ptr3 + x2, None) tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp8 = tmp6 + tmp7 tmp11 = tmp9 + tmp10 tmp12 = 0.0 tmp13 = tmp2 > tmp12 tmp14 = 1.0 tmp15 = tmp2 * tmp14 tmp16 = libdevice.expm1(tmp15) tmp17 = tmp16 * tmp14 tmp18 = tl.where(tmp13, tmp15, tmp17) tmp19 = tmp5 > tmp12 tmp20 = tmp5 * tmp14 tmp21 = libdevice.expm1(tmp20) tmp22 = tmp21 * tmp14 tmp23 = tl.where(tmp19, tmp20, tmp22) tmp24 = tmp18 + tmp23 tmp25 = tmp8 > tmp12 tmp26 = tmp8 * tmp14 tmp27 = libdevice.expm1(tmp26) tmp28 = tmp27 * tmp14 tmp29 = tl.where(tmp25, tmp26, tmp28) tmp30 = tmp24 + tmp29 tmp31 = tmp11 > tmp12 tmp32 = tmp11 * tmp14 tmp33 = libdevice.expm1(tmp32) tmp34 = tmp33 * tmp14 tmp35 = tl.where(tmp31, tmp32, tmp34) tmp36 = tmp30 + tmp35 tl.store(in_out_ptr0 + x2, tmp2, None) tl.store(in_out_ptr1 + x2, tmp5, None) tl.store(in_out_ptr2 + x2, tmp8, None) tl.store(in_out_ptr3 + x2, tmp11, None) tl.store(out_ptr0 + x2, tmp36, None) @triton.jit def triton_poi_fused_convolution_25(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_poi_fused_convolution_elu_26(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 = 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, None) @triton.jit def triton_poi_fused__to_copy_27(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_28(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 7, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_29(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = triton_helpers.minimum(tmp9, tmp2) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_mul_sub_30(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 % 256 x3 = xindex // 16384 x5 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 8, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (x2 + 256 * tmp8 + 2048 * tmp4 + 16384 * x3), None, eviction_policy='evict_last') tmp11 = tmp10 + tmp1 tmp12 = tmp10 < 0 tmp13 = tl.where(tmp12, tmp11, tmp10) tmp14 = tl.load(in_ptr2 + (x2 + 256 * tmp13 + 2048 * tmp4 + 16384 * x3), None, eviction_policy='evict_last') tmp15 = tmp14 - tmp9 tmp17 = tmp15 * tmp16 tmp18 = tmp9 + tmp17 tl.store(out_ptr0 + x5, tmp18, None) @triton.jit def triton_poi_fused_cat_31(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 512 x3 = xindex // 32768 x4 = xindex // 512 % 64 x2 = xindex // 4096 % 8 x1 = xindex // 512 % 8 x5 = xindex // 512 x6 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 64 * x0 + 16384 * x3), tmp4, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tl.full([XBLOCK], 8, tl.int32) tmp8 = tmp6 + tmp7 tmp9 = tmp6 < 0 tmp10 = tl.where(tmp9, tmp8, tmp6) tmp11 = tl.load(in_ptr2 + x1, tmp4, eviction_policy='evict_last', other=0.0 ) tmp12 = tmp11 + tmp7 tmp13 = tmp11 < 0 tmp14 = tl.where(tmp13, tmp12, tmp11) tmp15 = tl.load(in_ptr3 + (256 * tmp14 + 2048 * tmp10 + 16384 * x3 + x0 ), tmp4, eviction_policy='evict_last', other=0.0) tmp16 = tl.load(in_ptr4 + x1, tmp4, eviction_policy='evict_last', other=0.0 ) tmp17 = tmp16 + tmp7 tmp18 = tmp16 < 0 tmp19 = tl.where(tmp18, tmp17, tmp16) tmp20 = tl.load(in_ptr3 + (256 * tmp19 + 2048 * tmp10 + 16384 * x3 + x0 ), tmp4, eviction_policy='evict_last', other=0.0) tmp21 = tmp20 - tmp15 tmp22 = tl.load(in_ptr5 + x1, tmp4, eviction_policy='evict_last', other=0.0 ) tmp23 = tmp21 * tmp22 tmp24 = tmp15 + tmp23 tmp25 = tmp24 - tmp5 tmp26 = tl.load(in_ptr6 + x2, tmp4, eviction_policy='evict_last', other=0.0 ) tmp27 = tmp25 * tmp26 tmp28 = tmp5 + tmp27 tmp29 = tl.full(tmp28.shape, 0.0, tmp28.dtype) tmp30 = tl.where(tmp4, tmp28, tmp29) tmp31 = tmp0 >= tmp3 tl.full([1], 512, tl.int64) tmp34 = tl.load(in_ptr7 + (256 * x5 + (-256 + x0)), tmp31, eviction_policy='evict_last', other=0.0) tmp35 = 0.0 tmp36 = tmp34 > tmp35 tmp37 = 1.0 tmp38 = tmp34 * tmp37 tmp39 = libdevice.expm1(tmp38) tmp40 = tmp39 * tmp37 tmp41 = tl.where(tmp36, tmp38, tmp40) tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp31, tmp41, tmp42) tmp44 = tl.where(tmp4, tmp30, tmp43) tl.store(out_ptr0 + x6, tmp44, None) @triton.jit def triton_poi_fused_convolution_elu_32(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 = 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, None) @triton.jit def triton_poi_fused_convolution_elu_33(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 = 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, None) @triton.jit def triton_poi_fused_convolution_34(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_poi_fused__to_copy_35(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_36(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 15, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_37(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = triton_helpers.minimum(tmp9, tmp2) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_mul_sub_38(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 16 % 16 x0 = xindex % 16 x2 = xindex // 256 % 128 x3 = xindex // 32768 x5 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last') tmp16 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 16, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (x2 + 128 * tmp8 + 2048 * tmp4 + 32768 * x3), None, eviction_policy='evict_last') tmp11 = tmp10 + tmp1 tmp12 = tmp10 < 0 tmp13 = tl.where(tmp12, tmp11, tmp10) tmp14 = tl.load(in_ptr2 + (x2 + 128 * tmp13 + 2048 * tmp4 + 32768 * x3), None, eviction_policy='evict_last') tmp15 = tmp14 - tmp9 tmp17 = tmp15 * tmp16 tmp18 = tmp9 + tmp17 tl.store(out_ptr0 + x5, tmp18, None) @triton.jit def triton_poi_fused_cat_39(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, 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 % 256 x4 = xindex // 256 x3 = xindex // 65536 x5 = xindex // 256 % 256 x2 = xindex // 4096 % 16 x1 = xindex // 256 % 16 x6 = 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 * x4 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = 0.0 tmp7 = tmp5 > tmp6 tmp8 = 1.0 tmp9 = tmp5 * tmp8 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp8 tmp12 = tl.where(tmp7, tmp9, tmp11) tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp4, tmp12, tmp13) tmp15 = tmp0 >= tmp3 tl.full([1], 256, tl.int64) tmp18 = tl.load(in_ptr1 + (x5 + 256 * (-128 + x0) + 32768 * x3), tmp15, eviction_policy='evict_last', other=0.0) tmp19 = tl.load(in_ptr2 + x2, tmp15, eviction_policy='evict_last', other=0.0) tmp20 = tl.full([XBLOCK], 16, tl.int32) tmp21 = tmp19 + tmp20 tmp22 = tmp19 < 0 tmp23 = tl.where(tmp22, tmp21, tmp19) tmp24 = tl.load(in_ptr3 + x1, tmp15, eviction_policy='evict_last', other=0.0) tmp25 = tmp24 + tmp20 tmp26 = tmp24 < 0 tmp27 = tl.where(tmp26, tmp25, tmp24) tmp28 = tl.load(in_ptr4 + (128 * tmp27 + 2048 * tmp23 + 32768 * x3 + (- 128 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp29 = tl.load(in_ptr5 + x1, tmp15, eviction_policy='evict_last', other=0.0) tmp30 = tmp29 + tmp20 tmp31 = tmp29 < 0 tmp32 = tl.where(tmp31, tmp30, tmp29) tmp33 = tl.load(in_ptr4 + (128 * tmp32 + 2048 * tmp23 + 32768 * x3 + (- 128 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp34 = tmp33 - tmp28 tmp35 = tl.load(in_ptr6 + x1, tmp15, eviction_policy='evict_last', other=0.0) tmp36 = tmp34 * tmp35 tmp37 = tmp28 + tmp36 tmp38 = tmp37 - tmp18 tmp39 = tl.load(in_ptr7 + x2, tmp15, eviction_policy='evict_last', other=0.0) tmp40 = tmp38 * tmp39 tmp41 = tmp18 + tmp40 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp15, tmp41, tmp42) tmp44 = tl.where(tmp4, tmp14, tmp43) tl.store(out_ptr0 + x6, tmp44, None) @triton.jit def triton_poi_fused_convolution_elu_40(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) 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 = 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, None) @triton.jit def triton_poi_fused_convolution_41(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 % 96 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) @triton.jit def triton_poi_fused_cat_42(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 192 x1 = xindex // 192 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 96, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (96 * x1 + x0), tmp4, eviction_policy= 'evict_last', other=0.0) tmp6 = 0.0 tmp7 = tmp5 > tmp6 tmp8 = 1.0 tmp9 = tmp5 * tmp8 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp8 tmp12 = tl.where(tmp7, tmp9, tmp11) tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp4, tmp12, tmp13) tmp15 = tmp0 >= tmp3 tl.full([1], 192, tl.int64) tmp18 = tl.load(in_ptr1 + (96 * x1 + (-96 + x0)), tmp15, eviction_policy='evict_last', other=0.0) tmp19 = tmp18 > tmp6 tmp20 = tmp18 * tmp8 tmp21 = libdevice.expm1(tmp20) tmp22 = tmp21 * tmp8 tmp23 = tl.where(tmp19, tmp20, tmp22) tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype) tmp25 = tl.where(tmp15, tmp23, tmp24) tmp26 = tl.where(tmp4, tmp14, tmp25) tl.store(out_ptr0 + x2, tmp26, None) @triton.jit def triton_poi_fused_convolution_elu_43(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 % 192 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, 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 + x2, tmp9, None) @triton.jit def triton_poi_fused_convolution_44(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16384 * y1), ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4096 * y3), tmp2, 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, 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 ) = args args.clear() assert_size_stride(primals_1, (96, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (96,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (16, 96, 1, 1), (96, 1, 1, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (64, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (64, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (16, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_11, (16,), (1,)) assert_size_stride(primals_12, (64, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_13, (64,), (1,)) assert_size_stride(primals_14, (64, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_15, (64,), (1,)) assert_size_stride(primals_16, (32, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_17, (32,), (1,)) assert_size_stride(primals_18, (128, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_19, (128,), (1,)) assert_size_stride(primals_20, (128, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_21, (128,), (1,)) assert_size_stride(primals_22, (32, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_23, (32,), (1,)) assert_size_stride(primals_24, (128, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_25, (128,), (1,)) assert_size_stride(primals_26, (128, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_27, (128,), (1,)) assert_size_stride(primals_28, (64, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_29, (64,), (1,)) assert_size_stride(primals_30, (256, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_31, (256,), (1,)) assert_size_stride(primals_32, (256, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_33, (256,), (1,)) assert_size_stride(primals_34, (64, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_35, (64,), (1,)) assert_size_stride(primals_36, (256, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_37, (256,), (1,)) assert_size_stride(primals_38, (256, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_39, (256,), (1,)) assert_size_stride(primals_40, (64, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_41, (64,), (1,)) assert_size_stride(primals_42, (256, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_43, (256,), (1,)) assert_size_stride(primals_44, (256, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_45, (256,), (1,)) assert_size_stride(primals_46, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_47, (512,), (1,)) assert_size_stride(primals_48, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_49, (512,), (1,)) assert_size_stride(primals_50, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_51, (512,), (1,)) assert_size_stride(primals_52, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_53, (512,), (1,)) assert_size_stride(primals_54, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_55, (256,), (1,)) assert_size_stride(primals_56, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_57, (256,), (1,)) assert_size_stride(primals_58, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_59, (512,), (1,)) assert_size_stride(primals_60, (512, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_61, (128,), (1,)) assert_size_stride(primals_62, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_63, (128,), (1,)) assert_size_stride(primals_64, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_65, (256,), (1,)) assert_size_stride(primals_66, (256, 96, 3, 3), (864, 9, 3, 1)) assert_size_stride(primals_67, (96,), (1,)) assert_size_stride(primals_68, (96, 96, 3, 3), (864, 9, 3, 1)) assert_size_stride(primals_69, (96,), (1,)) assert_size_stride(primals_70, (192, 192, 3, 3), (1728, 9, 3, 1)) assert_size_stride(primals_71, (192,), (1,)) assert_size_stride(primals_72, (192, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_73, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((96, 3, 3, 3), (27, 1, 9, 3), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(288, 9)](primals_1, buf0, 288, 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, 16, 3, 3), (144, 1, 48, 16), torch. float32) triton_poi_fused_2[grid(1024, 9)](primals_8, buf2, 1024, 9, XBLOCK= 16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf3 = empty_strided_cuda((64, 16, 3, 3), (144, 1, 48, 16), torch. float32) triton_poi_fused_2[grid(1024, 9)](primals_14, buf3, 1024, 9, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del primals_14 buf4 = empty_strided_cuda((128, 32, 3, 3), (288, 1, 96, 32), torch. float32) triton_poi_fused_3[grid(4096, 9)](primals_20, buf4, 4096, 9, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del primals_20 buf5 = empty_strided_cuda((128, 32, 3, 3), (288, 1, 96, 32), torch. float32) triton_poi_fused_3[grid(4096, 9)](primals_26, buf5, 4096, 9, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del primals_26 buf6 = empty_strided_cuda((256, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_4[grid(16384, 9)](primals_32, buf6, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_32 buf7 = empty_strided_cuda((256, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_4[grid(16384, 9)](primals_38, buf7, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_38 buf8 = empty_strided_cuda((256, 64, 3, 3), (576, 1, 192, 64), torch .float32) triton_poi_fused_4[grid(16384, 9)](primals_44, buf8, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_44 buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_46, buf9, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_46 buf10 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_48, buf10, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_48 buf11 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_50, buf11, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_50 buf12 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_52, buf12, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_52 buf13 = empty_strided_cuda((512, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_6[grid(131072, 9)](primals_54, buf13, 131072, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_54 buf14 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_7[grid(65536, 9)](primals_56, buf14, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_56 buf15 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512), torch.float32) triton_poi_fused_5[grid(262144, 9)](primals_58, buf15, 262144, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_58 buf16 = empty_strided_cuda((512, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_8[grid(65536, 9)](primals_60, buf16, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_60 buf17 = empty_strided_cuda((128, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_9[grid(16384, 9)](primals_62, buf17, 16384, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_62 buf18 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_7[grid(65536, 9)](primals_64, buf18, 65536, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_64 buf19 = empty_strided_cuda((256, 96, 3, 3), (864, 1, 288, 96), torch.float32) triton_poi_fused_10[grid(24576, 9)](primals_66, buf19, 24576, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_66 buf20 = empty_strided_cuda((96, 96, 3, 3), (864, 1, 288, 96), torch .float32) triton_poi_fused_11[grid(9216, 9)](primals_68, buf20, 9216, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_68 buf21 = empty_strided_cuda((192, 192, 3, 3), (1728, 1, 576, 192), torch.float32) triton_poi_fused_12[grid(36864, 9)](primals_70, buf21, 36864, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_70 buf22 = empty_strided_cuda((192, 4, 3, 3), (36, 1, 12, 4), torch. float32) triton_poi_fused_13[grid(768, 9)](primals_72, buf22, 768, 9, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del primals_72 buf23 = extern_kernels.convolution(buf1, buf0, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf23, (4, 96, 32, 32), (98304, 1, 3072, 96)) buf24 = buf23 del buf23 triton_poi_fused_convolution_elu_14[grid(393216)](buf24, primals_2, 393216, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf25 = empty_strided_cuda((4, 96, 16, 16), (24576, 1, 1536, 96), torch.float32) buf26 = empty_strided_cuda((4, 96, 16, 16), (24576, 1, 1536, 96), torch.int8) triton_poi_fused_max_pool2d_with_indices_15[grid(98304)](buf24, buf25, buf26, 98304, XBLOCK=512, num_warps=8, num_stages=1) buf27 = extern_kernels.convolution(buf25, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 16, 16, 16), (4096, 1, 256, 16)) buf28 = buf27 del buf27 triton_poi_fused_convolution_elu_16[grid(16384)](buf28, primals_5, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf29 = extern_kernels.convolution(buf28, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf29, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf30 = extern_kernels.convolution(buf28, buf2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf31 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.float32) triton_poi_fused_cat_elu_17[grid(131072)](buf29, primals_7, buf30, primals_9, buf31, 131072, XBLOCK=512, num_warps=8, num_stages=1) del buf29 del primals_7 del primals_9 buf32 = extern_kernels.convolution(buf31, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 16, 16, 16), (4096, 1, 256, 16)) buf33 = buf32 del buf32 triton_poi_fused_convolution_elu_16[grid(16384)](buf33, primals_11, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 buf34 = extern_kernels.convolution(buf33, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf34, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf35 = extern_kernels.convolution(buf33, buf3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf35, (4, 64, 16, 16), (16384, 1, 1024, 64)) buf36 = empty_strided_cuda((4, 128, 16, 16), (32768, 1, 2048, 128), torch.float32) triton_poi_fused_cat_elu_17[grid(131072)](buf34, primals_13, buf35, primals_15, buf36, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_13 del primals_15 buf37 = empty_strided_cuda((4, 128, 8, 8), (8192, 1, 1024, 128), torch.float32) buf38 = empty_strided_cuda((4, 128, 8, 8), (8192, 1, 1024, 128), torch.int8) triton_poi_fused_max_pool2d_with_indices_18[grid(32768)](buf36, buf37, buf38, 32768, XBLOCK=128, num_warps=4, num_stages=1) buf39 = extern_kernels.convolution(buf37, primals_16, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf39, (4, 32, 8, 8), (2048, 1, 256, 32)) buf40 = buf39 del buf39 triton_poi_fused_convolution_elu_19[grid(8192)](buf40, primals_17, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_17 buf41 = extern_kernels.convolution(buf40, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf41, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf42 = extern_kernels.convolution(buf40, buf4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf42, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf43 = reinterpret_tensor(buf35, (4, 256, 8, 8), (16384, 1, 2048, 256), 0) del buf35 triton_poi_fused_cat_elu_20[grid(65536)](buf41, primals_19, buf42, primals_21, buf43, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_19 del primals_21 buf44 = extern_kernels.convolution(buf43, primals_22, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 32, 8, 8), (2048, 1, 256, 32)) buf45 = buf44 del buf44 triton_poi_fused_convolution_elu_19[grid(8192)](buf45, primals_23, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_23 buf46 = extern_kernels.convolution(buf45, primals_24, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf47 = extern_kernels.convolution(buf45, buf5, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf47, (4, 128, 8, 8), (8192, 1, 1024, 128)) buf48 = reinterpret_tensor(buf34, (4, 256, 8, 8), (16384, 1, 2048, 256), 0) del buf34 triton_poi_fused_cat_elu_20[grid(65536)](buf46, primals_25, buf47, primals_27, buf48, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_25 del primals_27 buf49 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.float32) buf50 = empty_strided_cuda((4, 256, 4, 4), (4096, 1, 1024, 256), torch.int8) triton_poi_fused_max_pool2d_with_indices_21[grid(16384)](buf48, buf49, buf50, 16384, XBLOCK=128, num_warps=4, num_stages=1) buf51 = extern_kernels.convolution(buf49, primals_28, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf51, (4, 64, 4, 4), (1024, 1, 256, 64)) buf52 = buf51 del buf51 triton_poi_fused_convolution_elu_22[grid(4096)](buf52, primals_29, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_29 buf53 = extern_kernels.convolution(buf52, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf53, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf54 = extern_kernels.convolution(buf52, buf6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf55 = reinterpret_tensor(buf47, (4, 512, 4, 4), (8192, 1, 2048, 512), 0) del buf47 triton_poi_fused_cat_elu_23[grid(32768)](buf53, primals_31, buf54, primals_33, buf55, 32768, XBLOCK=128, num_warps=4, num_stages=1) del buf53 del buf54 del primals_31 del primals_33 buf56 = extern_kernels.convolution(buf55, primals_34, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 64, 4, 4), (1024, 1, 256, 64)) buf57 = buf56 del buf56 triton_poi_fused_convolution_elu_22[grid(4096)](buf57, primals_35, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_35 buf58 = extern_kernels.convolution(buf57, primals_36, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf58, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf59 = extern_kernels.convolution(buf57, buf7, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf59, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf60 = reinterpret_tensor(buf46, (4, 512, 4, 4), (8192, 1, 2048, 512), 0) del buf46 triton_poi_fused_cat_elu_23[grid(32768)](buf58, primals_37, buf59, primals_39, buf60, 32768, XBLOCK=128, num_warps=4, num_stages=1) del buf58 del buf59 del primals_37 del primals_39 buf61 = extern_kernels.convolution(buf60, primals_40, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 64, 4, 4), (1024, 1, 256, 64)) buf62 = buf61 del buf61 triton_poi_fused_convolution_elu_22[grid(4096)](buf62, primals_41, 4096, XBLOCK=128, num_warps=4, num_stages=1) del primals_41 buf63 = extern_kernels.convolution(buf62, primals_42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf63, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf64 = extern_kernels.convolution(buf62, buf8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 256, 4, 4), (4096, 1, 1024, 256)) buf65 = reinterpret_tensor(buf42, (4, 512, 4, 4), (8192, 1, 2048, 512), 0) del buf42 triton_poi_fused_cat_elu_23[grid(32768)](buf63, primals_43, buf64, primals_45, buf65, 32768, XBLOCK=128, num_warps=4, num_stages=1) del buf63 del buf64 del primals_43 del primals_45 buf66 = extern_kernels.convolution(buf65, buf9, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf66, (4, 512, 4, 4), (8192, 1, 2048, 512)) buf68 = extern_kernels.convolution(buf65, buf10, stride=(1, 1), padding=(2, 2), dilation=(2, 2), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf68, (4, 512, 4, 4), (8192, 1, 2048, 512)) buf70 = extern_kernels.convolution(buf65, buf11, stride=(1, 1), padding=(3, 3), dilation=(3, 3), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 512, 4, 4), (8192, 1, 2048, 512)) buf72 = extern_kernels.convolution(buf65, buf12, stride=(1, 1), padding=(4, 4), dilation=(4, 4), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf72, (4, 512, 4, 4), (8192, 1, 2048, 512)) buf67 = buf66 del buf66 buf69 = buf68 del buf68 buf71 = buf70 del buf70 buf73 = buf72 del buf72 buf74 = reinterpret_tensor(buf41, (4, 512, 4, 4), (8192, 1, 2048, 512), 0) del buf41 triton_poi_fused_add_convolution_elu_24[grid(32768)](buf67, buf69, buf71, buf73, primals_47, primals_49, primals_51, primals_53, buf74, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_47 del primals_49 del primals_51 del primals_53 buf75 = extern_kernels.convolution(buf74, buf13, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(1, 1), groups=1, bias=None) assert_size_stride(buf75, (4, 256, 8, 8), (16384, 1, 2048, 256)) buf76 = buf75 del buf75 triton_poi_fused_convolution_25[grid(65536)](buf76, primals_55, 65536, XBLOCK=512, num_warps=4, num_stages=1) del primals_55 buf77 = extern_kernels.convolution(buf48, buf14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf77, (4, 256, 8, 8), (16384, 1, 2048, 256)) buf78 = buf77 del buf77 triton_poi_fused_convolution_elu_26[grid(65536)](buf78, primals_57, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_57 buf79 = empty_strided_cuda((8, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_27[grid(8)](buf79, 8, XBLOCK=8, num_warps =1, num_stages=1) buf80 = empty_strided_cuda((8, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_28[grid(8)](buf80, 8, XBLOCK=8, num_warps=1, num_stages=1) buf81 = empty_strided_cuda((8,), (1,), torch.int64) triton_poi_fused__to_copy_27[grid(8)](buf81, 8, XBLOCK=8, num_warps =1, num_stages=1) buf82 = empty_strided_cuda((8,), (1,), torch.int64) triton_poi_fused_add_clamp_28[grid(8)](buf82, 8, XBLOCK=8, num_warps=1, num_stages=1) buf83 = empty_strided_cuda((8,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_29[grid(8)](buf83, 8, XBLOCK=8, num_warps=1, num_stages=1) buf84 = reinterpret_tensor(buf30, (4, 256, 8, 8), (16384, 64, 8, 1), 0) del buf30 triton_poi_fused__unsafe_index_add_mul_sub_30[grid(65536)](buf79, buf81, buf78, buf82, buf83, buf84, 65536, XBLOCK=512, num_warps =4, num_stages=1) buf85 = empty_strided_cuda((8, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_29[grid(8)](buf85, 8, XBLOCK=8, num_warps=1, num_stages=1) buf86 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512), torch.float32) triton_poi_fused_cat_31[grid(131072)](buf84, buf80, buf81, buf78, buf82, buf83, buf85, buf76, buf86, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf87 = extern_kernels.convolution(buf86, buf15, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf87, (4, 512, 8, 8), (32768, 1, 4096, 512)) buf88 = buf87 del buf87 triton_poi_fused_convolution_elu_32[grid(131072)](buf88, primals_59, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_59 buf89 = extern_kernels.convolution(buf88, buf16, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(1, 1), groups=1, bias=None) assert_size_stride(buf89, (4, 128, 16, 16), (32768, 1, 2048, 128)) buf90 = buf89 del buf89 triton_poi_fused_convolution_elu_33[grid(131072)](buf90, primals_61, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_61 buf91 = extern_kernels.convolution(buf36, buf17, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf91, (4, 128, 16, 16), (32768, 1, 2048, 128)) buf92 = buf91 del buf91 triton_poi_fused_convolution_34[grid(131072)](buf92, primals_63, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_63 buf93 = empty_strided_cuda((16, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_35[grid(16)](buf93, 16, XBLOCK=16, num_warps=1, num_stages=1) buf94 = empty_strided_cuda((16, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_36[grid(16)](buf94, 16, XBLOCK=16, num_warps=1, num_stages=1) buf95 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused__to_copy_35[grid(16)](buf95, 16, XBLOCK=16, num_warps=1, num_stages=1) buf96 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused_add_clamp_36[grid(16)](buf96, 16, XBLOCK=16, num_warps=1, num_stages=1) buf97 = empty_strided_cuda((16,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_37[grid(16)](buf97, 16, XBLOCK=16, num_warps=1, num_stages=1) buf98 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.float32) triton_poi_fused__unsafe_index_add_mul_sub_38[grid(131072)](buf93, buf95, buf90, buf96, buf97, buf98, 131072, XBLOCK=512, num_warps=8, num_stages=1) buf99 = empty_strided_cuda((16, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_37[grid(16)](buf99, 16, XBLOCK=16, num_warps=1, num_stages=1) buf100 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_cat_39[grid(262144)](buf92, buf98, buf94, buf95, buf90, buf96, buf97, buf99, buf100, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf98 buf101 = extern_kernels.convolution(buf100, buf18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf101, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf102 = buf101 del buf101 triton_poi_fused_convolution_elu_40[grid(262144)](buf102, primals_65, 262144, XBLOCK=512, num_warps=8, num_stages=1) del primals_65 buf103 = extern_kernels.convolution(buf102, buf19, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(1, 1), groups=1, bias=None) assert_size_stride(buf103, (4, 96, 32, 32), (98304, 1, 3072, 96)) buf104 = buf103 del buf103 triton_poi_fused_convolution_41[grid(393216)](buf104, primals_67, 393216, XBLOCK=1024, num_warps=4, num_stages=1) del primals_67 buf105 = extern_kernels.convolution(buf24, buf20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf105, (4, 96, 32, 32), (98304, 1, 3072, 96)) buf106 = buf105 del buf105 triton_poi_fused_convolution_41[grid(393216)](buf106, primals_69, 393216, XBLOCK=1024, num_warps=4, num_stages=1) del primals_69 buf107 = empty_strided_cuda((4, 192, 32, 32), (196608, 1, 6144, 192 ), torch.float32) triton_poi_fused_cat_42[grid(786432)](buf106, buf104, buf107, 786432, XBLOCK=512, num_warps=8, num_stages=1) buf108 = extern_kernels.convolution(buf107, buf21, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf108, (4, 192, 32, 32), (196608, 1, 6144, 192)) buf109 = buf108 del buf108 triton_poi_fused_convolution_elu_43[grid(786432)](buf109, primals_71, 786432, XBLOCK=1024, num_warps=4, num_stages=1) del primals_71 buf110 = extern_kernels.convolution(buf109, buf22, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=True, output_padding=(1, 1), groups=1, bias=None) assert_size_stride(buf110, (4, 4, 64, 64), (16384, 1, 256, 4)) buf111 = reinterpret_tensor(buf84, (4, 4, 64, 64), (16384, 4096, 64, 1), 0) del buf84 triton_poi_fused_convolution_44[grid(16, 4096)](buf110, primals_73, buf111, 16, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del buf110 del primals_73 return (buf111, buf0, buf1, primals_4, primals_6, buf2, primals_10, primals_12, buf3, primals_16, primals_18, buf4, primals_22, primals_24, buf5, primals_28, primals_30, buf6, primals_34, primals_36, buf7, primals_40, primals_42, buf8, buf9, buf10, buf11, buf12, buf13, buf14, buf15, buf16, buf17, buf18, buf19, buf20, buf21, buf22, buf24, buf25, buf26, buf28, buf31, buf33, buf36, buf37, buf38, buf40, buf43, buf45, buf48, buf49, buf50, buf52, buf55, buf57, buf60, buf62, buf65, buf67, buf69, buf71, buf73, buf74, buf76, buf78, buf79, buf80, buf81, buf82, buf83, buf85, buf86, buf88, buf90, buf92, buf93, buf94, buf95, buf96, buf97, buf99, buf100, buf102, buf104, buf106, buf107, buf109) class Fire(nn.Module): def __init__(self, inplanes, squeeze_planes, expand_planes): super(Fire, self).__init__() self.conv1 = nn.Conv2d(inplanes, squeeze_planes, kernel_size=1, stride=1) self.relu1 = nn.ELU(inplace=True) self.conv2 = nn.Conv2d(squeeze_planes, expand_planes, kernel_size=1, stride=1) self.conv3 = nn.Conv2d(squeeze_planes, expand_planes, kernel_size=3, stride=1, padding=1) self.relu2 = nn.ELU(inplace=True) for m in self.modules(): if isinstance(m, nn.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels m.weight.data.normal_(0, math.sqrt(2.0 / n)) def forward(self, x): x = self.conv1(x) x = self.relu1(x) out1 = self.conv2(x) out2 = self.conv3(x) out = torch.cat([out1, out2], 1) out = self.relu2(out) return out class ParallelDilatedConv(nn.Module): def __init__(self, inplanes, planes): super(ParallelDilatedConv, self).__init__() self.dilated_conv_1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=1, dilation=1) self.dilated_conv_2 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=2, dilation=2) self.dilated_conv_3 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=3, dilation=3) self.dilated_conv_4 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=1, padding=4, dilation=4) self.relu1 = nn.ELU(inplace=True) self.relu2 = nn.ELU(inplace=True) self.relu3 = nn.ELU(inplace=True) self.relu4 = nn.ELU(inplace=True) def forward(self, x): out1 = self.dilated_conv_1(x) out2 = self.dilated_conv_2(x) out3 = self.dilated_conv_3(x) out4 = self.dilated_conv_4(x) out1 = self.relu1(out1) out2 = self.relu2(out2) out3 = self.relu3(out3) out4 = self.relu4(out4) out = out1 + out2 + out3 + out4 return out class SQNetNew(nn.Module): def __init__(self, classes): super().__init__() self.num_classes = classes self.conv1 = nn.Conv2d(3, 96, kernel_size=3, stride=2, padding=1) self.relu1 = nn.ELU(inplace=True) self.maxpool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire1_1 = Fire(96, 16, 64) self.fire1_2 = Fire(128, 16, 64) self.maxpool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire2_1 = Fire(128, 32, 128) self.fire2_2 = Fire(256, 32, 128) self.maxpool3 = nn.MaxPool2d(kernel_size=2, stride=2) self.fire3_1 = Fire(256, 64, 256) self.fire3_2 = Fire(512, 64, 256) self.fire3_3 = Fire(512, 64, 256) self.parallel = ParallelDilatedConv(512, 512) self.deconv1 = nn.ConvTranspose2d(512, 256, 3, stride=2, padding=1, output_padding=1) self.relu2 = nn.ELU(inplace=True) self.deconv2 = nn.ConvTranspose2d(512, 128, 3, stride=2, padding=1, output_padding=1) self.relu3 = nn.ELU(inplace=True) self.deconv3 = nn.ConvTranspose2d(256, 96, 3, stride=2, padding=1, output_padding=1) self.relu4 = nn.ELU(inplace=True) self.deconv4 = nn.ConvTranspose2d(192, self.num_classes, 3, stride= 2, padding=1, output_padding=1) self.conv3_1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv3_2 = nn.Conv2d(512, 512, kernel_size=3, stride=1, padding=1) self.conv2_1 = nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1) self.conv2_2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.conv1_1 = nn.Conv2d(96, 96, kernel_size=3, stride=1, padding=1) self.conv1_2 = nn.Conv2d(192, 192, kernel_size=3, stride=1, padding=1) self.relu1_1 = nn.ELU(inplace=True) self.relu1_2 = nn.ELU(inplace=True) self.relu2_1 = nn.ELU(inplace=True) self.relu2_2 = nn.ELU(inplace=True) self.relu3_1 = nn.ELU(inplace=True) self.relu3_2 = nn.ELU(inplace=True) for m in self.modules(): if isinstance(m, nn.Conv2d): n = m.kernel_size[0] * m.kernel_size[1] * m.in_channels m.weight.data.normal_(0, math.sqrt(2.0 / n)) elif isinstance(m, nn.BatchNorm2d): m.weight.data.fill_(1) m.bias.data.zero_() def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.fire1_1.conv1.weight primals_5 = self.fire1_1.conv1.bias primals_6 = self.fire1_1.conv2.weight primals_7 = self.fire1_1.conv2.bias primals_8 = self.fire1_1.conv3.weight primals_9 = self.fire1_1.conv3.bias primals_10 = self.fire1_2.conv1.weight primals_11 = self.fire1_2.conv1.bias primals_12 = self.fire1_2.conv2.weight primals_13 = self.fire1_2.conv2.bias primals_14 = self.fire1_2.conv3.weight primals_15 = self.fire1_2.conv3.bias primals_16 = self.fire2_1.conv1.weight primals_17 = self.fire2_1.conv1.bias primals_18 = self.fire2_1.conv2.weight primals_19 = self.fire2_1.conv2.bias primals_20 = self.fire2_1.conv3.weight primals_21 = self.fire2_1.conv3.bias primals_22 = self.fire2_2.conv1.weight primals_23 = self.fire2_2.conv1.bias primals_24 = self.fire2_2.conv2.weight primals_25 = self.fire2_2.conv2.bias primals_26 = self.fire2_2.conv3.weight primals_27 = self.fire2_2.conv3.bias primals_28 = self.fire3_1.conv1.weight primals_29 = self.fire3_1.conv1.bias primals_30 = self.fire3_1.conv2.weight primals_31 = self.fire3_1.conv2.bias primals_32 = self.fire3_1.conv3.weight primals_33 = self.fire3_1.conv3.bias primals_34 = self.fire3_2.conv1.weight primals_35 = self.fire3_2.conv1.bias primals_36 = self.fire3_2.conv2.weight primals_37 = self.fire3_2.conv2.bias primals_38 = self.fire3_2.conv3.weight primals_39 = self.fire3_2.conv3.bias primals_40 = self.fire3_3.conv1.weight primals_41 = self.fire3_3.conv1.bias primals_42 = self.fire3_3.conv2.weight primals_43 = self.fire3_3.conv2.bias primals_44 = self.fire3_3.conv3.weight primals_45 = self.fire3_3.conv3.bias primals_46 = self.parallel.dilated_conv_1.weight primals_47 = self.parallel.dilated_conv_1.bias primals_48 = self.parallel.dilated_conv_2.weight primals_49 = self.parallel.dilated_conv_2.bias primals_50 = self.parallel.dilated_conv_3.weight primals_51 = self.parallel.dilated_conv_3.bias primals_52 = self.parallel.dilated_conv_4.weight primals_53 = self.parallel.dilated_conv_4.bias primals_54 = self.deconv1.weight primals_55 = self.deconv1.bias primals_60 = self.deconv2.weight primals_61 = self.deconv2.bias primals_66 = self.deconv3.weight primals_67 = self.deconv3.bias primals_72 = self.deconv4.weight primals_73 = self.deconv4.bias primals_56 = self.conv3_1.weight primals_57 = self.conv3_1.bias primals_58 = self.conv3_2.weight primals_59 = self.conv3_2.bias primals_62 = self.conv2_1.weight primals_63 = self.conv2_1.bias primals_64 = self.conv2_2.weight primals_65 = self.conv2_2.bias primals_68 = self.conv1_1.weight primals_69 = self.conv1_1.bias primals_70 = self.conv1_2.weight primals_71 = self.conv1_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72, primals_73]) return output[0]
dcrmg/Efficient-Segmentation-Networks
SQNet
false
3,575
[ "MIT" ]
0
e2f2d90d69e4e9af464678b0f02bc754c28f643d
https://github.com/dcrmg/Efficient-Segmentation-Networks/tree/e2f2d90d69e4e9af464678b0f02bc754c28f643d
LinearFeedforward
import torch import torch.nn as nn import torch.utils.data class Linear(nn.Linear): def forward(self, x): size = x.size() return super().forward(x.contiguous().view(-1, size[-1])).view(* size[:-1], -1) class Feedforward(nn.Module): def __init__(self, d_in, d_out, activation=None, bias=True, dropout=0.2): super().__init__() if activation is not None: self.activation = getattr(torch, activation) else: self.activation = lambda x: x self.linear = Linear(d_in, d_out, bias=bias) self.dropout = nn.Dropout(dropout) def forward(self, x): return self.activation(self.linear(self.dropout(x))) class LinearFeedforward(nn.Module): def __init__(self, d_in, d_hid, d_out, activation='relu', dropout=0.2): super().__init__() self.feedforward = Feedforward(d_in, d_hid, activation=activation) self.linear = Linear(d_hid, d_out) self.dropout = nn.Dropout(dropout) def forward(self, x): return self.dropout(self.linear(self.feedforward(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_in': 4, 'd_hid': 4, 'd_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, primals_3, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_4, buf3 class Linear(nn.Linear): def forward(self, x): size = x.size() return super().forward(x.contiguous().view(-1, size[-1])).view(* size[:-1], -1) class Feedforward(nn.Module): def __init__(self, d_in, d_out, activation=None, bias=True, dropout=0.2): super().__init__() if activation is not None: self.activation = getattr(torch, activation) else: self.activation = lambda x: x self.linear = Linear(d_in, d_out, bias=bias) self.dropout = nn.Dropout(dropout) def forward(self, x): return self.activation(self.linear(self.dropout(x))) class LinearFeedforwardNew(nn.Module): def __init__(self, d_in, d_hid, d_out, activation='relu', dropout=0.2): super().__init__() self.feedforward = Feedforward(d_in, d_hid, activation=activation) self.linear = Linear(d_hid, d_out) self.dropout = nn.Dropout(dropout) def forward(self, input_0): primals_2 = self.feedforward.linear.weight primals_3 = self.feedforward.linear.bias primals_4 = self.linear.weight primals_5 = self.linear.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
harmdevries89/genienlp
LinearFeedforward
false
3,576
[ "BSD-3-Clause" ]
0
adf163c63a43adaddecb4b3645635f6ba92772f2
https://github.com/harmdevries89/genienlp/tree/adf163c63a43adaddecb4b3645635f6ba92772f2
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]
hansd410/mnemonic
SFU
false
3,577
[ "BSD-3-Clause" ]
0
409508d08da7f5d5940ffb56fd9715e6ef1e68a3
https://github.com/hansd410/mnemonic/tree/409508d08da7f5d5940ffb56fd9715e6ef1e68a3
CoAttention
import torch import torch.nn as nn from torch.nn import functional as F class CoAttention(nn.Module): """ CoAttention encoder in Dynamic Coattention Networks For Question Answering (https://arxiv.org/abs/1611.01604) check the Figure 2 in paper * Args: embed_dim: the number of input embedding dimension """ def __init__(self, embed_dim): super(CoAttention, self).__init__() self.W_0 = nn.Linear(embed_dim * 3, 1, bias=False) def forward(self, context_embed, question_embed, context_mask=None, question_mask=None): C, Q = context_embed, question_embed B, C_L, Q_L, D = C.size(0), C.size(1), Q.size(1), Q.size(2) similarity_matrix_shape = torch.zeros(B, C_L, Q_L, D) C_ = C.unsqueeze(2).expand_as(similarity_matrix_shape) Q_ = Q.unsqueeze(1).expand_as(similarity_matrix_shape) C_Q = torch.mul(C_, Q_) S = self.W_0(torch.cat([C_, Q_, C_Q], 3)).squeeze(3) S_question = S if question_mask is not None: S_question = f.add_masked_value(S_question, question_mask. unsqueeze(1), value=-10000000.0) S_q = F.softmax(S_question, 2) S_context = S.transpose(1, 2) if context_mask is not None: S_context = f.add_masked_value(S_context, context_mask. unsqueeze(1), value=-10000000.0) S_c = F.softmax(S_context, 2) A = torch.bmm(S_q, Q) B = torch.bmm(S_q, S_c).bmm(C) out = torch.cat([C, A, C * A, C * B], dim=-1) return out def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'embed_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 768 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 12 x4 = xindex // 48 x1 = xindex // 12 % 4 x3 = xindex // 192 x5 = 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 * x4 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (4 * x1 + 16 * x3 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tl.full([1], 12, tl.int64) tmp14 = tl.load(in_ptr0 + (4 * x4 + (-8 + x0)), tmp11 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl.load(in_ptr1 + (4 * x1 + 16 * x3 + (-8 + x0)), tmp11 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp14 * tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp11, tmp16, tmp17) tmp19 = tl.where(tmp9, tmp10, tmp18) tmp20 = tl.where(tmp4, tmp5, tmp19) tl.store(out_ptr0 + x5, tmp20, xmask) @triton.jit def triton_poi_fused__softmax_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 x4 = xindex x1 = xindex // 4 x0 = xindex % 4 x3 = xindex // 16 tmp0 = tl.load(in_ptr0 + x4, 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') tmp10 = tl.load(in_ptr0 + (x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp11 = tl.load(in_ptr0 + (4 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (8 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (12 + x0 + 16 * x3), 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) tmp12 = triton_helpers.maximum(tmp10, tmp11) tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp16 = triton_helpers.maximum(tmp14, tmp15) tmp17 = tmp0 - tmp16 tmp18 = tl_math.exp(tmp17) tl.store(out_ptr0 + x4, tmp9, xmask) tl.store(out_ptr1 + x4, tmp18, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__softmax_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + y0 + 16 * y1), ymask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + (x2 + 4 * y3), tmp8, xmask & ymask) @triton.jit def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 8, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp9 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = tmp0 >= tmp7 tmp12 = tl.full([1], 12, tl.int64) tmp13 = tmp0 < tmp12 tmp14 = tmp11 & tmp13 tmp15 = tl.load(in_ptr0 + (4 * x1 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.load(in_ptr1 + (4 * x1 + (-8 + x0)), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tmp15 * tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp14, tmp17, tmp18) tmp20 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp23 = tl.load(in_ptr0 + (4 * x1 + (-12 + x0)), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tl.load(in_ptr2 + (4 * x1 + (-12 + x0)), tmp20 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = tmp23 * tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp20, tmp25, tmp26) tmp28 = tl.where(tmp14, tmp19, tmp27) tmp29 = tl.where(tmp9, tmp10, tmp28) tmp30 = tl.where(tmp4, tmp5, tmp29) tl.store(out_ptr0 + x2, tmp30, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (1, 12), (12, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 12), (192, 48, 12, 1), torch. float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(768)](primals_2, primals_1, buf0, 768, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 12), (12, 1), 0), reinterpret_tensor(primals_3, (12, 1), (1, 12), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) triton_poi_fused__softmax_1[grid(64)](buf1, buf2, buf4, 64, XBLOCK= 64, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused__softmax_2[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = buf2 del buf2 triton_poi_fused__softmax_3[grid(16, 4)](buf4, buf5, 16, 4, XBLOCK= 4, YBLOCK=16, num_warps=1, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(buf3, primals_1, out=buf6) buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf3, buf5, out=buf7) buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf7, primals_2, out=buf8) del buf7 buf9 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_cat_4[grid(256)](primals_2, buf6, buf8, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del buf8 return buf9, primals_2, reinterpret_tensor(buf0, (64, 12), (12, 1), 0 ), buf3, buf5, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0) class CoAttentionNew(nn.Module): """ CoAttention encoder in Dynamic Coattention Networks For Question Answering (https://arxiv.org/abs/1611.01604) check the Figure 2 in paper * Args: embed_dim: the number of input embedding dimension """ def __init__(self, embed_dim): super(CoAttentionNew, self).__init__() self.W_0 = nn.Linear(embed_dim * 3, 1, bias=False) def forward(self, input_0, input_1): primals_3 = self.W_0.weight primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
hamishivi/claf
CoAttention
false
3,578
[ "MIT" ]
0
8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
https://github.com/hamishivi/claf/tree/8e35f30e3fc4a45a45cc0766eb6ab55a6ba3f0c2
SoftArgMax
import torch import torch.nn as nn import torch.nn.functional as F class SoftArgMax(nn.Module): def __init__(self): super().__init__() def forward(self, x, labels, kernel_size=0): """ Args x: [B, C, Nd] labels: [Nd] Returns [B, C] """ y = x * labels kernel_size = kernel_size if kernel_size > 0 else x.size(-1) x = F.avg_pool1d(x, kernel_size=kernel_size) * kernel_size y = F.avg_pool1d(y, kernel_size=kernel_size) * kernel_size y = y / (x + 1e-08) ind = x.argmax(dim=-1).unsqueeze(-1) res = torch.gather(y, dim=-1, index=ind) res = res.squeeze(-1) return res def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_div_gather_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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') tmp11 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp14 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp7 = 0.25 tmp8 = tmp6 * tmp7 tmp9 = 4.0 tmp10 = tmp8 * tmp9 tmp13 = tmp12 + tmp11 tmp15 = tmp14 + tmp13 tmp17 = tmp16 + tmp15 tmp18 = tmp17 * tmp7 tmp19 = tmp18 * tmp9 tmp20 = 1e-08 tmp21 = tmp19 + tmp20 tmp22 = tmp10 / tmp21 tl.store(out_ptr0 + x0, tmp22, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(16)](arg0_1, arg1_1, buf0, 16, XBLOCK= 16, num_warps=1, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 1), (1, 1), torch.float32) triton_poi_fused_add_div_gather_mul_1[grid(4)](buf0, arg0_1, buf1, 4, XBLOCK=4, num_warps=1, num_stages=1) del arg0_1 del buf0 return reinterpret_tensor(buf1, (4,), (1,), 0), class SoftArgMaxNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hcyz33/PlaneSweepPose
SoftArgMax
false
3,579
[ "MIT" ]
0
4ae3a4e7e939fa74c060eb1b354c34ea0fb55248
https://github.com/hcyz33/PlaneSweepPose/tree/4ae3a4e7e939fa74c060eb1b354c34ea0fb55248
AutoEncoder
import torch import torch.nn as nn import torch.utils.data class AutoEncoder(nn.Module): def __init__(self, num_question, k): """ Initialize a class AutoEncoder. :param num_question: int :param k: int """ super(AutoEncoder, self).__init__() self.g = nn.Linear(num_question, k) self.h = nn.Linear(k, num_question) def get_weight_norm(self): """ Return ||W^1||^2 + ||W^2||^2. :return: float """ g_w_norm = torch.norm(self.g.weight, 2) ** 2 h_w_norm = torch.norm(self.h.weight, 2) ** 2 return g_w_norm + h_w_norm def forward(self, inputs): """ Return a forward pass given inputs. :param inputs: user vector. :return: user vector. """ g = nn.Sigmoid() h = nn.Sigmoid() out = h(self.h(g(self.g(inputs)))) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_question': 4, '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 import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(256)](buf1, primals_2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_sigmoid_0[grid(256)](buf3, primals_5, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf3, primals_4 class AutoEncoderNew(nn.Module): def __init__(self, num_question, k): """ Initialize a class AutoEncoder. :param num_question: int :param k: int """ super(AutoEncoderNew, self).__init__() self.g = nn.Linear(num_question, k) self.h = nn.Linear(k, num_question) def get_weight_norm(self): """ Return ||W^1||^2 + ||W^2||^2. :return: float """ g_w_norm = torch.norm(self.g.weight, 2) ** 2 h_w_norm = torch.norm(self.h.weight, 2) ** 2 return g_w_norm + h_w_norm def forward(self, input_0): primals_1 = self.g.weight primals_2 = self.g.bias primals_4 = self.h.weight primals_5 = self.h.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
harryye930/ML-Performance-Prediction
AutoEncoder
false
3,580
[ "MIT" ]
0
82fac16da3c2dde6054cf5b579aa6864e9d37b30
https://github.com/harryye930/ML-Performance-Prediction/tree/82fac16da3c2dde6054cf5b579aa6864e9d37b30
CharbonnierLoss
import torch import torch.nn as nn from torch import autograd as autograd import torch.fft from itertools import product as product class CharbonnierLoss(nn.Module): """Charbonnier Loss (L1)""" def __init__(self, eps=1e-09): super(CharbonnierLoss, self).__init__() self.eps = eps def forward(self, x, y): diff = x - y loss = torch.mean(torch.sqrt(diff * diff + self.eps)) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch import autograd as autograd import torch.fft from itertools import product as product assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_mean_mul_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) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = 1e-09 tmp5 = tmp3 + tmp4 tmp6 = libdevice.sqrt(tmp5) tmp7 = tl.broadcast_to(tmp6, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = 256.0 tmp11 = tmp9 / tmp10 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp11, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_mul_sqrt_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class CharbonnierLossNew(nn.Module): """Charbonnier Loss (L1)""" def __init__(self, eps=1e-09): super(CharbonnierLossNew, self).__init__() self.eps = eps def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hduba/KAIR
CharbonnierLoss
false
3,581
[ "MIT" ]
0
dbd7596c7e4a4667b9b7baac369fc6c02571fa58
https://github.com/hduba/KAIR/tree/dbd7596c7e4a4667b9b7baac369fc6c02571fa58
FRM
import torch import torch.nn as nn import torch.nn.functional as F class FRM(nn.Module): def __init__(self, nb_dim, do_add=True, do_mul=True): super(FRM, self).__init__() self.fc = nn.Linear(nb_dim, nb_dim) self.sig = nn.Sigmoid() self.do_add = do_add self.do_mul = do_mul def forward(self, x): y = F.adaptive_avg_pool1d(x, 1).view(x.size(0), -1) y = self.sig(self.fc(y)).view(x.size(0), x.size(1), -1) if self.do_mul: x = x * y if self.do_add: x = x + y return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'nb_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_mul_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = tmp3 + tmp2 tl.store(out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (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, 1, 1), (4, 1, 16, 16), torch.float32) get_raw_stream(0) triton_poi_fused_mean_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha =1, beta=1, out=buf1) del primals_2 del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_1[grid(64)](primals_1, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf2, primals_1, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), buf1 class FRMNew(nn.Module): def __init__(self, nb_dim, do_add=True, do_mul=True): super(FRMNew, self).__init__() self.fc = nn.Linear(nb_dim, nb_dim) self.sig = nn.Sigmoid() self.do_add = do_add self.do_mul = do_mul def forward(self, input_0): primals_2 = self.fc.weight primals_3 = self.fc.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hdubey/RawNet
FRM
false
3,582
[ "MIT" ]
0
45589b2da9b0562ef2810e6097d4bdba23eb8a0a
https://github.com/hdubey/RawNet/tree/45589b2da9b0562ef2810e6097d4bdba23eb8a0a
UpsampleConvLayer
import torch import torch.nn as nn import torch.nn.functional as F class UpsampleConvLayer(nn.Module): """ Upsamples the input and then does a convolution. This method gives better results compared to ConvTranspose2d. """ def __init__(self, in_channels, out_channels, kernel_size, stride, upsample=None): super(UpsampleConvLayer, self).__init__() self.upsample = upsample reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReplicationPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride) def forward(self, x): if self.upsample: x = F.interpolate(x, mode='nearest', scale_factor=self.upsample) out = self.reflection_pad(x) out = self.conv2d(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4, 'stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_replication_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 % 8 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (4 * (3 * (3 <= 0 * (0 >= -2 + x1) + (-2 + x1) * (-2 + x1 > 0)) + (0 * (0 >= -2 + x1) + (-2 + x1) * (-2 + x1 > 0)) * (0 * (0 >= -2 + x1) + (-2 + x1) * (-2 + x1 > 0) < 3)) + 16 * x2 + ( 3 * (3 <= 0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0)) + (0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0)) * (0 * (0 >= -2 + x0) + (-2 + x0) * (-2 + x0 > 0) < 3))), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_replication_pad2d_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(400)](buf2, primals_3, 400, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class UpsampleConvLayerNew(nn.Module): """ Upsamples the input and then does a convolution. This method gives better results compared to ConvTranspose2d. """ def __init__(self, in_channels, out_channels, kernel_size, stride, upsample=None): super(UpsampleConvLayerNew, self).__init__() self.upsample = upsample reflection_padding = kernel_size // 2 self.reflection_pad = nn.ReplicationPad2d(reflection_padding) self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride) def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hehichens/NeuralStyle
UpsampleConvLayer
false
3,583
[ "Apache-2.0" ]
0
cf28a1eefd8713f85e94f50935562a663a53e8b5
https://github.com/hehichens/NeuralStyle/tree/cf28a1eefd8713f85e94f50935562a663a53e8b5
DiscreteCriticNetwork
import torch import torch.nn as nn import torch.nn.functional as F class DiscreteCriticNetwork(nn.Module): def __init__(self, obs_dim, act_dim, hidden_size=256): super(DiscreteCriticNetwork, self).__init__() self._l1 = nn.Linear(obs_dim, hidden_size) self._l2 = nn.Linear(hidden_size, hidden_size) self._l3 = nn.Linear(hidden_size, act_dim) def forward(self, s, a): s = F.relu(self._l1(s)) s = F.relu(self._l2(s)) s = self._l3(s) return s.gather(1, a.long()) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'obs_dim': 4, 'act_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 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__to_copy_gather_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex x1 = xindex % 16 x3 = xindex // 64 tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0.to(tl.int64) tmp2 = tl.full([XBLOCK], 4, tl.int32) tmp3 = tmp1 + tmp2 tmp4 = tmp1 < 0 tmp5 = tl.where(tmp4, tmp3, tmp1) tl.device_assert((0 <= tmp5) & (tmp5 < 4) | ~xmask, 'index out of bounds: 0 <= tmp5 < 4') tmp7 = tl.load(in_ptr1 + (x1 + 16 * tmp5 + 64 * x3), xmask) tl.store(out_ptr0 + x0, tmp1, xmask) tl.store(out_ptr1 + x0, 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, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 256), (256, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (4, 256), (256, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf1, primals_2, buf8, 16384, XBLOCK=128, 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, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 256), (1, 256), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf3, primals_5, buf7, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 256), (256, 1), 0), reinterpret_tensor(primals_6, (256, 4), (1, 256), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.int64) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__to_copy_gather_1[grid(256)](primals_8, buf4, buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf4 del primals_8 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 256), (256, 1), 0 ), reinterpret_tensor(buf3, (64, 256), (256, 1), 0 ), buf5, primals_6, buf7, primals_4, buf8 class DiscreteCriticNetworkNew(nn.Module): def __init__(self, obs_dim, act_dim, hidden_size=256): super(DiscreteCriticNetworkNew, self).__init__() self._l1 = nn.Linear(obs_dim, hidden_size) self._l2 = nn.Linear(hidden_size, hidden_size) self._l3 = nn.Linear(hidden_size, act_dim) def forward(self, input_0, input_1): 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 primals_8 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
harwiltz/sac
DiscreteCriticNetwork
false
3,584
[ "MIT" ]
0
076e01e63d8933665fbf4038513f163bbfd62800
https://github.com/harwiltz/sac/tree/076e01e63d8933665fbf4038513f163bbfd62800
AFMS
import torch import torch.nn as nn import torch.nn.functional as F class AFMS(nn.Module): """ Alpha-Feature map scaling, added to the output of each residual block[1,2]. Reference: [1] RawNet2 : https://www.isca-speech.org/archive/Interspeech_2020/pdfs/1011.pdf [2] AMFS : https://www.koreascience.or.kr/article/JAKO202029757857763.page """ def __init__(self, nb_dim): super(AFMS, self).__init__() self.alpha = nn.Parameter(torch.ones((nb_dim, 1))) self.fc = nn.Linear(nb_dim, nb_dim) self.sig = nn.Sigmoid() def forward(self, x): y = F.adaptive_avg_pool1d(x, 1).view(x.size(0), -1) y = self.sig(self.fc(y)).view(x.size(0), x.size(1), -1) x = x + self.alpha x = x * y return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'nb_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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 tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_mul_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 x3 = xindex x1 = xindex // 4 % 4 x4 = xindex // 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (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, 1), (1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) get_raw_stream(0) triton_poi_fused_mean_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), alpha =1, beta=1, out=buf1) del primals_2 del primals_3 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_mul_1[grid(64)](primals_1, primals_4, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf2, primals_1, primals_4, reinterpret_tensor(buf0, (4, 4), (4, 1), 0), buf1 class AFMSNew(nn.Module): """ Alpha-Feature map scaling, added to the output of each residual block[1,2]. Reference: [1] RawNet2 : https://www.isca-speech.org/archive/Interspeech_2020/pdfs/1011.pdf [2] AMFS : https://www.koreascience.or.kr/article/JAKO202029757857763.page """ def __init__(self, nb_dim): super(AFMSNew, self).__init__() self.alpha = nn.Parameter(torch.ones((nb_dim, 1))) self.fc = nn.Linear(nb_dim, nb_dim) self.sig = nn.Sigmoid() def forward(self, input_0): primals_4 = self.alpha primals_2 = self.fc.weight primals_3 = self.fc.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
hdubey/RawNet
AFMS
false
3,585
[ "MIT" ]
0
45589b2da9b0562ef2810e6097d4bdba23eb8a0a
https://github.com/hdubey/RawNet/tree/45589b2da9b0562ef2810e6097d4bdba23eb8a0a
Decoder
import torch import torch.nn as nn class Decoder(nn.Module): def __init__(self, latent_size, out_size): super().__init__() self.linear1 = nn.Linear(latent_size, int(out_size / 4)) self.linear2 = nn.Linear(int(out_size / 4), int(out_size / 2)) self.linear3 = nn.Linear(int(out_size / 2), out_size) self.relu = nn.ReLU(True) self.sigmoid = nn.Sigmoid() def forward(self, z): out = self.linear1(z) out = self.relu(out) out = self.linear2(out) out = self.relu(out) out = self.linear3(out) w = self.sigmoid(out) return w def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'latent_size': 4, 'out_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = 0.0 tmp7 = tmp5 <= tmp6 tl.store(in_out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x0 % 4 // 4) + 16 * ((4 * (x0 // 4 % 4) + x0 % 4) // 16)), xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, 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 x4 = xindex x0 = xindex % 2 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_view_3(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 % 2 x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 2 * x1 + 8 * (x1 % 4 // 4) + 32 * ((4 * (x1 // 4 % 4) + x1 % 4) // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_sigmoid_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (2, 1), (1, 1)) assert_size_stride(primals_5, (2,), (1,)) assert_size_stride(primals_6, (4, 2), (2, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(64)](buf1, primals_2, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused_view_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 buf3 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (1, 2), (1, 1 ), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf3 buf8 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(128)](buf4, primals_5, buf8, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 2), (2, 1), torch.float32) triton_poi_fused_view_3[grid(128)](buf4, buf5, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf4 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_6, (2, 4), (1, 2 ), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused_sigmoid_4[grid(256)](buf7, primals_7, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_7 return buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, buf5, buf7, primals_6, buf8, primals_4, buf9 class DecoderNew(nn.Module): def __init__(self, latent_size, out_size): super().__init__() self.linear1 = nn.Linear(latent_size, int(out_size / 4)) self.linear2 = nn.Linear(int(out_size / 4), int(out_size / 2)) self.linear3 = nn.Linear(int(out_size / 2), out_size) self.relu = nn.ReLU(True) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
hcgcarry/usad
Decoder
false
3,586
[ "BSD-3-Clause" ]
0
4e99a6acd43ef109be4d89b80e96978b9ad61c2f
https://github.com/hcgcarry/usad/tree/4e99a6acd43ef109be4d89b80e96978b9ad61c2f
SSD300
import torch import torchvision import torch.utils.data from torch import nn import torch.nn.functional as F from math import sqrt from itertools import product as product import torch.optim def decimate(tensor, m): """ Decimate a tensor by a factor 'm', i.e. downsample by keeping every 'm'th value. This is used when we convert FC layers to equivalent Convolutional layers, BUT of a smaller size. :param tensor: tensor to be decimated :param m: list of decimation factors for each dimension of the tensor; None if not to be decimated along a dimension :return: decimated tensor """ assert tensor.dim() == len(m) for d in range(tensor.dim()): if m[d] is not None: tensor = tensor.index_select(dim=d, index=torch.arange(start=0, end=tensor.size(d), step=m[d]).long()) return tensor def cxcy_to_xy(cxcy): """ Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max). :param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4) :return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4) """ return torch.cat([cxcy[:, :2] - cxcy[:, 2:] / 2, cxcy[:, :2] + cxcy[:, 2:] / 2], 1) def find_intersection(set_1, set_2): """ Find the intersection of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: intersection of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2]. unsqueeze(0)) upper_bounds = torch.min(set_1[:, 2:].unsqueeze(1), set_2[:, 2:]. unsqueeze(0)) intersection_dims = torch.clamp(upper_bounds - lower_bounds, min=0) return intersection_dims[:, :, 0] * intersection_dims[:, :, 1] def find_jaccard_overlap(set_1, set_2): """ Find the Jaccard Overlap (IoU) of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: Jaccard Overlap of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ intersection = find_intersection(set_1, set_2) areas_set_1 = (set_1[:, 2] - set_1[:, 0]) * (set_1[:, 3] - set_1[:, 1]) areas_set_2 = (set_2[:, 2] - set_2[:, 0]) * (set_2[:, 3] - set_2[:, 1]) union = areas_set_1.unsqueeze(1) + areas_set_2.unsqueeze(0) - intersection return intersection / union def gcxgcy_to_cxcy(gcxgcy, priors_cxcy): """ Decode bounding box coordinates predicted by the model, since they are encoded in the form mentioned above. They are decoded into center-size coordinates. This is the inverse of the function above. :param gcxgcy: encoded bounding boxes, i.e. output of the model, a tensor of size (n_priors, 4) :param priors_cxcy: prior boxes with respect to which the encoding is defined, a tensor of size (n_priors, 4) :return: decoded bounding boxes in center-size form, a tensor of size (n_priors, 4) """ return torch.cat([gcxgcy[:, :2] * priors_cxcy[:, 2:] / 10 + priors_cxcy [:, :2], torch.exp(gcxgcy[:, 2:] / 5) * priors_cxcy[:, 2:]], 1) class VGGBase(nn.Module): """ VGG base convolutions to produce lower-level feature maps. """ def __init__(self): super(VGGBase, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool5 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) self.conv7 = nn.Conv2d(1024, 1024, kernel_size=1) self.load_pretrained_layers() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: lower-level feature maps conv4_3 and conv7 """ out = F.relu(self.conv1_1(image)) out = F.relu(self.conv1_2(out)) out = self.pool1(out) out = F.relu(self.conv2_1(out)) out = F.relu(self.conv2_2(out)) out = self.pool2(out) out = F.relu(self.conv3_1(out)) out = F.relu(self.conv3_2(out)) out = F.relu(self.conv3_3(out)) out = self.pool3(out) out = F.relu(self.conv4_1(out)) out = F.relu(self.conv4_2(out)) out = F.relu(self.conv4_3(out)) conv4_3_feats = out out = self.pool4(out) out = F.relu(self.conv5_1(out)) out = F.relu(self.conv5_2(out)) out = F.relu(self.conv5_3(out)) out = self.pool5(out) out = F.relu(self.conv6(out)) conv7_feats = F.relu(self.conv7(out)) return conv4_3_feats, conv7_feats def load_pretrained_layers(self): """ As in the paper, we use a VGG-16 pretrained on the ImageNet task as the base network. There's one available in PyTorch, see https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.vgg16 We copy these parameters into our network. It's straightforward for conv1 to conv5. However, the original VGG-16 does not contain the conv6 and con7 layers. Therefore, we convert fc6 and fc7 into convolutional layers, and subsample by decimation. See 'decimate' in utils.py. """ state_dict = self.state_dict() param_names = list(state_dict.keys()) pretrained_state_dict = torchvision.models.vgg16(pretrained=True ).state_dict() pretrained_param_names = list(pretrained_state_dict.keys()) for i, param in enumerate(param_names[:-4]): state_dict[param] = pretrained_state_dict[pretrained_param_names[i] ] conv_fc6_weight = pretrained_state_dict['classifier.0.weight'].view( 4096, 512, 7, 7) conv_fc6_bias = pretrained_state_dict['classifier.0.bias'] state_dict['conv6.weight'] = decimate(conv_fc6_weight, m=[4, None, 3, 3]) state_dict['conv6.bias'] = decimate(conv_fc6_bias, m=[4]) conv_fc7_weight = pretrained_state_dict['classifier.3.weight'].view( 4096, 4096, 1, 1) conv_fc7_bias = pretrained_state_dict['classifier.3.bias'] state_dict['conv7.weight'] = decimate(conv_fc7_weight, m=[4, 4, None, None]) state_dict['conv7.bias'] = decimate(conv_fc7_bias, m=[4]) self.load_state_dict(state_dict) None class AuxiliaryConvolutions(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutions, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv7_feats): """ Forward propagation. :param conv7_feats: lower-level conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :return: higher-level feature maps conv8_2, conv9_2, conv10_2, and conv11_2 """ out = F.relu(self.conv8_1(conv7_feats)) out = F.relu(self.conv8_2(out)) conv8_2_feats = out out = F.relu(self.conv9_1(out)) out = F.relu(self.conv9_2(out)) conv9_2_feats = out out = F.relu(self.conv10_1(out)) out = F.relu(self.conv10_2(out)) conv10_2_feats = out out = F.relu(self.conv11_1(out)) conv11_2_feats = F.relu(self.conv11_2(out)) return conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats class PredictionConvolutions(nn.Module): """ Convolutions to predict class scores and bounding boxes using lower and higher-level feature maps. The bounding boxes (locations) are predicted as encoded offsets w.r.t each of the 8732 prior (default) boxes. See 'cxcy_to_gcxgcy' in utils.py for the encoding definition. The class scores represent the scores of each object class in each of the 8732 bounding boxes located. A high score for 'background' = no object. """ def __init__(self, n_classes): """ :param n_classes: number of different types of objects """ super(PredictionConvolutions, self).__init__() self.n_classes = n_classes n_boxes = {'conv4_3': 4, 'conv7': 6, 'conv8_2': 6, 'conv9_2': 6, 'conv10_2': 4, 'conv11_2': 4} self.loc_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * 4, kernel_size=3, padding=1) self.loc_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * 4, kernel_size= 3, padding=1) self.loc_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * 4, kernel_size=3, padding=1) self.loc_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * 4, kernel_size=3, padding=1) self.loc_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * 4, kernel_size=3, padding=1) self.loc_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * 4, kernel_size=3, padding=1) self.cl_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * n_classes, kernel_size=3, padding=1) self.cl_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * n_classes, kernel_size=3, padding=1) self.cl_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * n_classes, kernel_size=3, padding=1) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats): """ Forward propagation. :param conv4_3_feats: conv4_3 feature map, a tensor of dimensions (N, 512, 38, 38) :param conv7_feats: conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :param conv8_2_feats: conv8_2 feature map, a tensor of dimensions (N, 512, 10, 10) :param conv9_2_feats: conv9_2 feature map, a tensor of dimensions (N, 256, 5, 5) :param conv10_2_feats: conv10_2 feature map, a tensor of dimensions (N, 256, 3, 3) :param conv11_2_feats: conv11_2 feature map, a tensor of dimensions (N, 256, 1, 1) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ batch_size = conv4_3_feats.size(0) l_conv4_3 = self.loc_conv4_3(conv4_3_feats) l_conv4_3 = l_conv4_3.permute(0, 2, 3, 1).contiguous() l_conv4_3 = l_conv4_3.view(batch_size, -1, 4) l_conv7 = self.loc_conv7(conv7_feats) l_conv7 = l_conv7.permute(0, 2, 3, 1).contiguous() l_conv7 = l_conv7.view(batch_size, -1, 4) l_conv8_2 = self.loc_conv8_2(conv8_2_feats) l_conv8_2 = l_conv8_2.permute(0, 2, 3, 1).contiguous() l_conv8_2 = l_conv8_2.view(batch_size, -1, 4) l_conv9_2 = self.loc_conv9_2(conv9_2_feats) l_conv9_2 = l_conv9_2.permute(0, 2, 3, 1).contiguous() l_conv9_2 = l_conv9_2.view(batch_size, -1, 4) l_conv10_2 = self.loc_conv10_2(conv10_2_feats) l_conv10_2 = l_conv10_2.permute(0, 2, 3, 1).contiguous() l_conv10_2 = l_conv10_2.view(batch_size, -1, 4) l_conv11_2 = self.loc_conv11_2(conv11_2_feats) l_conv11_2 = l_conv11_2.permute(0, 2, 3, 1).contiguous() l_conv11_2 = l_conv11_2.view(batch_size, -1, 4) c_conv4_3 = self.cl_conv4_3(conv4_3_feats) c_conv4_3 = c_conv4_3.permute(0, 2, 3, 1).contiguous() c_conv4_3 = c_conv4_3.view(batch_size, -1, self.n_classes) c_conv7 = self.cl_conv7(conv7_feats) c_conv7 = c_conv7.permute(0, 2, 3, 1).contiguous() c_conv7 = c_conv7.view(batch_size, -1, self.n_classes) c_conv8_2 = self.cl_conv8_2(conv8_2_feats) c_conv8_2 = c_conv8_2.permute(0, 2, 3, 1).contiguous() c_conv8_2 = c_conv8_2.view(batch_size, -1, self.n_classes) c_conv9_2 = self.cl_conv9_2(conv9_2_feats) c_conv9_2 = c_conv9_2.permute(0, 2, 3, 1).contiguous() c_conv9_2 = c_conv9_2.view(batch_size, -1, self.n_classes) c_conv10_2 = self.cl_conv10_2(conv10_2_feats) c_conv10_2 = c_conv10_2.permute(0, 2, 3, 1).contiguous() c_conv10_2 = c_conv10_2.view(batch_size, -1, self.n_classes) c_conv11_2 = self.cl_conv11_2(conv11_2_feats) c_conv11_2 = c_conv11_2.permute(0, 2, 3, 1).contiguous() c_conv11_2 = c_conv11_2.view(batch_size, -1, self.n_classes) locs = torch.cat([l_conv4_3, l_conv7, l_conv8_2, l_conv9_2, l_conv10_2, l_conv11_2], dim=1) classes_scores = torch.cat([c_conv4_3, c_conv7, c_conv8_2, c_conv9_2, c_conv10_2, c_conv11_2], dim=1) return locs, classes_scores class SSD300(nn.Module): """ The SSD300 network - encapsulates the base VGG network, auxiliary, and prediction convolutions. """ def __init__(self, n_classes): super(SSD300, self).__init__() self.n_classes = n_classes self.base = VGGBase() self.aux_convs = AuxiliaryConvolutions() self.pred_convs = PredictionConvolutions(n_classes) self.rescale_factors = nn.Parameter(torch.FloatTensor(1, 512, 1, 1)) nn.init.constant_(self.rescale_factors, 20) self.priors_cxcy = self.create_prior_boxes() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ conv4_3_feats, conv7_feats = self.base(image) norm = conv4_3_feats.pow(2).sum(dim=1, keepdim=True).sqrt() conv4_3_feats = conv4_3_feats / norm conv4_3_feats = conv4_3_feats * self.rescale_factors conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats = (self .aux_convs(conv7_feats)) locs, classes_scores = self.pred_convs(conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats) return locs, classes_scores def create_prior_boxes(self): """ Create the 8732 prior (default) boxes for the SSD300, as defined in the paper. :return: prior boxes in center-size coordinates, a tensor of dimensions (8732, 4) """ fmap_dims = {'conv4_3': 38, 'conv7': 19, 'conv8_2': 10, 'conv9_2': 5, 'conv10_2': 3, 'conv11_2': 1} obj_scales = {'conv4_3': 0.1, 'conv7': 0.2, 'conv8_2': 0.375, 'conv9_2': 0.55, 'conv10_2': 0.725, 'conv11_2': 0.9} aspect_ratios = {'conv4_3': [1.0, 2.0, 0.5], 'conv7': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv8_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv9_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv10_2': [1.0, 2.0, 0.5], 'conv11_2': [1.0, 2.0, 0.5]} fmaps = list(fmap_dims.keys()) prior_boxes = [] for k, fmap in enumerate(fmaps): for i in range(fmap_dims[fmap]): for j in range(fmap_dims[fmap]): cx = (j + 0.5) / fmap_dims[fmap] cy = (i + 0.5) / fmap_dims[fmap] for ratio in aspect_ratios[fmap]: prior_boxes.append([cx, cy, obj_scales[fmap] * sqrt (ratio), obj_scales[fmap] / sqrt(ratio)]) if ratio == 1.0: try: additional_scale = sqrt(obj_scales[fmap] * obj_scales[fmaps[k + 1]]) except IndexError: additional_scale = 1.0 prior_boxes.append([cx, cy, additional_scale, additional_scale]) prior_boxes = torch.FloatTensor(prior_boxes) prior_boxes.clamp_(0, 1) return prior_boxes def detect_objects(self, predicted_locs, predicted_scores, min_score, max_overlap, top_k): """ Decipher the 8732 locations and class scores (output of ths SSD300) to detect objects. For each class, perform Non-Maximum Suppression (NMS) on boxes that are above a minimum threshold. :param predicted_locs: predicted locations/boxes w.r.t the 8732 prior boxes, a tensor of dimensions (N, 8732, 4) :param predicted_scores: class scores for each of the encoded locations/boxes, a tensor of dimensions (N, 8732, n_classes) :param min_score: minimum threshold for a box to be considered a match for a certain class :param max_overlap: maximum overlap two boxes can have so that the one with the lower score is not suppressed via NMS :param top_k: if there are a lot of resulting detection across all classes, keep only the top 'k' :return: detections (boxes, labels, and scores), lists of length batch_size """ batch_size = predicted_locs.size(0) n_priors = self.priors_cxcy.size(0) predicted_scores = F.softmax(predicted_scores, dim=2) all_images_boxes = list() all_images_labels = list() all_images_scores = list() assert n_priors == predicted_locs.size(1) == predicted_scores.size(1) for i in range(batch_size): decoded_locs = cxcy_to_xy(gcxgcy_to_cxcy(predicted_locs[i], self.priors_cxcy)) image_boxes = list() image_labels = list() image_scores = list() _max_scores, _best_label = predicted_scores[i].max(dim=1) for c in range(1, self.n_classes): class_scores = predicted_scores[i][:, c] score_above_min_score = class_scores > min_score n_above_min_score = score_above_min_score.sum().item() if n_above_min_score == 0: continue class_scores = class_scores[score_above_min_score] class_decoded_locs = decoded_locs[score_above_min_score] class_scores, sort_ind = class_scores.sort(dim=0, descending=True) class_decoded_locs = class_decoded_locs[sort_ind] overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs) suppress = torch.zeros(n_above_min_score, dtype=torch.uint8) for box in range(class_decoded_locs.size(0)): if suppress[box] == 1: continue suppress = torch.max(suppress, overlap[box] > max_overlap) suppress[box] = 0 image_boxes.append(class_decoded_locs[1 - suppress]) image_labels.append(torch.LongTensor((1 - suppress).sum(). item() * [c])) image_scores.append(class_scores[1 - suppress]) if len(image_boxes) == 0: image_boxes.append(torch.FloatTensor([[0.0, 0.0, 1.0, 1.0]])) image_labels.append(torch.LongTensor([0])) image_scores.append(torch.FloatTensor([0.0])) image_boxes = torch.cat(image_boxes, dim=0) image_labels = torch.cat(image_labels, dim=0) image_scores = torch.cat(image_scores, dim=0) n_objects = image_scores.size(0) if n_objects > top_k: image_scores, sort_ind = image_scores.sort(dim=0, descending=True) image_scores = image_scores[:top_k] image_boxes = image_boxes[sort_ind][:top_k] image_labels = image_labels[sort_ind][:top_k] all_images_boxes.append(image_boxes) all_images_labels.append(image_labels) all_images_scores.append(image_scores) return all_images_boxes, all_images_labels, all_images_scores def get_inputs(): return [torch.rand([4, 3, 512, 512])] def get_init_inputs(): return [[], {'n_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torchvision import torch.utils.data from torch import nn import torch.nn.functional as F from math import sqrt from itertools import product as product import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 262144 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 256 x1 = xindex // 256 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 1024 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (512 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (513 + 2 * x0 + 1024 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 65536 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 128 x1 = xindex // 128 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 512 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 512 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (256 + 2 * x0 + 512 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (257 + 2 * x0 + 512 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16384 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 64 x1 = xindex // 64 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 256 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 256 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (128 + 2 * x0 + 256 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (129 + 2 * x0 + 256 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_9(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 32 % 32 x0 = xindex % 32 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 32, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + x0 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-33 + x4), tmp10, other=float('-inf')) tmp12 = x0 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-32 + x4), tmp16, other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-31 + x4), tmp23, other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = x1 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-1 + x4), tmp30, other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + x4, tmp33, other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (1 + x4), tmp36, other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + x1 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (31 + x4), tmp43, other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (32 + x4), tmp46, other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (33 + x4), tmp49, other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tl.store(out_ptr0 + x4, tmp51, None) tl.store(out_ptr1 + x4, tmp76, None) @triton.jit def triton_poi_fused_convolution_relu_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 1024 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_red_fused_pow_sqrt_sum_11(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex % 4096 x1 = xindex // 4096 _tmp3 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) x3 = xindex for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r2 = rindex tmp0 = tl.load(in_ptr0 + (x0 + 4096 * r2 + 2097152 * x1), rmask, eviction_policy='evict_first', other=0.0) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = _tmp3 + tmp2 _tmp3 = tl.where(rmask, tmp4, _tmp3) tmp3 = tl.sum(_tmp3, 1)[:, None] tmp5 = libdevice.sqrt(tmp3) tl.debug_barrier() tl.store(in_out_ptr0 + x3, tmp5, None) @triton.jit def triton_poi_fused_div_mul_12(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x0 = xindex % 4096 x2 = xindex // 2097152 x1 = xindex // 4096 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 / tmp1 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x3, tmp2, None) tl.store(out_ptr1 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_13(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_15(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_16(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_17(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_18(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 36 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_19(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 36 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_20(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_cat_21(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, in_ptr11, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 394496 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 24656 x0 = xindex % 4 x2 = xindex // 98624 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 16384, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4096 * ((x0 + 4 * x1) % 16) + 65536 * ((x0 + 4 * x1 + 65536 * x2) // 65536 % 4) + (x0 + 4 * x1) // 16 % 4096), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + (x0 + 4 * x1) % 16, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tmp11 = tl.full([1], 22528, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (1024 * ((x0 + 4 * (-16384 + x1)) % 24) + 24576 * ((x0 + 4 * (-16384 + x1) + 24576 * x2) // 24576 % 4) + (x0 + 4 * (-16384 + x1)) // 24 % 1024), tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.load(in_ptr3 + (x0 + 4 * (-16384 + x1)) % 24, tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tmp20 = tl.full([1], 24064, tl.int64) tmp21 = tmp0 < tmp20 tmp22 = tmp19 & tmp21 tmp23 = tl.load(in_ptr4 + (256 * ((x0 + 4 * (-22528 + x1)) % 24) + 6144 * ((x0 + 4 * (-22528 + x1) + 6144 * x2) // 6144 % 4) + (x0 + 4 * (- 22528 + x1)) // 24 % 256), tmp22 & xmask, eviction_policy= 'evict_last', other=0.0) tmp24 = tl.load(in_ptr5 + (x0 + 4 * (-22528 + x1)) % 24, tmp22 & xmask, eviction_policy='evict_last', other=0.0) tmp25 = tmp23 + tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp22, tmp25, tmp26) tmp28 = tmp0 >= tmp20 tmp29 = tl.full([1], 24448, tl.int64) tmp30 = tmp0 < tmp29 tmp31 = tmp28 & tmp30 tmp32 = tl.load(in_ptr6 + (64 * ((x0 + 4 * (-24064 + x1)) % 24) + 1536 * ((x0 + 4 * (-24064 + x1) + 1536 * x2) // 1536 % 4) + (x0 + 4 * (- 24064 + x1)) // 24 % 64), tmp31 & xmask, eviction_policy= 'evict_last', other=0.0) tmp33 = tl.load(in_ptr7 + (x0 + 4 * (-24064 + x1)) % 24, tmp31 & xmask, eviction_policy='evict_last', other=0.0) tmp34 = tmp32 + tmp33 tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype) tmp36 = tl.where(tmp31, tmp34, tmp35) tmp37 = tmp0 >= tmp29 tmp38 = tl.full([1], 24592, tl.int64) tmp39 = tmp0 < tmp38 tmp40 = tmp37 & tmp39 tmp41 = tl.load(in_ptr8 + (36 * ((x0 + 4 * (-24448 + x1)) % 16) + 576 * ((x0 + 4 * (-24448 + x1) + 576 * x2) // 576 % 4) + (x0 + 4 * (- 24448 + x1)) // 16 % 36), tmp40 & xmask, eviction_policy= 'evict_last', other=0.0) tmp42 = tl.load(in_ptr9 + (x0 + 4 * (-24448 + x1)) % 16, tmp40 & xmask, eviction_policy='evict_last', other=0.0) tmp43 = tmp41 + tmp42 tmp44 = tl.full(tmp43.shape, 0.0, tmp43.dtype) tmp45 = tl.where(tmp40, tmp43, tmp44) tmp46 = tmp0 >= tmp38 tl.full([1], 24656, tl.int64) tmp49 = tl.load(in_ptr10 + (16 * ((x0 + 4 * (-24592 + x1)) % 16) + 256 * ((x0 + 4 * (-24592 + x1) + 256 * x2) // 256 % 4) + (x0 + 4 * (- 24592 + x1)) // 16 % 16), tmp46 & xmask, eviction_policy= 'evict_last', other=0.0) tmp50 = tl.load(in_ptr11 + (x0 + 4 * (-24592 + x1)) % 16, tmp46 & xmask, eviction_policy='evict_last', other=0.0) tmp51 = tmp49 + tmp50 tmp52 = tl.full(tmp51.shape, 0.0, tmp51.dtype) tmp53 = tl.where(tmp46, tmp51, tmp52) tmp54 = tl.where(tmp40, tmp45, tmp53) tmp55 = tl.where(tmp31, tmp36, tmp54) tmp56 = tl.where(tmp22, tmp27, tmp55) tmp57 = tl.where(tmp13, tmp18, tmp56) tmp58 = tl.where(tmp4, tmp9, tmp57) tl.store(out_ptr0 + x3, tmp58, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72) = args args.clear() assert_size_stride(primals_1, (64, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 3, 512, 512), (786432, 262144, 512, 1)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_15, (256,), (1,)) assert_size_stride(primals_16, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_17, (512,), (1,)) assert_size_stride(primals_18, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_19, (512,), (1,)) assert_size_stride(primals_20, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_21, (512,), (1,)) assert_size_stride(primals_22, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_23, (512,), (1,)) assert_size_stride(primals_24, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_25, (512,), (1,)) assert_size_stride(primals_26, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_27, (512,), (1,)) assert_size_stride(primals_28, (1024, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_29, (1024,), (1,)) assert_size_stride(primals_30, (1024, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_31, (1024,), (1,)) assert_size_stride(primals_32, (1, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_33, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_34, (256,), (1,)) assert_size_stride(primals_35, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_36, (512,), (1,)) assert_size_stride(primals_37, (128, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_38, (128,), (1,)) assert_size_stride(primals_39, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_40, (256,), (1,)) assert_size_stride(primals_41, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_42, (128,), (1,)) assert_size_stride(primals_43, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_44, (256,), (1,)) assert_size_stride(primals_45, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_46, (128,), (1,)) assert_size_stride(primals_47, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_48, (256,), (1,)) assert_size_stride(primals_49, (16, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_50, (16,), (1,)) assert_size_stride(primals_51, (24, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_52, (24,), (1,)) assert_size_stride(primals_53, (24, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_54, (24,), (1,)) assert_size_stride(primals_55, (24, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_56, (24,), (1,)) assert_size_stride(primals_57, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_58, (16,), (1,)) assert_size_stride(primals_59, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_60, (16,), (1,)) assert_size_stride(primals_61, (16, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_62, (16,), (1,)) assert_size_stride(primals_63, (24, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_64, (24,), (1,)) assert_size_stride(primals_65, (24, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_66, (24,), (1,)) assert_size_stride(primals_67, (24, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_68, (24,), (1,)) assert_size_stride(primals_69, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_70, (16,), (1,)) assert_size_stride(primals_71, (16, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_72, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 512, 512), (16777216, 262144, 512, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(67108864)](buf1, primals_2, 67108864, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 512, 512), (16777216, 262144, 512, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[grid(67108864)](buf3, primals_5, 67108864, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 64, 256, 256), (4194304, 65536, 256, 1), torch.float32) buf5 = empty_strided_cuda((4, 64, 256, 256), (4194304, 65536, 256, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(16777216)](buf3, buf4, buf5, 16777216, XBLOCK=512, num_warps=8, num_stages=1) buf6 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 256, 256), (8388608, 65536, 256, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_2[grid(33554432)](buf7, primals_7, 33554432, XBLOCK=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, 256, 256), (8388608, 65536, 256, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_2[grid(33554432)](buf9, primals_9, 33554432, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 128, 128, 128), (2097152, 16384, 128, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 128, 128), (2097152, 16384, 128, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(8388608)](buf9, buf10, buf11, 8388608, XBLOCK=512, num_warps=8, num_stages=1) buf12 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_4[grid(16777216)](buf13, primals_11, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_11 buf14 = extern_kernels.convolution(buf13, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_4[grid(16777216)](buf15, primals_13, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_13 buf16 = extern_kernels.convolution(buf15, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf16, (4, 256, 128, 128), (4194304, 16384, 128, 1)) buf17 = buf16 del buf16 triton_poi_fused_convolution_relu_4[grid(16777216)](buf17, primals_15, 16777216, XBLOCK=512, num_warps=8, num_stages=1) del primals_15 buf18 = empty_strided_cuda((4, 256, 64, 64), (1048576, 4096, 64, 1), torch.float32) buf19 = empty_strided_cuda((4, 256, 64, 64), (1048576, 4096, 64, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(4194304)](buf17, buf18, buf19, 4194304, XBLOCK=512, num_warps=8, num_stages=1) buf20 = extern_kernels.convolution(buf18, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_6[grid(8388608)](buf21, primals_17, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_17 buf22 = extern_kernels.convolution(buf21, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_6[grid(8388608)](buf23, primals_19, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_19 buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 512, 64, 64), (2097152, 4096, 64, 1)) buf25 = buf24 del buf24 triton_poi_fused_convolution_relu_6[grid(8388608)](buf25, primals_21, 8388608, XBLOCK=512, num_warps=8, num_stages=1) del primals_21 buf26 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.float32) buf27 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_7[grid(2097152)](buf25, buf26, buf27, 2097152, XBLOCK=512, num_warps=8, num_stages=1) buf28 = extern_kernels.convolution(buf26, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf29 = buf28 del buf28 triton_poi_fused_convolution_relu_8[grid(2097152)](buf29, primals_23, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_23 buf30 = extern_kernels.convolution(buf29, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf31 = buf30 del buf30 triton_poi_fused_convolution_relu_8[grid(2097152)](buf31, primals_25, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_25 buf32 = extern_kernels.convolution(buf31, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf32, (4, 512, 32, 32), (524288, 1024, 32, 1)) buf33 = buf32 del buf32 triton_poi_fused_convolution_relu_8[grid(2097152)](buf33, primals_27, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_27 buf34 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.float32) buf35 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_9[grid(2097152)](buf33, buf34, buf35, 2097152, XBLOCK=512, num_warps=8, num_stages=1) buf36 = extern_kernels.convolution(buf34, primals_28, stride=(1, 1), padding=(6, 6), dilation=(6, 6), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 1024, 32, 32), (1048576, 1024, 32, 1)) buf37 = buf36 del buf36 triton_poi_fused_convolution_relu_10[grid(4194304)](buf37, primals_29, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_29 buf38 = extern_kernels.convolution(buf37, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 1024, 32, 32), (1048576, 1024, 32, 1)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_10[grid(4194304)](buf39, primals_31, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_31 buf40 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) buf41 = reinterpret_tensor(buf40, (4, 1, 64, 64), (4096, 4096, 64, 1), 0) del buf40 triton_red_fused_pow_sqrt_sum_11[grid(16384)](buf41, buf25, 16384, 512, XBLOCK=64, RBLOCK=8, num_warps=4, num_stages=1) buf42 = empty_strided_cuda((4, 512, 64, 64), (2097152, 4096, 64, 1), torch.float32) buf43 = empty_strided_cuda((4, 512, 64, 64), (2097152, 4096, 64, 1), torch.float32) triton_poi_fused_div_mul_12[grid(8388608)](buf25, buf41, primals_32, buf42, buf43, 8388608, XBLOCK=512, num_warps=8, num_stages=1) buf44 = extern_kernels.convolution(buf39, primals_33, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf44, (4, 256, 32, 32), (262144, 1024, 32, 1)) buf45 = buf44 del buf44 triton_poi_fused_convolution_relu_13[grid(1048576)](buf45, primals_34, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_34 buf46 = extern_kernels.convolution(buf45, primals_35, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf46, (4, 512, 16, 16), (131072, 256, 16, 1)) buf47 = buf46 del buf46 triton_poi_fused_convolution_relu_14[grid(524288)](buf47, primals_36, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_36 buf48 = extern_kernels.convolution(buf47, primals_37, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf48, (4, 128, 16, 16), (32768, 256, 16, 1)) buf49 = buf48 del buf48 triton_poi_fused_convolution_relu_15[grid(131072)](buf49, primals_38, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_38 buf50 = extern_kernels.convolution(buf49, primals_39, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf50, (4, 256, 8, 8), (16384, 64, 8, 1)) buf51 = buf50 del buf50 triton_poi_fused_convolution_relu_16[grid(65536)](buf51, primals_40, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_40 buf52 = extern_kernels.convolution(buf51, primals_41, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf52, (4, 128, 8, 8), (8192, 64, 8, 1)) buf53 = buf52 del buf52 triton_poi_fused_convolution_relu_17[grid(32768)](buf53, primals_42, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_42 buf54 = extern_kernels.convolution(buf53, primals_43, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 256, 6, 6), (9216, 36, 6, 1)) buf55 = buf54 del buf54 triton_poi_fused_convolution_relu_18[grid(36864)](buf55, primals_44, 36864, XBLOCK=512, num_warps=4, num_stages=1) del primals_44 buf56 = extern_kernels.convolution(buf55, primals_45, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf56, (4, 128, 6, 6), (4608, 36, 6, 1)) buf57 = buf56 del buf56 triton_poi_fused_convolution_relu_19[grid(18432)](buf57, primals_46, 18432, XBLOCK=256, num_warps=4, num_stages=1) del primals_46 buf58 = extern_kernels.convolution(buf57, primals_47, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf58, (4, 256, 4, 4), (4096, 16, 4, 1)) buf59 = buf58 del buf58 triton_poi_fused_convolution_relu_20[grid(16384)](buf59, primals_48, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_48 buf60 = extern_kernels.convolution(buf43, primals_49, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf60, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf61 = extern_kernels.convolution(buf39, primals_51, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf61, (4, 24, 32, 32), (24576, 1024, 32, 1)) buf62 = extern_kernels.convolution(buf47, primals_53, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf62, (4, 24, 16, 16), (6144, 256, 16, 1)) buf63 = extern_kernels.convolution(buf51, primals_55, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf63, (4, 24, 8, 8), (1536, 64, 8, 1)) buf64 = extern_kernels.convolution(buf55, primals_57, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 16, 6, 6), (576, 36, 6, 1)) buf65 = extern_kernels.convolution(buf59, primals_59, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf65, (4, 16, 4, 4), (256, 16, 4, 1)) buf66 = extern_kernels.convolution(buf43, primals_61, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf66, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf67 = extern_kernels.convolution(buf39, primals_63, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf67, (4, 24, 32, 32), (24576, 1024, 32, 1)) buf68 = extern_kernels.convolution(buf47, primals_65, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf68, (4, 24, 16, 16), (6144, 256, 16, 1)) buf69 = extern_kernels.convolution(buf51, primals_67, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf69, (4, 24, 8, 8), (1536, 64, 8, 1)) buf70 = extern_kernels.convolution(buf55, primals_69, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf70, (4, 16, 6, 6), (576, 36, 6, 1)) buf71 = extern_kernels.convolution(buf59, primals_71, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf71, (4, 16, 4, 4), (256, 16, 4, 1)) buf72 = empty_strided_cuda((4, 24656, 4), (98624, 4, 1), torch.float32) triton_poi_fused_cat_21[grid(394496)](buf60, primals_50, buf61, primals_52, buf62, primals_54, buf63, primals_56, buf64, primals_58, buf65, primals_60, buf72, 394496, XBLOCK=512, num_warps=8, num_stages=1) del buf60 del buf61 del buf62 del buf63 del buf64 del buf65 del primals_50 del primals_52 del primals_54 del primals_56 del primals_58 del primals_60 buf73 = empty_strided_cuda((4, 24656, 4), (98624, 4, 1), torch.float32) triton_poi_fused_cat_21[grid(394496)](buf66, primals_62, buf67, primals_64, buf68, primals_66, buf69, primals_68, buf70, primals_70, buf71, primals_72, buf73, 394496, XBLOCK=512, num_warps=8, num_stages=1) del buf66 del buf67 del buf68 del buf69 del buf70 del buf71 del primals_62 del primals_64 del primals_66 del primals_68 del primals_70 del primals_72 return (buf72, buf73, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, primals_28, primals_30, primals_32, primals_33, primals_35, primals_37, primals_39, primals_41, primals_43, primals_45, primals_47, primals_49, primals_51, primals_53, primals_55, primals_57, primals_59, primals_61, primals_63, primals_65, primals_67, primals_69, primals_71, buf1, buf3, buf4, buf5, buf7, buf9, buf10, buf11, buf13, buf15, buf17, buf18, buf19, buf21, buf23, buf25, buf26, buf27, buf29, buf31, buf33, buf34, buf35, buf37, buf39, buf41, buf42, buf43, buf45, buf47, buf49, buf51, buf53, buf55, buf57, buf59) def decimate(tensor, m): """ Decimate a tensor by a factor 'm', i.e. downsample by keeping every 'm'th value. This is used when we convert FC layers to equivalent Convolutional layers, BUT of a smaller size. :param tensor: tensor to be decimated :param m: list of decimation factors for each dimension of the tensor; None if not to be decimated along a dimension :return: decimated tensor """ assert tensor.dim() == len(m) for d in range(tensor.dim()): if m[d] is not None: tensor = tensor.index_select(dim=d, index=torch.arange(start=0, end=tensor.size(d), step=m[d]).long()) return tensor def cxcy_to_xy(cxcy): """ Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max). :param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4) :return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4) """ return torch.cat([cxcy[:, :2] - cxcy[:, 2:] / 2, cxcy[:, :2] + cxcy[:, 2:] / 2], 1) def find_intersection(set_1, set_2): """ Find the intersection of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: intersection of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2]. unsqueeze(0)) upper_bounds = torch.min(set_1[:, 2:].unsqueeze(1), set_2[:, 2:]. unsqueeze(0)) intersection_dims = torch.clamp(upper_bounds - lower_bounds, min=0) return intersection_dims[:, :, 0] * intersection_dims[:, :, 1] def find_jaccard_overlap(set_1, set_2): """ Find the Jaccard Overlap (IoU) of every box combination between two sets of boxes that are in boundary coordinates. :param set_1: set 1, a tensor of dimensions (n1, 4) :param set_2: set 2, a tensor of dimensions (n2, 4) :return: Jaccard Overlap of each of the boxes in set 1 with respect to each of the boxes in set 2, a tensor of dimensions (n1, n2) """ intersection = find_intersection(set_1, set_2) areas_set_1 = (set_1[:, 2] - set_1[:, 0]) * (set_1[:, 3] - set_1[:, 1]) areas_set_2 = (set_2[:, 2] - set_2[:, 0]) * (set_2[:, 3] - set_2[:, 1]) union = areas_set_1.unsqueeze(1) + areas_set_2.unsqueeze(0) - intersection return intersection / union def gcxgcy_to_cxcy(gcxgcy, priors_cxcy): """ Decode bounding box coordinates predicted by the model, since they are encoded in the form mentioned above. They are decoded into center-size coordinates. This is the inverse of the function above. :param gcxgcy: encoded bounding boxes, i.e. output of the model, a tensor of size (n_priors, 4) :param priors_cxcy: prior boxes with respect to which the encoding is defined, a tensor of size (n_priors, 4) :return: decoded bounding boxes in center-size form, a tensor of size (n_priors, 4) """ return torch.cat([gcxgcy[:, :2] * priors_cxcy[:, 2:] / 10 + priors_cxcy [:, :2], torch.exp(gcxgcy[:, 2:] / 5) * priors_cxcy[:, 2:]], 1) class VGGBase(nn.Module): """ VGG base convolutions to produce lower-level feature maps. """ def __init__(self): super(VGGBase, self).__init__() self.conv1_1 = nn.Conv2d(3, 64, kernel_size=3, padding=1) self.conv1_2 = nn.Conv2d(64, 64, kernel_size=3, padding=1) self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv2_1 = nn.Conv2d(64, 128, kernel_size=3, padding=1) self.conv2_2 = nn.Conv2d(128, 128, kernel_size=3, padding=1) self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv3_1 = nn.Conv2d(128, 256, kernel_size=3, padding=1) self.conv3_2 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.conv3_3 = nn.Conv2d(256, 256, kernel_size=3, padding=1) self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True) self.conv4_1 = nn.Conv2d(256, 512, kernel_size=3, padding=1) self.conv4_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv4_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2) self.conv5_1 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_2 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.conv5_3 = nn.Conv2d(512, 512, kernel_size=3, padding=1) self.pool5 = nn.MaxPool2d(kernel_size=3, stride=1, padding=1) self.conv6 = nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6) self.conv7 = nn.Conv2d(1024, 1024, kernel_size=1) self.load_pretrained_layers() def forward(self, image): """ Forward propagation. :param image: images, a tensor of dimensions (N, 3, 300, 300) :return: lower-level feature maps conv4_3 and conv7 """ out = F.relu(self.conv1_1(image)) out = F.relu(self.conv1_2(out)) out = self.pool1(out) out = F.relu(self.conv2_1(out)) out = F.relu(self.conv2_2(out)) out = self.pool2(out) out = F.relu(self.conv3_1(out)) out = F.relu(self.conv3_2(out)) out = F.relu(self.conv3_3(out)) out = self.pool3(out) out = F.relu(self.conv4_1(out)) out = F.relu(self.conv4_2(out)) out = F.relu(self.conv4_3(out)) conv4_3_feats = out out = self.pool4(out) out = F.relu(self.conv5_1(out)) out = F.relu(self.conv5_2(out)) out = F.relu(self.conv5_3(out)) out = self.pool5(out) out = F.relu(self.conv6(out)) conv7_feats = F.relu(self.conv7(out)) return conv4_3_feats, conv7_feats def load_pretrained_layers(self): """ As in the paper, we use a VGG-16 pretrained on the ImageNet task as the base network. There's one available in PyTorch, see https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.vgg16 We copy these parameters into our network. It's straightforward for conv1 to conv5. However, the original VGG-16 does not contain the conv6 and con7 layers. Therefore, we convert fc6 and fc7 into convolutional layers, and subsample by decimation. See 'decimate' in utils.py. """ state_dict = self.state_dict() param_names = list(state_dict.keys()) pretrained_state_dict = torchvision.models.vgg16(pretrained=True ).state_dict() pretrained_param_names = list(pretrained_state_dict.keys()) for i, param in enumerate(param_names[:-4]): state_dict[param] = pretrained_state_dict[pretrained_param_names[i] ] conv_fc6_weight = pretrained_state_dict['classifier.0.weight'].view( 4096, 512, 7, 7) conv_fc6_bias = pretrained_state_dict['classifier.0.bias'] state_dict['conv6.weight'] = decimate(conv_fc6_weight, m=[4, None, 3, 3]) state_dict['conv6.bias'] = decimate(conv_fc6_bias, m=[4]) conv_fc7_weight = pretrained_state_dict['classifier.3.weight'].view( 4096, 4096, 1, 1) conv_fc7_bias = pretrained_state_dict['classifier.3.bias'] state_dict['conv7.weight'] = decimate(conv_fc7_weight, m=[4, 4, None, None]) state_dict['conv7.bias'] = decimate(conv_fc7_bias, m=[4]) self.load_state_dict(state_dict) None class AuxiliaryConvolutions(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutions, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv7_feats): """ Forward propagation. :param conv7_feats: lower-level conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :return: higher-level feature maps conv8_2, conv9_2, conv10_2, and conv11_2 """ out = F.relu(self.conv8_1(conv7_feats)) out = F.relu(self.conv8_2(out)) conv8_2_feats = out out = F.relu(self.conv9_1(out)) out = F.relu(self.conv9_2(out)) conv9_2_feats = out out = F.relu(self.conv10_1(out)) out = F.relu(self.conv10_2(out)) conv10_2_feats = out out = F.relu(self.conv11_1(out)) conv11_2_feats = F.relu(self.conv11_2(out)) return conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats class PredictionConvolutions(nn.Module): """ Convolutions to predict class scores and bounding boxes using lower and higher-level feature maps. The bounding boxes (locations) are predicted as encoded offsets w.r.t each of the 8732 prior (default) boxes. See 'cxcy_to_gcxgcy' in utils.py for the encoding definition. The class scores represent the scores of each object class in each of the 8732 bounding boxes located. A high score for 'background' = no object. """ def __init__(self, n_classes): """ :param n_classes: number of different types of objects """ super(PredictionConvolutions, self).__init__() self.n_classes = n_classes n_boxes = {'conv4_3': 4, 'conv7': 6, 'conv8_2': 6, 'conv9_2': 6, 'conv10_2': 4, 'conv11_2': 4} self.loc_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * 4, kernel_size=3, padding=1) self.loc_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * 4, kernel_size= 3, padding=1) self.loc_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * 4, kernel_size=3, padding=1) self.loc_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * 4, kernel_size=3, padding=1) self.loc_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * 4, kernel_size=3, padding=1) self.loc_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * 4, kernel_size=3, padding=1) self.cl_conv4_3 = nn.Conv2d(512, n_boxes['conv4_3'] * n_classes, kernel_size=3, padding=1) self.cl_conv7 = nn.Conv2d(1024, n_boxes['conv7'] * n_classes, kernel_size=3, padding=1) self.cl_conv8_2 = nn.Conv2d(512, n_boxes['conv8_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv9_2 = nn.Conv2d(256, n_boxes['conv9_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv10_2 = nn.Conv2d(256, n_boxes['conv10_2'] * n_classes, kernel_size=3, padding=1) self.cl_conv11_2 = nn.Conv2d(256, n_boxes['conv11_2'] * n_classes, kernel_size=3, padding=1) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv4_3_feats, conv7_feats, conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats): """ Forward propagation. :param conv4_3_feats: conv4_3 feature map, a tensor of dimensions (N, 512, 38, 38) :param conv7_feats: conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :param conv8_2_feats: conv8_2 feature map, a tensor of dimensions (N, 512, 10, 10) :param conv9_2_feats: conv9_2 feature map, a tensor of dimensions (N, 256, 5, 5) :param conv10_2_feats: conv10_2 feature map, a tensor of dimensions (N, 256, 3, 3) :param conv11_2_feats: conv11_2 feature map, a tensor of dimensions (N, 256, 1, 1) :return: 8732 locations and class scores (i.e. w.r.t each prior box) for each image """ batch_size = conv4_3_feats.size(0) l_conv4_3 = self.loc_conv4_3(conv4_3_feats) l_conv4_3 = l_conv4_3.permute(0, 2, 3, 1).contiguous() l_conv4_3 = l_conv4_3.view(batch_size, -1, 4) l_conv7 = self.loc_conv7(conv7_feats) l_conv7 = l_conv7.permute(0, 2, 3, 1).contiguous() l_conv7 = l_conv7.view(batch_size, -1, 4) l_conv8_2 = self.loc_conv8_2(conv8_2_feats) l_conv8_2 = l_conv8_2.permute(0, 2, 3, 1).contiguous() l_conv8_2 = l_conv8_2.view(batch_size, -1, 4) l_conv9_2 = self.loc_conv9_2(conv9_2_feats) l_conv9_2 = l_conv9_2.permute(0, 2, 3, 1).contiguous() l_conv9_2 = l_conv9_2.view(batch_size, -1, 4) l_conv10_2 = self.loc_conv10_2(conv10_2_feats) l_conv10_2 = l_conv10_2.permute(0, 2, 3, 1).contiguous() l_conv10_2 = l_conv10_2.view(batch_size, -1, 4) l_conv11_2 = self.loc_conv11_2(conv11_2_feats) l_conv11_2 = l_conv11_2.permute(0, 2, 3, 1).contiguous() l_conv11_2 = l_conv11_2.view(batch_size, -1, 4) c_conv4_3 = self.cl_conv4_3(conv4_3_feats) c_conv4_3 = c_conv4_3.permute(0, 2, 3, 1).contiguous() c_conv4_3 = c_conv4_3.view(batch_size, -1, self.n_classes) c_conv7 = self.cl_conv7(conv7_feats) c_conv7 = c_conv7.permute(0, 2, 3, 1).contiguous() c_conv7 = c_conv7.view(batch_size, -1, self.n_classes) c_conv8_2 = self.cl_conv8_2(conv8_2_feats) c_conv8_2 = c_conv8_2.permute(0, 2, 3, 1).contiguous() c_conv8_2 = c_conv8_2.view(batch_size, -1, self.n_classes) c_conv9_2 = self.cl_conv9_2(conv9_2_feats) c_conv9_2 = c_conv9_2.permute(0, 2, 3, 1).contiguous() c_conv9_2 = c_conv9_2.view(batch_size, -1, self.n_classes) c_conv10_2 = self.cl_conv10_2(conv10_2_feats) c_conv10_2 = c_conv10_2.permute(0, 2, 3, 1).contiguous() c_conv10_2 = c_conv10_2.view(batch_size, -1, self.n_classes) c_conv11_2 = self.cl_conv11_2(conv11_2_feats) c_conv11_2 = c_conv11_2.permute(0, 2, 3, 1).contiguous() c_conv11_2 = c_conv11_2.view(batch_size, -1, self.n_classes) locs = torch.cat([l_conv4_3, l_conv7, l_conv8_2, l_conv9_2, l_conv10_2, l_conv11_2], dim=1) classes_scores = torch.cat([c_conv4_3, c_conv7, c_conv8_2, c_conv9_2, c_conv10_2, c_conv11_2], dim=1) return locs, classes_scores class SSD300New(nn.Module): """ The SSD300 network - encapsulates the base VGG network, auxiliary, and prediction convolutions. """ def __init__(self, n_classes): super(SSD300New, self).__init__() self.n_classes = n_classes self.base = VGGBase() self.aux_convs = AuxiliaryConvolutions() self.pred_convs = PredictionConvolutions(n_classes) self.rescale_factors = nn.Parameter(torch.FloatTensor(1, 512, 1, 1)) nn.init.constant_(self.rescale_factors, 20) self.priors_cxcy = self.create_prior_boxes() def create_prior_boxes(self): """ Create the 8732 prior (default) boxes for the SSD300, as defined in the paper. :return: prior boxes in center-size coordinates, a tensor of dimensions (8732, 4) """ fmap_dims = {'conv4_3': 38, 'conv7': 19, 'conv8_2': 10, 'conv9_2': 5, 'conv10_2': 3, 'conv11_2': 1} obj_scales = {'conv4_3': 0.1, 'conv7': 0.2, 'conv8_2': 0.375, 'conv9_2': 0.55, 'conv10_2': 0.725, 'conv11_2': 0.9} aspect_ratios = {'conv4_3': [1.0, 2.0, 0.5], 'conv7': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv8_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv9_2': [1.0, 2.0, 3.0, 0.5, 0.333], 'conv10_2': [1.0, 2.0, 0.5], 'conv11_2': [1.0, 2.0, 0.5]} fmaps = list(fmap_dims.keys()) prior_boxes = [] for k, fmap in enumerate(fmaps): for i in range(fmap_dims[fmap]): for j in range(fmap_dims[fmap]): cx = (j + 0.5) / fmap_dims[fmap] cy = (i + 0.5) / fmap_dims[fmap] for ratio in aspect_ratios[fmap]: prior_boxes.append([cx, cy, obj_scales[fmap] * sqrt (ratio), obj_scales[fmap] / sqrt(ratio)]) if ratio == 1.0: try: additional_scale = sqrt(obj_scales[fmap] * obj_scales[fmaps[k + 1]]) except IndexError: additional_scale = 1.0 prior_boxes.append([cx, cy, additional_scale, additional_scale]) prior_boxes = torch.FloatTensor(prior_boxes) prior_boxes.clamp_(0, 1) return prior_boxes def detect_objects(self, predicted_locs, predicted_scores, min_score, max_overlap, top_k): """ Decipher the 8732 locations and class scores (output of ths SSD300) to detect objects. For each class, perform Non-Maximum Suppression (NMS) on boxes that are above a minimum threshold. :param predicted_locs: predicted locations/boxes w.r.t the 8732 prior boxes, a tensor of dimensions (N, 8732, 4) :param predicted_scores: class scores for each of the encoded locations/boxes, a tensor of dimensions (N, 8732, n_classes) :param min_score: minimum threshold for a box to be considered a match for a certain class :param max_overlap: maximum overlap two boxes can have so that the one with the lower score is not suppressed via NMS :param top_k: if there are a lot of resulting detection across all classes, keep only the top 'k' :return: detections (boxes, labels, and scores), lists of length batch_size """ batch_size = predicted_locs.size(0) n_priors = self.priors_cxcy.size(0) predicted_scores = F.softmax(predicted_scores, dim=2) all_images_boxes = list() all_images_labels = list() all_images_scores = list() assert n_priors == predicted_locs.size(1) == predicted_scores.size(1) for i in range(batch_size): decoded_locs = cxcy_to_xy(gcxgcy_to_cxcy(predicted_locs[i], self.priors_cxcy)) image_boxes = list() image_labels = list() image_scores = list() _max_scores, _best_label = predicted_scores[i].max(dim=1) for c in range(1, self.n_classes): class_scores = predicted_scores[i][:, c] score_above_min_score = class_scores > min_score n_above_min_score = score_above_min_score.sum().item() if n_above_min_score == 0: continue class_scores = class_scores[score_above_min_score] class_decoded_locs = decoded_locs[score_above_min_score] class_scores, sort_ind = class_scores.sort(dim=0, descending=True) class_decoded_locs = class_decoded_locs[sort_ind] overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs) suppress = torch.zeros(n_above_min_score, dtype=torch.uint8) for box in range(class_decoded_locs.size(0)): if suppress[box] == 1: continue suppress = torch.max(suppress, overlap[box] > max_overlap) suppress[box] = 0 image_boxes.append(class_decoded_locs[1 - suppress]) image_labels.append(torch.LongTensor((1 - suppress).sum(). item() * [c])) image_scores.append(class_scores[1 - suppress]) if len(image_boxes) == 0: image_boxes.append(torch.FloatTensor([[0.0, 0.0, 1.0, 1.0]])) image_labels.append(torch.LongTensor([0])) image_scores.append(torch.FloatTensor([0.0])) image_boxes = torch.cat(image_boxes, dim=0) image_labels = torch.cat(image_labels, dim=0) image_scores = torch.cat(image_scores, dim=0) n_objects = image_scores.size(0) if n_objects > top_k: image_scores, sort_ind = image_scores.sort(dim=0, descending=True) image_scores = image_scores[:top_k] image_boxes = image_boxes[sort_ind][:top_k] image_labels = image_labels[sort_ind][:top_k] all_images_boxes.append(image_boxes) all_images_labels.append(image_labels) all_images_scores.append(image_scores) return all_images_boxes, all_images_labels, all_images_scores def forward(self, input_0): primals_32 = self.rescale_factors primals_1 = self.base.conv1_1.weight primals_2 = self.base.conv1_1.bias primals_4 = self.base.conv1_2.weight primals_5 = self.base.conv1_2.bias primals_6 = self.base.conv2_1.weight primals_7 = self.base.conv2_1.bias primals_8 = self.base.conv2_2.weight primals_9 = self.base.conv2_2.bias primals_10 = self.base.conv3_1.weight primals_11 = self.base.conv3_1.bias primals_12 = self.base.conv3_2.weight primals_13 = self.base.conv3_2.bias primals_14 = self.base.conv3_3.weight primals_15 = self.base.conv3_3.bias primals_16 = self.base.conv4_1.weight primals_17 = self.base.conv4_1.bias primals_18 = self.base.conv4_2.weight primals_19 = self.base.conv4_2.bias primals_20 = self.base.conv4_3.weight primals_21 = self.base.conv4_3.bias primals_22 = self.base.conv5_1.weight primals_23 = self.base.conv5_1.bias primals_24 = self.base.conv5_2.weight primals_25 = self.base.conv5_2.bias primals_26 = self.base.conv5_3.weight primals_27 = self.base.conv5_3.bias primals_28 = self.base.conv6.weight primals_29 = self.base.conv6.bias primals_30 = self.base.conv7.weight primals_31 = self.base.conv7.bias primals_33 = self.aux_convs.conv8_1.weight primals_34 = self.aux_convs.conv8_1.bias primals_35 = self.aux_convs.conv8_2.weight primals_36 = self.aux_convs.conv8_2.bias primals_37 = self.aux_convs.conv9_1.weight primals_38 = self.aux_convs.conv9_1.bias primals_39 = self.aux_convs.conv9_2.weight primals_40 = self.aux_convs.conv9_2.bias primals_41 = self.aux_convs.conv10_1.weight primals_42 = self.aux_convs.conv10_1.bias primals_43 = self.aux_convs.conv10_2.weight primals_44 = self.aux_convs.conv10_2.bias primals_45 = self.aux_convs.conv11_1.weight primals_46 = self.aux_convs.conv11_1.bias primals_47 = self.aux_convs.conv11_2.weight primals_48 = self.aux_convs.conv11_2.bias primals_49 = self.pred_convs.loc_conv4_3.weight primals_50 = self.pred_convs.loc_conv4_3.bias primals_51 = self.pred_convs.loc_conv7.weight primals_52 = self.pred_convs.loc_conv7.bias primals_53 = self.pred_convs.loc_conv8_2.weight primals_54 = self.pred_convs.loc_conv8_2.bias primals_55 = self.pred_convs.loc_conv9_2.weight primals_56 = self.pred_convs.loc_conv9_2.bias primals_57 = self.pred_convs.loc_conv10_2.weight primals_58 = self.pred_convs.loc_conv10_2.bias primals_59 = self.pred_convs.loc_conv11_2.weight primals_60 = self.pred_convs.loc_conv11_2.bias primals_61 = self.pred_convs.cl_conv4_3.weight primals_62 = self.pred_convs.cl_conv4_3.bias primals_63 = self.pred_convs.cl_conv7.weight primals_64 = self.pred_convs.cl_conv7.bias primals_65 = self.pred_convs.cl_conv8_2.weight primals_66 = self.pred_convs.cl_conv8_2.bias primals_67 = self.pred_convs.cl_conv9_2.weight primals_68 = self.pred_convs.cl_conv9_2.bias primals_69 = self.pred_convs.cl_conv10_2.weight primals_70 = self.pred_convs.cl_conv10_2.bias primals_71 = self.pred_convs.cl_conv11_2.weight primals_72 = self.pred_convs.cl_conv11_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47, primals_48, primals_49, primals_50, primals_51, primals_52, primals_53, primals_54, primals_55, primals_56, primals_57, primals_58, primals_59, primals_60, primals_61, primals_62, primals_63, primals_64, primals_65, primals_66, primals_67, primals_68, primals_69, primals_70, primals_71, primals_72]) return output[0], output[1]
adityag6994/pytorch_ssd_training
SSD300
false
3,587
[ "MIT" ]
0
404f3cbef815e314337ec2c1b4f06a2403a7ce03
https://github.com/adityag6994/pytorch_ssd_training/tree/404f3cbef815e314337ec2c1b4f06a2403a7ce03
Attention
import torch import torch.nn as nn import torch.utils.data class Attention(nn.Module): def __init__(self): super(Attention, self).__init__() def forward(self, input_hidden_traces, target_hidden_traces): Attn = torch.bmm(target_hidden_traces, input_hidden_traces. transpose(1, 2)) Attn_size = Attn.size() Attn = Attn - Attn.max(2)[0].unsqueeze(2).expand(Attn_size) exp_Attn = torch.exp(Attn) Attn = exp_Attn / exp_Attn.sum(2).unsqueeze(2).expand(Attn_size) return Attn def get_inputs(): return [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 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_exp_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_div_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 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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_exp_sub_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused_div_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 return buf2, class AttentionNew(nn.Module): def __init__(self): super(AttentionNew, self).__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hk19960522/2018-DL-Final
Attention
false
3,588
[ "MIT" ]
0
cbc70260aa22d7df366a1d28bee472f1fc5b82c7
https://github.com/hk19960522/2018-DL-Final/tree/cbc70260aa22d7df366a1d28bee472f1fc5b82c7
Autoencoder
import torch import torch.nn as nn class Autoencoder(nn.Module): def __init__(self): super(Autoencoder, self).__init__() self.encoder = nn.Conv2d(1024, 128, kernel_size=1) self.decoder = nn.Conv2d(128, 1024, kernel_size=1) self.relu = nn.ReLU() def forward(self, local_f): encoded_f = self.encoder(local_f) decoded_f = self.decoder(encoded_f) decoded_f = self.relu(decoded_f) return encoded_f, decoded_f def get_inputs(): return [torch.rand([4, 1024, 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 1024 y1 = yindex // 1024 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), None) tl.store(out_ptr0 + (y0 + 1024 * x2 + 4194304 * y1), tmp0, None) @triton.jit def triton_poi_fused_convolution_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 512 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y0 = yindex % 128 y1 = yindex // 128 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 128 * x2 + 524288 * y1), ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4096 * y3), tmp2, ymask) tl.store(out_ptr1 + (y0 + 128 * x2 + 524288 * y1), tmp2, ymask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl. constexpr): yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y0 = yindex % 1024 y1 = yindex // 1024 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 1024 * x2 + 4194304 * y1), None) 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 + 4096 * y3), tmp4, None) tl.store(out_ptr1 + (y0 + 1024 * x2 + 4194304 * y1), tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (128, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 1024, 64, 64), (4194304, 4096, 64, 1)) assert_size_stride(primals_4, (1024, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_5, (1024,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1024, 64, 64), (4194304, 1, 65536, 1024), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(4096, 4096)](primals_3, buf0, 4096, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_3 buf1 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 128, 64, 64), (524288, 1, 8192, 128)) buf2 = empty_strided_cuda((4, 128, 64, 64), (524288, 4096, 64, 1), torch.float32) buf3 = empty_strided_cuda((4, 128, 64, 64), (524288, 1, 8192, 128), torch.float32) triton_poi_fused_convolution_1[grid(512, 4096)](buf1, primals_2, buf2, buf3, 512, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf1 del primals_2 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 1024, 64, 64), (4194304, 1, 65536, 1024)) del buf3 buf5 = empty_strided_cuda((4, 1024, 64, 64), (4194304, 4096, 64, 1), torch.float32) buf6 = empty_strided_cuda((4, 1024, 64, 64), (4194304, 1, 65536, 1024), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_2[grid(4096, 4096) ](buf4, primals_5, buf5, buf6, 4096, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf4 del primals_5 return buf2, buf5, primals_1, buf0, primals_4, buf2, buf6 class AutoencoderNew(nn.Module): def __init__(self): super(AutoencoderNew, self).__init__() self.encoder = nn.Conv2d(1024, 128, kernel_size=1) self.decoder = nn.Conv2d(128, 1024, kernel_size=1) self.relu = nn.ReLU() def forward(self, input_0): primals_1 = self.encoder.weight primals_2 = self.encoder.bias primals_4 = self.decoder.weight primals_5 = self.decoder.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0], output[1]
esha-singh/DL_project
Autoencoder
false
3,589
[ "MIT" ]
0
11ac2874845bc3982435cc37f4e0b8896b95660e
https://github.com/esha-singh/DL_project/tree/11ac2874845bc3982435cc37f4e0b8896b95660e
TVLoss
import torch from torch import nn from torch.nn import functional as F class TVLoss(nn.Module): """L2 total variation loss, as in Mahendran et al.""" def forward(self, input): input = F.pad(input, (0, 1, 0, 1), 'replicate') x_diff = input[:, :-1, 1:] - input[:, :-1, :-1] y_diff = input[:, 1:, :-1] - input[:, :-1, :-1] return (x_diff ** 2 + y_diff ** 2).mean() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_mean_pow_sub_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): rnumel = 240 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r0 = rindex % 5 r1 = rindex // 5 % 4 r2 = rindex // 20 % 3 r3 = rindex // 60 tmp0 = tl.load(in_ptr0 + (4 * (3 * (3 <= 1 + r1) + (1 + r1) * (1 + r1 < 3)) + 16 * r2 + 64 * r3 + (3 * (3 <= r0) + r0 * (r0 < 3))), rmask, other=0.0) tmp1 = tl.load(in_ptr0 + (4 * (3 * (3 <= r1) + r1 * (r1 < 3)) + 16 * r2 + 64 * r3 + (3 * (3 <= r0) + r0 * (r0 < 3))), rmask, other=0.0) tmp4 = tl.load(in_ptr0 + (16 + 4 * (3 * (3 <= r1) + r1 * (r1 < 3)) + 16 * r2 + 64 * r3 + (3 * (3 <= r0) + r0 * (r0 < 3))), rmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp5 = tmp4 - tmp1 tmp6 = tmp5 * tmp5 tmp7 = tmp3 + tmp6 tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = tl.where(rmask, tmp8, 0) tmp11 = tl.sum(tmp10, 1)[:, None] tmp12 = 240.0 tmp13 = tmp11 / tmp12 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp13, None) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_pow_sub_0[grid(1)](buf1, arg0_1, 1, 240, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf1, class TVLossNew(nn.Module): """L2 total variation loss, as in Mahendran et al.""" def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
hjk0918/style-transfer-pytorch
TVLoss
false
3,590
[ "MIT" ]
0
acbc054c734aa9c723a3a9bb36e33afb9bd7833b
https://github.com/hjk0918/style-transfer-pytorch/tree/acbc054c734aa9c723a3a9bb36e33afb9bd7833b
Bar
import torch import torch.onnx import torch.nn class Bar(torch.nn.Module): def __init__(self, x): super(Bar, self).__init__() self.x = x def forward(self, a, b): return a * b + self.x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'x': 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.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 * tmp1 tmp3 = 4.0 tmp4 = tmp2 + tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class BarNew(torch.nn.Module): def __init__(self, x): super(BarNew, self).__init__() self.x = x def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hl475/glow
Bar
false
3,591
[ "Apache-2.0" ]
0
f24d960e3cc80db95ac0bc17b1900dbf60ca044a
https://github.com/hl475/glow/tree/f24d960e3cc80db95ac0bc17b1900dbf60ca044a
LegacyXOR
import torch import torch.utils.data.distributed import torch.nn as nn import torch.utils.data class LegacyXOR(nn.Module): def __init__(self, input_dim, output_dim): super(LegacyXOR, self).__init__() self.lin1 = nn.Linear(input_dim, 8) self.lin2 = nn.Linear(8, output_dim) def forward(self, features): x = features.float() x = self.lin1(x) x = torch.tanh(x) x = self.lin2(x) x = torch.sigmoid(x) return 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.utils.data.distributed import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (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 = reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(512)](buf1, primals_3, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused_sigmoid_1[grid(256)](buf3, primals_5, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf1, buf3, primals_4 class LegacyXORNew(nn.Module): def __init__(self, input_dim, output_dim): super(LegacyXORNew, self).__init__() self.lin1 = nn.Linear(input_dim, 8) self.lin2 = nn.Linear(8, output_dim) def forward(self, input_0): primals_2 = self.lin1.weight primals_3 = self.lin1.bias primals_4 = self.lin2.weight primals_5 = self.lin2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
heyfey/horovod
LegacyXOR
false
3,592
[ "Apache-2.0" ]
0
7a697111eef7d88899551c176e31cde5ab61545c
https://github.com/heyfey/horovod/tree/7a697111eef7d88899551c176e31cde5ab61545c
Upsample
import torch from torch import nn class Upsample(nn.Module): """ Since the number of channels of the feature map changes after upsampling in HRNet. we have to write a new Upsample class. """ def __init__(self, in_channels, out_channels, scale_factor, mode): super(Upsample, self).__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=2, padding=1) self.upsample = nn.Upsample(scale_factor=scale_factor, mode='nearest') self.instance = nn.InstanceNorm2d(out_channels) self.relu = nn.ReLU(inplace=False) def forward(self, x): out = self.conv(x) out = self.upsample(out) out = self.instance(out) out = self.relu(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'scale_factor': 1.0, 'mode': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice from torch import nn 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_arange_mul_0(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 2 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 2 % 2 x0 = xindex % 2 x5 = xindex // 4 x2 = xindex // 4 % 4 x6 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 2, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 2 * tmp4 + 4 * x5), xmask, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tl.store(out_ptr0 + x6, tmp11, xmask) @triton.jit def triton_poi_fused__native_batch_norm_legit_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = 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') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = 0.0 tmp8 = tmp6 <= tmp7 tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(out_ptr1 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 2, 2), (16, 4, 2, 1)) buf1 = empty_strided_cuda((2,), (1,), torch.int64) get_raw_stream(0) triton_poi_fused__to_copy_add_arange_mul_0[grid(2)](buf1, 2, XBLOCK =2, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_1[grid(64)](buf1, buf0, primals_2, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf3 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf4 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) triton_poi_fused__native_batch_norm_legit_2[grid(16)](buf2, buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = buf0 del buf0 buf6 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool) triton_poi_fused_relu_threshold_backward_3[grid(64)](buf2, buf3, buf4, buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 del buf4 return buf5, primals_1, primals_3, buf1, buf2, buf6 class UpsampleNew(nn.Module): """ Since the number of channels of the feature map changes after upsampling in HRNet. we have to write a new Upsample class. """ def __init__(self, in_channels, out_channels, scale_factor, mode): super(UpsampleNew, self).__init__() self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=2, padding=1) self.upsample = nn.Upsample(scale_factor=scale_factor, mode='nearest') self.instance = nn.InstanceNorm2d(out_channels) self.relu = nn.ReLU(inplace=False) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hjk0918/style-transfer-pytorch
Upsample
false
3,593
[ "MIT" ]
0
acbc054c734aa9c723a3a9bb36e33afb9bd7833b
https://github.com/hjk0918/style-transfer-pytorch/tree/acbc054c734aa9c723a3a9bb36e33afb9bd7833b
Encoder
import torch import torch.nn as nn class Encoder(nn.Module): def __init__(self, in_size, latent_size): super().__init__() self.linear1 = nn.Linear(in_size, int(in_size / 2)) self.linear2 = nn.Linear(int(in_size / 2), int(in_size / 4)) self.linear3 = nn.Linear(int(in_size / 4), latent_size) self.relu = nn.ReLU(True) def forward(self, w): out = self.linear1(w) out = self.relu(out) out = self.linear2(out) out = self.relu(out) out = self.linear3(out) z = self.relu(out) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'latent_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_relu_threshold_backward_0(in_out_ptr0, 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 x4 = xindex x0 = xindex % 2 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 2 * x1 + 8 * (x1 % 4 // 4) + 32 * ((4 * (x1 // 4 % 4) + x1 % 4) // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = 0.0 tmp7 = tmp5 <= tmp6 tl.store(in_out_ptr0 + x0, tmp5, xmask) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_view_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x0 % 4 // 4) + 16 * ((4 * (x0 // 4 % 4) + x0 % 4) // 16)), xmask) tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_view_4(in_out_ptr0, in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr1 + x4, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (2, 4), (4, 1)) assert_size_stride(primals_2, (2,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 2), (2, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4, 1), (1, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 2), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf0 buf11 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(128)](buf1, primals_2, buf11, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32) triton_poi_fused_view_1[grid(128)](buf1, buf2, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf1 buf3 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (2, 1), (1, 2 ), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf3 buf10 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(64)](buf4, primals_5, buf10, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused_view_3[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf4 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_6, (1, 4), (1, 1 ), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_view_4[grid(256)](buf7, primals_7, buf8, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf7 del primals_7 return buf8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, buf5, buf9, primals_6, buf10, primals_4, buf11 class EncoderNew(nn.Module): def __init__(self, in_size, latent_size): super().__init__() self.linear1 = nn.Linear(in_size, int(in_size / 2)) self.linear2 = nn.Linear(int(in_size / 2), int(in_size / 4)) self.linear3 = nn.Linear(int(in_size / 4), latent_size) self.relu = nn.ReLU(True) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
hcgcarry/usad
Encoder
false
3,594
[ "BSD-3-Clause" ]
0
4e99a6acd43ef109be4d89b80e96978b9ad61c2f
https://github.com/hcgcarry/usad/tree/4e99a6acd43ef109be4d89b80e96978b9ad61c2f
Baz
import torch import torch.onnx import torch.nn class Baz(torch.nn.Module): def __init__(self, x): super(Baz, self).__init__() self.x = x def forward(self, a, b): return a + b * self.x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'x': 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.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = 4.0 tmp3 = tmp1 * tmp2 tmp4 = tmp0 + tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class BazNew(torch.nn.Module): def __init__(self, x): super(BazNew, self).__init__() self.x = x def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hl475/glow
Baz
false
3,595
[ "Apache-2.0" ]
0
f24d960e3cc80db95ac0bc17b1900dbf60ca044a
https://github.com/hl475/glow/tree/f24d960e3cc80db95ac0bc17b1900dbf60ca044a
L2_DistanceAttention
import torch import torch.nn as nn import torch.utils.data class L2_DistanceAttention(nn.Module): def __init__(self): super(L2_DistanceAttention, self).__init__() def forward(self, input_hidden_traces, target_hidden_traces): standard_size = input_hidden_traces.size(0), input_hidden_traces.size(1 ), input_hidden_traces.size(1) target_hidden_traces_square = (target_hidden_traces ** 2).sum(2 ).unsqueeze(2).expand(standard_size) input_hidden_traces_square = (input_hidden_traces ** 2).transpose(1, 2 ).sum(1).unsqueeze(1).expand(standard_size) input_target_mm = torch.bmm(target_hidden_traces, input_hidden_traces.transpose(1, 2)) inner_distance = (target_hidden_traces_square + input_hidden_traces_square - 2 * input_target_mm) Attn = -inner_distance Attn = Attn - Attn.max(2)[0].unsqueeze(2).expand(standard_size) exp_Attn = torch.exp(Attn) Attn = exp_Attn / exp_Attn.sum(2).unsqueeze(2).expand(standard_size) return Attn, inner_distance def get_inputs(): return [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 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_add_mul_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 x3 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex tmp0 = tl.load(in_ptr0 + 4 * x3, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp19 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tmp0 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp12 = tmp11 * tmp11 tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp17 = tmp16 * tmp16 tmp18 = tmp15 + tmp17 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp10 + tmp21 tmp24 = 2.0 tmp25 = tmp23 * tmp24 tmp26 = tmp22 - tmp25 tl.store(in_out_ptr0 + x4, tmp26, xmask) @triton.jit def triton_poi_fused_exp_neg_sub_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) tmp2 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = -tmp0 tmp3 = -tmp2 tmp5 = -tmp4 tmp6 = triton_helpers.maximum(tmp3, tmp5) tmp8 = -tmp7 tmp9 = triton_helpers.maximum(tmp6, tmp8) tmp11 = -tmp10 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp13 = tmp1 - tmp12 tmp14 = tl_math.exp(tmp13) tl.store(out_ptr0 + x2, tmp14, xmask) @triton.jit def triton_poi_fused_div_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_mul_sub_0[grid(64)](buf1, arg1_1, arg0_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_exp_neg_sub_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_div_2[grid(64)](buf2, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf2 return buf3, buf1 class L2_DistanceAttentionNew(nn.Module): def __init__(self): super(L2_DistanceAttentionNew, self).__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0], output[1]
hk19960522/2018-DL-Final
L2_DistanceAttention
false
3,596
[ "MIT" ]
0
cbc70260aa22d7df366a1d28bee472f1fc5b82c7
https://github.com/hk19960522/2018-DL-Final/tree/cbc70260aa22d7df366a1d28bee472f1fc5b82c7
PerfectProd
import torch import torch.utils.data from torch import nn class PerfectProd(nn.Module): def __init__(self, in_features, out_features): super().__init__() def reset_parameters(self): pass def forward(self, x): return torch.prod(2 * x[:, :-1], dim=-1, keepdim=True) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_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 import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_prod_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 48 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 12 x1 = xindex // 12 x2 = xindex tmp0 = tl.load(in_ptr0 + (4 * x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0 + 64 * x1), xmask, eviction_policy ='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x0 + 64 * x1), xmask, eviction_policy ='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x0 + 64 * x1), xmask, eviction_policy ='evict_last') tmp1 = 2.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp5 = tmp2 * tmp4 tmp7 = tmp6 * tmp1 tmp8 = tmp5 * tmp7 tmp10 = tmp9 * tmp1 tmp11 = tmp8 * tmp10 tl.store(out_ptr0 + x2, tmp11, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 4, 1), (12, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_prod_0[grid(48)](arg0_1, buf0, 48, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf0, class PerfectProdNew(nn.Module): def __init__(self, in_features, out_features): super().__init__() def reset_parameters(self): pass def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
hoedt/stable-nalu
PerfectProd
false
3,597
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
LearnedUpUnit
import torch from torch import nn class LearnedUpUnit(nn.Module): def __init__(self, in_feats): super().__init__() self.up = nn.UpsamplingNearest2d(scale_factor=2) self.dep_conv = nn.Conv2d(in_feats, in_feats, kernel_size=3, stride =1, padding=1, groups=in_feats, bias=False) def forward(self, x): x = self.up(x) x = self.dep_conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_feats': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch 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__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) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 1, 3, 3), (9, 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=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None) assert_size_stride(buf1, (4, 4, 8, 8), (256, 64, 8, 1)) return buf1, primals_2, buf0 class LearnedUpUnitNew(nn.Module): def __init__(self, in_feats): super().__init__() self.up = nn.UpsamplingNearest2d(scale_factor=2) self.dep_conv = nn.Conv2d(in_feats, in_feats, kernel_size=3, stride =1, padding=1, groups=in_feats, bias=False) def forward(self, input_0): primals_2 = self.dep_conv.weight primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
hmdliu/PCGNet
LearnedUpUnit
false
3,598
[ "MIT" ]
0
c03f25dc1b138afc52f612c1c517b61874baa02a
https://github.com/hmdliu/PCGNet/tree/c03f25dc1b138afc52f612c1c517b61874baa02a
LMA_Merge
import torch from torch import nn class LMA_Merge(nn.Module): def __init__(self, *args, **kwargs): super().__init__() self.lamb = nn.Parameter(torch.zeros(1)) def forward(self, x, y): return x + self.lamb * y def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tl.load(in_ptr2 + x0, xmask) tmp4 = tmp2 * tmp3 tmp5 = tmp0 + tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (1,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](primals_3, primals_1, primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_3 return buf0, primals_2 class LMA_MergeNew(nn.Module): def __init__(self, *args, **kwargs): super().__init__() self.lamb = nn.Parameter(torch.zeros(1)) def forward(self, input_0, input_1): primals_1 = self.lamb primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
hmdliu/PCGNet
LMA_Merge
false
3,599
[ "MIT" ]
0
c03f25dc1b138afc52f612c1c517b61874baa02a
https://github.com/hmdliu/PCGNet/tree/c03f25dc1b138afc52f612c1c517b61874baa02a
ESA
import torch import torch.nn as nn import torch.nn.functional as F from torch import autograd as autograd import torch.fft from itertools import product as product class ESA(nn.Module): def __init__(self, channel=64, reduction=4, bias=True): super(ESA, self).__init__() self.r_nc = channel // reduction self.conv1 = nn.Conv2d(channel, self.r_nc, kernel_size=1) self.conv21 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=1) self.conv2 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, stride= 2, padding=0) self.conv3 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv4 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv5 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv6 = nn.Conv2d(self.r_nc, channel, kernel_size=1) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU(inplace=True) def forward(self, x): x1 = self.conv1(x) x2 = F.max_pool2d(self.conv2(x1), kernel_size=7, stride=3) x2 = self.relu(self.conv3(x2)) x2 = self.relu(self.conv4(x2)) x2 = F.interpolate(self.conv5(x2), (x.size(2), x.size(3)), mode= 'bilinear', align_corners=False) x2 = self.conv6(x2 + self.conv21(x1)) return x.mul(self.sigmoid(x2)) def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch import autograd as autograd import torch.fft from itertools import product as product assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 16 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 61504 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 961 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 5184 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 81 % 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__to_copy_3(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 0.140625 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tl.store(out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_poi_fused_add_clamp_4(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 0.140625 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = tl.full([1], 1, tl.int64) tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 8, tl.int64) tmp13 = triton_helpers.minimum(tmp11, tmp12) tl.store(out_ptr0 + x0, tmp13, xmask) @triton.jit def triton_poi_fused__to_copy_add_arange_clamp_mul_sub_5(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 + tmp2 tmp4 = 0.140625 tmp5 = tmp3 * tmp4 tmp6 = tmp5 - tmp2 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8.to(tl.int32) tmp10 = tmp9.to(tl.float32) tmp11 = tmp8 - tmp10 tmp12 = triton_helpers.maximum(tmp11, tmp7) tmp13 = 1.0 tmp14 = triton_helpers.minimum(tmp12, tmp13) tl.store(out_ptr0 + x0, tmp14, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_mul_sub_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 64 % 64 x0 = xindex % 64 x5 = xindex // 4096 x2 = xindex // 4096 % 16 x6 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp34 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp37 = tl.load(in_ptr8 + x6, None) tmp38 = tl.load(in_ptr9 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 9, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 9 * tmp4 + 81 * x5), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp13 = tmp12 + tmp1 tmp14 = tmp12 < 0 tmp15 = tl.where(tmp14, tmp13, tmp12) tmp16 = tl.load(in_ptr2 + (tmp15 + 9 * tmp4 + 81 * x5), None, eviction_policy='evict_last') tmp17 = tmp16 + tmp10 tmp18 = tmp17 - tmp11 tmp20 = tmp18 * tmp19 tmp21 = tmp11 + tmp20 tmp23 = tmp22 + tmp1 tmp24 = tmp22 < 0 tmp25 = tl.where(tmp24, tmp23, tmp22) tmp26 = tl.load(in_ptr2 + (tmp8 + 9 * tmp25 + 81 * x5), None, eviction_policy='evict_last') tmp27 = tmp26 + tmp10 tmp28 = tl.load(in_ptr2 + (tmp15 + 9 * tmp25 + 81 * x5), None, eviction_policy='evict_last') tmp29 = tmp28 + tmp10 tmp30 = tmp29 - tmp27 tmp31 = tmp30 * tmp19 tmp32 = tmp27 + tmp31 tmp33 = tmp32 - tmp21 tmp35 = tmp33 * tmp34 tmp36 = tmp21 + tmp35 tmp39 = tmp37 + tmp38 tmp40 = tmp36 + tmp39 tl.store(in_out_ptr0 + x6, tmp40, None) @triton.jit def triton_poi_fused_convolution_mul_sigmoid_7(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, None) tmp2 = tmp0 + tmp1 tmp4 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tl.store(in_out_ptr0 + x3, tmp2, None) tl.store(out_ptr0 + x3, tmp5, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15) = args args.clear() assert_size_stride(primals_1, (16, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_4, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_11, (16,), (1,)) assert_size_stride(primals_12, (16, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_13, (16,), (1,)) assert_size_stride(primals_14, (64, 16, 1, 1), (16, 1, 1, 1)) assert_size_stride(primals_15, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(262144)](buf1, primals_2, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = 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, 16, 31, 31), (15376, 961, 31, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_1[grid(61504)](buf3, primals_5, 61504, XBLOCK=512, num_warps=4, num_stages=1) del primals_5 buf4 = torch.ops.aten.max_pool2d_with_indices.default(buf3, [7, 7], [3, 3]) buf5 = buf4[0] buf6 = buf4[1] del buf4 buf7 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 16, 9, 9), (1296, 81, 9, 1)) buf8 = buf7 del buf7 triton_poi_fused_convolution_relu_2[grid(5184)](buf8, primals_7, 5184, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 16, 9, 9), (1296, 81, 9, 1)) buf10 = buf9 del buf9 triton_poi_fused_convolution_relu_2[grid(5184)](buf10, primals_9, 5184, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf11 = 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(buf11, (4, 16, 9, 9), (1296, 81, 9, 1)) buf12 = empty_strided_cuda((64, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_3[grid(64)](buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((64, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_4[grid(64)](buf13, 64, XBLOCK=64, num_warps=1, num_stages=1) buf14 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused__to_copy_3[grid(64)](buf14, 64, XBLOCK=64, num_warps=1, num_stages=1) buf15 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused_add_clamp_4[grid(64)](buf15, 64, XBLOCK=64, num_warps=1, num_stages=1) buf16 = empty_strided_cuda((64,), (1,), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_5[grid(64)](buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) buf18 = empty_strided_cuda((64, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_add_arange_clamp_mul_sub_5[grid(64)](buf18, 64, XBLOCK=64, num_warps=1, num_stages=1) buf20 = extern_kernels.convolution(buf1, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 16, 64, 64), (65536, 4096, 64, 1)) buf19 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.float32) buf21 = buf19 del buf19 triton_poi_fused__unsafe_index_add_convolution_mul_sub_6[grid(262144)]( buf21, buf12, buf14, buf11, primals_11, buf15, buf16, buf13, buf18, buf20, primals_13, 262144, XBLOCK=512, num_warps=8, num_stages=1) del buf11 del buf20 del primals_11 del primals_13 buf22 = extern_kernels.convolution(buf21, primals_14, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf23 = buf22 del buf22 buf24 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.float32) triton_poi_fused_convolution_mul_sigmoid_7[grid(1048576)](buf23, primals_15, primals_3, buf24, 1048576, XBLOCK=512, num_warps=8, num_stages=1) del primals_15 return (buf24, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, buf1, buf3, buf5, buf6, buf8, buf10, buf12, buf13, buf14, buf15, buf16, buf18, buf21, buf23) class ESANew(nn.Module): def __init__(self, channel=64, reduction=4, bias=True): super(ESANew, self).__init__() self.r_nc = channel // reduction self.conv1 = nn.Conv2d(channel, self.r_nc, kernel_size=1) self.conv21 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=1) self.conv2 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, stride= 2, padding=0) self.conv3 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv4 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv5 = nn.Conv2d(self.r_nc, self.r_nc, kernel_size=3, padding=1) self.conv6 = nn.Conv2d(self.r_nc, channel, kernel_size=1) self.sigmoid = nn.Sigmoid() self.relu = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_12 = self.conv21.weight primals_5 = self.conv21.bias primals_4 = self.conv2.weight primals_7 = self.conv2.bias primals_6 = self.conv3.weight primals_9 = self.conv3.bias primals_8 = self.conv4.weight primals_11 = self.conv4.bias primals_10 = self.conv5.weight primals_13 = self.conv5.bias primals_14 = self.conv6.weight primals_15 = self.conv6.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15]) return output[0]
hduba/KAIR
ESA
false
3,600
[ "MIT" ]
0
dbd7596c7e4a4667b9b7baac369fc6c02571fa58
https://github.com/hduba/KAIR/tree/dbd7596c7e4a4667b9b7baac369fc6c02571fa58
NormalisedSigmoid
import torch import torch.utils.data from torch import nn class NormalisedSigmoid(nn.Module): """ Normalised logistic sigmoid function. """ def __init__(self, p: 'float'=1, dim: 'int'=-1): super().__init__() self.p = p self.dim = dim def forward(self, s: 'torch.Tensor') ->torch.Tensor: a = torch.sigmoid(s) return torch.nn.functional.normalize(a, p=self.p, dim=self.dim) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = tl.sigmoid(tmp0) tmp3 = tl.sigmoid(tmp2) tmp4 = tl_math.abs(tmp3) tmp6 = tl.sigmoid(tmp5) tmp7 = tl_math.abs(tmp6) tmp8 = tmp4 + tmp7 tmp10 = tl.sigmoid(tmp9) tmp11 = tl_math.abs(tmp10) tmp12 = tmp8 + tmp11 tmp14 = tl.sigmoid(tmp13) tmp15 = tl_math.abs(tmp14) tmp16 = tmp12 + tmp15 tmp17 = 1e-12 tmp18 = triton_helpers.maximum(tmp16, tmp17) tmp19 = tmp1 / tmp18 tl.store(out_ptr0 + x2, tmp19, 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_sigmoid_0[grid(256)](arg0_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) del arg0_1 return buf0, class NormalisedSigmoidNew(nn.Module): """ Normalised logistic sigmoid function. """ def __init__(self, p: 'float'=1, dim: 'int'=-1): super().__init__() self.p = p self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
hoedt/stable-nalu
NormalisedSigmoid
false
3,601
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
DisplacementPrediction
import torch import torch.nn as nn import torch.utils.data class DisplacementPrediction(nn.Module): def __init__(self, pedestrian_num, input_size, output_size): super(DisplacementPrediction, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.output_size = output_size self.fc1 = nn.Linear(input_size, output_size) def forward(self, data): output_list = [] for idx in range(0, self.pedestrian_num): output_list.append(self.fc1(data[:, idx])) output = torch.stack(output_list, 1) return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'pedestrian_num': 4, 'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_clone_3(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 + (48 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_stack_4(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 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 + 16 * x2), tmp4 & xmask, other=0.0) tmp6 = tl.load(in_ptr1 + x0, 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], 8, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (x0 + 4 * (-4 + x1) + 16 * x2), tmp13 & xmask, other=0.0) tmp15 = tl.load(in_ptr1 + x0, tmp13 & xmask, eviction_policy= 'evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tmp20 = tl.full([1], 12, tl.int64) tmp21 = tmp0 < tmp20 tmp22 = tmp19 & tmp21 tmp23 = tl.load(in_ptr3 + (x0 + 4 * (-8 + x1) + 16 * x2), tmp22 & xmask, other=0.0) tmp24 = tl.load(in_ptr1 + x0, tmp22 & xmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tmp23 + tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp22, tmp25, tmp26) tmp28 = tmp0 >= tmp20 tl.full([1], 16, tl.int64) tmp31 = tl.load(in_ptr4 + (x0 + 4 * (-12 + x1) + 16 * x2), tmp28 & xmask, other=0.0) tmp32 = tl.load(in_ptr1 + x0, tmp28 & xmask, eviction_policy= 'evict_last', other=0.0) tmp33 = tmp31 + tmp32 tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp28, tmp33, tmp34) tmp36 = tl.where(tmp22, tmp27, tmp35) tmp37 = tl.where(tmp13, tmp18, tmp36) tmp38 = tl.where(tmp4, tmp9, tmp37) tl.store(out_ptr0 + x3, tmp38, 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) 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) buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_1[grid(64)](primals_1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_2[grid(64)](primals_1, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf4, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf5) buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_3[grid(64)](primals_1, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf7 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf6, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf7) del primals_2 buf8 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32) triton_poi_fused_stack_4[grid(256)](buf1, primals_3, buf3, buf5, buf7, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del buf3 del buf5 del buf7 del primals_3 return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor( buf2, (16, 4), (4, 1), 0), reinterpret_tensor(buf4, (16, 4), (4, 1), 0 ), reinterpret_tensor(buf6, (16, 4), (4, 1), 0) class DisplacementPredictionNew(nn.Module): def __init__(self, pedestrian_num, input_size, output_size): super(DisplacementPredictionNew, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.output_size = output_size self.fc1 = nn.Linear(input_size, output_size) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hk19960522/2018-DL-Final
DisplacementPrediction
false
3,602
[ "MIT" ]
0
cbc70260aa22d7df366a1d28bee472f1fc5b82c7
https://github.com/hk19960522/2018-DL-Final/tree/cbc70260aa22d7df366a1d28bee472f1fc5b82c7
decoder5
import torch import torch.nn as nn class decoder5(nn.Module): def __init__(self): super(decoder5, self).__init__() self.reflecPad15 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv15 = nn.Conv2d(512, 512, 3, 1, 0) self.relu15 = nn.ReLU(inplace=True) self.unpool = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad16 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv16 = nn.Conv2d(512, 512, 3, 1, 0) self.relu16 = nn.ReLU(inplace=True) self.reflecPad17 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv17 = nn.Conv2d(512, 512, 3, 1, 0) self.relu17 = nn.ReLU(inplace=True) self.reflecPad18 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv18 = nn.Conv2d(512, 512, 3, 1, 0) self.relu18 = nn.ReLU(inplace=True) self.reflecPad19 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv19 = nn.Conv2d(512, 256, 3, 1, 0) self.relu19 = nn.ReLU(inplace=True) self.unpool2 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad20 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv20 = nn.Conv2d(256, 256, 3, 1, 0) self.relu20 = nn.ReLU(inplace=True) self.reflecPad21 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv21 = nn.Conv2d(256, 256, 3, 1, 0) self.relu21 = nn.ReLU(inplace=True) self.reflecPad22 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv22 = nn.Conv2d(256, 256, 3, 1, 0) self.relu22 = nn.ReLU(inplace=True) self.reflecPad23 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv23 = nn.Conv2d(256, 128, 3, 1, 0) self.relu23 = nn.ReLU(inplace=True) self.unpool3 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad24 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv24 = nn.Conv2d(128, 128, 3, 1, 0) self.relu24 = nn.ReLU(inplace=True) self.reflecPad25 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv25 = nn.Conv2d(128, 64, 3, 1, 0) self.relu25 = nn.ReLU(inplace=True) self.unpool4 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad26 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv26 = nn.Conv2d(64, 64, 3, 1, 0) self.relu26 = nn.ReLU(inplace=True) self.reflecPad27 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv27 = nn.Conv2d(64, 3, 3, 1, 0) def forward(self, x): out = self.reflecPad15(x) out = self.conv15(out) out = self.relu15(out) out = self.unpool(out) out = self.reflecPad16(out) out = self.conv16(out) out = self.relu16(out) out = self.reflecPad17(out) out = self.conv17(out) out = self.relu17(out) out = self.reflecPad18(out) out = self.conv18(out) out = self.relu18(out) out = self.reflecPad19(out) out = self.conv19(out) out = self.relu19(out) out = self.unpool2(out) out = self.reflecPad20(out) out = self.conv20(out) out = self.relu20(out) out = self.reflecPad21(out) out = self.conv21(out) out = self.relu21(out) out = self.reflecPad22(out) out = self.conv22(out) out = self.relu22(out) out = self.reflecPad23(out) out = self.conv23(out) out = self.relu23(out) out = self.unpool3(out) out = self.reflecPad24(out) out = self.conv24(out) out = self.relu24(out) out = self.reflecPad25(out) out = self.conv25(out) out = self.relu25(out) out = self.unpool4(out) out = self.reflecPad26(out) out = self.conv26(out) out = self.relu26(out) out = self.reflecPad27(out) out = self.conv27(out) return out def get_inputs(): return [torch.rand([4, 512, 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 @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 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), None, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_1(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 10 % 10 x0 = xindex % 10 x4 = xindex // 100 x2 = xindex // 100 % 512 x7 = xindex tmp0 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x1 ))), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (7 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x0 ))), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 4 * tmp4 + 16 * x4), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, None) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 10 x1 = xindex // 10 % 10 x4 = xindex // 100 x2 = xindex // 100 % 512 x5 = xindex tmp0 = tl.load(in_ptr0 + (63 + -1 * tl_math.abs(-7 + tl_math.abs(-1 + x0)) + -8 * tl_math.abs(-7 + tl_math.abs(-1 + x1)) + 64 * x4), None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_4(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 18 % 18 x0 = xindex % 18 x4 = xindex // 324 x2 = xindex // 324 % 256 x7 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x1))), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x0))), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 8, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 8 * tmp4 + 64 * x4), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, None) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 18 x1 = xindex // 18 % 18 x4 = xindex // 324 x2 = xindex // 324 % 256 x5 = xindex tmp0 = tl.load(in_ptr0 + (255 + -1 * tl_math.abs(-15 + tl_math.abs(-1 + x0)) + -16 * tl_math.abs(-15 + tl_math.abs(-1 + x1)) + 256 * x4), None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, None) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_7(out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 34 % 34 x0 = xindex % 34 x4 = xindex // 1156 x2 = xindex // 1156 % 128 x7 = xindex tmp0 = tl.load(in_ptr0 + (31 + -1 * tl_math.abs(-31 + tl_math.abs(-1 + x1))), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (31 + -1 * tl_math.abs(-31 + tl_math.abs(-1 + x0))), None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 16, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 16 * tmp4 + 256 * x4), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, None) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_9(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 34 x1 = xindex // 34 % 34 x4 = xindex // 1156 x2 = xindex // 1156 % 128 x5 = xindex tmp0 = tl.load(in_ptr0 + (1023 + -1 * tl_math.abs(-31 + tl_math.abs(-1 + x0)) + -32 * tl_math.abs(-31 + tl_math.abs(-1 + x1)) + 1024 * x4), None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, None) @triton.jit def triton_poi_fused_arange_10(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused__to_copy_add_arange_mul_11(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_12(in_ptr0 , in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1115136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 66 % 66 x0 = xindex % 66 x4 = xindex // 4356 x2 = xindex // 4356 % 64 x7 = xindex tmp0 = tl.load(in_ptr0 + (63 + -1 * tl_math.abs(-63 + tl_math.abs(-1 + x1))), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (63 + -1 * tl_math.abs(-63 + tl_math.abs(-1 + x0))), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 32, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr1 + (tmp8 + 32 * tmp4 + 1024 * x4), xmask, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x7, tmp13, xmask) @triton.jit def triton_poi_fused_convolution_reflection_pad2d_relu_13(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1115136 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 66 x1 = xindex // 66 % 66 x4 = xindex // 4356 x2 = xindex // 4356 % 64 x5 = xindex tmp0 = tl.load(in_ptr0 + (4095 + -1 * tl_math.abs(-63 + tl_math.abs(-1 + x0)) + -64 * tl_math.abs(-63 + tl_math.abs(-1 + x1)) + 4096 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + x5, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_14(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 3 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_15(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_16(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_17(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_18(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 128 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_19(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_20(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_21(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_22(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 16 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, 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, (4, 512, 4, 4), (8192, 16, 4, 1)) assert_size_stride(primals_2, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_3, (512,), (1,)) assert_size_stride(primals_4, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_5, (512,), (1,)) assert_size_stride(primals_6, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_7, (512,), (1,)) assert_size_stride(primals_8, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_9, (512,), (1,)) assert_size_stride(primals_10, (256, 512, 3, 3), (4608, 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, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_19, (128,), (1,)) assert_size_stride(primals_20, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_21, (128,), (1,)) assert_size_stride(primals_22, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_23, (64,), (1,)) assert_size_stride(primals_24, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_25, (64,), (1,)) assert_size_stride(primals_26, (3, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_27, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 512, 6, 6), (18432, 36, 6, 1), torch. float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(73728)](primals_1, buf0, 73728, XBLOCK=1024, 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, 512, 4, 4), (8192, 16, 4, 1)) buf2 = empty_strided_cuda((8,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_1[grid(8)](buf2, 8, XBLOCK =8, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 512, 10, 10), (51200, 100, 10, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_2[grid (204800)](buf2, buf1, primals_3, buf3, 204800, XBLOCK=512, num_warps=8, num_stages=1) buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 512, 8, 8), (32768, 64, 8, 1)) buf5 = empty_strided_cuda((4, 512, 10, 10), (51200, 100, 10, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(204800)](buf4 , primals_5, buf5, 204800, XBLOCK=512, num_warps=8, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 512, 8, 8), (32768, 64, 8, 1)) buf7 = empty_strided_cuda((4, 512, 10, 10), (51200, 100, 10, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(204800)](buf6 , primals_7, buf7, 204800, XBLOCK=512, num_warps=8, num_stages=1) buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 512, 8, 8), (32768, 64, 8, 1)) buf9 = empty_strided_cuda((4, 512, 10, 10), (51200, 100, 10, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(204800)](buf8 , primals_9, buf9, 204800, XBLOCK=512, num_warps=8, num_stages=1) buf10 = extern_kernels.convolution(buf9, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 256, 8, 8), (16384, 64, 8, 1)) buf11 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_4[grid(16)](buf11, 16, XBLOCK=16, num_warps=1, num_stages=1) buf12 = empty_strided_cuda((4, 256, 18, 18), (82944, 324, 18, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_5[grid (331776)](buf11, buf10, primals_11, buf12, 331776, XBLOCK=1024, num_warps=4, num_stages=1) buf13 = extern_kernels.convolution(buf12, primals_12, 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, 16, 16), (65536, 256, 16, 1)) buf14 = empty_strided_cuda((4, 256, 18, 18), (82944, 324, 18, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_6[grid(331776)]( buf13, primals_13, buf14, 331776, XBLOCK=1024, num_warps=4, num_stages=1) buf15 = extern_kernels.convolution(buf14, primals_14, 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, 16, 16), (65536, 256, 16, 1)) buf16 = empty_strided_cuda((4, 256, 18, 18), (82944, 324, 18, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_6[grid(331776)]( buf15, primals_15, buf16, 331776, XBLOCK=1024, num_warps=4, num_stages=1) buf17 = extern_kernels.convolution(buf16, primals_16, 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, 16, 16), (65536, 256, 16, 1)) buf18 = empty_strided_cuda((4, 256, 18, 18), (82944, 324, 18, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_6[grid(331776)]( buf17, primals_17, buf18, 331776, XBLOCK=1024, num_warps=4, num_stages=1) buf19 = extern_kernels.convolution(buf18, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 128, 16, 16), (32768, 256, 16, 1)) buf20 = empty_strided_cuda((32,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_7[grid(32)](buf20, 32, XBLOCK=32, num_warps=1, num_stages=1) buf21 = empty_strided_cuda((4, 128, 34, 34), (147968, 1156, 34, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_8[grid (591872)](buf20, buf19, primals_19, buf21, 591872, XBLOCK=1024, num_warps=4, num_stages=1) buf22 = extern_kernels.convolution(buf21, primals_20, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 128, 32, 32), (131072, 1024, 32, 1)) buf23 = empty_strided_cuda((4, 128, 34, 34), (147968, 1156, 34, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_9[grid(591872)]( buf22, primals_21, buf23, 591872, XBLOCK=512, num_warps=8, num_stages=1) buf24 = extern_kernels.convolution(buf23, primals_22, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 64, 32, 32), (65536, 1024, 32, 1)) buf25 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused_arange_10[grid(64)](buf25, 64, XBLOCK=64, num_warps=1, num_stages=1) buf26 = empty_strided_cuda((64,), (1,), torch.int64) triton_poi_fused__to_copy_add_arange_mul_11[grid(64)](buf26, 64, XBLOCK=64, num_warps=1, num_stages=1) buf27 = empty_strided_cuda((4, 64, 66, 66), (278784, 4356, 66, 1), torch.float32) triton_poi_fused__unsafe_index_convolution_reflection_pad2d_relu_12[ grid(1115136)](buf26, buf24, primals_23, buf27, 1115136, XBLOCK =1024, num_warps=4, num_stages=1) buf28 = extern_kernels.convolution(buf27, primals_24, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf28, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf29 = empty_strided_cuda((4, 64, 66, 66), (278784, 4356, 66, 1), torch.float32) triton_poi_fused_convolution_reflection_pad2d_relu_13[grid(1115136)]( buf28, primals_25, buf29, 1115136, XBLOCK=1024, num_warps=4, num_stages=1) buf30 = extern_kernels.convolution(buf29, primals_26, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf30, (4, 3, 64, 64), (12288, 4096, 64, 1)) buf31 = buf30 del buf30 triton_poi_fused_convolution_14[grid(49152)](buf31, primals_27, 49152, XBLOCK=512, num_warps=4, num_stages=1) del primals_27 buf32 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_15[grid(1048576)]( buf28, primals_25, buf32, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf28 del primals_25 buf33 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_16[grid(262144)]( buf24, primals_23, buf33, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf24 del primals_23 buf34 = empty_strided_cuda((4, 128, 32, 32), (131072, 1024, 32, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_17[grid(524288)]( buf22, primals_21, buf34, 524288, XBLOCK=512, num_warps=8, num_stages=1) del buf22 del primals_21 buf35 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_18[grid(131072)]( buf19, primals_19, buf35, 131072, XBLOCK=512, num_warps=8, num_stages=1) del buf19 del primals_19 buf36 = empty_strided_cuda((4, 256, 16, 16), (65536, 256, 16, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_19[grid(262144)]( buf17, primals_17, buf36, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf17 del primals_17 buf37 = empty_strided_cuda((4, 256, 16, 16), (65536, 256, 16, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_19[grid(262144)]( buf15, primals_15, buf37, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf15 del primals_15 buf38 = empty_strided_cuda((4, 256, 16, 16), (65536, 256, 16, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_19[grid(262144)]( buf13, primals_13, buf38, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del buf13 del primals_13 buf39 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_20[grid(65536)]( buf10, primals_11, buf39, 65536, XBLOCK=512, num_warps=4, num_stages=1) del buf10 del primals_11 buf40 = empty_strided_cuda((4, 512, 8, 8), (32768, 64, 8, 1), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_21[grid(131072)]( buf8, primals_9, buf40, 131072, XBLOCK=512, num_warps=8, num_stages=1) del buf8 del primals_9 buf41 = empty_strided_cuda((4, 512, 8, 8), (32768, 64, 8, 1), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_21[grid(131072)]( buf6, primals_7, buf41, 131072, XBLOCK=512, num_warps=8, num_stages=1) del buf6 del primals_7 buf42 = empty_strided_cuda((4, 512, 8, 8), (32768, 64, 8, 1), torch .bool) triton_poi_fused_convolution_relu_threshold_backward_21[grid(131072)]( buf4, primals_5, buf42, 131072, XBLOCK=512, num_warps=8, num_stages=1) del buf4 del primals_5 buf43 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.bool ) triton_poi_fused_convolution_relu_threshold_backward_22[grid(32768)]( buf1, primals_3, buf43, 32768, XBLOCK=256, num_warps=4, num_stages=1) del buf1 del primals_3 return (buf31, primals_2, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, buf0, buf2, buf3, buf5, buf7, buf9, buf11, buf12, buf14, buf16, buf18, buf20, buf21, buf23, buf25, buf26, buf27, buf29, buf32, buf33, buf34, buf35, buf36, buf37, buf38, buf39, buf40, buf41, buf42, buf43) class decoder5New(nn.Module): def __init__(self): super(decoder5New, self).__init__() self.reflecPad15 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv15 = nn.Conv2d(512, 512, 3, 1, 0) self.relu15 = nn.ReLU(inplace=True) self.unpool = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad16 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv16 = nn.Conv2d(512, 512, 3, 1, 0) self.relu16 = nn.ReLU(inplace=True) self.reflecPad17 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv17 = nn.Conv2d(512, 512, 3, 1, 0) self.relu17 = nn.ReLU(inplace=True) self.reflecPad18 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv18 = nn.Conv2d(512, 512, 3, 1, 0) self.relu18 = nn.ReLU(inplace=True) self.reflecPad19 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv19 = nn.Conv2d(512, 256, 3, 1, 0) self.relu19 = nn.ReLU(inplace=True) self.unpool2 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad20 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv20 = nn.Conv2d(256, 256, 3, 1, 0) self.relu20 = nn.ReLU(inplace=True) self.reflecPad21 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv21 = nn.Conv2d(256, 256, 3, 1, 0) self.relu21 = nn.ReLU(inplace=True) self.reflecPad22 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv22 = nn.Conv2d(256, 256, 3, 1, 0) self.relu22 = nn.ReLU(inplace=True) self.reflecPad23 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv23 = nn.Conv2d(256, 128, 3, 1, 0) self.relu23 = nn.ReLU(inplace=True) self.unpool3 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad24 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv24 = nn.Conv2d(128, 128, 3, 1, 0) self.relu24 = nn.ReLU(inplace=True) self.reflecPad25 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv25 = nn.Conv2d(128, 64, 3, 1, 0) self.relu25 = nn.ReLU(inplace=True) self.unpool4 = nn.UpsamplingNearest2d(scale_factor=2) self.reflecPad26 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv26 = nn.Conv2d(64, 64, 3, 1, 0) self.relu26 = nn.ReLU(inplace=True) self.reflecPad27 = nn.ReflectionPad2d((1, 1, 1, 1)) self.conv27 = nn.Conv2d(64, 3, 3, 1, 0) def forward(self, input_0): primals_2 = self.conv15.weight primals_3 = self.conv15.bias primals_4 = self.conv16.weight primals_5 = self.conv16.bias primals_6 = self.conv17.weight primals_7 = self.conv17.bias primals_8 = self.conv18.weight primals_9 = self.conv18.bias primals_10 = self.conv19.weight primals_11 = self.conv19.bias primals_12 = self.conv20.weight primals_13 = self.conv20.bias primals_14 = self.conv21.weight primals_15 = self.conv21.bias primals_16 = self.conv22.weight primals_17 = self.conv22.bias primals_18 = self.conv23.weight primals_19 = self.conv23.bias primals_20 = self.conv24.weight primals_21 = self.conv24.bias primals_22 = self.conv25.weight primals_23 = self.conv25.bias primals_24 = self.conv26.weight primals_25 = self.conv26.bias primals_26 = self.conv27.weight primals_27 = self.conv27.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, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27]) return output[0]
guswl8033/ARtists
decoder5
false
3,603
[ "Apache-2.0" ]
0
d353195872c1ef1a1aa68659a32fb47779a416fc
https://github.com/guswl8033/ARtists/tree/d353195872c1ef1a1aa68659a32fb47779a416fc
LocationEncoder
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class LocationEncoder(nn.Module): def __init__(self, pedestrian_num, input_size, hidden_size, batch_size): super(LocationEncoder, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.hidden_size = hidden_size self.batch_size = batch_size self.fc1 = nn.Linear(input_size, 32) self.fc2 = nn.Linear(32, 64) self.fc3 = nn.Linear(64, self.hidden_size) self.soft = nn.Softmax(dim=1) pass def forward(self, data): outputs = self.get_hidden_output(data) output = self.Attention(outputs, outputs) return output def get_hidden_output(self, data): output_list = [] for idx in range(0, self.pedestrian_num): output = F.relu(self.fc1(data[:, idx])) output = F.relu(self.fc2(output)) output = self.fc3(output) output_list.append(output) outputs = torch.stack(output_list, 1) return outputs def Attention(self, input_data, target_data): Attn = torch.bmm(target_data, input_data.transpose(1, 2)) Attn_size = Attn.size() Attn = Attn - Attn.max(2)[0].unsqueeze(2).expand(Attn_size) exp_Attn = torch.exp(Attn) Attn = exp_Attn / exp_Attn.sum(2).unsqueeze(2).expand(Attn_size) return Attn def get_spatial_affinity(self, data): output = torch.zeros(self.batch_size, self.pedestrian_num, self. pedestrian_num) for batch in range(0, self.batch_size): for i in range(0, self.pedestrian_num): row_data = torch.Tensor([]) for j in range(0, i + 1): row_data = torch.cat([row_data, torch.dot(data[batch][i ], data[batch][j]).unsqueeze(0)], dim=0) output[batch, i, 0:i + 1] = row_data for i in range(0, self.pedestrian_num): col_data = output[batch, :, i].view(1, -1) output[batch, i, :] = col_data output[batch] = self.soft(output[batch]) """ outputs will be like this : <h1, h1>, <h2, h1>, <h3, h1> ... <h2, h1>, <h2, h2>, <h3, h2> ... <h3, h1>, <h3, h2>, <h3, h3> ... ...... """ return output def softmax(self, data): output = torch.zeros(self.batch_size, self.pedestrian_num, self. pedestrian_num) exp_data = torch.exp(data) for batch in range(0, self.batch_size): for i in range(0, self.pedestrian_num): count = 0 for j in range(0, self.pedestrian_num): count += exp_data[batch][max(i, j)][min(i, j)].item() for j in range(0, self.pedestrian_num): output[batch][i][j] = exp_data[batch][max(i, j)][min(i, j) ].item() / count return output def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'pedestrian_num': 4, 'input_size': 4, 'hidden_size': 4, 'batch_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.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_0(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_out_ptr1 + x2, xmask) tmp8 = tl.load(in_out_ptr2 + x2, xmask) tmp11 = tl.load(in_out_ptr3 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp5 + tmp1 tmp7 = triton_helpers.maximum(tmp3, tmp6) tmp9 = tmp8 + tmp1 tmp10 = triton_helpers.maximum(tmp3, tmp9) tmp12 = tmp11 + tmp1 tmp13 = triton_helpers.maximum(tmp3, tmp12) tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(in_out_ptr1 + x2, tmp7, xmask) tl.store(in_out_ptr2 + x2, tmp10, xmask) tl.store(in_out_ptr3 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, 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') tmp5 = tl.load(in_out_ptr1 + x2, xmask) tmp8 = tl.load(in_out_ptr2 + x2, xmask) tmp11 = tl.load(in_out_ptr3 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp5 + tmp1 tmp7 = triton_helpers.maximum(tmp3, tmp6) tmp9 = tmp8 + tmp1 tmp10 = triton_helpers.maximum(tmp3, tmp9) tmp12 = tmp11 + tmp1 tmp13 = triton_helpers.maximum(tmp3, tmp12) tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(in_out_ptr1 + x2, tmp7, xmask) tl.store(in_out_ptr2 + x2, tmp10, xmask) tl.store(in_out_ptr3 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_exp_sub_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = 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_div_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (32, 4), (4, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (64, 32), (32, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (16, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf0) buf12 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (16, 1), 12 ), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf12) buf4 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (16, 1), 4), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf4) buf8 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (4, 4), (16, 1), 8), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf8) del primals_2 buf1 = buf0 del buf0 buf5 = buf4 del buf4 buf9 = buf8 del buf8 buf13 = buf12 del buf12 get_raw_stream(0) triton_poi_fused_relu_0[grid(128)](buf1, buf5, buf9, buf13, primals_3, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf2) buf10 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf10) buf14 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf13, reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf14) buf6 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf5, reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf6) buf3 = buf2 del buf2 buf7 = buf6 del buf6 buf11 = buf10 del buf10 buf15 = buf14 del buf14 triton_poi_fused_relu_1[grid(256)](buf3, buf7, buf11, buf15, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf20 = empty_strided_cuda((4, 16), (16, 1), torch.float32) buf16 = reinterpret_tensor(buf20, (4, 4), (16, 1), 0) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf16) buf17 = reinterpret_tensor(buf20, (4, 4), (16, 1), 4) extern_kernels.addmm(primals_7, buf7, reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf17) buf18 = reinterpret_tensor(buf20, (4, 4), (16, 1), 8) extern_kernels.addmm(primals_7, buf11, reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf18) buf19 = reinterpret_tensor(buf20, (4, 4), (16, 1), 12) extern_kernels.addmm(primals_7, buf15, reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf19) del primals_7 buf21 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf20, (4, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf20, (4, 4, 4), (16, 1, 4), 0), out=buf21) buf22 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_exp_sub_2[grid(64)](buf21, buf22, 64, XBLOCK=64, num_warps=1, num_stages=1) buf23 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_div_3[grid(64)](buf22, buf23, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf22 return buf23, reinterpret_tensor(primals_1, (4, 4), (16, 1), 0 ), buf1, buf3, reinterpret_tensor(primals_1, (4, 4), (16, 1), 4 ), buf5, buf7, reinterpret_tensor(primals_1, (4, 4), (16, 1), 8 ), buf9, buf11, reinterpret_tensor(primals_1, (4, 4), (16, 1), 12 ), buf13, buf15, reinterpret_tensor(buf20, (4, 4, 4), (16, 1, 4), 0 ), buf21, primals_6, primals_4 class LocationEncoderNew(nn.Module): def __init__(self, pedestrian_num, input_size, hidden_size, batch_size): super(LocationEncoderNew, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.hidden_size = hidden_size self.batch_size = batch_size self.fc1 = nn.Linear(input_size, 32) self.fc2 = nn.Linear(32, 64) self.fc3 = nn.Linear(64, self.hidden_size) self.soft = nn.Softmax(dim=1) pass def get_hidden_output(self, data): output_list = [] for idx in range(0, self.pedestrian_num): output = F.relu(self.fc1(data[:, idx])) output = F.relu(self.fc2(output)) output = self.fc3(output) output_list.append(output) outputs = torch.stack(output_list, 1) return outputs def Attention(self, input_data, target_data): Attn = torch.bmm(target_data, input_data.transpose(1, 2)) Attn_size = Attn.size() Attn = Attn - Attn.max(2)[0].unsqueeze(2).expand(Attn_size) exp_Attn = torch.exp(Attn) Attn = exp_Attn / exp_Attn.sum(2).unsqueeze(2).expand(Attn_size) return Attn def get_spatial_affinity(self, data): output = torch.zeros(self.batch_size, self.pedestrian_num, self. pedestrian_num) for batch in range(0, self.batch_size): for i in range(0, self.pedestrian_num): row_data = torch.Tensor([]) for j in range(0, i + 1): row_data = torch.cat([row_data, torch.dot(data[batch][i ], data[batch][j]).unsqueeze(0)], dim=0) output[batch, i, 0:i + 1] = row_data for i in range(0, self.pedestrian_num): col_data = output[batch, :, i].view(1, -1) output[batch, i, :] = col_data output[batch] = self.soft(output[batch]) """ outputs will be like this : <h1, h1>, <h2, h1>, <h3, h1> ... <h2, h1>, <h2, h2>, <h3, h2> ... <h3, h1>, <h3, h2>, <h3, h3> ... ...... """ return output def softmax(self, data): output = torch.zeros(self.batch_size, self.pedestrian_num, self. pedestrian_num) exp_data = torch.exp(data) for batch in range(0, self.batch_size): for i in range(0, self.pedestrian_num): count = 0 for j in range(0, self.pedestrian_num): count += exp_data[batch][max(i, j)][min(i, j)].item() for j in range(0, self.pedestrian_num): output[batch][i][j] = exp_data[batch][max(i, j)][min(i, j) ].item() / count return output 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_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
hk19960522/2018-DL-Final
LocationEncoder
false
3,604
[ "MIT" ]
0
cbc70260aa22d7df366a1d28bee472f1fc5b82c7
https://github.com/hk19960522/2018-DL-Final/tree/cbc70260aa22d7df366a1d28bee472f1fc5b82c7
EncoderNet
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.data class EncoderNet(nn.Module): def __init__(self, pedestrian_num, input_size, hidden_size): super(EncoderNet, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.hidden_size = hidden_size hidden1_size = 32 hidden2_size = 64 self.fc1 = torch.nn.Linear(input_size, hidden1_size) self.fc2 = torch.nn.Linear(hidden1_size, hidden2_size) self.fc3 = torch.nn.Linear(hidden2_size, hidden_size) def forward(self, input_traces): hidden_list = [] for i in range(self.pedestrian_num): input_trace = input_traces[:, i, :] hidden_trace = F.relu(self.fc1(input_trace)) hidden_trace = F.relu(self.fc2(hidden_trace)) hidden_trace = self.fc3(hidden_trace) hidden_list.append(hidden_trace) hidden_traces = torch.stack(hidden_list, 1) return hidden_traces def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'pedestrian_num': 4, '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 import triton_helpers import torch.nn as nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_clone_3(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 + (16 + x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_relu_threshold_backward_4(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_out_ptr1 + x2, xmask) tmp11 = tl.load(in_out_ptr2 + x2, xmask) tmp15 = tl.load(in_out_ptr3 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tmp8 = tmp7 + tmp1 tmp9 = triton_helpers.maximum(tmp3, tmp8) tmp10 = tmp9 <= tmp5 tmp12 = tmp11 + tmp1 tmp13 = triton_helpers.maximum(tmp3, tmp12) tmp14 = tmp13 <= tmp5 tmp16 = tmp15 + tmp1 tmp17 = triton_helpers.maximum(tmp3, tmp16) tmp18 = tmp17 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(in_out_ptr1 + x2, tmp9, xmask) tl.store(out_ptr1 + x2, tmp10, xmask) tl.store(in_out_ptr2 + x2, tmp13, xmask) tl.store(out_ptr2 + x2, tmp14, xmask) tl.store(in_out_ptr3 + x2, tmp17, xmask) tl.store(out_ptr3 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_5(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, out_ptr0, out_ptr1, out_ptr2, out_ptr3, 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 % 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_out_ptr1 + x2, xmask) tmp11 = tl.load(in_out_ptr2 + x2, xmask) tmp15 = tl.load(in_out_ptr3 + x2, xmask) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tmp8 = tmp7 + tmp1 tmp9 = triton_helpers.maximum(tmp3, tmp8) tmp10 = tmp9 <= tmp5 tmp12 = tmp11 + tmp1 tmp13 = triton_helpers.maximum(tmp3, tmp12) tmp14 = tmp13 <= tmp5 tmp16 = tmp15 + tmp1 tmp17 = triton_helpers.maximum(tmp3, tmp16) tmp18 = tmp17 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(in_out_ptr1 + x2, tmp9, xmask) tl.store(out_ptr1 + x2, tmp10, xmask) tl.store(in_out_ptr2 + x2, tmp13, xmask) tl.store(out_ptr2 + x2, tmp14, xmask) tl.store(in_out_ptr3 + x2, tmp17, xmask) tl.store(out_ptr3 + x2, tmp18, xmask) @triton.jit def triton_poi_fused_stack_6(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 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 + 16 * 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_ptr1 + (x0 + 4 * (-4 + x1) + 16 * 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_ptr2 + (x0 + 4 * (-8 + x1) + 16 * x2), tmp14 & xmask, other=0.0) tmp16 = tmp0 >= tmp12 tl.full([1], 16, tl.int64) tmp19 = tl.load(in_ptr3 + (x0 + 4 * (-12 + x1) + 16 * 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): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (32, 4), (4, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (64, 32), (32, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf1) buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_1[grid(64)](primals_1, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf12, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf13) buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_2[grid(64)](primals_1, buf18, 64, XBLOCK=64, num_warps=1, num_stages=1) buf19 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf18, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf19) buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_3[grid(64)](primals_1, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf7 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf6, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 32), (1, 4), 0), out=buf7) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 32), (128, 32, 1), 0) del buf1 buf32 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) buf8 = reinterpret_tensor(buf7, (4, 4, 32), (128, 32, 1), 0) del buf7 buf30 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) buf14 = reinterpret_tensor(buf13, (4, 4, 32), (128, 32, 1), 0) del buf13 buf28 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) buf20 = reinterpret_tensor(buf19, (4, 4, 32), (128, 32, 1), 0) del buf19 buf26 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) triton_poi_fused_add_relu_threshold_backward_4[grid(512)](buf2, buf8, buf14, buf20, primals_3, buf32, buf30, buf28, buf26, 512, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = empty_strided_cuda((16, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf3) buf15 = empty_strided_cuda((16, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf14, (16, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf15) buf21 = empty_strided_cuda((16, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf20, (16, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf21) buf9 = empty_strided_cuda((16, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf8, (16, 32), (32, 1), 0), reinterpret_tensor(primals_4, (32, 64), (1, 32), 0), out=buf9) buf4 = reinterpret_tensor(buf3, (4, 4, 64), (256, 64, 1), 0) del buf3 buf31 = empty_strided_cuda((4, 4, 64), (256, 64, 1), torch.bool) buf10 = reinterpret_tensor(buf9, (4, 4, 64), (256, 64, 1), 0) del buf9 buf29 = empty_strided_cuda((4, 4, 64), (256, 64, 1), torch.bool) buf16 = reinterpret_tensor(buf15, (4, 4, 64), (256, 64, 1), 0) del buf15 buf27 = empty_strided_cuda((4, 4, 64), (256, 64, 1), torch.bool) buf22 = reinterpret_tensor(buf21, (4, 4, 64), (256, 64, 1), 0) del buf21 buf25 = empty_strided_cuda((4, 4, 64), (256, 64, 1), torch.bool) triton_poi_fused_relu_threshold_backward_5[grid(1024)](buf4, buf10, buf16, buf22, primals_5, buf31, buf29, buf27, buf25, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf4, (16, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf5) buf11 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf10, (16, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf11) buf17 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf16, (16, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf17) buf23 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf22, (16, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf23) del primals_7 buf24 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32) triton_poi_fused_stack_6[grid(256)](buf5, buf11, buf17, buf23, buf24, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf11 del buf17 del buf23 del buf5 return (reinterpret_tensor(buf24, (4, 4, 4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor( buf2, (16, 32), (32, 1), 0), reinterpret_tensor(buf4, (16, 64), (64, 1), 0), reinterpret_tensor(buf6, (16, 4), (4, 1), 0), reinterpret_tensor(buf8, (16, 32), (32, 1), 0), reinterpret_tensor( buf10, (16, 64), (64, 1), 0), reinterpret_tensor(buf12, (16, 4), (4, 1), 0), reinterpret_tensor(buf14, (16, 32), (32, 1), 0), reinterpret_tensor(buf16, (16, 64), (64, 1), 0), reinterpret_tensor (buf18, (16, 4), (4, 1), 0), reinterpret_tensor(buf20, (16, 32), ( 32, 1), 0), reinterpret_tensor(buf22, (16, 64), (64, 1), 0), primals_6, buf25, primals_4, buf26, buf27, buf28, buf29, buf30, buf31, buf32) class EncoderNetNew(nn.Module): def __init__(self, pedestrian_num, input_size, hidden_size): super(EncoderNetNew, self).__init__() self.pedestrian_num = pedestrian_num self.input_size = input_size self.hidden_size = hidden_size hidden1_size = 32 hidden2_size = 64 self.fc1 = torch.nn.Linear(input_size, hidden1_size) self.fc2 = torch.nn.Linear(hidden1_size, hidden2_size) self.fc3 = torch.nn.Linear(hidden2_size, hidden_size) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
hk19960522/2018-DL-Final
EncoderNet
false
3,605
[ "MIT" ]
0
cbc70260aa22d7df366a1d28bee472f1fc5b82c7
https://github.com/hk19960522/2018-DL-Final/tree/cbc70260aa22d7df366a1d28bee472f1fc5b82c7
PosNACLayer
import collections import torch import torch.utils.data def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class PosNACLayer(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): torch.nn.init.xavier_normal_(self.W_hat) def forward(self, input, reuse=False): W = torch.sigmoid(self.W_hat) self.writer.add_histogram('W', W) self.writer.add_tensor('W', W) self.writer.add_scalar('W/sparsity_error', sparsity_error(W), verbose_only=False) return torch.nn.functional.linear(input, W, self.bias) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) 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 collections import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sigmoid_0(in_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 = tl.sigmoid(tmp0) tl.store(out_ptr0 + x0, tmp1, 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((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf1) del buf0 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0) def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class PosNACLayerNew(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): torch.nn.init.xavier_normal_(self.W_hat) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_1 = self.W_hat primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
hoedt/stable-nalu
PosNACLayer
false
3,606
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
MNACLayer
import collections import math import torch import torch.utils.data def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class MNACLayer(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = math.sqrt(3.0) * std torch.nn.init.uniform_(self.W_hat, -r, r) def forward(self, x, reuse=False): W = torch.sigmoid(self.W_hat) self.writer.add_histogram('W', W) self.writer.add_tensor('W', W) self.writer.add_scalar('W/sparsity_error', sparsity_error(W), verbose_only=False) return mnac(x, W) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def get_inputs(): return [torch.rand([4, 4, 1])] def get_init_inputs(): return [[], {'in_features': 4, 'out_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 import collections import math import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 16 x3 = xindex % 16 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tmp4 = 1.0 tmp5 = tmp3 + tmp4 tmp6 = tmp5 - tmp2 tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_prod_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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 tl.store(out_ptr0 + x0, tmp6, 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, 1), (4, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sub_0[grid(64)](primals_2, primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_prod_1[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf1, primals_1, primals_2, buf0 def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class MNACLayerNew(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = math.sqrt(3.0) * std torch.nn.init.uniform_(self.W_hat, -r, r) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_1 = self.W_hat primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
hoedt/stable-nalu
MNACLayer
false
3,607
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
GumbelMNACLayer
import collections import torch import torch.utils.data def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class GumbelMNACLayer(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.tau = torch.nn.Parameter(torch.tensor(1, dtype=torch.float32), requires_grad=False) self.register_buffer('target_weights', torch.tensor([1, -1, 0], dtype=torch.float32)) self.U = torch.Tensor(out_features, in_features, 3) self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): torch.nn.init.constant_(self.W_hat, 0) torch.nn.init.constant_(self.tau, 1) def forward(self, x, reuse=False): if self.allow_random: gumbel = -torch.log(1e-08 - torch.log(torch.rand(self. out_features, self.in_features, device=x.device) + 1e-08)) W = torch.sigmoid((self.W_hat + gumbel) / self.tau) else: W = torch.sigmoid(self.W_hat) expected_W = torch.sigmoid(self.W_hat) self.writer.add_histogram('W', expected_W) self.writer.add_tensor('W', expected_W, verbose_only=False) return mnac(x, W) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def get_inputs(): return [torch.rand([4, 4, 1])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch import device import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import collections import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_sub_0(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 x2 = xindex // 16 x3 = xindex % 16 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + 0) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp3 = 1e-08 tmp4 = tmp2 + tmp3 tmp5 = tl_math.log(tmp4) tmp6 = tmp3 - tmp5 tmp7 = tl_math.log(tmp6) tmp8 = -tmp7 tmp9 = tmp1 + tmp8 tmp12 = tmp9 / tmp11 tmp13 = tl.sigmoid(tmp12) tmp14 = tmp0 * tmp13 tmp15 = 1.0 tmp16 = tmp14 + tmp15 tmp17 = tmp16 - tmp13 tl.store(out_ptr0 + x4, tmp17, xmask) @triton.jit def triton_poi_fused_prod_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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 tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_div_log_neg_rsub_sigmoid_sigmoid_backward_2( in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_out_ptr0 + x0, xmask) tmp9 = tl.load(in_ptr1 + 0) tmp10 = tl.broadcast_to(tmp9, [XBLOCK]) tmp2 = 1e-08 tmp3 = tmp1 + tmp2 tmp4 = tl_math.log(tmp3) tmp5 = tmp2 - tmp4 tmp6 = tl_math.log(tmp5) tmp7 = -tmp6 tmp8 = tmp0 + tmp7 tmp11 = tmp8 / tmp10 tmp12 = tl.sigmoid(tmp11) tmp13 = 1.0 tmp14 = tmp13 - tmp12 tmp15 = tmp12 * tmp14 tl.store(in_out_ptr0 + x0, tmp15, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (), ()) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.rand.default([4, 4], device=device(type= 'cuda', index=0), pin_memory=False) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sub_0[grid(64)](primals_1, primals_2, buf1, primals_3, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_prod_1[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = buf1 del buf1 triton_poi_fused_add_div_log_neg_rsub_sigmoid_sigmoid_backward_2[grid (16)](buf4, primals_2, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf3, primals_1, primals_3, buf2, buf4 def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class GumbelMNACLayerNew(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.tau = torch.nn.Parameter(torch.tensor(1, dtype=torch.float32), requires_grad=False) self.register_buffer('target_weights', torch.tensor([1, -1, 0], dtype=torch.float32)) self.U = torch.Tensor(out_features, in_features, 3) self.W_hat = torch.nn.Parameter(torch.Tensor(out_features, in_features) ) self.register_parameter('bias', None) def reset_parameters(self): torch.nn.init.constant_(self.W_hat, 0) torch.nn.init.constant_(self.tau, 1) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_3 = self.tau primals_2 = self.W_hat primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hoedt/stable-nalu
GumbelMNACLayer
false
3,608
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
DocUnetLossPow
import torch import torch.nn as nn import torch.nn.functional as F class DocUnetLossPow(nn.Module): """ 对应公式5的loss """ def __init__(self, r=0.1): super(DocUnetLossPow, self).__init__() self.r = r def forward(self, y, label): d = y - label lossf = d.pow(2).mean() - self.r * d.mean().pow(2) loss = F.mse_loss(y, label) + lossf return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_mean_mse_loss_mul_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tl.broadcast_to(tmp2, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = 256.0 tmp11 = tmp6 / tmp10 tmp12 = tmp9 / tmp10 tmp13 = tmp12 * tmp12 tmp14 = 0.1 tmp15 = tmp13 * tmp14 tmp16 = tmp11 - tmp15 tmp17 = tmp11 + tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp17, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf3 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_mse_loss_mul_pow_sub_0[grid(1)](buf3, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf3, class DocUnetLossPowNew(nn.Module): """ 对应公式5的loss """ def __init__(self, r=0.1): super(DocUnetLossPowNew, self).__init__() self.r = r def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hologerry/DewarpNet
DocUnetLossPow
false
3,609
[ "MIT" ]
0
b0a11b9fbb98bd124e65d3165ce177d9ebf2e836
https://github.com/hologerry/DewarpNet/tree/b0a11b9fbb98bd124e65d3165ce177d9ebf2e836
MultiplicativeLinear
import collections import torch import torch.utils.data from torch import nn class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class MultiplicativeLinear(ExtendedTorchModule): def __init__(self, in_features, out_features, **kwargs): super().__init__('MulLin', **kwargs) self.fc = nn.Linear(in_features, out_features) @torch.no_grad() def reset_parameters(self): nn.init.kaiming_uniform_(self.fc.weight, nonlinearity='linear') nn.init.zeros_(self.fc.bias) def log_gradients(self): for name, parameter in self.named_parameters(): gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) def forward(self, x): return self.fc(torch.log(x)).exp() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import collections import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_log_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_math.log(tmp0) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_exp_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl_math.exp(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_log_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_exp_1[grid(256)](buf2, primals_3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf2, reinterpret_tensor(buf0, (64, 4), (4, 1), 0), buf2 class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class MultiplicativeLinearNew(ExtendedTorchModule): def __init__(self, in_features, out_features, **kwargs): super().__init__('MulLin', **kwargs) self.fc = nn.Linear(in_features, out_features) @torch.no_grad() def reset_parameters(self): nn.init.kaiming_uniform_(self.fc.weight, nonlinearity='linear') nn.init.zeros_(self.fc.bias) def log_gradients(self): for name, parameter in self.named_parameters(): gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) def forward(self, input_0): primals_2 = self.fc.weight primals_3 = self.fc.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
hoedt/stable-nalu
MultiplicativeLinear
false
3,610
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
DocUnetLoss
import torch import torch.nn as nn import torch.nn.functional as F class DocUnetLoss(nn.Module): """ 只使用一个unet的loss 目前使用这个loss训练的比较好 """ def __init__(self, r=0.1): super(DocUnetLoss, self).__init__() self.r = r def forward(self, y, label): d = y - label lossf = torch.abs(d).mean() - self.r * torch.abs(d.mean()) loss = F.mse_loss(y, label) + lossf return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_mean_mse_loss_mul_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tl_math.abs(tmp2) tmp8 = tl.broadcast_to(tmp7, [RBLOCK]) tmp10 = triton_helpers.promote_to_tensor(tl.sum(tmp8, 0)) tmp11 = tl.broadcast_to(tmp2, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = 256.0 tmp15 = tmp6 / tmp14 tmp16 = tmp10 / tmp14 tmp17 = tmp13 / tmp14 tmp18 = tl_math.abs(tmp17) tmp19 = 0.1 tmp20 = tmp18 * tmp19 tmp21 = tmp16 - tmp20 tmp22 = tmp15 + tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp22, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf3 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_add_mean_mse_loss_mul_sub_0[grid(1)](buf3, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf3, class DocUnetLossNew(nn.Module): """ 只使用一个unet的loss 目前使用这个loss训练的比较好 """ def __init__(self, r=0.1): super(DocUnetLossNew, self).__init__() self.r = r def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
hologerry/DewarpNet
DocUnetLoss
false
3,611
[ "MIT" ]
0
b0a11b9fbb98bd124e65d3165ce177d9ebf2e836
https://github.com/hologerry/DewarpNet/tree/b0a11b9fbb98bd124e65d3165ce177d9ebf2e836
ReRegualizedLinearNACLayer
import collections import math import torch import torch.utils.data def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class RegualizerNAUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - torch.abs(W)) * (0 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class ReRegualizedLinearNACLayer(ExtendedTorchModule): """Implements the RegualizedLinearNAC Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='nac', type='bias', shape=regualizer_shape) self._regualizer_oob = Regualizer(support='nac', type='oob', shape= regualizer_shape, zero=self.nac_oob == 'clip') self._regualizer_nau_z = RegualizerNAUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(2.0 / (self.in_features + self.out_features)) r = min(0.5, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, -r, r) def optimize(self, loss): self._regualizer_nau_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(-1.0, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nau_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def forward(self, x, reuse=False): if self.allow_random: self._regualizer_nau_z.append_input(x) W = torch.clamp(self.W, -1.0, 1.0) self.writer.add_histogram('W', W) self.writer.add_tensor('W', W) self.writer.add_scalar('W/sparsity_error', sparsity_error(W), verbose_only=False) return torch.nn.functional.linear(x, W, self.bias) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import collections import math import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clamp_ge_le_logical_and_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = -1.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp5 = tmp0 >= tmp1 tmp6 = tmp0 <= tmp3 tmp7 = tmp5 & tmp6 tl.store(out_ptr0 + x0, tmp4, xmask) tl.store(out_ptr1 + x0, tmp7, 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((4, 4), (4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_clamp_ge_le_logical_and_0[grid(16)](primals_1, buf0, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf1) del buf0 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf2 def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class RegualizerNAUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - torch.abs(W)) * (0 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class ReRegualizedLinearNACLayerNew(ExtendedTorchModule): """Implements the RegualizedLinearNAC Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='nac', type='bias', shape=regualizer_shape) self._regualizer_oob = Regualizer(support='nac', type='oob', shape= regualizer_shape, zero=self.nac_oob == 'clip') self._regualizer_nau_z = RegualizerNAUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(2.0 / (self.in_features + self.out_features)) r = min(0.5, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, -r, r) def optimize(self, loss): self._regualizer_nau_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(-1.0, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nau_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_1 = self.W primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
hoedt/stable-nalu
ReRegualizedLinearNACLayer
false
3,612
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
ResidualBlock_noBN
import torch import torch.nn as nn import torch.nn.functional as F from torch import autograd as autograd import torch.nn.init as init import torch.fft from itertools import product as product def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBN(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+- |________________| """ def __init__(self, nc=64): super(ResidualBlock_noBN, self).__init__() self.conv1 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, x): identity = x out = F.relu(self.conv1(x), inplace=True) out = self.conv2(out) return identity + out def get_inputs(): return [torch.rand([4, 64, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch import autograd as autograd import torch.nn.init as init import torch.fft from itertools import product as product assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_add_convolution_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 64 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_out_ptr0 + x3, None) tmp2 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 64, 64, 64), (262144, 4096, 64, 1)) assert_size_stride(primals_2, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1048576)](buf1, primals_3, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 64, 64), (262144, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_add_convolution_1[grid(1048576)](buf3, primals_1, primals_5, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1 def initialize_weights(net_l, scale=1): if not isinstance(net_l, list): net_l = [net_l] for net in net_l: for m in net.modules(): if isinstance(m, nn.Conv2d): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.Linear): init.kaiming_normal_(m.weight, a=0, mode='fan_in') m.weight.data *= scale if m.bias is not None: m.bias.data.zero_() elif isinstance(m, nn.BatchNorm2d): init.constant_(m.weight, 1) init.constant_(m.bias.data, 0.0) class ResidualBlock_noBNNew(nn.Module): """Residual block w/o BN ---Conv-ReLU-Conv-+- |________________| """ def __init__(self, nc=64): super(ResidualBlock_noBNNew, self).__init__() self.conv1 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) self.conv2 = nn.Conv2d(nc, nc, 3, 1, 1, bias=True) initialize_weights([self.conv1, self.conv2], 0.1) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
hduba/KAIR
ResidualBlock_noBN
false
3,613
[ "MIT" ]
0
dbd7596c7e4a4667b9b7baac369fc6c02571fa58
https://github.com/hduba/KAIR/tree/dbd7596c7e4a4667b9b7baac369fc6c02571fa58
ReRegualizedLinearMNACLayer
import collections import math import torch import torch.utils.data def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class RegualizerNMUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - W) * (1 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class ReRegualizedLinearMNACLayer(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', mnac_epsilon=0, mnac_normalized=False, regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.mnac_normalized = mnac_normalized self.mnac_epsilon = mnac_epsilon self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='mnac', type='bias', shape=regualizer_shape, zero_epsilon=mnac_epsilon) self._regualizer_oob = Regualizer(support='mnac', type='oob', shape =regualizer_shape, zero_epsilon=mnac_epsilon, zero=self.nac_oob == 'clip') self._regualizer_nmu_z = RegualizerNMUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = min(0.25, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, 0.5 - r, 0.5 + r) self._regualizer_nmu_z.reset() def optimize(self, loss): self._regualizer_nmu_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(0.0 + self.mnac_epsilon, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nmu_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def forward(self, x, reuse=False): if self.allow_random: self._regualizer_nmu_z.append_input(x) W = torch.clamp(self.W, 0.0 + self.mnac_epsilon, 1.0 ) if self.nac_oob == 'regualized' else self.W self.writer.add_histogram('W', W) self.writer.add_tensor('W', W) self.writer.add_scalar('W/sparsity_error', sparsity_error(W), verbose_only=False) if self.mnac_normalized: c = torch.std(x) x_normalized = x / c z_normalized = mnac(x_normalized, W, mode='prod') out = z_normalized * c ** torch.sum(W, 1) else: out = mnac(x, W, mode='prod') return out def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def get_inputs(): return [torch.rand([4, 4, 1])] def get_init_inputs(): return [[], {'in_features': 4, 'out_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 import triton_helpers import collections import math import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 16 x3 = xindex % 16 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last') tmp2 = 0.0 tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp4 = 1.0 tmp5 = triton_helpers.minimum(tmp3, tmp4) tmp6 = tmp0 * tmp5 tmp7 = tmp6 + tmp4 tmp8 = tmp7 - tmp5 tl.store(out_ptr0 + x4, tmp8, xmask) @triton.jit def triton_poi_fused_prod_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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 tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_ge_le_logical_and_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 = 0.0 tmp2 = tmp0 >= tmp1 tmp3 = 1.0 tmp4 = tmp0 <= tmp3 tmp5 = tmp2 & tmp4 tl.store(out_ptr0 + x0, tmp5, 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, 1), (4, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_sub_0[grid(64)](primals_2, primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_prod_1[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_ge_le_logical_and_2[grid(16)](primals_1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 return buf1, primals_2, buf0, buf2 def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) def mnac(x, W, mode='prod'): out_size, in_size = W.size() x = x.view(x.size()[0], in_size, 1) W = W.t().view(1, in_size, out_size) if mode == 'prod': return torch.prod(x * W + 1 - W, -2) elif mode == 'exp-log': return torch.exp(torch.sum(torch.log(x * W + 1 - W), -2)) elif mode == 'no-idendity': return torch.prod(x * W, -2) else: raise ValueError(f'mnac mode "{mode}" is not implemented') class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class RegualizerNMUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - W) * (1 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class ReRegualizedLinearMNACLayerNew(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', mnac_epsilon=0, mnac_normalized=False, regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.mnac_normalized = mnac_normalized self.mnac_epsilon = mnac_epsilon self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='mnac', type='bias', shape=regualizer_shape, zero_epsilon=mnac_epsilon) self._regualizer_oob = Regualizer(support='mnac', type='oob', shape =regualizer_shape, zero_epsilon=mnac_epsilon, zero=self.nac_oob == 'clip') self._regualizer_nmu_z = RegualizerNMUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = min(0.25, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, 0.5 - r, 0.5 + r) self._regualizer_nmu_z.reset() def optimize(self, loss): self._regualizer_nmu_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(0.0 + self.mnac_epsilon, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nmu_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_1 = self.W primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
hoedt/stable-nalu
ReRegualizedLinearMNACLayer
false
3,614
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035
ReRegualizedLinearPosNACLayer
import collections import math import torch import torch.utils.data def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class RegualizerNMUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - W) * (1 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class ReRegualizedLinearPosNACLayer(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', mnac_epsilon=0, mnac_normalized=False, regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.mnac_normalized = mnac_normalized self.mnac_epsilon = mnac_epsilon self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='mnac', type='bias', shape=regualizer_shape, zero_epsilon=mnac_epsilon) self._regualizer_oob = Regualizer(support='mnac', type='oob', shape =regualizer_shape, zero_epsilon=mnac_epsilon, zero=self.nac_oob == 'clip') self._regualizer_nmu_z = RegualizerNMUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = min(0.25, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, 0.5 - r, 0.5 + r) self._regualizer_nmu_z.reset() def optimize(self, loss): self._regualizer_nmu_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(0.0 + self.mnac_epsilon, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nmu_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def forward(self, x, reuse=False): if self.allow_random: self._regualizer_nmu_z.append_input(x) W = torch.clamp(self.W, 0.0 + self.mnac_epsilon, 1.0 ) if self.nac_oob == 'regualized' else self.W self.writer.add_histogram('W', W) self.writer.add_tensor('W', W) self.writer.add_scalar('W/sparsity_error', sparsity_error(W), verbose_only=False) return torch.nn.functional.linear(x, W, self.bias) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import collections import math import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clamp_ge_le_logical_and_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp5 = tmp0 >= tmp1 tmp6 = tmp0 <= tmp3 tmp7 = tmp5 & tmp6 tl.store(out_ptr0 + x0, tmp4, xmask) tl.store(out_ptr1 + x0, tmp7, 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((4, 4), (4, 1), torch.float32) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_clamp_ge_le_logical_and_0[grid(16)](primals_1, buf0, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf1) del buf0 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf2 def sparsity_error(W): W_error = torch.min(torch.abs(W), torch.abs(1 - torch.abs(W))) return torch.max(W_error) class SummaryWriterNamespaceNoLoggingScope: def __init__(self, writer): self._writer = writer def __enter__(self): self._writer._logging_enabled = False def __exit__(self, type, value, traceback): self._writer._logging_enabled = True return False class DummySummaryWriter: def __init__(self, **kwargs): self._logging_enabled = False pass def add_scalar(self, name, value, verbose_only=True): pass def add_summary(self, name, tensor, verbose_only=True): pass def add_histogram(self, name, tensor, verbose_only=True): pass def add_tensor(self, name, tensor, verbose_only=True): pass def print(self, name, tensor, verbose_only=True): pass def namespace(self, name): return self def every(self, epoch_interval): return self def verbose(self, verbose): return self def no_logging(self): return SummaryWriterNamespaceNoLoggingScope(self) class NoRandomScope: def __init__(self, module): self._module = module def __enter__(self): self._module._disable_random() def __exit__(self, type, value, traceback): self._module._enable_random() return False class ExtendedTorchModule(torch.nn.Module): def __init__(self, default_name, *args, writer=None, name=None, **kwargs): super().__init__() if writer is None: writer = DummySummaryWriter() self.writer = writer.namespace(default_name if name is None else name) self.allow_random = True def set_parameter(self, name, value): parameter = getattr(self, name, None) if isinstance(parameter, torch.nn.Parameter): parameter.fill_(value) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.set_parameter(name, value) def regualizer(self, merge_in=None): regualizers = collections.defaultdict(int) if merge_in is not None: for key, value in merge_in.items(): self.writer.add_scalar(f'regualizer/{key}', value) regualizers[key] += value for module in self.children(): if isinstance(module, ExtendedTorchModule): for key, value in module.regualizer().items(): regualizers[key] += value return regualizers def optimize(self, loss): for module in self.children(): if isinstance(module, ExtendedTorchModule): module.optimize(loss) def log_gradients(self): for name, parameter in self.named_parameters(recurse=False): if parameter.requires_grad: gradient, *_ = parameter.grad.data self.writer.add_summary(f'{name}/grad', gradient) self.writer.add_histogram(f'{name}/grad', gradient) for module in self.children(): if isinstance(module, ExtendedTorchModule): module.log_gradients() def no_internal_logging(self): return self.writer.no_logging() def _disable_random(self): self.allow_random = False for module in self.children(): if isinstance(module, ExtendedTorchModule): module._disable_random() def _enable_random(self): self.allow_random = True for module in self.children(): if isinstance(module, ExtendedTorchModule): module._enable_random() def no_random(self): return NoRandomScope(self) class Regualizer: def __init__(self, support='nac', type='bias', shape='squared', zero= False, zero_epsilon=0): super() self.zero_epsilon = 0 if zero: self.fn = self._zero else: identifier = '_'.join(['', support, type, shape]) self.fn = getattr(self, identifier) def __call__(self, W): return self.fn(W) def _zero(self, W): return 0 def _mnac_bias_linear(self, W): return torch.mean(torch.min(torch.abs(W - self.zero_epsilon), torch .abs(1 - W))) def _mnac_bias_squared(self, W): return torch.mean((W - self.zero_epsilon) ** 2 * (1 - W) ** 2) def _mnac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon)) def _mnac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W - 0.5 - self.zero_epsilon) - 0.5 + self.zero_epsilon) ** 2) def _nac_bias_linear(self, W): W_abs = torch.abs(W) return torch.mean(torch.min(W_abs, torch.abs(1 - W_abs))) def _nac_bias_squared(self, W): return torch.mean(W ** 2 * (1 - torch.abs(W)) ** 2) def _nac_oob_linear(self, W): return torch.mean(torch.relu(torch.abs(W) - 1)) def _nac_oob_squared(self, W): return torch.mean(torch.relu(torch.abs(W) - 1) ** 2) class RegualizerNMUZ: def __init__(self, zero=False): self.zero = zero self.stored_inputs = [] def __call__(self, W): if self.zero: return 0 x_mean = torch.mean(torch.cat(self.stored_inputs, dim=0), dim=0, keepdim=True) return torch.mean((1 - W) * (1 - x_mean) ** 2) def append_input(self, x): if self.zero: return self.stored_inputs.append(x) def reset(self): if self.zero: return self.stored_inputs = [] class ReRegualizedLinearPosNACLayerNew(ExtendedTorchModule): """Implements the NAC (Neural Accumulator) Arguments: in_features: number of ingoing features out_features: number of outgoing features """ def __init__(self, in_features, out_features, nac_oob='regualized', regualizer_shape='squared', mnac_epsilon=0, mnac_normalized=False, regualizer_z=0, **kwargs): super().__init__('nac', **kwargs) self.in_features = in_features self.out_features = out_features self.mnac_normalized = mnac_normalized self.mnac_epsilon = mnac_epsilon self.nac_oob = nac_oob self._regualizer_bias = Regualizer(support='mnac', type='bias', shape=regualizer_shape, zero_epsilon=mnac_epsilon) self._regualizer_oob = Regualizer(support='mnac', type='oob', shape =regualizer_shape, zero_epsilon=mnac_epsilon, zero=self.nac_oob == 'clip') self._regualizer_nmu_z = RegualizerNMUZ(zero=regualizer_z == 0) self.W = torch.nn.Parameter(torch.Tensor(out_features, in_features)) self.register_parameter('bias', None) def reset_parameters(self): std = math.sqrt(0.25) r = min(0.25, math.sqrt(3.0) * std) torch.nn.init.uniform_(self.W, 0.5 - r, 0.5 + r) self._regualizer_nmu_z.reset() def optimize(self, loss): self._regualizer_nmu_z.reset() if self.nac_oob == 'clip': self.W.data.clamp_(0.0 + self.mnac_epsilon, 1.0) def regualizer(self): return super().regualizer({'W': self._regualizer_bias(self.W), 'z': self._regualizer_nmu_z(self.W), 'W-OOB': self._regualizer_oob( self.W)}) def extra_repr(self): return 'in_features={}, out_features={}'.format(self.in_features, self.out_features) def forward(self, input_0): primals_1 = self.W primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
hoedt/stable-nalu
ReRegualizedLinearPosNACLayer
false
3,615
[ "MIT" ]
0
64b3d240db8bff4da857d955f213ef3c7e38e035
https://github.com/hoedt/stable-nalu/tree/64b3d240db8bff4da857d955f213ef3c7e38e035