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
HardSigmoid
import torch import torch.nn as nn class HardSigmoid(nn.Module): def __init__(self, bias=1.0, divisor=2.0, min_value=0.0, max_value=1.0): super(HardSigmoid, self).__init__() assert divisor != 0, 'divisor is not allowed to be equal to zero' self.bias = bias self.divisor = divisor self.min_value = min_value self.max_value = max_value """forward""" def forward(self, x): x = (x + self.bias) / self.divisor return x.clamp_(self.min_value, self.max_value) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_clamp_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.0 tmp2 = tmp0 + tmp1 tmp3 = 0.5 tmp4 = tmp2 * tmp3 tmp5 = 0.0 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = triton_helpers.minimum(tmp6, tmp1) tl.store(out_ptr0 + x0, tmp7, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_clamp_div_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class HardSigmoidNew(nn.Module): def __init__(self, bias=1.0, divisor=2.0, min_value=0.0, max_value=1.0): super(HardSigmoidNew, self).__init__() assert divisor != 0, 'divisor is not allowed to be equal to zero' self.bias = bias self.divisor = divisor self.min_value = min_value self.max_value = max_value """forward""" def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
DetectionBLWX/WSDDN.pytorch
HardSigmoid
false
17,216
[ "MIT" ]
7
05020d9d0445af90ba0af3f095aa12b18e3da7d2
https://github.com/DetectionBLWX/WSDDN.pytorch/tree/05020d9d0445af90ba0af3f095aa12b18e3da7d2
MaxPoolStride1
import torch import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch.nn.functional as F import torch._utils class MaxPoolStride1(nn.Module): def __init__(self, kernel_size): super(MaxPoolStride1, self).__init__() self.kernel_size = kernel_size self.pad = kernel_size - 1 def forward(self, x): padding = int(self.pad / 2) padded_x = F.pad(x, (padding, padding, padding, padding), mode= 'constant', value=0) pooled_x = nn.MaxPool2d(self.kernel_size, 1)(padded_x) return pooled_x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.utils.data import torch.utils.data.distributed import torch._utils assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 144 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 3 % 3 x0 = xindex % 3 x2 = xindex // 9 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tmp12 = x0 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp8 & tmp13 tmp16 = tmp15 & tmp14 tmp17 = tl.load(in_ptr0 + (-4 + x0 + 4 * x1 + 16 * x2), tmp16 & xmask, other=0.0) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp8 & tmp20 tmp23 = tmp22 & tmp21 tmp24 = tl.load(in_ptr0 + (-3 + x0 + 4 * x1 + 16 * x2), tmp23 & xmask, other=0.0) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 + x0 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp8 & tmp27 tmp30 = tmp29 & tmp28 tmp31 = tl.load(in_ptr0 + (-2 + x0 + 4 * x1 + 16 * x2), tmp30 & xmask, other=0.0) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = x1 tmp34 = tmp33 >= tmp1 tmp35 = tmp33 < tmp3 tmp36 = tmp34 & tmp35 tmp37 = tmp36 & tmp6 tmp38 = tmp37 & tmp7 tmp39 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1 + 16 * x2), tmp38 & xmask, other=0.0) tmp40 = triton_helpers.maximum(tmp39, tmp32) tmp41 = tmp36 & tmp13 tmp42 = tmp41 & tmp14 tmp43 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp42 & xmask, other=0.0 ) tmp44 = triton_helpers.maximum(tmp43, tmp40) tmp45 = tmp36 & tmp20 tmp46 = tmp45 & tmp21 tmp47 = tl.load(in_ptr0 + (1 + x0 + 4 * x1 + 16 * x2), tmp46 & xmask, other=0.0) tmp48 = triton_helpers.maximum(tmp47, tmp44) tmp49 = tmp36 & tmp27 tmp50 = tmp49 & tmp28 tmp51 = tl.load(in_ptr0 + (2 + x0 + 4 * x1 + 16 * x2), tmp50 & xmask, other=0.0) tmp52 = triton_helpers.maximum(tmp51, tmp48) tmp53 = 1 + x1 tmp54 = tmp53 >= tmp1 tmp55 = tmp53 < tmp3 tmp56 = tmp54 & tmp55 tmp57 = tmp56 & tmp6 tmp58 = tmp57 & tmp7 tmp59 = tl.load(in_ptr0 + (3 + x0 + 4 * x1 + 16 * x2), tmp58 & xmask, other=0.0) tmp60 = triton_helpers.maximum(tmp59, tmp52) tmp61 = tmp56 & tmp13 tmp62 = tmp61 & tmp14 tmp63 = tl.load(in_ptr0 + (4 + x0 + 4 * x1 + 16 * x2), tmp62 & xmask, other=0.0) tmp64 = triton_helpers.maximum(tmp63, tmp60) tmp65 = tmp56 & tmp20 tmp66 = tmp65 & tmp21 tmp67 = tl.load(in_ptr0 + (5 + x0 + 4 * x1 + 16 * x2), tmp66 & xmask, other=0.0) tmp68 = triton_helpers.maximum(tmp67, tmp64) tmp69 = tmp56 & tmp27 tmp70 = tmp69 & tmp28 tmp71 = tl.load(in_ptr0 + (6 + x0 + 4 * x1 + 16 * x2), tmp70 & xmask, other=0.0) tmp72 = triton_helpers.maximum(tmp71, tmp68) tmp73 = 2 + x1 tmp74 = tmp73 >= tmp1 tmp75 = tmp73 < tmp3 tmp76 = tmp74 & tmp75 tmp77 = tmp76 & tmp6 tmp78 = tmp77 & tmp7 tmp79 = tl.load(in_ptr0 + (7 + x0 + 4 * x1 + 16 * x2), tmp78 & xmask, other=0.0) tmp80 = triton_helpers.maximum(tmp79, tmp72) tmp81 = tmp76 & tmp13 tmp82 = tmp81 & tmp14 tmp83 = tl.load(in_ptr0 + (8 + x0 + 4 * x1 + 16 * x2), tmp82 & xmask, other=0.0) tmp84 = triton_helpers.maximum(tmp83, tmp80) tmp85 = tmp76 & tmp20 tmp86 = tmp85 & tmp21 tmp87 = tl.load(in_ptr0 + (9 + x0 + 4 * x1 + 16 * x2), tmp86 & xmask, other=0.0) tmp88 = triton_helpers.maximum(tmp87, tmp84) tmp89 = tmp76 & tmp27 tmp90 = tmp89 & tmp28 tmp91 = tl.load(in_ptr0 + (10 + x0 + 4 * x1 + 16 * x2), tmp90 & xmask, other=0.0) tmp92 = triton_helpers.maximum(tmp91, tmp88) tl.store(out_ptr0 + x4, tmp92, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_pool2d_with_indices_0[grid(144)](arg0_1, buf0, 144, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class MaxPoolStride1New(nn.Module): def __init__(self, kernel_size): super(MaxPoolStride1New, self).__init__() self.kernel_size = kernel_size self.pad = kernel_size - 1 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
DatatangAILAB/SuanFaShiXun04
MaxPoolStride1
false
17,217
[ "Apache-2.0" ]
5
f478e40dd84240ac71cbb54e6bacf9ff556fbb3e
https://github.com/DatatangAILAB/SuanFaShiXun04/tree/f478e40dd84240ac71cbb54e6bacf9ff556fbb3e
SamePadConv2d
import torch import torch.nn as nn import torch.nn.functional as F class SamePadConv2d(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): super(SamePadConv2d, self).__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) def get_pad_odd(self, in_, weight, stride, dilation): effective_filter_size_rows = (weight - 1) * dilation + 1 out_rows = (in_ + stride - 1) // stride max(0, (out_rows - 1) * stride + effective_filter_size_rows - in_) padding_rows = max(0, (out_rows - 1) * stride + (weight - 1) * dilation + 1 - in_) rows_odd = padding_rows % 2 != 0 return padding_rows, rows_odd def forward(self, x): padding_rows, rows_odd = self.get_pad_odd(x.shape[2], self.weight. shape[2], self.stride[0], self.dilation[0]) padding_cols, cols_odd = self.get_pad_odd(x.shape[3], self.weight. shape[3], self.stride[1], self.dilation[1]) if rows_odd or cols_odd: x = F.pad(x, [0, int(cols_odd), 0, int(rows_odd)]) return F.conv2d(x, self.weight, self.bias, self.stride, padding=( padding_rows // 2, padding_cols // 2), dilation=self.dilation, groups=self.groups) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 5 % 5 x0 = xindex % 5 x2 = xindex // 25 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = x0 tmp4 = tmp3 < tmp1 tmp5 = tmp2 & tmp4 tmp6 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp5 & xmask, other=0.0) tl.store(out_ptr0 + x3, tmp6, xmask) @triton.jit def triton_poi_fused_convolution_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 = 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, 5, 5), (100, 25, 5, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(400)](primals_1, buf0, 400, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class SamePadConv2dNew(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True): super(SamePadConv2dNew, self).__init__(in_channels, out_channels, kernel_size, stride, 0, dilation, groups, bias) def get_pad_odd(self, in_, weight, stride, dilation): effective_filter_size_rows = (weight - 1) * dilation + 1 out_rows = (in_ + stride - 1) // stride max(0, (out_rows - 1) * stride + effective_filter_size_rows - in_) padding_rows = max(0, (out_rows - 1) * stride + (weight - 1) * dilation + 1 - in_) rows_odd = padding_rows % 2 != 0 return padding_rows, rows_odd def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
DandelionLau/NetworkCollections
SamePadConv2d
false
17,218
[ "Apache-2.0" ]
8
29e5cd2091f7085b3241209ed9447f2baadbce41
https://github.com/DandelionLau/NetworkCollections/tree/29e5cd2091f7085b3241209ed9447f2baadbce41
NormedLinear
import torch import torch.utils.data import torch import torch.nn as nn import torch.nn.functional as F from torch.nn import Parameter class NormedLinear(nn.Module): def __init__(self, in_features, out_features): super(NormedLinear, self).__init__() self.weight = Parameter(torch.Tensor(in_features, out_features)) self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0) def forward(self, x): out = F.normalize(x, dim=1).mm(F.normalize(self.weight, dim=0)) return out def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.utils.data import torch import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_poi_fused_div_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (4 + x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (8 + x0), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (12 + x0), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_1[grid(16)](primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, buf1, out=buf2) del buf1 return buf2, primals_2, reinterpret_tensor(buf0, (4, 4), (1, 4), 0) class NormedLinearNew(nn.Module): def __init__(self, in_features, out_features): super(NormedLinearNew, self).__init__() self.weight = Parameter(torch.Tensor(in_features, out_features)) self.weight.data.uniform_(-1, 1).renorm_(2, 1, 1e-05).mul_(100000.0) def forward(self, input_0): primals_1 = self.weight primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
Data-Designer/Feature-Space-Augmentation-for-Long-Tailed-Data
NormedLinear
false
17,219
[ "MIT" ]
9
ac6bced6269d6ebaa3fc0935603d905a7f11a6fa
https://github.com/Data-Designer/Feature-Space-Augmentation-for-Long-Tailed-Data/tree/ac6bced6269d6ebaa3fc0935603d905a7f11a6fa
L
import math import torch import torch.nn as nn def drop_none(**kwargs): r = {k: v for k, v in kwargs.items() if v is not None} return r class L(nn.Module): def __init__(self, num_linear, input_features, output_features, dtype= None, device=None): super().__init__() options = drop_none(dtype=dtype, device=device) self.num_linear = num_linear self.input_features = input_features self.output_features = output_features self.weight = nn.Parameter(torch.empty((num_linear, input_features, output_features), **options)) self.bias = nn.Parameter(torch.empty((num_linear, output_features), **options)) self.reset_parameters() @torch.no_grad() def reset_parameters(self): k = 1.0 / self.input_features bound = math.sqrt(k) nn.init.uniform_(self.weight, -bound, bound) nn.init.uniform_(self.bias, -bound, bound) def forward(self, x): out = torch.matmul(x.unsqueeze(dim=2), self.weight.unsqueeze(dim=0)) out = out.squeeze(dim=2) if self.bias is not None: out += self.bias return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_linear': 4, 'input_features': 4, 'output_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_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 = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_squeeze_2(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 x4 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x4, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(1024)](primals_1, buf0, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) triton_poi_fused_clone_1[grid(1024)](primals_2, buf1, 1024, XBLOCK= 256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (64, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf1, (64, 4, 4), (16, 4, 1), 0), out=buf2) del buf1 buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ) del buf2 buf4 = buf3 del buf3 triton_poi_fused_add_squeeze_2[grid(1024)](buf4, primals_3, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf4, reinterpret_tensor(buf0, (64, 4, 4), (16, 1, 4), 0) def drop_none(**kwargs): r = {k: v for k, v in kwargs.items() if v is not None} return r class LNew(nn.Module): def __init__(self, num_linear, input_features, output_features, dtype= None, device=None): super().__init__() options = drop_none(dtype=dtype, device=device) self.num_linear = num_linear self.input_features = input_features self.output_features = output_features self.weight = nn.Parameter(torch.empty((num_linear, input_features, output_features), **options)) self.bias = nn.Parameter(torch.empty((num_linear, output_features), **options)) self.reset_parameters() @torch.no_grad() def reset_parameters(self): k = 1.0 / self.input_features bound = math.sqrt(k) nn.init.uniform_(self.weight, -bound, bound) nn.init.uniform_(self.bias, -bound, bound) def forward(self, input_0): primals_2 = self.weight primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
DataCanvasIO/YLearn
L
false
17,220
[ "Apache-2.0" ]
3
d65b5afb83deed154c710de9096317165d95014a
https://github.com/DataCanvasIO/YLearn/tree/d65b5afb83deed154c710de9096317165d95014a
Downsample
import torch from torch import nn class Downsample(nn.Module): def __init__(self, dim): super().__init__() self.conv = nn.Conv2d(dim, dim, 3, 2, 1) def forward(self, x): return self.conv(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 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 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(64)](buf1, primals_2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 return buf1, primals_1, primals_3 class DownsampleNew(nn.Module): def __init__(self, dim): super().__init__() self.conv = nn.Conv2d(dim, dim, 3, 2, 1) 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]
DavidRuhe/simple-variational-diffusion-models
Downsample
false
17,221
[ "MIT" ]
4
a32355bf052a8f08e9c1919080588d0b22c8de4e
https://github.com/DavidRuhe/simple-variational-diffusion-models/tree/a32355bf052a8f08e9c1919080588d0b22c8de4e
Upsample
import torch from torch import nn class Upsample(nn.Module): def __init__(self, dim): super().__init__() self.conv = nn.ConvTranspose2d(dim, dim, 4, 2, 1) def forward(self, x): return self.conv(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (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=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=128, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3 class UpsampleNew(nn.Module): def __init__(self, dim): super().__init__() self.conv = nn.ConvTranspose2d(dim, dim, 4, 2, 1) 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]
DavidRuhe/simple-variational-diffusion-models
Upsample
false
17,222
[ "MIT" ]
4
a32355bf052a8f08e9c1919080588d0b22c8de4e
https://github.com/DavidRuhe/simple-variational-diffusion-models/tree/a32355bf052a8f08e9c1919080588d0b22c8de4e
SqueezeExcitate
import torch from torch import nn import torch.nn.functional as F class SqueezeExcitate(nn.Module): def __init__(self, in_channels, se_size, activation=None): super(SqueezeExcitate, self).__init__() self.dim_reduce = nn.Conv2d(in_channels=in_channels, out_channels= se_size, kernel_size=1) self.dim_restore = nn.Conv2d(in_channels=se_size, out_channels= in_channels, kernel_size=1) self.activation = F.relu if activation is None else activation def forward(self, x): inp = x x = F.adaptive_avg_pool2d(x, (1, 1)) x = self.dim_reduce(x) x = self.activation(x) x = self.dim_restore(x) x = torch.sigmoid(x) return torch.mul(inp, x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'se_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn import torch.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 = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_2[grid(16)](buf5, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf5, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf6, primals_1, primals_2, primals_4, buf1, buf3, buf5 class SqueezeExcitateNew(nn.Module): def __init__(self, in_channels, se_size, activation=None): super(SqueezeExcitateNew, self).__init__() self.dim_reduce = nn.Conv2d(in_channels=in_channels, out_channels= se_size, kernel_size=1) self.dim_restore = nn.Conv2d(in_channels=se_size, out_channels= in_channels, kernel_size=1) self.activation = F.relu if activation is None else activation def forward(self, input_0): primals_2 = self.dim_reduce.weight primals_3 = self.dim_reduce.bias primals_4 = self.dim_restore.weight primals_5 = self.dim_restore.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
Dogy06/COVID-Efficientnet-Pytorch-1
SqueezeExcitate
false
17,223
[ "MIT" ]
4
3c1f7d9513abe59783152efca28dc886bf4afc2f
https://github.com/Dogy06/COVID-Efficientnet-Pytorch-1/tree/3c1f7d9513abe59783152efca28dc886bf4afc2f
LabelSmoothingCrossEntropyBCE
import torch import torch.nn as nn import torch.nn.functional as F class LabelSmoothingCrossEntropyBCE(nn.Module): def __init__(self, smoothing=0.1): super(LabelSmoothingCrossEntropyBCE, self).__init__() assert smoothing < 1.0 self.smoothing = smoothing self.confidence = 1.0 - smoothing def forward(self, x, target): target = target.float() * self.confidence + 0.5 * self.smoothing return F.binary_cross_entropy_with_logits(x, target.type_as(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_binary_cross_entropy_with_logits_mul_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp7 = tl.load(in_ptr1 + r0, None) tmp1 = 0.9 tmp2 = tmp0 * tmp1 tmp3 = 0.05 tmp4 = tmp2 + tmp3 tmp5 = 1.0 tmp6 = tmp5 - tmp4 tmp8 = tmp6 * tmp7 tmp9 = 0.0 tmp10 = triton_helpers.minimum(tmp9, tmp7) tmp11 = tl_math.abs(tmp7) tmp12 = -tmp11 tmp13 = tl_math.exp(tmp12) tmp14 = libdevice.log1p(tmp13) tmp15 = tmp10 - tmp14 tmp16 = tmp8 - tmp15 tmp17 = tl.broadcast_to(tmp16, [RBLOCK]) tmp19 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0)) tmp20 = 256.0 tmp21 = tmp19 / tmp20 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_binary_cross_entropy_with_logits_mul_0[grid(1)]( buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class LabelSmoothingCrossEntropyBCENew(nn.Module): def __init__(self, smoothing=0.1): super(LabelSmoothingCrossEntropyBCENew, self).__init__() assert smoothing < 1.0 self.smoothing = smoothing self.confidence = 1.0 - smoothing def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Diyago/Graph-clasification-by-computer-vision
LabelSmoothingCrossEntropyBCE
false
17,224
[ "Apache-2.0" ]
9
703c44b98f9875d7a7b6db1c2b96372e11e256d6
https://github.com/Diyago/Graph-clasification-by-computer-vision/tree/703c44b98f9875d7a7b6db1c2b96372e11e256d6
PositiveLinear
import torch from torch import nn class PositiveLinear(nn.Module): def __init__(self, in_features: 'int', out_features: 'int') ->None: super().__init__() self.weight = nn.Parameter(torch.randn(in_features, out_features)) self.bias = nn.Parameter(torch.zeros(out_features)) self.softplus = nn.Softplus() def forward(self, input: 'torch.Tensor'): return input @ self.softplus(self.weight) + self.softplus(self.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 libdevice, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_softplus_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 = 1.0 tmp2 = tmp0 * tmp1 tmp3 = 20.0 tmp4 = tmp2 > tmp3 tmp5 = tl_math.exp(tmp2) tmp6 = libdevice.log1p(tmp5) tmp7 = tmp6 * tmp1 tmp8 = tl.where(tmp4, tmp0, tmp7) tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_softplus_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 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 20.0 tmp5 = tmp3 > tmp4 tmp6 = tl_math.exp(tmp3) tmp7 = libdevice.log1p(tmp6) tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp5, tmp1, tmp8) tmp10 = tmp0 + tmp9 tl.store(in_out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (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_softplus_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), buf0, out=buf1) del buf0 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf1 triton_poi_fused_add_softplus_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf2, primals_1, primals_3, reinterpret_tensor(primals_2, (4, 64 ), (1, 4), 0) class PositiveLinearNew(nn.Module): def __init__(self, in_features: 'int', out_features: 'int') ->None: super().__init__() self.weight = nn.Parameter(torch.randn(in_features, out_features)) self.bias = nn.Parameter(torch.zeros(out_features)) self.softplus = nn.Softplus() def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
DavidRuhe/simple-variational-diffusion-models
PositiveLinear
false
17,225
[ "MIT" ]
4
a32355bf052a8f08e9c1919080588d0b22c8de4e
https://github.com/DavidRuhe/simple-variational-diffusion-models/tree/a32355bf052a8f08e9c1919080588d0b22c8de4e
Residual_Covolution
import torch import torch.nn as nn class Residual_Covolution(nn.Module): def __init__(self, icol, ocol, num_classes): super(Residual_Covolution, self).__init__() self.conv1 = nn.Conv2d(icol, ocol, kernel_size=3, stride=1, padding =12, dilation=12, bias=True) self.conv2 = nn.Conv2d(ocol, num_classes, kernel_size=3, stride=1, padding=12, dilation=12, bias=True) self.conv3 = nn.Conv2d(num_classes, ocol, kernel_size=1, stride=1, padding=0, dilation=1, bias=True) self.conv4 = nn.Conv2d(ocol, icol, kernel_size=1, stride=1, padding =0, dilation=1, bias=True) self.relu = nn.ReLU(inplace=True) def forward(self, x): dow1 = self.conv1(x) dow1 = self.relu(dow1) seg = self.conv2(dow1) inc1 = self.conv3(seg) add1 = dow1 + self.relu(inc1) inc2 = self.conv4(add1) out = x + self.relu(inc2) return out, seg def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'icol': 4, 'ocol': 4, 'num_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_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) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x3, xmask) tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp6 = tmp0 + tmp5 tmp7 = 0.0 tmp8 = tmp5 <= tmp7 tl.store(out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr1 + x3, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = 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,)) assert_size_stride(primals_6, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(12, 12), dilation=(12, 12), 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=(12, 12), dilation=(12, 12), 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_convolution_1[grid(256)](buf3, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = 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_add_convolution_relu_threshold_backward_2[grid(256)]( buf1, buf4, primals_7, buf5, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1)) buf7 = buf4 del buf4 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_2[grid(256)]( primals_3, buf6, primals_9, buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del primals_9 return (buf7, buf3, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf3, buf5, buf8, buf9) class Residual_CovolutionNew(nn.Module): def __init__(self, icol, ocol, num_classes): super(Residual_CovolutionNew, self).__init__() self.conv1 = nn.Conv2d(icol, ocol, kernel_size=3, stride=1, padding =12, dilation=12, bias=True) self.conv2 = nn.Conv2d(ocol, num_classes, kernel_size=3, stride=1, padding=12, dilation=12, bias=True) self.conv3 = nn.Conv2d(num_classes, ocol, kernel_size=1, stride=1, padding=0, dilation=1, bias=True) self.conv4 = nn.Conv2d(ocol, icol, kernel_size=1, stride=1, padding =0, dilation=1, bias=True) self.relu = 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_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], output[1]
Dayan-Guan/SVMin
Residual_Covolution
false
17,227
[ "MIT" ]
6
d72b21f65958b1fda0abdbb60bd78d01e9d9cc8f
https://github.com/Dayan-Guan/SVMin/tree/d72b21f65958b1fda0abdbb60bd78d01e9d9cc8f
GroupNorm
import torch import torch.nn as nn class GroupNorm(nn.Module): def __init__(self, num_features, num_groups=32, eps=1e-05): super(GroupNorm, self).__init__() self.weight = nn.Parameter(torch.ones(1, num_features, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, num_features, 1, 1)) self.num_groups = num_groups self.eps = eps def forward(self, x): N, C, H, W = x.size() G = self.num_groups x = x.view(N, G, -1) mean = x.mean(-1, keepdim=True) var = x.var(-1, keepdim=True) x = (x - mean) / (var + self.eps).sqrt() x = x.view(N, C, H, W) return x * self.weight + self.bias def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @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 x5 = xindex x0 = xindex % 4 x3 = xindex // 64 x6 = xindex // 4 % 16 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x5, xmask) tmp1 = tl.load(in_ptr0 + (2 * (x0 // 2) + 4 * x6 + 64 * x3 + 64 * ((x0 + 4 * x6) // 64)), xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 2 * (x0 // 2) + 4 * x6 + 64 * x3 + 64 * ( (x0 + 4 * x6) // 64)), xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp20 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = 2.0 tmp5 = tmp3 / tmp4 tmp6 = tmp0 - tmp5 tmp7 = tmp1 - tmp5 tmp8 = tmp7 * tmp7 tmp9 = tmp2 - tmp5 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 / tmp12 tmp14 = 1e-05 tmp15 = tmp13 + tmp14 tmp16 = libdevice.sqrt(tmp15) tmp17 = tmp6 / tmp16 tmp19 = tmp17 * tmp18 tmp21 = tmp19 + tmp20 tl.store(out_ptr0 + x5, tmp21, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class GroupNormNew(nn.Module): def __init__(self, num_features, num_groups=32, eps=1e-05): super(GroupNormNew, self).__init__() self.weight = nn.Parameter(torch.ones(1, num_features, 1, 1)) self.bias = nn.Parameter(torch.zeros(1, num_features, 1, 1)) self.num_groups = num_groups self.eps = eps def forward(self, input_0): primals_2 = self.weight primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
E-Dreamer-LQ/Astronomical_Target_Detection
GroupNorm
false
17,228
[ "MIT" ]
6
0c2d6c2e516ff1efa28d44582442123c3a03f079
https://github.com/E-Dreamer-LQ/Astronomical_Target_Detection/tree/0c2d6c2e516ff1efa28d44582442123c3a03f079
FCUDown
import torch import torch.nn as nn from functools import partial class FCUDown(nn.Module): """ CNN feature maps -> Transformer patch embeddings """ def __init__(self, inplanes, outplanes, dw_stride, act_layer=nn.GELU, norm_layer=partial(nn.LayerNorm, eps=1e-06)): super(FCUDown, self).__init__() self.dw_stride = dw_stride self.conv_project = nn.Conv2d(inplanes, outplanes, kernel_size=1, stride=1, padding=0) self.sample_pooling = nn.AvgPool2d(kernel_size=dw_stride, stride= dw_stride) self.ln = norm_layer(outplanes) self.act = act_layer() def forward(self, x, x_t): x = self.conv_project(x) x = self.sample_pooling(x).flatten(2).transpose(1, 2) x = self.ln(x) x = self.act(x) x = torch.cat([x_t[:, 0][:, None, :], x], dim=1) return x def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'inplanes': 4, 'outplanes': 4, 'dw_stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from functools import partial assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_avg_pool2d_convolution_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 x2 = xindex x1 = xindex // 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 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 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-06 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x2, tmp8, xmask) tl.store(out_ptr1 + x2, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 x1 = xindex // 4 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), 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') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_cat_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 80 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 5 x0 = xindex % 4 x2 = xindex // 20 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 5, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x0 + 16 * x2 + (-1 + x1)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = 0.5 tmp11 = tmp9 * tmp10 tmp12 = 0.7071067811865476 tmp13 = tmp9 * tmp12 tmp14 = libdevice.erf(tmp13) tmp15 = 1.0 tmp16 = tmp14 + tmp15 tmp17 = tmp11 * tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp6, tmp17, tmp18) tmp20 = tl.where(tmp4, tmp5, tmp19) tl.store(out_ptr0 + x3, tmp20, 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, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4, 4), (64, 16, 4, 1), 0), 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, (1, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_avg_pool2d_convolution_0[grid(64)](buf1, primals_2, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf4 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_native_layer_norm_1[grid(16)](buf2, buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32) triton_poi_fused_native_layer_norm_2[grid(64)](buf2, buf3, buf4, primals_4, primals_5, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 del buf4 buf6 = empty_strided_cuda((4, 5, 4), (20, 4, 1), torch.float32) triton_poi_fused_cat_3[grid(80)](primals_6, buf5, buf6, 80, XBLOCK= 128, num_warps=4, num_stages=1) del buf5 del primals_6 return buf6, primals_1, primals_4, primals_5, reinterpret_tensor(primals_3, (1, 4, 4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(buf1, (4, 4, 4 ), (16, 4, 1), 0), buf2 class FCUDownNew(nn.Module): """ CNN feature maps -> Transformer patch embeddings """ def __init__(self, inplanes, outplanes, dw_stride, act_layer=nn.GELU, norm_layer=partial(nn.LayerNorm, eps=1e-06)): super(FCUDownNew, self).__init__() self.dw_stride = dw_stride self.conv_project = nn.Conv2d(inplanes, outplanes, kernel_size=1, stride=1, padding=0) self.sample_pooling = nn.AvgPool2d(kernel_size=dw_stride, stride= dw_stride) self.ln = norm_layer(outplanes) self.act = act_layer() def forward(self, input_0, input_1): primals_1 = self.conv_project.weight primals_2 = self.conv_project.bias primals_4 = self.ln.weight primals_5 = self.ln.bias primals_3 = input_0 primals_6 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
Curli-quan/fewshot-select
FCUDown
false
17,229
[ "Apache-2.0" ]
7
34f8ce5069ed1fbd01c1fa73a3ef264c98dadafe
https://github.com/Curli-quan/fewshot-select/tree/34f8ce5069ed1fbd01c1fa73a3ef264c98dadafe
LINEAR_LOGSOFTMAX
import torch import torch.nn as nn class LINEAR_LOGSOFTMAX(nn.Module): def __init__(self, input_dim, nclass): super(LINEAR_LOGSOFTMAX, self).__init__() self.fc = nn.Linear(input_dim, nclass) self.logic = nn.LogSoftmax(dim=1) self.lossfunction = nn.NLLLoss() def forward(self, x): o = self.logic(self.fc(x)) return o def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'nclass': 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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x3, tmp13, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](buf0, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 triton_poi_fused__log_softmax_1[grid(256)](buf1, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del buf1 return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf2 class LINEAR_LOGSOFTMAXNew(nn.Module): def __init__(self, input_dim, nclass): super(LINEAR_LOGSOFTMAXNew, self).__init__() self.fc = nn.Linear(input_dim, nclass) self.logic = nn.LogSoftmax(dim=1) self.lossfunction = nn.NLLLoss() def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Drkun/Lifelong-Zero-Shot-Learning
LINEAR_LOGSOFTMAX
false
17,231
[ "Apache-2.0" ]
9
5cea07c25e14aed1c544c83863f4733a8213ddb0
https://github.com/Drkun/Lifelong-Zero-Shot-Learning/tree/5cea07c25e14aed1c544c83863f4733a8213ddb0
GroupBatchnorm2d
import torch import torch.nn as nn class GroupBatchnorm2d(nn.Module): def __init__(self, c_num, group_num=16, eps=1e-10): super(GroupBatchnorm2d, self).__init__() self.group_num = group_num self.gamma = nn.Parameter(torch.ones(c_num, 1, 1)) self.beta = nn.Parameter(torch.zeros(c_num, 1, 1)) self.eps = eps def forward(self, x): N, C, H, W = x.size() x = x.view(N, self.group_num, -1) mean = x.mean(dim=2, keepdim=True) std = x.std(dim=2, keepdim=True) x = (x - mean) / (std + self.eps) x = x.view(N, C, H, W) return x * self.gamma + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'c_num': 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_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 x4 = xindex x5 = xindex // 4 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + 4 * x5, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x5), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x5), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x5), xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tmp11 = tmp1 - tmp9 tmp12 = tmp11 * tmp11 tmp13 = tmp2 - tmp9 tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp16 = tmp4 - tmp9 tmp17 = tmp16 * tmp16 tmp18 = tmp15 + tmp17 tmp19 = tmp6 - tmp9 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = 3.0 tmp23 = tmp21 / tmp22 tmp24 = libdevice.sqrt(tmp23) tmp25 = 1e-10 tmp26 = tmp24 + tmp25 tmp27 = tmp10 / tmp26 tmp29 = tmp27 * tmp28 tmp31 = tmp29 + tmp30 tl.store(out_ptr0 + x4, tmp31, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 1, 1), (1, 1, 1)) assert_size_stride(primals_3, (4, 1, 1), (1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(256)](primals_1, primals_2, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class GroupBatchnorm2dNew(nn.Module): def __init__(self, c_num, group_num=16, eps=1e-10): super(GroupBatchnorm2dNew, self).__init__() self.group_num = group_num self.gamma = nn.Parameter(torch.ones(c_num, 1, 1)) self.beta = nn.Parameter(torch.zeros(c_num, 1, 1)) 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]
E-Dreamer-LQ/Astronomical_Target_Detection
GroupBatchnorm2d
false
17,232
[ "MIT" ]
6
0c2d6c2e516ff1efa28d44582442123c3a03f079
https://github.com/E-Dreamer-LQ/Astronomical_Target_Detection/tree/0c2d6c2e516ff1efa28d44582442123c3a03f079
Attention
import torch import torch.nn as nn import torch.nn.functional as F class Attention(nn.Module): """ Applies an attention mechanism on the output features from the decoder. .. math:: \\begin{array}{ll} x = context*output \\\\ attn = exp(x_i) / sum_j exp(x_j) \\\\ output = \\tanh(w * (attn * context) + b * output) \\end{array} Args: dim(int): The number of expected features in the output Inputs: output, context - **output** (batch, output_len, dimensions): tensor containing the output features from the decoder. - **context** (batch, input_len, dimensions): tensor containing features of the encoded input sequence. Outputs: output, attn - **output** (batch, output_len, dimensions): tensor containing the attended output features from the decoder. - **attn** (batch, output_len, input_len): tensor containing attention weights. Attributes: linear_out (torch.nn.Linear): applies a linear transformation to the incoming data: :math:`y = Ax + b`. mask (torch.Tensor, optional): applies a :math:`-inf` to the indices specified in the `Tensor`. Examples:: >>> attention = seq2seq.models.Attention(256) >>> context = Variable(torch.randn(5, 3, 256)) >>> output = Variable(torch.randn(5, 5, 256)) >>> output, attn = attention(output, context) """ def __init__(self, dim): super(Attention, self).__init__() self.linear_out = nn.Linear(dim * 2, dim) self.mask = None def set_mask(self, mask): """ Sets indices to be masked Args: mask (torch.Tensor): tensor containing indices to be masked """ self.mask = mask def forward(self, output, context): batch_size = output.size(0) hidden_size = output.size(2) input_size = context.size(1) attn = torch.bmm(output, context.transpose(1, 2)) if self.mask is not None: attn.data.masked_fill_(self.mask, -float('inf')) attn = F.softmax(attn.view(-1, input_size), dim=1).view(batch_size, -1, input_size) mix = torch.bmm(attn, context) combined = torch.cat((mix, output), dim=2) output = torch.tanh(self.linear_out(combined.view(-1, 2 * hidden_size)) ).view(batch_size, -1, hidden_size) return output, attn def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'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_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) 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_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) @triton.jit def triton_poi_fused_cat_2(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_tanh_tanh_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tmp4 = tmp3 * tmp3 tmp5 = 1.0 tmp6 = tmp5 - tmp4 tl.store(in_out_ptr0 + x2, tmp3, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(primals_1, reinterpret_tensor(primals_2, (4, 4, 4), (16, 1, 4), 0), out=buf0) buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0) del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 extern_kernels.bmm(reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0), primals_2, out=buf3) del primals_2 buf4 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) triton_poi_fused_cat_2[grid(128)](buf3, primals_1, buf4, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0) del buf3 extern_kernels.mm(reinterpret_tensor(buf4, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf5) del primals_3 buf6 = buf5 del buf5 buf7 = empty_strided_cuda((16, 4), (4, 1), torch.float32) triton_poi_fused_tanh_tanh_backward_3[grid(64)](buf6, primals_4, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_4 return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1), 0 ), reinterpret_tensor(buf4, (16, 8), (8, 1), 0), buf7 class AttentionNew(nn.Module): """ Applies an attention mechanism on the output features from the decoder. .. math:: \\begin{array}{ll} x = context*output \\\\ attn = exp(x_i) / sum_j exp(x_j) \\\\ output = \\tanh(w * (attn * context) + b * output) \\end{array} Args: dim(int): The number of expected features in the output Inputs: output, context - **output** (batch, output_len, dimensions): tensor containing the output features from the decoder. - **context** (batch, input_len, dimensions): tensor containing features of the encoded input sequence. Outputs: output, attn - **output** (batch, output_len, dimensions): tensor containing the attended output features from the decoder. - **attn** (batch, output_len, input_len): tensor containing attention weights. Attributes: linear_out (torch.nn.Linear): applies a linear transformation to the incoming data: :math:`y = Ax + b`. mask (torch.Tensor, optional): applies a :math:`-inf` to the indices specified in the `Tensor`. Examples:: >>> attention = seq2seq.models.Attention(256) >>> context = Variable(torch.randn(5, 3, 256)) >>> output = Variable(torch.randn(5, 5, 256)) >>> output, attn = attention(output, context) """ def __init__(self, dim): super(AttentionNew, self).__init__() self.linear_out = nn.Linear(dim * 2, dim) self.mask = None def set_mask(self, mask): """ Sets indices to be masked Args: mask (torch.Tensor): tensor containing indices to be masked """ self.mask = mask def forward(self, input_0, input_1): primals_3 = self.linear_out.weight primals_4 = self.linear_out.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0], output[1]
EVASHINJI/Seq2Seq-PyTorch
Attention
false
17,233
[ "Apache-2.0" ]
4
d53f8d7c240bd7c16ebd1475384774bd064b4b03
https://github.com/EVASHINJI/Seq2Seq-PyTorch/tree/d53f8d7c240bd7c16ebd1475384774bd064b4b03
InstanceNormalization
import torch import torch.nn as nn class InstanceNormalization(torch.nn.Module): """InstanceNormalization Improves convergence of neural-style. ref: https://arxiv.org/pdf/1607.08022.pdf """ def __init__(self, dim, eps=1e-09): super(InstanceNormalization, self).__init__() self.scale = nn.Parameter(torch.FloatTensor(dim)) self.shift = nn.Parameter(torch.FloatTensor(dim)) self.eps = eps self._reset_parameters() def _reset_parameters(self): self.scale.data.uniform_() self.shift.data.zero_() def forward(self, x): n = x.size(2) * x.size(3) t = x.view(x.size(0), x.size(1), n) mean = torch.mean(t, 2).unsqueeze(2).unsqueeze(3).expand_as(x) var = torch.var(t, 2).unsqueeze(2).unsqueeze(3).expand_as(x) * ((n - 1) / float(n)) scale_broadcast = self.scale.unsqueeze(1).unsqueeze(1).unsqueeze(0) scale_broadcast = scale_broadcast.expand_as(x) shift_broadcast = self.shift.unsqueeze(1).unsqueeze(1).unsqueeze(0) shift_broadcast = shift_broadcast.expand_as(x) out = (x - mean) / torch.sqrt(var + self.eps) out = out * scale_broadcast + shift_broadcast return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_sqrt_sub_var_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp30 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp4 / tmp19 tmp21 = 15.0 tmp22 = tmp18 / tmp21 tmp23 = tmp0 - tmp20 tmp24 = 0.9375 tmp25 = tmp22 * tmp24 tmp26 = 1e-09 tmp27 = tmp25 + tmp26 tmp28 = libdevice.sqrt(tmp27) tmp29 = tmp23 / tmp28 tmp31 = tmp29 * tmp30 tmp33 = tmp31 + tmp32 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp22, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp33, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (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, 1), torch.float32) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 buf5 = buf3 del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_sqrt_sub_var_0[grid(16)](buf1, buf5, primals_1, primals_2, primals_3, buf6, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf6, primals_1, reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0), reinterpret_tensor(buf5, (4, 4, 1, 1), (4, 1, 1, 1), 0) class InstanceNormalizationNew(torch.nn.Module): """InstanceNormalization Improves convergence of neural-style. ref: https://arxiv.org/pdf/1607.08022.pdf """ def __init__(self, dim, eps=1e-09): super(InstanceNormalizationNew, self).__init__() self.scale = nn.Parameter(torch.FloatTensor(dim)) self.shift = nn.Parameter(torch.FloatTensor(dim)) self.eps = eps self._reset_parameters() def _reset_parameters(self): self.scale.data.uniform_() self.shift.data.zero_() def forward(self, input_0): primals_2 = self.scale primals_3 = self.shift primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
E-Dreamer-LQ/Astronomical_Target_Detection
InstanceNormalization
false
17,234
[ "MIT" ]
6
0c2d6c2e516ff1efa28d44582442123c3a03f079
https://github.com/E-Dreamer-LQ/Astronomical_Target_Detection/tree/0c2d6c2e516ff1efa28d44582442123c3a03f079
ConvLSTMCls
import torch import torch.nn as nn class ConvLSTMCls(nn.Module): def __init__(self, in_channels, out_channels): """ Convolutional LSTM block for generation network Args: - in_channels: Int. Number of channels of the input of Conv2D - out_channels: Int. Number of channels of the result of Conv2D - skip_out_channels: Int. Number of channels of the result of transposed Conv2D in skip connection """ super(ConvLSTMCls, self).__init__() in_channels = in_channels + out_channels self.forget_conv = nn.Conv2d(in_channels, out_channels, kernel_size =5, stride=1, padding=2) self.input_conv_1 = nn.Conv2d(in_channels, out_channels, kernel_size=5, stride=1, padding=2) self.input_conv_2 = nn.Conv2d(in_channels, out_channels, kernel_size=5, stride=1, padding=2) self.output_conv = nn.Conv2d(in_channels, out_channels, kernel_size =5, stride=1, padding=2) def forward(self, input, hidden_in, cell_in): """ Forward propagation Args: - input: A tuple of Tensors. - hidden_in: A Tensor of shape (B, C, H, W). Hidden variable from previous ConvLSTM cell. - cell_in: A Tensor of shape (B, C, H, W). Cell state from previous ConvLSTM cell. Returns: A tuple of Tensors. - hidden: A Tensor of shape (B, C, H, W). - cell: A Tensor of shape (B, C, H, W). """ x = torch.cat((input, hidden_in), dim=1) forget_gate = torch.sigmoid(self.forget_conv(x)) input_gate = torch.sigmoid(self.input_conv_1(x)) * torch.tanh(self. input_conv_2(x)) output_gate = torch.sigmoid(self.output_conv(x)) cell = forget_gate * cell_in + input_gate hidden = output_gate * torch.tanh(cell) return hidden, cell 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 [[], {'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.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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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) @triton.jit def triton_poi_fused_add_convolution_mul_sigmoid_tanh_1(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr2 + x3, xmask) tmp7 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_out_ptr3 + x3, xmask) tmp10 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr4 + x3, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp8 = tmp6 + tmp7 tmp11 = tmp9 + tmp10 tmp12 = tl.sigmoid(tmp2) tmp14 = tmp12 * tmp13 tmp15 = tl.sigmoid(tmp5) tmp16 = libdevice.tanh(tmp8) tmp17 = tmp15 * tmp16 tmp18 = tmp14 + tmp17 tmp19 = tl.sigmoid(tmp11) tmp20 = libdevice.tanh(tmp18) tmp21 = tmp19 * tmp20 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(in_out_ptr1 + x3, tmp5, xmask) tl.store(in_out_ptr2 + x3, tmp8, xmask) tl.store(in_out_ptr3 + x3, tmp11, xmask) tl.store(out_ptr0 + x3, tmp18, xmask) tl.store(out_ptr1 + x3, tmp21, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 8, 5, 5), (200, 25, 5, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 8, 5, 5), (200, 25, 5, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 8, 5, 5), (200, 25, 5, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 8, 5, 5), (200, 25, 5, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (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, 4), (128, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](primals_1, primals_2, buf0, 512, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = extern_kernels.convolution(buf0, primals_5, stride=(1, 1), padding=(2, 2), 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)) buf5 = extern_kernels.convolution(buf0, primals_7, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 4, 4, 4), (64, 16, 4, 1)) buf7 = extern_kernels.convolution(buf0, primals_9, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 buf4 = buf3 del buf3 buf6 = buf5 del buf5 buf8 = buf7 del buf7 buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_mul_sigmoid_tanh_1[grid(256)](buf2, buf4, buf6, buf8, primals_4, primals_6, primals_8, primals_10, primals_11, buf9, buf10, 256, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_10 del primals_4 del primals_6 del primals_8 return (buf10, buf9, primals_3, primals_5, primals_7, primals_9, primals_11, buf0, buf2, buf4, buf6, buf8, buf9) class ConvLSTMClsNew(nn.Module): def __init__(self, in_channels, out_channels): """ Convolutional LSTM block for generation network Args: - in_channels: Int. Number of channels of the input of Conv2D - out_channels: Int. Number of channels of the result of Conv2D - skip_out_channels: Int. Number of channels of the result of transposed Conv2D in skip connection """ super(ConvLSTMClsNew, self).__init__() in_channels = in_channels + out_channels self.forget_conv = nn.Conv2d(in_channels, out_channels, kernel_size =5, stride=1, padding=2) self.input_conv_1 = nn.Conv2d(in_channels, out_channels, kernel_size=5, stride=1, padding=2) self.input_conv_2 = nn.Conv2d(in_channels, out_channels, kernel_size=5, stride=1, padding=2) self.output_conv = nn.Conv2d(in_channels, out_channels, kernel_size =5, stride=1, padding=2) def forward(self, input_0, input_1, input_2): primals_3 = self.forget_conv.weight primals_4 = self.forget_conv.bias primals_5 = self.input_conv_1.weight primals_6 = self.input_conv_1.bias primals_7 = self.input_conv_2.weight primals_8 = self.input_conv_2.bias primals_9 = self.output_conv.weight primals_10 = self.output_conv.bias primals_1 = input_0 primals_2 = input_1 primals_11 = input_2 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0], output[1]
DveloperY0115/torch-gqn
ConvLSTMCls
false
17,235
[ "Apache-2.0" ]
3
3d1be9d73522e3d52f15076e0e9cb485dcab638b
https://github.com/DveloperY0115/torch-gqn/tree/3d1be9d73522e3d52f15076e0e9cb485dcab638b
FiLMSIREN
import math import torch from torch import nn class FiLMSIREN(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', omega_0: 'float'=30.0, is_first: 'bool'=False, bias: 'bool'=True): super().__init__() self.in_features = in_features self.out_features = out_features self.is_first = is_first self.omega_0 = omega_0 self.linear = nn.Linear(in_features, out_features, bias=bias) self.init_weights() def init_weights(self): with torch.no_grad(): b = math.sqrt(6.0 / self.in_features ) if self.is_first else math.sqrt(6.0 / self.in_features ) / self.omega_0 self.linear.weight.uniform_(-b, b) def forward(self, x, gamma=None, beta=None): out = self.linear(x) if gamma is not None: out = out * gamma if beta is not None: out = out + beta out = torch.sin(self.omega_0 * out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_features': 4, 'out_features': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sin_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 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 = 30.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.sin(tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sin_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0 class FiLMSIRENNew(nn.Module): def __init__(self, in_features: 'int', out_features: 'int', omega_0: 'float'=30.0, is_first: 'bool'=False, bias: 'bool'=True): super().__init__() self.in_features = in_features self.out_features = out_features self.is_first = is_first self.omega_0 = omega_0 self.linear = nn.Linear(in_features, out_features, bias=bias) self.init_weights() def init_weights(self): with torch.no_grad(): b = math.sqrt(6.0 / self.in_features ) if self.is_first else math.sqrt(6.0 / self.in_features ) / self.omega_0 self.linear.weight.uniform_(-b, b) def forward(self, input_0): primals_1 = self.linear.weight primals_2 = self.linear.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
EasternJournalist/pi-GAN
FiLMSIREN
false
17,236
[ "MIT" ]
4
3d57611e1c8fca2f3cd00fde1989ec1f9dd94d55
https://github.com/EasternJournalist/pi-GAN/tree/3d57611e1c8fca2f3cd00fde1989ec1f9dd94d55
IOUloss
import torch import torch.nn as nn class IOUloss(nn.Module): def __init__(self, reduction='none', loss_type='iou'): super(IOUloss, self).__init__() self.reduction = reduction self.loss_type = loss_type def forward(self, pred, target): assert pred.shape[0] == target.shape[0] pred = pred.view(-1, 4) target = target.view(-1, 4) tl = torch.max(pred[:, :2] - pred[:, 2:] / 2, target[:, :2] - target[:, 2:] / 2) br = torch.min(pred[:, :2] + pred[:, 2:] / 2, target[:, :2] + target[:, 2:] / 2) area_p = torch.prod(pred[:, 2:], 1) area_g = torch.prod(target[:, 2:], 1) en = (tl < br).type(tl.type()).prod(dim=1) area_i = torch.prod(br - tl, 1) * en iou = area_i / (area_p + area_g - area_i + 1e-16) if self.loss_type == 'iou': loss = 1 - iou ** 2 elif self.loss_type == 'giou': c_tl = torch.min(pred[:, :2] - pred[:, 2:] / 2, target[:, :2] - target[:, 2:] / 2) c_br = torch.max(pred[:, :2] + pred[:, 2:] / 2, target[:, :2] + target[:, 2:] / 2) area_c = torch.prod(c_br - c_tl, 1) giou = iou - (area_c - area_i) / area_c.clamp(1e-16) loss = 1 - giou.clamp(min=-1.0, max=1.0) if self.reduction == 'mean': loss = loss.mean() elif self.reduction == 'sum': loss = loss.sum() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy_add_div_lt_maximum_minimum_mul_pow_prod_rsub_sub_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp19 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp0 + tmp3 tmp7 = tmp6 * tmp2 tmp8 = tmp5 + tmp7 tmp9 = triton_helpers.minimum(tmp4, tmp8) tmp10 = tmp0 - tmp3 tmp11 = tmp5 - tmp7 tmp12 = triton_helpers.maximum(tmp10, tmp11) tmp13 = tmp9 - tmp12 tmp16 = tmp15 * tmp2 tmp17 = tmp14 + tmp16 tmp20 = tmp19 * tmp2 tmp21 = tmp18 + tmp20 tmp22 = triton_helpers.minimum(tmp17, tmp21) tmp23 = tmp14 - tmp16 tmp24 = tmp18 - tmp20 tmp25 = triton_helpers.maximum(tmp23, tmp24) tmp26 = tmp22 - tmp25 tmp27 = tmp13 * tmp26 tmp28 = tmp12 < tmp9 tmp29 = tmp28.to(tl.float32) tmp30 = tmp25 < tmp22 tmp31 = tmp30.to(tl.float32) tmp32 = tmp29 * tmp31 tmp33 = tmp27 * tmp32 tmp34 = tmp1 * tmp15 tmp35 = tmp6 * tmp19 tmp36 = tmp34 + tmp35 tmp37 = tmp36 - tmp33 tmp38 = 1e-16 tmp39 = tmp37 + tmp38 tmp40 = tmp33 / tmp39 tmp41 = tmp40 * tmp40 tmp42 = 1.0 tmp43 = tmp42 - tmp41 tl.store(in_out_ptr0 + x0, tmp43, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64,), (1,), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused__to_copy_add_div_lt_maximum_minimum_mul_pow_prod_rsub_sub_0[ grid(64)](buf1, arg0_1, arg1_1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf1, class IOUlossNew(nn.Module): def __init__(self, reduction='none', loss_type='iou'): super(IOUlossNew, self).__init__() self.reduction = reduction self.loss_type = loss_type def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
DerryHub/ByteTrack-attack
IOUloss
false
17,237
[ "MIT" ]
6
f237894c7985863c0830401933ebd89ca92bde96
https://github.com/DerryHub/ByteTrack-attack/tree/f237894c7985863c0830401933ebd89ca92bde96
NetEnd
import torch import torch.nn as nn class NetEnd(nn.Module): def __init__(self, num_classes: 'int'): super(NetEnd, self).__init__() self.num_classes = num_classes self.fc_net1 = nn.Conv2d(21, self.num_classes, kernel_size=1, stride=1) assert self.num_classes > 0, 'The number of classes must be a positive integer.' if self.num_classes > 1: self.final = nn.Softmax() else: self.final = nn.Sigmoid() def forward(self, x): out = self.fc_net1(x) out = self.final(out) return out def get_inputs(): return [torch.rand([4, 21, 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_convolution_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) x0 = xindex % 4096 x1 = xindex // 4096 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16384 * x1), None) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr0 + (4096 + x0 + 16384 * x1), None) tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp9 = tl.load(in_ptr0 + (8192 + x0 + 16384 * x1), None) tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (12288 + x0 + 16384 * x1), None) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp7 = tmp4 + tmp6 tmp8 = triton_helpers.maximum(tmp3, tmp7) tmp12 = tmp9 + tmp11 tmp13 = triton_helpers.maximum(tmp8, tmp12) tmp17 = tmp14 + tmp16 tmp18 = triton_helpers.maximum(tmp13, tmp17) tmp19 = tmp3 - tmp18 tmp20 = tl_math.exp(tmp19) tmp21 = tmp7 - tmp18 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tmp12 - tmp18 tmp25 = tl_math.exp(tmp24) tmp26 = tmp23 + tmp25 tmp27 = tmp17 - tmp18 tmp28 = tl_math.exp(tmp27) tmp29 = tmp26 + tmp28 tl.store(out_ptr0 + x2, tmp18, None) tl.store(out_ptr1 + x2, tmp29, None) @triton.jit def triton_poi_fused__softmax_convolution_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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 % 4 x0 = xindex % 4096 x2 = xindex // 16384 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr2 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(in_out_ptr0 + x3, tmp7, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 21, 1, 1), (21, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 21, 64, 64), (86016, 4096, 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, 4, 64, 64), (16384, 4096, 64, 1)) buf1 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) buf2 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_convolution_0[grid(16384)](buf0, primals_2, buf1, buf2, 16384, XBLOCK=256, num_warps=4, num_stages=1 ) buf3 = buf0 del buf0 triton_poi_fused__softmax_convolution_1[grid(65536)](buf3, primals_2, buf1, buf2, 65536, XBLOCK=256, num_warps=4, num_stages=1 ) del buf1 del buf2 del primals_2 return buf3, primals_1, primals_3, buf3 class NetEndNew(nn.Module): def __init__(self, num_classes: 'int'): super(NetEndNew, self).__init__() self.num_classes = num_classes self.fc_net1 = nn.Conv2d(21, self.num_classes, kernel_size=1, stride=1) assert self.num_classes > 0, 'The number of classes must be a positive integer.' if self.num_classes > 1: self.final = nn.Softmax() else: self.final = nn.Sigmoid() def forward(self, input_0): primals_1 = self.fc_net1.weight primals_2 = self.fc_net1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
EadCat/Road-Extraction
NetEnd
false
17,238
[ "MIT" ]
4
9d4831b6c3a5ef07676cbe1c79b03045fda427ea
https://github.com/EadCat/Road-Extraction/tree/9d4831b6c3a5ef07676cbe1c79b03045fda427ea
IN_self
import torch import torch.nn as nn class IN_self(nn.Module): def __init__(self, num_features): super(IN_self, self).__init__() self.num_features = num_features self.gamma = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.beta = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.ones_(self.gamma) nn.init.zeros_(self.beta) def forward(self, X, eps=1e-05): var, mean = torch.var_mean(X, dim=(2, 3), keepdim=True, unbiased=False) X = (X - mean) / torch.sqrt(var + eps) return self.gamma * X + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mul_sqrt_sub_var_mean_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr ): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp22 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp26 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 16.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.sqrt(tmp20) tmp23 = tmp0 - tmp10 tmp24 = tmp23 / tmp21 tmp25 = tmp22 * tmp24 tmp27 = tmp25 + tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(out_ptr1 + (r1 + 16 * x0), tmp27, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf3 = reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mul_sqrt_sub_var_mean_0[grid(16)](buf3, primals_1, primals_2, primals_3, buf0, buf4, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf4, primals_1, buf0, buf3 class IN_selfNew(nn.Module): def __init__(self, num_features): super(IN_selfNew, self).__init__() self.num_features = num_features self.gamma = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.beta = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.ones_(self.gamma) nn.init.zeros_(self.beta) 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]
EkdeepSLubana/BeyondBatchNorm
IN_self
false
17,239
[ "MIT" ]
10
2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
https://github.com/EkdeepSLubana/BeyondBatchNorm/tree/2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
LN_self
import torch import torch.nn as nn class LN_self(nn.Module): def __init__(self, num_features): super().__init__() shape = 1, num_features, 1, 1 self.gamma = nn.Parameter(torch.ones(shape)) self.beta = nn.Parameter(torch.zeros(shape)) def forward(self, X, eps=1e-05): var, mean = torch.var_mean(X, dim=(1, 2, 3), keepdim=True, unbiased =False) X = (X - mean) / torch.sqrt(var + eps) return self.gamma * X + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mul_sqrt_sub_var_mean_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr ): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex r3 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp22 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last') tmp26 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 64, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 64.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.sqrt(tmp20) tmp23 = tmp0 - tmp10 tmp24 = tmp23 / tmp21 tmp25 = tmp22 * tmp24 tmp27 = tmp25 + tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(out_ptr1 + (r1 + 64 * x0), tmp27, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32) buf1 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf3 = reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mul_sqrt_sub_var_mean_0[grid(4)](buf3, primals_1, primals_2, primals_3, buf0, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 del primals_3 return buf4, primals_1, buf0, buf3 class LN_selfNew(nn.Module): def __init__(self, num_features): super().__init__() shape = 1, num_features, 1, 1 self.gamma = nn.Parameter(torch.ones(shape)) self.beta = nn.Parameter(torch.zeros(shape)) 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]
EkdeepSLubana/BeyondBatchNorm
LN_self
false
17,240
[ "MIT" ]
10
2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
https://github.com/EkdeepSLubana/BeyondBatchNorm/tree/2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
TLU
import torch import torch.nn as nn class TLU(nn.Module): def __init__(self, num_features): """max(y, tau) = max(y - tau, 0) + tau = ReLU(y - tau) + tau""" super(TLU, self).__init__() self.num_features = num_features self.tau = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.zeros_(self.tau) def extra_repr(self): return 'num_features={num_features}'.format(**self.__dict__) def forward(self, x): return torch.max(x, self.tau) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_eq_gt_maximum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = tmp0 == tmp1 tmp4 = tmp0 > tmp1 tl.store(out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr1 + x3, tmp3, xmask) tl.store(out_ptr2 + x3, tmp4, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_eq_gt_maximum_0[grid(256)](primals_2, primals_1, buf0, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, buf1, buf2 class TLUNew(nn.Module): def __init__(self, num_features): """max(y, tau) = max(y - tau, 0) + tau = ReLU(y - tau) + tau""" super(TLUNew, self).__init__() self.num_features = num_features self.tau = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.zeros_(self.tau) def extra_repr(self): return 'num_features={num_features}'.format(**self.__dict__) def forward(self, input_0): primals_1 = self.tau primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
EkdeepSLubana/BeyondBatchNorm
TLU
false
17,241
[ "MIT" ]
10
2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
https://github.com/EkdeepSLubana/BeyondBatchNorm/tree/2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
Net
import torch import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.lin1 = nn.Linear(4, 50) self.lin2 = nn.Linear(50, 50) self.out = nn.Linear(50, 3) def forward(self, x): x = F.relu(self.lin1(x)) x = F.relu(self.lin2(x)) x = self.out(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 = 3200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 50 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (50, 4), (4, 1)) assert_size_stride(primals_2, (50,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (50, 50), (50, 1)) assert_size_stride(primals_5, (50,), (1,)) assert_size_stride(primals_6, (3, 50), (50, 1)) assert_size_stride(primals_7, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 50), (50, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 50), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 50), (800, 200, 50, 1), 0) del buf0 buf6 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(3200)](buf1, primals_2, buf6, 3200, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 50), (50, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 50), (50, 1), 0), reinterpret_tensor(primals_4, (50, 50), (1, 50), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 50), (800, 200, 50, 1), 0) del buf2 buf5 = empty_strided_cuda((4, 4, 4, 50), (800, 200, 50, 1), torch.bool) triton_poi_fused_relu_threshold_backward_0[grid(3200)](buf3, primals_5, buf5, 3200, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 3), (3, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 50), (50, 1), 0), reinterpret_tensor(primals_6, (50, 3), (1, 50), 0), alpha=1, beta=1, out=buf4) del primals_7 return reinterpret_tensor(buf4, (4, 4, 4, 3), (48, 12, 3, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 50), (50, 1), 0), reinterpret_tensor( buf3, (64, 50), (50, 1), 0), primals_6, buf5, primals_4, buf6 class NetNew(nn.Module): def __init__(self): super(NetNew, self).__init__() self.lin1 = nn.Linear(4, 50) self.lin2 = nn.Linear(50, 50) self.out = nn.Linear(50, 3) def forward(self, input_0): primals_1 = self.lin1.weight primals_2 = self.lin1.bias primals_4 = self.lin2.weight primals_5 = self.lin2.bias primals_6 = self.out.weight primals_7 = self.out.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
Elli1993/custom_net_on_movidius
Net
false
17,242
[ "MIT" ]
9
cd7ed784e6d38fe696c1ae1ff0e5a31d1b52c7dc
https://github.com/Elli1993/custom_net_on_movidius/tree/cd7ed784e6d38fe696c1ae1ff0e5a31d1b52c7dc
CoughNet
import torch class CoughNet(torch.nn.Module): def __init__(self, input_size): super(CoughNet, self).__init__() self.l1 = torch.nn.Linear(input_size, 512) self.l2 = torch.nn.Linear(512, 256) self.l3 = torch.nn.Linear(256, 128) self.l4 = torch.nn.Linear(128, 64) self.l5 = torch.nn.Linear(64, 10) self.l6 = torch.nn.Linear(10, 2) def forward(self, x): x = torch.relu(self.l1(x)) x = torch.relu(self.l2(x)) x = torch.relu(self.l3(x)) x = torch.relu(self.l4(x)) x = torch.relu(self.l5(x)) x = self.l6(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 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_4(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 640 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 10 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13) = args args.clear() assert_size_stride(primals_1, (512, 4), (4, 1)) assert_size_stride(primals_2, (512,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (256, 512), (512, 1)) assert_size_stride(primals_5, (256,), (1,)) assert_size_stride(primals_6, (128, 256), (256, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (64, 128), (128, 1)) assert_size_stride(primals_9, (64,), (1,)) assert_size_stride(primals_10, (10, 64), (64, 1)) assert_size_stride(primals_11, (10,), (1,)) assert_size_stride(primals_12, (2, 10), (10, 1)) assert_size_stride(primals_13, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 512), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 512), (8192, 2048, 512, 1), 0 ) del buf0 buf15 = empty_strided_cuda((4, 4, 4, 512), (8192, 2048, 512, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(32768)](buf1, primals_2, buf15, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 512), (512, 1), 0), reinterpret_tensor(primals_4, (512, 256), (1, 512), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf2 buf14 = 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, buf14, 16384, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 256), (256, 1), 0), reinterpret_tensor(primals_6, (256, 128), (1, 256), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf4 buf13 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(8192)](buf5, primals_7, buf13, 8192, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 128), (128, 1), 0), reinterpret_tensor(primals_8, (128, 64), (1, 128), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf6 buf12 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch .bool) triton_poi_fused_relu_threshold_backward_3[grid(4096)](buf7, primals_9, buf12, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf8 = empty_strided_cuda((64, 10), (10, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (64, 64), (64, 1), 0), reinterpret_tensor(primals_10, (64, 10), (1, 64), 0), out=buf8) buf9 = reinterpret_tensor(buf8, (4, 4, 4, 10), (160, 40, 10, 1), 0) del buf8 buf11 = empty_strided_cuda((4, 4, 4, 10), (160, 40, 10, 1), torch.bool) triton_poi_fused_relu_threshold_backward_4[grid(640)](buf9, primals_11, buf11, 640, XBLOCK=128, num_warps=4, num_stages=1) del primals_11 buf10 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_13, reinterpret_tensor(buf9, (64, 10), (10, 1), 0), reinterpret_tensor(primals_12, (10, 2), (1, 10), 0 ), alpha=1, beta=1, out=buf10) del primals_13 return (reinterpret_tensor(buf10, (4, 4, 4, 2), (32, 8, 2, 1), 0), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (64, 512), (512, 1), 0), reinterpret_tensor(buf3, (64, 256), (256, 1), 0), reinterpret_tensor(buf5, (64, 128), (128, 1), 0), reinterpret_tensor(buf7, (64, 64), (64, 1), 0), reinterpret_tensor( buf9, (64, 10), (10, 1), 0), primals_12, buf11, primals_10, buf12, primals_8, buf13, primals_6, buf14, primals_4, buf15) class CoughNetNew(torch.nn.Module): def __init__(self, input_size): super(CoughNetNew, self).__init__() self.l1 = torch.nn.Linear(input_size, 512) self.l2 = torch.nn.Linear(512, 256) self.l3 = torch.nn.Linear(256, 128) self.l4 = torch.nn.Linear(128, 64) self.l5 = torch.nn.Linear(64, 10) self.l6 = torch.nn.Linear(10, 2) def forward(self, input_0): primals_1 = self.l1.weight primals_2 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_6 = self.l3.weight primals_7 = self.l3.bias primals_8 = self.l4.weight primals_9 = self.l4.bias primals_10 = self.l5.weight primals_11 = self.l5.bias primals_12 = self.l6.weight primals_13 = self.l6.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]
DerWaldi/COVID-19-Cough-Classification
CoughNet
false
17,243
[ "MIT" ]
7
40f85133b0b8973c088dc2730c592af1b89b29b7
https://github.com/DerWaldi/COVID-19-Cough-Classification/tree/40f85133b0b8973c088dc2730c592af1b89b29b7
FRN_self
import torch import torch.nn as nn class FRN_self(nn.Module): def __init__(self, num_features, eps=1e-05, is_eps_learnable=True): super(FRN_self, self).__init__() self.num_features = num_features self.init_eps = eps self.is_eps_learnable = is_eps_learnable self.gamma = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.beta = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.eps = nn.Parameter(torch.Tensor(1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.ones_(self.gamma) nn.init.zeros_(self.beta) if self.is_eps_learnable: nn.init.constant_(self.eps, self.init_eps) def extra_repr(self): return 'num_features={num_features}, eps={init_eps}'.format(**self. __dict__) def forward(self, x): nu2 = x.pow(2).mean(dim=[2, 3], keepdim=True) x = x * torch.rsqrt(nu2 + self.eps.abs()) return self.gamma * x + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, 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_abs_add_mean_mul_pow_rsqrt_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp8 = tl.load(in_ptr1 + 0) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, 1]) tmp13 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp16 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last') tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = 16.0 tmp7 = tmp5 / tmp6 tmp10 = tl_math.abs(tmp9) tmp11 = tmp7 + tmp10 tmp12 = libdevice.rsqrt(tmp11) tmp14 = tmp0 * tmp12 tmp15 = tmp13 * tmp14 tmp17 = tmp15 + tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp12, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp17, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_4, (1, 4, 1, 1), (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) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_abs_add_mean_mul_pow_rsqrt_0[grid(16)](buf1, primals_1, primals_2, primals_3, primals_4, buf2, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_4 return buf2, primals_1, primals_2, primals_3, buf1 class FRN_selfNew(nn.Module): def __init__(self, num_features, eps=1e-05, is_eps_learnable=True): super(FRN_selfNew, self).__init__() self.num_features = num_features self.init_eps = eps self.is_eps_learnable = is_eps_learnable self.gamma = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.beta = nn.Parameter(torch.Tensor(1, num_features, 1, 1), requires_grad=True) self.eps = nn.Parameter(torch.Tensor(1), requires_grad=True) self.reset_parameters() def reset_parameters(self): nn.init.ones_(self.gamma) nn.init.zeros_(self.beta) if self.is_eps_learnable: nn.init.constant_(self.eps, self.init_eps) def extra_repr(self): return 'num_features={num_features}, eps={init_eps}'.format(**self. __dict__) def forward(self, input_0): primals_3 = self.gamma primals_4 = self.beta primals_2 = self.eps primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
EkdeepSLubana/BeyondBatchNorm
FRN_self
false
17,244
[ "MIT" ]
10
2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
https://github.com/EkdeepSLubana/BeyondBatchNorm/tree/2ab1626a1ebfdfe55f0a4bc6ac24c8bbdd4e0196
custom_embedding
import torch import torch.nn as nn import torch.nn.functional as F def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class custom_embedding(nn.Module): def __init__(self, input_size, output_size): super(custom_embedding, self).__init__() self.affine1 = mlp_layer(input_size, output_size) self.affine2 = mlp_layer(output_size, output_size) weight_init(self.affine1) weight_init(self.affine2) def forward(self, x): return self.affine2(self.affine1(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import 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_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, 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_tanh_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_tanh_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 def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class custom_embeddingNew(nn.Module): def __init__(self, input_size, output_size): super(custom_embeddingNew, self).__init__() self.affine1 = mlp_layer(input_size, output_size) self.affine2 = mlp_layer(output_size, output_size) weight_init(self.affine1) weight_init(self.affine2) def forward(self, input_0): primals_1 = self.affine1.affine.weight primals_2 = self.affine1.affine.bias primals_4 = self.affine2.affine.weight primals_5 = self.affine2.affine.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
EpiSci/SoCRATES
custom_embedding
false
17,245
[ "MIT" ]
6
901a896c5a765e3cb56f290188cde71c8707192d
https://github.com/EpiSci/SoCRATES/tree/901a896c5a765e3cb56f290188cde71c8707192d
ClassifierEnd
import torch import torch.nn as nn class ClassifierEnd(nn.Module): def __init__(self, num_classes: 'int'): super(ClassifierEnd, self).__init__() self.num_classes = num_classes self.fc_net1 = nn.Conv2d(21, self.num_classes, kernel_size=1, stride=1) self.fc_net2 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) self.fc_net3 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) self.fc_net4 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) assert self.num_classes > 0, 'The number of classes must be a positive integer.' if self.num_classes > 1: self.final = nn.Softmax() else: self.final = nn.Sigmoid() def forward(self, x): out = self.fc_net1(x) out = self.fc_net2(out) out = self.fc_net3(out) out = self.fc_net4(out) out = self.final(out) return out def get_inputs(): return [torch.rand([4, 21, 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 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 % 4 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__softmax_convolution_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 4096 x1 = xindex // 4096 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16384 * x1), None) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr0 + (4096 + x0 + 16384 * x1), None) tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp9 = tl.load(in_ptr0 + (8192 + x0 + 16384 * x1), None) tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (12288 + x0 + 16384 * x1), None) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp7 = tmp4 + tmp6 tmp8 = triton_helpers.maximum(tmp3, tmp7) tmp12 = tmp9 + tmp11 tmp13 = triton_helpers.maximum(tmp8, tmp12) tmp17 = tmp14 + tmp16 tmp18 = triton_helpers.maximum(tmp13, tmp17) tmp19 = tmp3 - tmp18 tmp20 = tl_math.exp(tmp19) tmp21 = tmp7 - tmp18 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tmp12 - tmp18 tmp25 = tl_math.exp(tmp24) tmp26 = tmp23 + tmp25 tmp27 = tmp17 - tmp18 tmp28 = tl_math.exp(tmp27) tmp29 = tmp26 + tmp28 tl.store(out_ptr0 + x2, tmp18, None) tl.store(out_ptr1 + x2, tmp29, None) @triton.jit def triton_poi_fused__softmax_convolution_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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 % 4 x0 = xindex % 4096 x2 = xindex // 16384 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr2 + (x0 + 4096 * x2), None, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(in_out_ptr0 + x3, tmp7, 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, (4, 21, 1, 1), (21, 1, 1, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 21, 64, 64), (86016, 4096, 64, 1)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_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, 64, 64), (16384, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(65536)](buf1, primals_2, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 64, 64), (16384, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(65536)](buf3, primals_5, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 64, 64), (16384, 4096, 64, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_0[grid(65536)](buf5, primals_7, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 64, 64), (16384, 4096, 64, 1)) buf7 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) buf8 = empty_strided_cuda((4, 1, 64, 64), (4096, 16384, 64, 1), torch.float32) triton_poi_fused__softmax_convolution_1[grid(16384)](buf6, primals_9, buf7, buf8, 16384, XBLOCK=256, num_warps=4, num_stages=1 ) buf9 = buf6 del buf6 triton_poi_fused__softmax_convolution_2[grid(65536)](buf9, primals_9, buf7, buf8, 65536, XBLOCK=256, num_warps=4, num_stages=1 ) del buf7 del buf8 del primals_9 return (buf9, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf3, buf5, buf9) class ClassifierEndNew(nn.Module): def __init__(self, num_classes: 'int'): super(ClassifierEndNew, self).__init__() self.num_classes = num_classes self.fc_net1 = nn.Conv2d(21, self.num_classes, kernel_size=1, stride=1) self.fc_net2 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) self.fc_net3 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) self.fc_net4 = nn.Conv2d(self.num_classes, self.num_classes, kernel_size=1, stride=1) assert self.num_classes > 0, 'The number of classes must be a positive integer.' if self.num_classes > 1: self.final = nn.Softmax() else: self.final = nn.Sigmoid() def forward(self, input_0): primals_1 = self.fc_net1.weight primals_2 = self.fc_net1.bias primals_4 = self.fc_net2.weight primals_5 = self.fc_net2.bias primals_6 = self.fc_net3.weight primals_7 = self.fc_net3.bias primals_8 = self.fc_net4.weight primals_9 = self.fc_net4.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]
EadCat/Road-Extraction
ClassifierEnd
false
17,246
[ "MIT" ]
4
9d4831b6c3a5ef07676cbe1c79b03045fda427ea
https://github.com/EadCat/Road-Extraction/tree/9d4831b6c3a5ef07676cbe1c79b03045fda427ea
CoordConv2D
import torch from torch import nn class CoordConv2D(nn.Module): def __init__(self, in_channels: 'int', out_channels: 'int', kernel_size: 'int'=3, stride: 'int'=1, padding: 'int'=1, with_r: 'bool'=False): super().__init__() self.in_channel = in_channels self.with_r = with_r self.conv = nn.Conv2d(in_channels=in_channels + (2 if not with_r else 3), out_channels=out_channels, kernel_size=kernel_size, stride= stride, padding=padding) def forward(self, input_tensor: 'torch.Tensor'): batch_size, _, y_dim, x_dim = input_tensor.size() xx_channel = torch.arange(x_dim).repeat(1, y_dim, 1) yy_channel = torch.arange(y_dim).repeat(1, x_dim, 1).transpose(1, 2) xx_channel = xx_channel.float() / (x_dim - 1) * 2.0 - 1.0 yy_channel = yy_channel.float() / (y_dim - 1) * 2.0 - 1.0 xx_channel = xx_channel.repeat(batch_size, 1, 1, 1) yy_channel = yy_channel.repeat(batch_size, 1, 1, 1) x = torch.cat([input_tensor, xx_channel.type_as(input_tensor), yy_channel.type_as(input_tensor)], dim=1) if self.with_r: rr = torch.sqrt(torch.pow(xx_channel.type_as(input_tensor) - 0.5, 2) + torch.pow(yy_channel.type_as(input_tensor) - 0.5, 2)) x = torch.cat([x, rr], dim=1) x = self.conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 16 % 6 x3 = xindex // 96 x4 = xindex % 16 x0 = xindex % 4 x1 = xindex // 4 % 4 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 64 * x3), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tmp7 = tl.full([1], 5, tl.int64) tmp8 = tmp0 < tmp7 tmp9 = tmp6 & tmp8 tmp10 = x0 tmp11 = tmp10.to(tl.float32) tmp12 = 0.3333333333333333 tmp13 = tmp11 * tmp12 tmp14 = 2.0 tmp15 = tmp13 * tmp14 tmp16 = 1.0 tmp17 = tmp15 - tmp16 tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype) tmp19 = tl.where(tmp9, tmp17, tmp18) tmp20 = tmp0 >= tmp7 tl.full([1], 6, tl.int64) tmp23 = x1 tmp24 = tmp23.to(tl.float32) tmp25 = tmp24 * tmp12 tmp26 = tmp25 * tmp14 tmp27 = tmp26 - tmp16 tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype) tmp29 = tl.where(tmp20, tmp27, tmp28) tmp30 = tl.where(tmp9, tmp19, tmp29) tmp31 = tl.where(tmp4, tmp5, tmp30) tl.store(out_ptr0 + x5, tmp31, 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 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 6, 3, 3), (54, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 6, 4, 4), (96, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(384)](primals_1, buf0, 384, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class CoordConv2DNew(nn.Module): def __init__(self, in_channels: 'int', out_channels: 'int', kernel_size: 'int'=3, stride: 'int'=1, padding: 'int'=1, with_r: 'bool'=False): super().__init__() self.in_channel = in_channels self.with_r = with_r self.conv = nn.Conv2d(in_channels=in_channels + (2 if not with_r else 3), out_channels=out_channels, kernel_size=kernel_size, stride= stride, padding=padding) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
EasternJournalist/pi-GAN
CoordConv2D
false
17,247
[ "MIT" ]
4
3d57611e1c8fca2f3cd00fde1989ec1f9dd94d55
https://github.com/EasternJournalist/pi-GAN/tree/3d57611e1c8fca2f3cd00fde1989ec1f9dd94d55
DoubleSymLayer
import copy import math import torch import torch.nn as nn def normalInit(dims): """ Essentially, PyTorch's init.xavier_normal_ but clamped :param K: tensor to be initialized/overwritten :return: initialized tensor on the device in the nn.Parameter wrapper """ K = torch.zeros(dims) fan_in, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(K) sd = math.sqrt(2.0 / (fan_in + fan_out)) with torch.no_grad(): K = K.normal_(0, sd) K = torch.clamp(K, min=-2 * sd, max=2 * sd) return K def regMetric(x, y): return torch.norm(x - y, p=1) class ClippedModule(nn.Module): """ Extend nn.Module to include max and min values for bound constraints / clipping """ def __init__(self): super().__init__() self.minConv = -0.5 self.maxConv = 0.5 self.minDef = -1.5 self.maxDef = 1.5 def setClipValues(self, minConv=-0.5, maxConv=0.5, minDef=-1.5, maxDef=1.5 ): """ set box constraints :param minConv: float, lower bound for convolutions :param maxConv: float, upper bound for convolutions :param minDef: float, lower bound for all other parameters :param maxDef: float, upper bound for all other parameters """ self.minConv = minConv self.maxConv = maxConv self.minDef = minDef self.maxDef = maxDef def calcClipValues(self, h, nPixels, nChan): """ calculation for setting bound constraints....not tuned yet""" mult = 1 / h mult = mult / math.sqrt(nPixels) mult = mult * (500 / nChan ** 2) minConv = -1 maxConv = 1 self.setClipValues(minConv=mult * minConv, maxConv=mult * maxConv, minDef=-1.5, maxDef=1.5) def clip(self): """project values onto box constraints""" if hasattr(self, 'conv'): self.conv.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv.bias is not None: self.conv.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv1'): self.conv1.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv1.bias is not None: self.conv1.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv2'): self.conv2.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv2.bias is not None: self.conv2.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'weight'): w = self.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for module in self.children(): if hasattr(module, 'clip'): module.clip() else: if hasattr(module, 'weight'): w = module.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for child in module.children(): if hasattr(child, 'clip'): child.clip() return self class DoubleSymLayer(ClippedModule): """ Implementation of the double symmetric layer, also referred to as a Parabolic Layer. - K^T ( act( N( K(Y)))) Attributes: conv (sub-module): convolution class, default is 3x3 2Dconvolution act (sub-module): activation function, default is ReLU() normLayer (sub-module): normalization with affine bias and weight, default is no normalization Typical attributes for the children: conv.weight (Parameter): dims (nChanOut,nChanIn,3,3) for default 2DConvolution from nChanIn -> nChanOut channels conv.bias (Parameter): vector, dims (nChanIn) normLayer.weight (Parameter): vector, dims (nChanOut) affine scaling normLayer.bias (Parameter): vector, dims (nChanOut) affine scaling bias """ def __init__(self, vFeat, params={}): super().__init__() if type(vFeat) is not list: vFeat = [vFeat, vFeat] nChanIn = vFeat[0] nChanOut = vFeat[1] szKernel = 3 stride = 1 padding = 1 self.conv = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.act = nn.ReLU() if 'conv' in params.keys(): self.conv = copy.deepcopy(params.get('conv')) szKernel = self.conv.kernel_size[0] stride = self.conv.stride padding = self.conv.padding if 'szKernel' in params.keys(): szKernel = params.get('szKernel') if 'act' in params.keys(): self.act = params.get('act') if 'normLayer' in params.keys(): self.normLayer = copy.deepcopy(params.get('normLayer')) self.normLayer.weight.data = torch.ones(nChanOut) self.convt = nn.ConvTranspose2d(in_channels=nChanOut, kernel_size= szKernel, out_channels=nChanIn, stride=stride, padding=padding) self.weight = nn.Parameter(normalInit([vFeat[1], vFeat[0], szKernel, szKernel]), requires_grad=True) self.conv.weight = self.weight self.convt.weight = self.weight if self.conv.bias is not None: self.conv.bias.data *= 0 if self.convt.bias is not None: self.convt.bias.data *= 0 def forward(self, x): z = self.conv(x) if hasattr(self, 'normLayer'): z = self.normLayer(z) z = self.act(z) z = -self.convt(z) return z def calcClipValues(self, h, nPixels, nChan): """DoubleSym should have bound constraints half of those in DoubleLayer""" super().calcClipValues(h, nPixels, nChan) self.minConv = 0.5 * self.minConv self.maxConv = 0.5 * self.maxConv def weight_variance(self, other): """apply regularization in time""" value = 0 value += regMetric(nn.utils.convert_parameters.parameters_to_vector (self.parameters()), nn.utils.convert_parameters. parameters_to_vector(other.parameters())) return value def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'vFeat': 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 copy import math import torch.nn as 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_convolution_neg_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = -tmp2 tl.store(in_out_ptr0 + x3, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = 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,), (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_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=True, 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_convolution_neg_1[grid(256)](buf3, primals_4, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 return buf3, primals_1, primals_3, buf1 def normalInit(dims): """ Essentially, PyTorch's init.xavier_normal_ but clamped :param K: tensor to be initialized/overwritten :return: initialized tensor on the device in the nn.Parameter wrapper """ K = torch.zeros(dims) fan_in, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(K) sd = math.sqrt(2.0 / (fan_in + fan_out)) with torch.no_grad(): K = K.normal_(0, sd) K = torch.clamp(K, min=-2 * sd, max=2 * sd) return K def regMetric(x, y): return torch.norm(x - y, p=1) class ClippedModule(nn.Module): """ Extend nn.Module to include max and min values for bound constraints / clipping """ def __init__(self): super().__init__() self.minConv = -0.5 self.maxConv = 0.5 self.minDef = -1.5 self.maxDef = 1.5 def setClipValues(self, minConv=-0.5, maxConv=0.5, minDef=-1.5, maxDef=1.5 ): """ set box constraints :param minConv: float, lower bound for convolutions :param maxConv: float, upper bound for convolutions :param minDef: float, lower bound for all other parameters :param maxDef: float, upper bound for all other parameters """ self.minConv = minConv self.maxConv = maxConv self.minDef = minDef self.maxDef = maxDef def calcClipValues(self, h, nPixels, nChan): """ calculation for setting bound constraints....not tuned yet""" mult = 1 / h mult = mult / math.sqrt(nPixels) mult = mult * (500 / nChan ** 2) minConv = -1 maxConv = 1 self.setClipValues(minConv=mult * minConv, maxConv=mult * maxConv, minDef=-1.5, maxDef=1.5) def clip(self): """project values onto box constraints""" if hasattr(self, 'conv'): self.conv.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv.bias is not None: self.conv.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv1'): self.conv1.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv1.bias is not None: self.conv1.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv2'): self.conv2.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv2.bias is not None: self.conv2.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'weight'): w = self.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for module in self.children(): if hasattr(module, 'clip'): module.clip() else: if hasattr(module, 'weight'): w = module.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for child in module.children(): if hasattr(child, 'clip'): child.clip() return self class DoubleSymLayerNew(ClippedModule): """ Implementation of the double symmetric layer, also referred to as a Parabolic Layer. - K^T ( act( N( K(Y)))) Attributes: conv (sub-module): convolution class, default is 3x3 2Dconvolution act (sub-module): activation function, default is ReLU() normLayer (sub-module): normalization with affine bias and weight, default is no normalization Typical attributes for the children: conv.weight (Parameter): dims (nChanOut,nChanIn,3,3) for default 2DConvolution from nChanIn -> nChanOut channels conv.bias (Parameter): vector, dims (nChanIn) normLayer.weight (Parameter): vector, dims (nChanOut) affine scaling normLayer.bias (Parameter): vector, dims (nChanOut) affine scaling bias """ def __init__(self, vFeat, params={}): super().__init__() if type(vFeat) is not list: vFeat = [vFeat, vFeat] nChanIn = vFeat[0] nChanOut = vFeat[1] szKernel = 3 stride = 1 padding = 1 self.conv = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.act = nn.ReLU() if 'conv' in params.keys(): self.conv = copy.deepcopy(params.get('conv')) szKernel = self.conv.kernel_size[0] stride = self.conv.stride padding = self.conv.padding if 'szKernel' in params.keys(): szKernel = params.get('szKernel') if 'act' in params.keys(): self.act = params.get('act') if 'normLayer' in params.keys(): self.normLayer = copy.deepcopy(params.get('normLayer')) self.normLayer.weight.data = torch.ones(nChanOut) self.convt = nn.ConvTranspose2d(in_channels=nChanOut, kernel_size= szKernel, out_channels=nChanIn, stride=stride, padding=padding) self.weight = nn.Parameter(normalInit([vFeat[1], vFeat[0], szKernel, szKernel]), requires_grad=True) self.conv.weight = self.weight self.convt.weight = self.weight if self.conv.bias is not None: self.conv.bias.data *= 0 if self.convt.bias is not None: self.convt.bias.data *= 0 def calcClipValues(self, h, nPixels, nChan): """DoubleSym should have bound constraints half of those in DoubleLayer""" super().calcClipValues(h, nPixels, nChan) self.minConv = 0.5 * self.minConv self.maxConv = 0.5 * self.maxConv def weight_variance(self, other): """apply regularization in time""" value = 0 value += regMetric(nn.utils.convert_parameters.parameters_to_vector (self.parameters()), nn.utils.convert_parameters. parameters_to_vector(other.parameters())) return value def forward(self, input_0): primals_1 = self.weight primals_2 = self.conv.bias primals_4 = self.convt.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
EmoryMLIP/DynamicBlocks
DoubleSymLayer
false
17,248
[ "MIT" ]
9
52acc9fbc1a2640c6ac8922fa18105279ccaea97
https://github.com/EmoryMLIP/DynamicBlocks/tree/52acc9fbc1a2640c6ac8922fa18105279ccaea97
MolDQN
import torch import torch.nn as nn class MolDQN(nn.Module): def __init__(self, input_length, output_length): super(MolDQN, self).__init__() self.linear_1 = nn.Linear(input_length, 1024) self.linear_2 = nn.Linear(1024, 512) self.linear_3 = nn.Linear(512, 128) self.linear_4 = nn.Linear(128, 32) self.linear_5 = nn.Linear(32, output_length) self.activation = nn.ReLU() def forward(self, x): x = self.activation(self.linear_1(x)) x = self.activation(self.linear_2(x)) x = self.activation(self.linear_3(x)) x = self.activation(self.linear_4(x)) x = self.linear_5(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_length': 4, 'output_length': 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 % 1024 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) 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 % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 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) 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, (1024, 4), (4, 1)) assert_size_stride(primals_2, (1024,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (512, 1024), (1024, 1)) assert_size_stride(primals_5, (512,), (1,)) assert_size_stride(primals_6, (128, 512), (512, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (32, 128), (128, 1)) assert_size_stride(primals_9, (32,), (1,)) assert_size_stride(primals_10, (4, 32), (32, 1)) assert_size_stride(primals_11, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1024), (1024, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1024), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 1024), (16384, 4096, 1024, 1), 0) del buf0 buf12 = empty_strided_cuda((4, 4, 4, 1024), (16384, 4096, 1024, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(65536)](buf1, primals_2, buf12, 65536, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 1024), (1024, 1), 0 ), reinterpret_tensor(primals_4, (1024, 512), (1, 1024), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 512), (8192, 2048, 512, 1), 0 ) del buf2 buf11 = empty_strided_cuda((4, 4, 4, 512), (8192, 2048, 512, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(32768)](buf3, primals_5, buf11, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 512), (512, 1), 0), reinterpret_tensor(primals_6, (512, 128), (1, 512), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf4 buf10 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(8192)](buf5, primals_7, buf10, 8192, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 128), (128, 1), 0), reinterpret_tensor(primals_8, (128, 32), (1, 128), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 32), (512, 128, 32, 1), 0) del buf6 buf9 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.bool) triton_poi_fused_relu_threshold_backward_3[grid(2048)](buf7, primals_9, buf9, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf8 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf7, (64, 32), (32, 1), 0), reinterpret_tensor(primals_10, (32, 4), (1, 32), 0 ), alpha=1, beta=1, out=buf8) del primals_11 return reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 1024), (1024, 1), 0 ), reinterpret_tensor(buf3, (64, 512), (512, 1), 0 ), reinterpret_tensor(buf5, (64, 128), (128, 1), 0 ), reinterpret_tensor(buf7, (64, 32), (32, 1), 0 ), primals_10, buf9, primals_8, buf10, primals_6, buf11, primals_4, buf12 class MolDQNNew(nn.Module): def __init__(self, input_length, output_length): super(MolDQNNew, self).__init__() self.linear_1 = nn.Linear(input_length, 1024) self.linear_2 = nn.Linear(1024, 512) self.linear_3 = nn.Linear(512, 128) self.linear_4 = nn.Linear(128, 32) self.linear_5 = nn.Linear(32, output_length) self.activation = nn.ReLU() def forward(self, input_0): primals_1 = self.linear_1.weight primals_2 = self.linear_1.bias primals_4 = self.linear_2.weight primals_5 = self.linear_2.bias primals_6 = self.linear_3.weight primals_7 = self.linear_3.bias primals_8 = self.linear_4.weight primals_9 = self.linear_4.bias primals_10 = self.linear_5.weight primals_11 = self.linear_5.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
EXJUSTICE/MolDQN-pytorch
MolDQN
false
17,249
[ "MIT" ]
4
86828f898461e9f7722ac8a1e0b9fede2c45afe0
https://github.com/EXJUSTICE/MolDQN-pytorch/tree/86828f898461e9f7722ac8a1e0b9fede2c45afe0
Attention
import torch import torch.nn as nn def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class Attention(nn.Module): def __init__(self, hidden_size, query_size, use_softmax=False): super(Attention, self).__init__() self.use_softmax = use_softmax self.W_query = nn.Linear(query_size, hidden_size, bias=True) self.W_ref = nn.Linear(hidden_size, hidden_size, bias=False) V = torch.normal(torch.zeros(hidden_size), 0.0001) self.V = nn.Parameter(V) weight_init(V) weight_init(self.W_query) weight_init(self.W_ref) def forward(self, query, ref): """ Args: query: [hidden_size] ref: [seq_len x hidden_size] """ ref.size(0) query = self.W_query(query) _ref = self.W_ref(ref) m = torch.tanh(query + _ref) logits = torch.matmul(m, self.V) if self.use_softmax: logits = torch.softmax(logits, dim=0) else: logits = logits return logits def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'query_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_add_tanh_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = libdevice.tanh(tmp4) tl.store(in_out_ptr0 + x2, tmp5, xmask) @triton.jit def triton_poi_fused_mv_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp4 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp9 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp14 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK]) tmp3 = tmp0 * tmp2 tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp12 = tmp9 * tmp11 tmp13 = tmp8 + tmp12 tmp17 = tmp14 * tmp16 tmp18 = tmp13 + tmp17 tl.store(out_ptr0 + x0, tmp18, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf1) del primals_5 buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_add_tanh_0[grid(256)](buf2, primals_3, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_3 buf3 = empty_strided_cuda((64,), (1,), torch.float32) triton_poi_fused_mv_1[grid(64)](buf2, primals_6, buf3, 64, XBLOCK= 64, num_warps=1, num_stages=1) return reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0 ), primals_6, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), buf2 def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class AttentionNew(nn.Module): def __init__(self, hidden_size, query_size, use_softmax=False): super(AttentionNew, self).__init__() self.use_softmax = use_softmax self.W_query = nn.Linear(query_size, hidden_size, bias=True) self.W_ref = nn.Linear(hidden_size, hidden_size, bias=False) V = torch.normal(torch.zeros(hidden_size), 0.0001) self.V = nn.Parameter(V) weight_init(V) weight_init(self.W_query) weight_init(self.W_ref) def forward(self, input_0, input_1): primals_3 = self.V primals_2 = self.W_query.weight primals_6 = self.W_query.bias primals_5 = self.W_ref.weight primals_1 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
EpiSci/SoCRATES
Attention
false
17,250
[ "MIT" ]
6
901a896c5a765e3cb56f290188cde71c8707192d
https://github.com/EpiSci/SoCRATES/tree/901a896c5a765e3cb56f290188cde71c8707192d
LinearAttention
import torch from torch import nn class LinearAttention(nn.Module): def __init__(self, dim, heads=4, dim_head=32): super().__init__() self.heads = heads self.dim_head = dim_head self.hidden_dim = dim_head * heads self.to_qkv = nn.Conv2d(dim, self.hidden_dim * 3, 1, bias=False) self.to_out = nn.Conv2d(self.hidden_dim, dim, 1) def forward(self, x): b, _, h, w = x.shape qkv = self.to_qkv(x) qkv = qkv.reshape(b, 3, self.heads, self.dim_head, h * w) q, k, v = qkv[:, 0], qkv[:, 1], qkv[:, 2] k = k.softmax(dim=-1) context = torch.matmul(k, v.permute(0, 1, 3, 2)) out = torch.matmul(context.permute(0, 1, 3, 2), q) out = out.reshape(b, -1, h, w) return self.to_out(out) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask) tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask) @triton.jit def triton_per_fused__softmax_1(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 512 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 128 x1 = xindex // 128 x3 = xindex tmp0 = tl.load(in_ptr0 + (128 + x0 + 384 * r2 + 6144 * x1), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp10, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 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] xmask = xindex < xnumel x2 = xindex % 16 x3 = xindex // 16 y0 = yindex % 4 y1 = yindex // 4 y4 = yindex x5 = xindex tmp0 = tl.load(in_ptr0 + (128 + x3 + 32 * y0 + 384 * x2 + 6144 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x3 + 32 * y4), xmask & ymask, eviction_policy ='evict_last') tmp4 = tl.load(in_ptr2 + (x3 + 32 * y4), xmask & ymask, eviction_policy ='evict_last') tmp2 = tmp0 - tmp1 tmp3 = tl_math.exp(tmp2) tmp5 = tmp3 / tmp4 tl.store(out_ptr0 + (y0 + 4 * x5 + 2048 * y1), tmp5, xmask & ymask) @triton.jit def triton_poi_fused_bmm_3(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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (4 * x1 + 2048 * (x0 // 4) + x0 % 4), None) tl.store(out_ptr0 + x2, tmp0, None) @triton.jit def triton_poi_fused_clone_4(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 % 32 x1 = xindex // 32 % 16 x2 = xindex // 512 % 4 x3 = xindex // 2048 x4 = xindex tmp0 = tl.load(in_ptr0 + (256 + x0 + 32 * x2 + 384 * x1 + 6144 * x3), None) tl.store(out_ptr0 + x4, tmp0, None) @triton.jit def triton_poi_fused_clone_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 512 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 128 y1 = yindex // 128 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 384 * x2 + 6144 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 16 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_view_6(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 512 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 128 * x2 + 2048 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_7(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask) tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (384, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (4, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(16, 16)](primals_1, buf0, 16, 16, XBLOCK=16, YBLOCK=16, 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, 384, 4, 4), (6144, 1, 1536, 384)) buf2 = empty_strided_cuda((4, 4, 32, 1), (128, 32, 1, 512), torch. float32) buf3 = empty_strided_cuda((4, 4, 32, 1), (128, 32, 1, 512), torch. float32) triton_per_fused__softmax_1[grid(512)](buf1, buf2, buf3, 512, 16, XBLOCK=8, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4, 4, 32, 16), (2048, 1, 64, 4), torch. float32) triton_poi_fused__softmax_2[grid(16, 512)](buf1, buf2, buf3, buf4, 16, 512, XBLOCK=256, YBLOCK=1, num_warps=4, num_stages=1) del buf2 del buf3 buf5 = empty_strided_cuda((16, 32, 16), (1, 256, 16), torch.float32) triton_poi_fused_bmm_3[grid(8192)](buf4, buf5, 8192, XBLOCK=128, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((4, 4, 16, 32), (2048, 512, 32, 1), torch .float32) triton_poi_fused_clone_4[grid(8192)](buf1, buf6, 8192, XBLOCK=256, num_warps=4, num_stages=1) buf7 = empty_strided_cuda((16, 32, 32), (1024, 32, 1), torch.float32) extern_kernels.bmm(buf5, reinterpret_tensor(buf6, (16, 16, 32), ( 512, 32, 1), 0), out=buf7) buf8 = reinterpret_tensor(buf5, (4, 4, 32, 16), (2048, 512, 16, 1), 0) del buf5 triton_poi_fused_clone_5[grid(512, 16)](buf1, buf8, 512, 16, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del buf1 buf9 = empty_strided_cuda((16, 32, 16), (512, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf7, (16, 32, 32), (1024, 1, 32), 0), reinterpret_tensor(buf8, (16, 32, 16), (512, 16, 1), 0 ), out=buf9) buf10 = empty_strided_cuda((4, 128, 4, 4), (2048, 1, 512, 128), torch.float32) triton_poi_fused_view_6[grid(512, 16)](buf9, buf10, 512, 16, XBLOCK =16, YBLOCK=64, num_warps=4, num_stages=1) del buf9 buf11 = extern_kernels.convolution(buf10, primals_3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 4, 4, 4), (64, 1, 16, 4)) buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_convolution_7[grid(16, 16)](buf11, primals_4, buf12, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del buf11 del primals_4 return (buf12, buf0, primals_2, primals_3, buf4, buf10, buf7, reinterpret_tensor(buf8, (16, 16, 32), (512, 1, 16), 0), reinterpret_tensor(buf6, (16, 32, 16), (512, 1, 32), 0)) class LinearAttentionNew(nn.Module): def __init__(self, dim, heads=4, dim_head=32): super().__init__() self.heads = heads self.dim_head = dim_head self.hidden_dim = dim_head * heads self.to_qkv = nn.Conv2d(dim, self.hidden_dim * 3, 1, bias=False) self.to_out = nn.Conv2d(self.hidden_dim, dim, 1) def forward(self, input_0): primals_2 = self.to_qkv.weight primals_3 = self.to_out.weight primals_4 = self.to_out.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
DavidRuhe/simple-variational-diffusion-models
LinearAttention
false
17,251
[ "MIT" ]
4
a32355bf052a8f08e9c1919080588d0b22c8de4e
https://github.com/DavidRuhe/simple-variational-diffusion-models/tree/a32355bf052a8f08e9c1919080588d0b22c8de4e
EltwiseSubEmbed
import torch from torch import nn class EltwiseSubEmbed(nn.Module): def __init__(self, nonlinearity='square', use_batch_norm=False, use_classifier=False, num_features=0, num_classes=0): super(EltwiseSubEmbed, self).__init__() self.nonlinearity = nonlinearity if nonlinearity is not None and nonlinearity not in ['square', 'abs']: raise KeyError('Unknown nonlinearity:', nonlinearity) self.use_batch_norm = use_batch_norm self.use_classifier = use_classifier if self.use_batch_norm: self.bn = nn.BatchNorm1d(num_features) self.bn.weight.data.fill_(1) self.bn.bias.data.zero_() if self.use_classifier: assert num_features > 0 and num_classes > 0 self.classifier = nn.Linear(num_features, num_classes) self.classifier.weight.data.normal_(0, 0.001) self.classifier.bias.data.zero_() def forward(self, x1, x2): x = x1 - x2 if self.nonlinearity == 'square': x = x.pow(2) elif self.nonlinearity == 'abs': x = x.abs() if self.use_batch_norm: x = self.bn(x) if self.use_classifier: x = x.view(x.size(0), -1) x = self.classifier(x) else: x = x.sum(1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_pow_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask) tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask) tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask) tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp16 * tmp16 tmp18 = tmp13 + tmp17 tl.store(out_ptr0 + x2, tmp18, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_pow_sub_sum_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return buf0, class EltwiseSubEmbedNew(nn.Module): def __init__(self, nonlinearity='square', use_batch_norm=False, use_classifier=False, num_features=0, num_classes=0): super(EltwiseSubEmbedNew, self).__init__() self.nonlinearity = nonlinearity if nonlinearity is not None and nonlinearity not in ['square', 'abs']: raise KeyError('Unknown nonlinearity:', nonlinearity) self.use_batch_norm = use_batch_norm self.use_classifier = use_classifier if self.use_batch_norm: self.bn = nn.BatchNorm1d(num_features) self.bn.weight.data.fill_(1) self.bn.bias.data.zero_() if self.use_classifier: assert num_features > 0 and num_classes > 0 self.classifier = nn.Linear(num_features, num_classes) self.classifier.weight.data.normal_(0, 0.001) self.classifier.bias.data.zero_() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Event0511/curling-reid
EltwiseSubEmbed
false
17,252
[ "Apache-2.0" ]
3
1494d0faeed951e495573c694362f001df5bf6fd
https://github.com/Event0511/curling-reid/tree/1494d0faeed951e495573c694362f001df5bf6fd
SNRNetwork
import torch from torch import nn class PositiveLinear(nn.Module): def __init__(self, in_features: 'int', out_features: 'int') ->None: super().__init__() self.weight = nn.Parameter(torch.randn(in_features, out_features)) self.bias = nn.Parameter(torch.zeros(out_features)) self.softplus = nn.Softplus() def forward(self, input: 'torch.Tensor'): return input @ self.softplus(self.weight) + self.softplus(self.bias) class SNRNetwork(nn.Module): def __init__(self) ->None: super().__init__() self.l1 = PositiveLinear(1, 1) self.l2 = PositiveLinear(1, 1024) self.l3 = PositiveLinear(1024, 1) self.gamma_min = nn.Parameter(torch.tensor(-10.0)) self.gamma_max = nn.Parameter(torch.tensor(20.0)) self.softplus = nn.Softplus() def forward(self, t: 'torch.Tensor'): t = torch.cat([torch.tensor([0.0, 1.0], device=t.device), t]) l1 = self.l1(t[:, None]) l2 = torch.sigmoid(self.l2(l1)) l3 = torch.squeeze(l1 + self.l3(l2), dim=-1) s0, s1, sched = l3[0], l3[1], l3[2:] norm_nlogsnr = (sched - s0) / (s1 - s0) nlogsnr = self.gamma_min + self.softplus(self.gamma_max) * norm_nlogsnr return -nlogsnr, norm_nlogsnr def get_inputs(): return [torch.rand([4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 1, tl.int64) tmp6 = tmp0 < tmp5 tmp7 = 0.0 tmp8 = 1.0 tmp9 = tl.where(tmp6, tmp7, tmp8) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 6, tl.int64) tmp15 = tl.load(in_ptr0 + (-2 + x0), tmp12 & xmask, eviction_policy= 'evict_last', other=0.0) tmp16 = tl.where(tmp4, tmp11, tmp15) tl.store(out_ptr0 + x0, tmp16, xmask) @triton.jit def triton_poi_fused_softplus_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 20.0 tmp5 = tmp3 > tmp4 tmp6 = tl_math.exp(tmp3) tmp7 = libdevice.log1p(tmp6) tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp5, tmp1, tmp8) tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp9, None) @triton.jit def triton_poi_fused_softplus_2(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 = 1.0 tmp2 = tmp0 * tmp1 tmp3 = 20.0 tmp4 = tmp2 > tmp3 tmp5 = tl_math.exp(tmp2) tmp6 = libdevice.log1p(tmp5) tmp7 = tmp6 * tmp1 tmp8 = tl.where(tmp4, tmp0, tmp7) tl.store(out_ptr0 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_sigmoid_softplus_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 1024 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = 20.0 tmp5 = tmp3 > tmp4 tmp6 = tl_math.exp(tmp3) tmp7 = libdevice.log1p(tmp6) tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp5, tmp1, tmp8) tmp10 = tmp0 + tmp9 tmp11 = tl.sigmoid(tmp10) tl.store(in_out_ptr0 + x2, tmp11, None) @triton.jit def triton_poi_fused_sub_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) tmp0 = tl.load(in_ptr0 + 1) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + 1) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp4 = tl.load(in_ptr2 + 0) tmp5 = tl.broadcast_to(tmp4, [XBLOCK]) tmp16 = tl.load(in_ptr0 + 0) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp18 = tl.load(in_ptr1 + 0) tmp19 = tl.broadcast_to(tmp18, [XBLOCK]) tmp6 = 1.0 tmp7 = tmp5 * tmp6 tmp8 = 20.0 tmp9 = tmp7 > tmp8 tmp10 = tl_math.exp(tmp7) tmp11 = libdevice.log1p(tmp10) tmp12 = tmp11 * tmp6 tmp13 = tl.where(tmp9, tmp5, tmp12) tmp14 = tmp3 + tmp13 tmp15 = tmp1 + tmp14 tmp20 = tmp19 + tmp13 tmp21 = tmp17 + tmp20 tmp22 = tmp15 - tmp21 tl.store(out_ptr0 + tl.full([XBLOCK], 0, tl.int32), tmp22, None) @triton.jit def triton_poi_fused_add_div_mul_neg_softplus_sub_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr1, out_ptr2, out_ptr3, 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) tmp1 = tl.load(in_ptr1 + (2 + x0), xmask) tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp14 = tl.load(in_ptr0 + 0) tmp15 = tl.broadcast_to(tmp14, [XBLOCK]) tmp16 = tl.load(in_ptr1 + 0) tmp17 = tl.broadcast_to(tmp16, [XBLOCK]) tmp21 = tl.load(in_ptr3 + 0) tmp22 = tl.broadcast_to(tmp21, [XBLOCK]) tmp25 = tl.load(in_ptr4 + 0) tmp26 = tl.broadcast_to(tmp25, [XBLOCK]) tmp27 = tl.load(in_ptr5 + 0) tmp28 = tl.broadcast_to(tmp27, [XBLOCK]) tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp6 = 20.0 tmp7 = tmp5 > tmp6 tmp8 = tl_math.exp(tmp5) tmp9 = libdevice.log1p(tmp8) tmp10 = tmp9 * tmp4 tmp11 = tl.where(tmp7, tmp3, tmp10) tmp12 = tmp1 + tmp11 tmp13 = tmp0 + tmp12 tmp18 = tmp17 + tmp11 tmp19 = tmp15 + tmp18 tmp20 = tmp13 - tmp19 tmp23 = tmp20 / tmp22 tmp24 = tmp23 / tmp22 tmp29 = tmp28 * tmp4 tmp30 = tmp29 > tmp6 tmp31 = tl_math.exp(tmp29) tmp32 = libdevice.log1p(tmp31) tmp33 = tmp32 * tmp4 tmp34 = tl.where(tmp30, tmp28, tmp33) tmp35 = tmp34 * tmp23 tmp36 = tmp26 + tmp35 tmp37 = -tmp36 tl.store(out_ptr1 + x0, tmp23, xmask) tl.store(out_ptr2 + x0, tmp24, xmask) tl.store(out_ptr3 + x0, tmp37, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (1, 1), (1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (1, 1024), (1024, 1)) assert_size_stride(primals_5, (1024,), (1,)) assert_size_stride(primals_6, (1024, 1), (1, 1)) assert_size_stride(primals_7, (1,), (1,)) assert_size_stride(primals_8, (), ()) assert_size_stride(primals_9, (), ()) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((6,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(6)](primals_1, buf0, 6, XBLOCK=8, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((1, 1), (1, 1), torch.float32) triton_poi_fused_softplus_1[grid(1)](primals_2, buf1, 1, XBLOCK=1, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((1,), (1,), torch.float32) triton_poi_fused_softplus_1[grid(1)](primals_3, buf2, 1, XBLOCK=1, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((6, 1), (1, 1), torch.float32) extern_kernels.addmm(buf2, reinterpret_tensor(buf0, (6, 1), (1, 0), 0), buf1, alpha=1, beta=1, out=buf4) del buf1 buf5 = empty_strided_cuda((1, 1024), (1024, 1), torch.float32) triton_poi_fused_softplus_2[grid(1024)](primals_4, buf5, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((6, 1024), (1024, 1), torch.float32) extern_kernels.mm(buf4, buf5, out=buf6) buf7 = buf6 del buf6 triton_poi_fused_add_sigmoid_softplus_3[grid(6144)](buf7, primals_5, 6144, XBLOCK=128, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((1024, 1), (1, 1), torch.float32) triton_poi_fused_softplus_2[grid(1024)](primals_6, buf8, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((6, 1), (1, 1), torch.float32) extern_kernels.mm(buf7, buf8, out=buf9) buf11 = reinterpret_tensor(buf2, (), (), 0) del buf2 triton_poi_fused_sub_4[grid(1)](buf4, buf9, primals_7, buf11, 1, XBLOCK=1, num_warps=1, num_stages=1) buf12 = empty_strided_cuda((4,), (1,), torch.float32) buf14 = empty_strided_cuda((4,), (1,), torch.float32) buf13 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_add_div_mul_neg_softplus_sub_5[grid(4)](buf4, buf9, primals_7, buf11, primals_8, primals_9, buf12, buf14, buf13, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf9 del primals_8 return (buf13, buf12, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_9, reinterpret_tensor(buf0, (6, 1), ( 1, 1), 0), buf7, buf11, buf12, buf14, reinterpret_tensor(buf8, (1, 1024), (1, 1), 0), reinterpret_tensor(buf4, (1, 6), (1, 1), 0), reinterpret_tensor(buf5, (1024, 1), (1, 1024), 0)) class PositiveLinear(nn.Module): def __init__(self, in_features: 'int', out_features: 'int') ->None: super().__init__() self.weight = nn.Parameter(torch.randn(in_features, out_features)) self.bias = nn.Parameter(torch.zeros(out_features)) self.softplus = nn.Softplus() def forward(self, input: 'torch.Tensor'): return input @ self.softplus(self.weight) + self.softplus(self.bias) class SNRNetworkNew(nn.Module): def __init__(self) ->None: super().__init__() self.l1 = PositiveLinear(1, 1) self.l2 = PositiveLinear(1, 1024) self.l3 = PositiveLinear(1024, 1) self.gamma_min = nn.Parameter(torch.tensor(-10.0)) self.gamma_max = nn.Parameter(torch.tensor(20.0)) self.softplus = nn.Softplus() def forward(self, input_0): primals_8 = self.gamma_min primals_9 = self.gamma_max primals_2 = self.l1.weight primals_3 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_6 = self.l3.weight primals_7 = self.l3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0], output[1]
DavidRuhe/simple-variational-diffusion-models
SNRNetwork
false
17,253
[ "MIT" ]
4
a32355bf052a8f08e9c1919080588d0b22c8de4e
https://github.com/DavidRuhe/simple-variational-diffusion-models/tree/a32355bf052a8f08e9c1919080588d0b22c8de4e
EmbeddingLayer
import torch import torch.nn as nn import torch.nn.functional as F def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class custom_embedding(nn.Module): def __init__(self, input_size, output_size): super(custom_embedding, self).__init__() self.affine1 = mlp_layer(input_size, output_size) self.affine2 = mlp_layer(output_size, output_size) weight_init(self.affine1) weight_init(self.affine2) def forward(self, x): return self.affine2(self.affine1(x)) class EmbeddingLayer(nn.Module): def __init__(self, job_dim, machine_dim, embedding_size=16): super(EmbeddingLayer, self).__init__() self.job_dim = job_dim self.machine_dim = machine_dim self.embedding_size = embedding_size self.job_embedding = custom_embedding(self.job_dim, self.embedding_size ) self.machine_embedding = custom_embedding(self.machine_dim, self. embedding_size) def forward(self, jobs, machines): job_embedding = self.job_embedding(jobs) machine_embedding = self.machine_embedding(machines) return job_embedding, machine_embedding def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'job_dim': 4, 'machine_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn 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_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10) = 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, (16, 16), (16, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (16, 4), (4, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_9, (16, 16), (16, 1)) assert_size_stride(primals_10, (16,), (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 get_raw_stream(0) triton_poi_fused_tanh_0[grid(1024)](buf1, primals_2, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 16), (16, 1), 0), reinterpret_tensor(primals_4, (16, 16), (1, 16), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf2 triton_poi_fused_tanh_0[grid(1024)](buf3, primals_5, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_8, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 16), (1, 4), 0), out=buf4) del primals_6 buf5 = reinterpret_tensor(buf4, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf4 triton_poi_fused_tanh_0[grid(1024)](buf5, primals_7, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 16), (16, 1), 0), reinterpret_tensor(primals_9, (16, 16), (1, 16), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf6 triton_poi_fused_tanh_0[grid(1024)](buf7, primals_10, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_10 return buf3, buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf3, reinterpret_tensor(primals_8, (64, 4), (4, 1), 0 ), buf5, buf7, primals_9, primals_4 def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class custom_embedding(nn.Module): def __init__(self, input_size, output_size): super(custom_embedding, self).__init__() self.affine1 = mlp_layer(input_size, output_size) self.affine2 = mlp_layer(output_size, output_size) weight_init(self.affine1) weight_init(self.affine2) def forward(self, x): return self.affine2(self.affine1(x)) class EmbeddingLayerNew(nn.Module): def __init__(self, job_dim, machine_dim, embedding_size=16): super(EmbeddingLayerNew, self).__init__() self.job_dim = job_dim self.machine_dim = machine_dim self.embedding_size = embedding_size self.job_embedding = custom_embedding(self.job_dim, self.embedding_size ) self.machine_embedding = custom_embedding(self.machine_dim, self. embedding_size) def forward(self, input_0, input_1): primals_1 = self.job_embedding.affine1.affine.weight primals_2 = self.job_embedding.affine1.affine.bias primals_4 = self.job_embedding.affine2.affine.weight primals_5 = self.job_embedding.affine2.affine.bias primals_6 = self.machine_embedding.affine1.affine.weight primals_7 = self.machine_embedding.affine1.affine.bias primals_9 = self.machine_embedding.affine2.affine.weight primals_10 = self.machine_embedding.affine2.affine.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, primals_9, primals_10]) return output[0], output[1]
EpiSci/SoCRATES
EmbeddingLayer
false
17,254
[ "MIT" ]
6
901a896c5a765e3cb56f290188cde71c8707192d
https://github.com/EpiSci/SoCRATES/tree/901a896c5a765e3cb56f290188cde71c8707192d
FakeReLUM
import torch import torch.nn as nn import torch.utils.data class FakeReLU(torch.autograd.Function): @staticmethod def forward(ctx, input): return input.clamp(min=0) @staticmethod def backward(ctx, grad_output): return grad_output class FakeReLUM(nn.Module): def forward(self, x): return FakeReLU.apply(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn 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_clamp_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class FakeReLU(torch.autograd.Function): @staticmethod def forward(ctx, input): return input.clamp(min=0) @staticmethod def backward(ctx, grad_output): return grad_output class FakeReLUMNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Ethos-lab/robust-representation-matching
FakeReLUM
false
17,255
[ "MIT" ]
3
80d98f11846468c31278146583b9ef4750190211
https://github.com/Ethos-lab/robust-representation-matching/tree/80d98f11846468c31278146583b9ef4750190211
ConditionalBatchNorm
import torch class ConditionalBatchNorm(torch.nn.Module): def __init__(self, no, z_dim): super().__init__() self.no = no self.bn = torch.nn.InstanceNorm2d(no, affine=False) self.condition = torch.nn.Linear(z_dim, 2 * no) def forward(self, x, z): cond = self.condition(z).view(-1, 2 * self.no, 1, 1) return self.bn(x) * cond[:, :self.no] + cond[:, self.no:] def get_inputs(): return [torch.rand([64, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'no': 4, 'z_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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__native_batch_norm_legit_add_mul_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex x2 = xindex % 4 x3 = xindex // 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp24 = tl.load(in_ptr1 + (x2 + 8 * x3), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr1 + (4 + x2 + 8 * x3), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr2 + (4 + x2), xmask, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 16.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.rsqrt(tmp20) tmp22 = tmp0 - tmp10 tmp23 = tmp22 * tmp21 tmp26 = tmp24 + tmp25 tmp27 = tmp23 * tmp26 tmp30 = tmp28 + tmp29 tmp31 = tmp27 + tmp30 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(out_ptr1 + (r1 + 16 * x0), tmp31, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (64, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 1, 1), torch.float32 ) buf2 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256), torch .float32) buf4 = reinterpret_tensor(buf2, (1, 256, 1, 1), (256, 1, 1, 1), 0) del buf2 buf5 = empty_strided_cuda((64, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_add_mul_0[grid(256)](buf4, primals_4, buf0, primals_2, buf1, buf5, 256, 16, XBLOCK=32, num_warps=4, num_stages=1) del buf0 del primals_2 return buf5, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf4 class ConditionalBatchNormNew(torch.nn.Module): def __init__(self, no, z_dim): super().__init__() self.no = no self.bn = torch.nn.InstanceNorm2d(no, affine=False) self.condition = torch.nn.Linear(z_dim, 2 * no) def forward(self, input_0, input_1): primals_1 = self.condition.weight primals_2 = self.condition.bias primals_4 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
ElementAI/beyond-trivial-explanations
ConditionalBatchNorm
false
17,256
[ "Apache-2.0" ]
3
c517d7bdbab68b6a26f74cee4d15e948b3b47238
https://github.com/ElementAI/beyond-trivial-explanations/tree/c517d7bdbab68b6a26f74cee4d15e948b3b47238
mlp_layer
import torch import torch.nn as nn import torch.nn.functional as F def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import 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_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(256)](buf1, primals_2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1 def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layerNew(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layerNew, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, input_0): primals_1 = self.affine.weight primals_2 = self.affine.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
EpiSci/SoCRATES
mlp_layer
false
17,257
[ "MIT" ]
6
901a896c5a765e3cb56f290188cde71c8707192d
https://github.com/EpiSci/SoCRATES/tree/901a896c5a765e3cb56f290188cde71c8707192d
MultVAE_encoder
import torch import torch.sparse import torch.nn as nn class MultVAE_encoder(nn.Module): def __init__(self, item_dim: 'int', hidden_dim=600, latent_dim=200, n_hidden_layers=1, dropout=0.5, nonlinearity=nn.Tanh): super(MultVAE_encoder, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nn.Tanh() self.layers = nn.Sequential() self.layers.add_module('input_dropout', nn.Dropout(dropout)) self.layers.add_module('linear_enc_1', nn.Linear(in_features= item_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_enc_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_{}'.format(i + 2), self. nonlinearity) self.mu = nn.Linear(in_features=hidden_dim, out_features=latent_dim) self.logvar = nn.Linear(in_features=hidden_dim, out_features=latent_dim ) def forward(self, x): output = self.layers(x) mu = self.mu(output) logvar = self.logvar(output) return mu, logvar def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'item_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.sparse 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 = 38400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 600 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (600, 4), (4, 1)) assert_size_stride(primals_3, (600,), (1,)) assert_size_stride(primals_4, (600, 600), (600, 1)) assert_size_stride(primals_5, (600,), (1,)) assert_size_stride(primals_6, (200, 600), (600, 1)) assert_size_stride(primals_7, (200,), (1,)) assert_size_stride(primals_8, (200, 600), (600, 1)) assert_size_stride(primals_9, (200,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 600), (600, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 600), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 600), (9600, 2400, 600, 1), 0 ) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(38400)](buf1, primals_3, 38400, XBLOCK =256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((64, 600), (600, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 600), (600, 1), 0), reinterpret_tensor(primals_4, (600, 600), (1, 600), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 600), (9600, 2400, 600, 1), 0 ) del buf2 triton_poi_fused_tanh_0[grid(38400)](buf3, primals_5, 38400, XBLOCK =256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 200), (200, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 600), (600, 1), 0), reinterpret_tensor(primals_6, (600, 200), (1, 600 ), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((64, 200), (200, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf3, (64, 600), (600, 1), 0), reinterpret_tensor(primals_8, (600, 200), (1, 600 ), 0), alpha=1, beta=1, out=buf5) del primals_9 return reinterpret_tensor(buf4, (4, 4, 4, 200), (3200, 800, 200, 1), 0 ), reinterpret_tensor(buf5, (4, 4, 4, 200), (3200, 800, 200, 1), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf1, buf3, primals_8, primals_6, primals_4 class MultVAE_encoderNew(nn.Module): def __init__(self, item_dim: 'int', hidden_dim=600, latent_dim=200, n_hidden_layers=1, dropout=0.5, nonlinearity=nn.Tanh): super(MultVAE_encoderNew, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nn.Tanh() self.layers = nn.Sequential() self.layers.add_module('input_dropout', nn.Dropout(dropout)) self.layers.add_module('linear_enc_1', nn.Linear(in_features= item_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_enc_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_{}'.format(i + 2), self. nonlinearity) self.mu = nn.Linear(in_features=hidden_dim, out_features=latent_dim) self.logvar = nn.Linear(in_features=hidden_dim, out_features=latent_dim ) def forward(self, input_0): primals_2 = self.layers.linear_enc_1.weight primals_3 = self.layers.linear_enc_1.bias primals_4 = self.layers.hidden_enc_1.weight primals_5 = self.layers.hidden_enc_1.bias primals_6 = self.mu.weight primals_7 = self.mu.bias primals_8 = self.logvar.weight primals_9 = self.logvar.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0], output[1]
EricHe98/sad_final_project
MultVAE_encoder
false
17,258
[ "MIT" ]
3
4b2b57e44f939840eede6f134493c5f8d809b1a7
https://github.com/EricHe98/sad_final_project/tree/4b2b57e44f939840eede6f134493c5f8d809b1a7
VAE
import torch import numpy as np import torch.utils.data import torch.nn as nn class VAE(nn.Module): def __init__(self, input_size, latent_size): super(VAE, self).__init__() self.latent_size = latent_size self.input_size = input_size self.mu_layer = nn.Linear(self.input_size, self.latent_size) self.logvar_layer = nn.Linear(self.input_size, self.latent_size) def _reparametrize(self, mu, logvar): std_dev = torch.exp(0.5 * logvar) eps = torch.randn_like(std_dev) return eps.mul(std_dev).add_(mu) def forward(self, input): mu = self.mu_layer(input) logvar = self.logvar_layer(input) z = self._reparametrize(mu, logvar) return z, mu, logvar def default_loss(self, x, recon_x, mu, logvar): BCE = nn.functional.cross_entropy(recon_x, x) KLD = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp()) return BCE + KLD def kl_anneal_function(self, step, k=0.0025, x0=2500, anneal_function= 'linear'): if anneal_function == 'logistic': return float(1 / (1 + np.exp(-k * (step - x0)))) elif anneal_function == 'linear': return min(1, step / x0) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'latent_size': 4}]
import torch from torch import device from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import numpy as np import torch.utils.data import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_exp_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 + x0, xmask) tmp6 = tl.load(in_ptr2 + x0, xmask) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tl_math.exp(tmp3) tmp5 = tmp0 * tmp4 tmp7 = tmp5 + tmp6 tl.store(out_ptr0 + x0, tmp7, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = torch.ops.aten.randn.default([4, 4, 4, 4], dtype=torch. float32, device=device(type='cuda', index=0), pin_memory=False) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_exp_mul_0[grid(256)](buf3, buf1, buf0, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf4, reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0), buf3 class VAENew(nn.Module): def __init__(self, input_size, latent_size): super(VAENew, self).__init__() self.latent_size = latent_size self.input_size = input_size self.mu_layer = nn.Linear(self.input_size, self.latent_size) self.logvar_layer = nn.Linear(self.input_size, self.latent_size) def _reparametrize(self, mu, logvar): std_dev = torch.exp(0.5 * logvar) eps = torch.randn_like(std_dev) return eps.mul(std_dev).add_(mu) def default_loss(self, x, recon_x, mu, logvar): BCE = nn.functional.cross_entropy(recon_x, x) KLD = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp()) return BCE + KLD def kl_anneal_function(self, step, k=0.0025, x0=2500, anneal_function= 'linear'): if anneal_function == 'logistic': return float(1 / (1 + np.exp(-k * (step - x0)))) elif anneal_function == 'linear': return min(1, step / x0) def forward(self, input_0): primals_1 = self.mu_layer.weight primals_2 = self.mu_layer.bias primals_4 = self.logvar_layer.weight primals_5 = self.logvar_layer.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0], output[1], output[2]
ErikHumphrey/sustain-seq2seq
VAE
false
17,259
[ "Apache-2.0" ]
4
c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
https://github.com/ErikHumphrey/sustain-seq2seq/tree/c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
MLP
import torch class MLP(torch.nn.Module): def __init__(self, ni, no, nhidden, nlayers): super().__init__() self.nlayers = nlayers for i in range(nlayers): if i == 0: setattr(self, 'linear%d' % i, torch.nn.Linear(ni, nhidden, bias=False)) else: setattr(self, 'linear%d' % i, torch.nn.Linear(nhidden, nhidden, bias=False)) setattr(self, 'bn%d' % i, torch.nn.LayerNorm(nhidden)) if nlayers == 0: nhidden = ni self.linear_out = torch.nn.Linear(nhidden, no) def forward(self, x): for i in range(self.nlayers): linear = getattr(self, 'linear%d' % i) bn = getattr(self, 'bn%d' % i) x = linear(x) x = bn(x) x = x * torch.sigmoid(x) return self.linear_out(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'ni': 4, 'no': 4, 'nhidden': 4, 'nlayers': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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_mul_native_layer_norm_sigmoid_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tmp9 = tl.sigmoid(tmp8) tmp10 = tmp8 * tmp9 tl.store(in_out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_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, 1), (16, 4, 1, 64), torch.float32) buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(64)](buf0, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = buf3 del buf3 triton_poi_fused_mul_native_layer_norm_sigmoid_1[grid(256)](buf4, buf0, buf1, buf2, primals_3, primals_4, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del buf2 buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(buf4, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf5) del primals_6 return reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_3, primals_4, reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf0, reinterpret_tensor(buf4, (64, 4), (4, 1), 0), primals_5 class MLPNew(torch.nn.Module): def __init__(self, ni, no, nhidden, nlayers): super().__init__() self.nlayers = nlayers for i in range(nlayers): if i == 0: setattr(self, 'linear%d' % i, torch.nn.Linear(ni, nhidden, bias=False)) else: setattr(self, 'linear%d' % i, torch.nn.Linear(nhidden, nhidden, bias=False)) setattr(self, 'bn%d' % i, torch.nn.LayerNorm(nhidden)) if nlayers == 0: nhidden = ni self.linear_out = torch.nn.Linear(nhidden, no) def forward(self, input_0): primals_1 = self.linear0.weight primals_3 = self.bn0.weight primals_4 = self.bn0.bias primals_5 = self.linear_out.weight primals_6 = self.linear_out.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
ElementAI/beyond-trivial-explanations
MLP
false
17,260
[ "Apache-2.0" ]
3
c517d7bdbab68b6a26f74cee4d15e948b3b47238
https://github.com/ElementAI/beyond-trivial-explanations/tree/c517d7bdbab68b6a26f74cee4d15e948b3b47238
merge_layer
import torch import torch.nn as nn import torch.nn.functional as F def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class merge_layer(nn.Module): def __init__(self, hidden_size, output_size, activation='tanh'): super(merge_layer, self).__init__() self.mlp_layer = mlp_layer(hidden_size, output_size, activation= activation) def forward(self, x): x = torch.mean(x, dim=-1) return self.mlp_layer(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = 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_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 = 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_mean_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_tanh_1[grid(64)](buf2, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf2, reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf2 def weight_init(m): if isinstance(m, nn.Linear): size = m.weight.size() size[0] size[1] variance = 0.001 m.weight.data.normal_(0.0, variance) try: m.bias.data.normal_(0.0, 0.0001) except: pass class mlp_layer(nn.Module): def __init__(self, input_size, output_size, activation='tanh', drouput_prob=0.0): super(mlp_layer, self).__init__() self.affine = nn.Linear(input_size, output_size) weight_init(self.affine) if activation.lower() == 'tanh': self.activation = torch.tanh elif activation.lower() == 'relu': self.activation = F.relu() def forward(self, x): x = self.activation(self.affine(x)) return x class merge_layerNew(nn.Module): def __init__(self, hidden_size, output_size, activation='tanh'): super(merge_layerNew, self).__init__() self.mlp_layer = mlp_layer(hidden_size, output_size, activation= activation) def forward(self, input_0): primals_2 = self.mlp_layer.affine.weight primals_3 = self.mlp_layer.affine.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
EpiSci/SoCRATES
merge_layer
false
17,261
[ "MIT" ]
6
901a896c5a765e3cb56f290188cde71c8707192d
https://github.com/EpiSci/SoCRATES/tree/901a896c5a765e3cb56f290188cde71c8707192d
PreactDoubleLayer
import copy import math import torch import torch.nn as nn def normalInit(dims): """ Essentially, PyTorch's init.xavier_normal_ but clamped :param K: tensor to be initialized/overwritten :return: initialized tensor on the device in the nn.Parameter wrapper """ K = torch.zeros(dims) fan_in, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(K) sd = math.sqrt(2.0 / (fan_in + fan_out)) with torch.no_grad(): K = K.normal_(0, sd) K = torch.clamp(K, min=-2 * sd, max=2 * sd) return K def regMetric(x, y): return torch.norm(x - y, p=1) class ClippedModule(nn.Module): """ Extend nn.Module to include max and min values for bound constraints / clipping """ def __init__(self): super().__init__() self.minConv = -0.5 self.maxConv = 0.5 self.minDef = -1.5 self.maxDef = 1.5 def setClipValues(self, minConv=-0.5, maxConv=0.5, minDef=-1.5, maxDef=1.5 ): """ set box constraints :param minConv: float, lower bound for convolutions :param maxConv: float, upper bound for convolutions :param minDef: float, lower bound for all other parameters :param maxDef: float, upper bound for all other parameters """ self.minConv = minConv self.maxConv = maxConv self.minDef = minDef self.maxDef = maxDef def calcClipValues(self, h, nPixels, nChan): """ calculation for setting bound constraints....not tuned yet""" mult = 1 / h mult = mult / math.sqrt(nPixels) mult = mult * (500 / nChan ** 2) minConv = -1 maxConv = 1 self.setClipValues(minConv=mult * minConv, maxConv=mult * maxConv, minDef=-1.5, maxDef=1.5) def clip(self): """project values onto box constraints""" if hasattr(self, 'conv'): self.conv.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv.bias is not None: self.conv.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv1'): self.conv1.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv1.bias is not None: self.conv1.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv2'): self.conv2.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv2.bias is not None: self.conv2.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'weight'): w = self.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for module in self.children(): if hasattr(module, 'clip'): module.clip() else: if hasattr(module, 'weight'): w = module.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for child in module.children(): if hasattr(child, 'clip'): child.clip() return self class DoubleLayer(ClippedModule): """ Implementation of the double layer, also referred to as a Basic ResNet Block. act2( N2( K2( act1( N1( K1(Y) ))))) Attributes: conv1 (sub-module): convolution class, default is 3x3 2Dconvolution conv2 (sub-module): '' act1 (sub-module): activation function, default is ReLU() act2 (sub-module): '' normLayer1 (sub-module): normalization with affine bias and weight, default is no normalization normLayer2 (sub-module): '' Typical attributes for the children: conv#.weight (Parameter): dims (nChanOut,nChanIn,3,3) for default 2DConvolution from nChanIn -> nChanOut channels conv#.bias (Parameter): vector, dims (nChanIn) normLayer#.weight (Parameter): vector, dims (nChanOut) affine scaling normLayer#.bias (Parameter): vector, dims (nChanOut) affine scaling bias """ def __init__(self, vFeat, params={}): """ :param vFeat: 2-item list of number of expected input channels and number of channels to return, [nChanIn,nChanOut] :param params: dict of possible parameters ( 'conv1' , 'conv2', 'act1' , 'act2' , 'normLayer1' , 'normLayer2' ) """ super().__init__() if type(vFeat) is not list: vFeat = [vFeat, vFeat] nChanIn = vFeat[0] nChanOut = vFeat[1] szKernel = 3 stride = 1 padding = 1 self.conv1 = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.conv2 = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.act1 = nn.ReLU() self.act2 = nn.ReLU() if 'conv1' in params.keys(): self.conv1 = copy.deepcopy(params.get('conv1')) if 'conv2' in params.keys(): self.conv2 = copy.deepcopy(params.get('conv2')) if 'act1' in params.keys(): self.act1 = params.get('act1') if 'act2' in params.keys(): self.act2 = params.get('act2') if 'normLayer1' in params.keys(): self.normLayer1 = copy.deepcopy(params.get('normLayer1')) self.normLayer1.weight.data = torch.ones(nChanOut) self.normLayer1.bias.data = torch.zeros(nChanOut) if 'normLayer2' in params.keys(): self.normLayer2 = copy.deepcopy(params.get('normLayer2')) self.normLayer2.weight.data = torch.ones(nChanOut) self.normLayer2.bias.data = torch.zeros(nChanOut) if 'conv' in params.keys(): self.conv1 = copy.deepcopy(params.get('conv')) self.conv2 = copy.deepcopy(self.conv1) if 'act' in params.keys(): self.act1 = params.get('act') self.act2 = copy.deepcopy(self.act1) if 'normLayer' in params.keys(): self.normLayer1 = copy.deepcopy(params.get('normLayer')) self.normLayer1.weight.data = torch.ones(nChanOut) self.normLayer2 = copy.deepcopy(self.normLayer1) self.conv1.weight.data = normalInit(self.conv1.weight.data.shape) self.conv2.weight.data = normalInit(self.conv2.weight.data.shape) if self.conv1.bias is not None: self.conv1.bias.data *= 0 if self.conv2.bias is not None: self.conv2.bias.data *= 0 def forward(self, x): z = self.conv1(x) if hasattr(self, 'normLayer1'): z = self.normLayer1(z) z = self.act1(z) z = self.conv2(z) if hasattr(self, 'normLayer2'): z = self.normLayer2(z) z = self.act2(z) return z def weight_variance(self, other): """apply regularization in time""" value = 0 value += regMetric(nn.utils.convert_parameters.parameters_to_vector (self.parameters()), nn.utils.convert_parameters. parameters_to_vector(other.parameters())) return value class PreactDoubleLayer(DoubleLayer): """ pre-activated version of the DoubleLayer N2( act2( K2( N1( act1( K1(Y) ))))) """ def __init__(self, vFeat, params={}): super().__init__(vFeat, params=params) def forward(self, x): z = self.act1(x) z = self.conv1(z) if hasattr(self, 'normLayer1'): z = self.normLayer1(z) z = self.act2(z) z = self.conv2(z) if hasattr(self, 'normLayer2'): z = self.normLayer2(z) return z def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'vFeat': 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 copy 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 @triton.jit def triton_poi_fused_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_2[grid(256)](buf4, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf4, primals_2, primals_4, buf0, buf2 def normalInit(dims): """ Essentially, PyTorch's init.xavier_normal_ but clamped :param K: tensor to be initialized/overwritten :return: initialized tensor on the device in the nn.Parameter wrapper """ K = torch.zeros(dims) fan_in, fan_out = torch.nn.init._calculate_fan_in_and_fan_out(K) sd = math.sqrt(2.0 / (fan_in + fan_out)) with torch.no_grad(): K = K.normal_(0, sd) K = torch.clamp(K, min=-2 * sd, max=2 * sd) return K def regMetric(x, y): return torch.norm(x - y, p=1) class ClippedModule(nn.Module): """ Extend nn.Module to include max and min values for bound constraints / clipping """ def __init__(self): super().__init__() self.minConv = -0.5 self.maxConv = 0.5 self.minDef = -1.5 self.maxDef = 1.5 def setClipValues(self, minConv=-0.5, maxConv=0.5, minDef=-1.5, maxDef=1.5 ): """ set box constraints :param minConv: float, lower bound for convolutions :param maxConv: float, upper bound for convolutions :param minDef: float, lower bound for all other parameters :param maxDef: float, upper bound for all other parameters """ self.minConv = minConv self.maxConv = maxConv self.minDef = minDef self.maxDef = maxDef def calcClipValues(self, h, nPixels, nChan): """ calculation for setting bound constraints....not tuned yet""" mult = 1 / h mult = mult / math.sqrt(nPixels) mult = mult * (500 / nChan ** 2) minConv = -1 maxConv = 1 self.setClipValues(minConv=mult * minConv, maxConv=mult * maxConv, minDef=-1.5, maxDef=1.5) def clip(self): """project values onto box constraints""" if hasattr(self, 'conv'): self.conv.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv.bias is not None: self.conv.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv1'): self.conv1.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv1.bias is not None: self.conv1.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'conv2'): self.conv2.weight.data.clamp_(min=self.minConv, max=self.maxConv) if self.conv2.bias is not None: self.conv2.bias.data.clamp_(min=self.minConv, max=self.maxConv) if hasattr(self, 'weight'): w = self.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for module in self.children(): if hasattr(module, 'clip'): module.clip() else: if hasattr(module, 'weight'): w = module.weight.data w.clamp_(min=self.minDef, max=self.maxDef) for child in module.children(): if hasattr(child, 'clip'): child.clip() return self class DoubleLayer(ClippedModule): """ Implementation of the double layer, also referred to as a Basic ResNet Block. act2( N2( K2( act1( N1( K1(Y) ))))) Attributes: conv1 (sub-module): convolution class, default is 3x3 2Dconvolution conv2 (sub-module): '' act1 (sub-module): activation function, default is ReLU() act2 (sub-module): '' normLayer1 (sub-module): normalization with affine bias and weight, default is no normalization normLayer2 (sub-module): '' Typical attributes for the children: conv#.weight (Parameter): dims (nChanOut,nChanIn,3,3) for default 2DConvolution from nChanIn -> nChanOut channels conv#.bias (Parameter): vector, dims (nChanIn) normLayer#.weight (Parameter): vector, dims (nChanOut) affine scaling normLayer#.bias (Parameter): vector, dims (nChanOut) affine scaling bias """ def __init__(self, vFeat, params={}): """ :param vFeat: 2-item list of number of expected input channels and number of channels to return, [nChanIn,nChanOut] :param params: dict of possible parameters ( 'conv1' , 'conv2', 'act1' , 'act2' , 'normLayer1' , 'normLayer2' ) """ super().__init__() if type(vFeat) is not list: vFeat = [vFeat, vFeat] nChanIn = vFeat[0] nChanOut = vFeat[1] szKernel = 3 stride = 1 padding = 1 self.conv1 = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.conv2 = nn.Conv2d(in_channels=nChanIn, kernel_size=szKernel, out_channels=nChanOut, stride=stride, padding=padding) self.act1 = nn.ReLU() self.act2 = nn.ReLU() if 'conv1' in params.keys(): self.conv1 = copy.deepcopy(params.get('conv1')) if 'conv2' in params.keys(): self.conv2 = copy.deepcopy(params.get('conv2')) if 'act1' in params.keys(): self.act1 = params.get('act1') if 'act2' in params.keys(): self.act2 = params.get('act2') if 'normLayer1' in params.keys(): self.normLayer1 = copy.deepcopy(params.get('normLayer1')) self.normLayer1.weight.data = torch.ones(nChanOut) self.normLayer1.bias.data = torch.zeros(nChanOut) if 'normLayer2' in params.keys(): self.normLayer2 = copy.deepcopy(params.get('normLayer2')) self.normLayer2.weight.data = torch.ones(nChanOut) self.normLayer2.bias.data = torch.zeros(nChanOut) if 'conv' in params.keys(): self.conv1 = copy.deepcopy(params.get('conv')) self.conv2 = copy.deepcopy(self.conv1) if 'act' in params.keys(): self.act1 = params.get('act') self.act2 = copy.deepcopy(self.act1) if 'normLayer' in params.keys(): self.normLayer1 = copy.deepcopy(params.get('normLayer')) self.normLayer1.weight.data = torch.ones(nChanOut) self.normLayer2 = copy.deepcopy(self.normLayer1) self.conv1.weight.data = normalInit(self.conv1.weight.data.shape) self.conv2.weight.data = normalInit(self.conv2.weight.data.shape) if self.conv1.bias is not None: self.conv1.bias.data *= 0 if self.conv2.bias is not None: self.conv2.bias.data *= 0 def forward(self, x): z = self.conv1(x) if hasattr(self, 'normLayer1'): z = self.normLayer1(z) z = self.act1(z) z = self.conv2(z) if hasattr(self, 'normLayer2'): z = self.normLayer2(z) z = self.act2(z) return z def weight_variance(self, other): """apply regularization in time""" value = 0 value += regMetric(nn.utils.convert_parameters.parameters_to_vector (self.parameters()), nn.utils.convert_parameters. parameters_to_vector(other.parameters())) return value class PreactDoubleLayerNew(DoubleLayer): """ pre-activated version of the DoubleLayer N2( act2( K2( N1( act1( K1(Y) ))))) """ def __init__(self, vFeat, params={}): super().__init__(vFeat, params=params) 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]
EmoryMLIP/DynamicBlocks
PreactDoubleLayer
false
17,262
[ "MIT" ]
9
52acc9fbc1a2640c6ac8922fa18105279ccaea97
https://github.com/EmoryMLIP/DynamicBlocks/tree/52acc9fbc1a2640c6ac8922fa18105279ccaea97
conv_head_pooling
import torch import torch.nn as nn class conv_head_pooling(nn.Module): def __init__(self, in_feature, out_feature, stride, padding_mode='zeros'): super(conv_head_pooling, self).__init__() self.conv = nn.Conv2d(in_feature, out_feature, kernel_size=stride + 1, padding=stride // 2, stride=stride, padding_mode= padding_mode, groups=in_feature) def forward(self, x): x = self.conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_feature': 4, 'out_feature': 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 @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 144 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 9 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 1, 2, 2), (4, 4, 2, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, bias=None) assert_size_stride(buf0, (4, 4, 3, 3), (36, 9, 3, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(144)](buf1, primals_2, 144, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3 class conv_head_poolingNew(nn.Module): def __init__(self, in_feature, out_feature, stride, padding_mode='zeros'): super(conv_head_poolingNew, self).__init__() self.conv = nn.Conv2d(in_feature, out_feature, kernel_size=stride + 1, padding=stride // 2, stride=stride, padding_mode= padding_mode, groups=in_feature) 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]
Equationliu/GA-Attack
conv_head_pooling
false
17,263
[ "MIT" ]
8
b0280674a211f6451774ec6b1d4cee2fc19a4de6
https://github.com/Equationliu/GA-Attack/tree/b0280674a211f6451774ec6b1d4cee2fc19a4de6
Denoise_NormalizeLayer
import torch import torch.nn as nn class Denoise_NormalizeLayer(nn.Module): def __init__(self): super(Denoise_NormalizeLayer, self).__init__() def forward(self, inputs: 'torch.tensor'): permute_RGBtoBGR = [2, 1, 0] inputs = inputs[:, permute_RGBtoBGR, :, :] out = inputs / 0.5 - 1 return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_index_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 3 x0 = xindex % 16 x2 = xindex // 48 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 1, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 0, tl.int64) tmp6 = tl.where(tmp4, tmp1, tmp5) tmp7 = tl.where(tmp2, tmp3, tmp6) tmp8 = tl.load(in_ptr0 + (x0 + 16 * tmp7 + 64 * x2), xmask) tmp9 = 2.0 tmp10 = tmp8 * tmp9 tmp11 = 1.0 tmp12 = tmp10 - tmp11 tl.store(out_ptr0 + x3, 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, 3, 4, 4), (48, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_index_sub_0[grid(192)](arg0_1, buf0, 192, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class Denoise_NormalizeLayerNew(nn.Module): def __init__(self): super(Denoise_NormalizeLayerNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Equationliu/GA-Attack
Denoise_NormalizeLayer
false
17,264
[ "MIT" ]
8
b0280674a211f6451774ec6b1d4cee2fc19a4de6
https://github.com/Equationliu/GA-Attack/tree/b0280674a211f6451774ec6b1d4cee2fc19a4de6
CEL
import torch from torch import nn class CEL(nn.Module): def __init__(self): super(CEL, self).__init__() None self.eps = 1e-06 def forward(self, pred, target): pred = pred.sigmoid() intersection = pred * target numerator = (pred - intersection).sum() + (target - intersection).sum() denominator = pred.sum() + target.sum() return numerator / (denominator + self.eps) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_sigmoid_sub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp2 = tl.load(in_ptr1 + r0, None) tmp1 = tl.sigmoid(tmp0) tmp3 = tmp1 * tmp2 tmp4 = tmp1 - tmp3 tmp5 = tl.broadcast_to(tmp4, [RBLOCK]) tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0)) tmp8 = tmp2 - tmp3 tmp9 = tl.broadcast_to(tmp8, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = tl.broadcast_to(tmp1, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = tl.broadcast_to(tmp2, [RBLOCK]) tmp17 = triton_helpers.promote_to_tensor(tl.sum(tmp15, 0)) tmp18 = tmp7 + tmp11 tmp19 = tmp14 + tmp17 tmp20 = 1e-06 tmp21 = tmp19 + tmp20 tmp22 = tmp18 / 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) buf4 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_div_mul_sigmoid_sub_sum_0[grid(1)](buf4, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf4, class CELNew(nn.Module): def __init__(self): super(CELNew, self).__init__() None self.eps = 1e-06 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Farzanehkaji/MINet
CEL
false
17,265
[ "MIT" ]
9
cc2852cb2b3b20208f5edf38ec6952363a9b04a7
https://github.com/Farzanehkaji/MINet/tree/cc2852cb2b3b20208f5edf38ec6952363a9b04a7
Conv2d
import torch from torch import nn from torch.nn import functional as F class Conv2d(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): super(Conv2d, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias) def forward(self, x): weight = self.weight weight_mean = weight.mean(dim=1, keepdim=True).mean(dim=2, keepdim=True ).mean(dim=3, keepdim=True) weight = weight - weight_mean std = weight.view(weight.size(0), -1).std(dim=1).view(-1, 1, 1, 1 ) + 1e-05 weight = weight / std.expand_as(weight) return F.conv2d(x, weight, self.bias, self.stride, self.padding, self.dilation, self.groups) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice 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_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp9 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), xmask) tmp10 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), xmask) tmp12 = tl.load(in_ptr0 + (36 + x0 + 64 * x1), xmask) tmp14 = tl.load(in_ptr0 + (52 + x0 + 64 * x1), xmask) tmp18 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), xmask) tmp19 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), xmask) tmp21 = tl.load(in_ptr0 + (40 + x0 + 64 * x1), xmask) tmp23 = tl.load(in_ptr0 + (56 + x0 + 64 * x1), xmask) tmp27 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), xmask) tmp28 = tl.load(in_ptr0 + (28 + x0 + 64 * x1), xmask) tmp30 = tl.load(in_ptr0 + (44 + x0 + 64 * x1), xmask) tmp32 = tl.load(in_ptr0 + (60 + x0 + 64 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp11 = tmp9 + tmp10 tmp13 = tmp11 + tmp12 tmp15 = tmp13 + tmp14 tmp16 = tmp15 / tmp7 tmp17 = tmp8 + tmp16 tmp20 = tmp18 + tmp19 tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp25 = tmp24 / tmp7 tmp26 = tmp17 + tmp25 tmp29 = tmp27 + tmp28 tmp31 = tmp29 + tmp30 tmp33 = tmp31 + tmp32 tmp34 = tmp33 / tmp7 tmp35 = tmp26 + tmp34 tmp36 = tmp35 / tmp7 tl.store(out_ptr0 + x2, tmp36, xmask) @triton.jit def triton_per_fused_div_mean_std_sub_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tl.where(xmask, tmp11, 0) tmp14 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK]) tmp16 = tl.where(xmask, tmp14, 0) tmp17 = tl.sum(tmp16, 1)[:, None] tmp18 = tl.full([XBLOCK, 1], 64, tl.int32) tmp19 = tmp18.to(tl.float32) tmp20 = tmp17 / tmp19 tmp21 = tmp11 - tmp20 tmp22 = tmp21 * tmp21 tmp23 = tl.broadcast_to(tmp22, [XBLOCK, RBLOCK]) tmp25 = tl.where(xmask, tmp23, 0) tmp26 = tl.sum(tmp25, 1)[:, None] tmp27 = 63.0 tmp28 = tmp26 / tmp27 tmp29 = libdevice.sqrt(tmp28) tmp30 = 1e-05 tmp31 = tmp29 + tmp30 tmp32 = tmp10 / tmp31 tl.store(out_ptr0 + (r1 + 64 * x0), tmp10, xmask) tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp29, xmask) tl.store(out_ptr1 + (r1 + 64 * x0), tmp32, xmask) @triton.jit def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1, 4), (4, 16, 16, 1), 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, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4,), (1,), torch.float32) buf5 = buf3 del buf3 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_per_fused_div_mean_std_sub_1[grid(4)](buf5, primals_1, buf0, buf1, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf1 buf7 = extern_kernels.convolution(primals_3, buf6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 1, 1), (4, 1, 1, 1)) buf8 = buf7 del buf7 triton_poi_fused_convolution_2[grid(16)](buf8, primals_2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf8, primals_1, primals_3, buf5, buf6 class Conv2dNew(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True): super(Conv2dNew, self).__init__(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias) def forward(self, input_0): primals_1 = self.weight primals_2 = self.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Farzanehkaji/MINet
Conv2d
false
17,266
[ "MIT" ]
9
cc2852cb2b3b20208f5edf38ec6952363a9b04a7
https://github.com/Farzanehkaji/MINet/tree/cc2852cb2b3b20208f5edf38ec6952363a9b04a7
ChannelPool
import torch import torch.nn as nn class ChannelPool(nn.Module): def forward(self, x): return torch.cat((torch.max(x, 1)[0].unsqueeze(1), torch.mean(x, 1) .unsqueeze(1)), dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 2 x0 = xindex % 16 x2 = xindex // 32 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = triton_helpers.maximum(tmp7, tmp8) tmp10 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp11 = triton_helpers.maximum(tmp9, tmp10) tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype) tmp13 = tl.where(tmp4, tmp11, tmp12) tmp14 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp17 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp18 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp19 = tmp17 + tmp18 tmp20 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp21 = tmp19 + tmp20 tmp22 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp14 & xmask, eviction_policy='evict_last', other=0.0) tmp23 = tmp21 + tmp22 tmp24 = 4.0 tmp25 = tmp23 / tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp14, tmp25, tmp26) tmp28 = tl.where(tmp4, tmp13, tmp27) tl.store(out_ptr0 + x3, tmp28, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](arg0_1, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class ChannelPoolNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
FVL2020/2DImage_BMI_estimation
ChannelPool
false
17,267
[ "MIT" ]
4
3ae8469c3c86aac1afd09b3ba1716ecd94f5ec3f
https://github.com/FVL2020/2DImage_BMI_estimation/tree/3ae8469c3c86aac1afd09b3ba1716ecd94f5ec3f
ScaleToModel
import torch import torch.nn as nn import torch.cuda from torch import linalg as linalg class ScaleToModel(nn.Module): """ This class acts as an adapter module that scales pixel values from the test run domain to the model domain. """ def __init__(self, model_value_range, test_value_range): """ Initializes the scaler module by setting the model domain and test domain value range. Args: model_value_range (List[float]): The model's value range. test_value_range (List[float]): The test run's value range. """ super(ScaleToModel, self).__init__() self.m_min, self.m_max = model_value_range self.t_min, self.t_max = test_value_range def forward(self, img: 'torch.Tensor'): """ Scales the input image from the test run domain to the model domain. Args: img (torch.Tensor): The image to scale. Returns: The scaled image. """ img = (img - self.t_min) / (self.t_max - self.t_min) img = img * (self.m_max - self.m_min) + self.m_min return img def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'model_value_range': [4, 4], 'test_value_range': [4, 4]}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.cuda from torch import linalg as linalg assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 4.0 tmp2 = tmp0 - tmp1 tmp3 = float('inf') tmp4 = tmp2 * tmp3 tmp5 = 0.0 tmp6 = tmp4 * tmp5 tmp7 = tmp6 + tmp1 tl.store(out_ptr0 + x0, tmp7, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mul_sub_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class ScaleToModelNew(nn.Module): """ This class acts as an adapter module that scales pixel values from the test run domain to the model domain. """ def __init__(self, model_value_range, test_value_range): """ Initializes the scaler module by setting the model domain and test domain value range. Args: model_value_range (List[float]): The model's value range. test_value_range (List[float]): The test run's value range. """ super(ScaleToModelNew, self).__init__() self.m_min, self.m_max = model_value_range self.t_min, self.t_max = test_value_range def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Flunzmas/vp-suite
ScaleToModel
false
17,268
[ "MIT" ]
3
391570121b5bd9e3fd23aca9a0945a63c4173a24
https://github.com/Flunzmas/vp-suite/tree/391570121b5bd9e3fd23aca9a0945a63c4173a24
MultVae
import torch import torch.sparse import torch.nn as nn class MultVAE_encoder(nn.Module): def __init__(self, item_dim: 'int', hidden_dim=600, latent_dim=200, n_hidden_layers=1, dropout=0.5, nonlinearity=nn.Tanh): super(MultVAE_encoder, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nn.Tanh() self.layers = nn.Sequential() self.layers.add_module('input_dropout', nn.Dropout(dropout)) self.layers.add_module('linear_enc_1', nn.Linear(in_features= item_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_enc_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_{}'.format(i + 2), self. nonlinearity) self.mu = nn.Linear(in_features=hidden_dim, out_features=latent_dim) self.logvar = nn.Linear(in_features=hidden_dim, out_features=latent_dim ) def forward(self, x): output = self.layers(x) mu = self.mu(output) logvar = self.logvar(output) return mu, logvar class MultVAE_decoder(nn.Module): def __init__(self, item_dim, hidden_dim=600, latent_dim=200, n_hidden_layers=1, nonlinearity=nn.Tanh): super(MultVAE_decoder, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nonlinearity() self.layers = nn.Sequential() self.layers.add_module('linear_dec_1', nn.Linear(in_features= latent_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_dec_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_dec_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_dec_{}'.format(i + 2), self. nonlinearity) self.item_layer = nn.Linear(in_features=hidden_dim, out_features= item_dim) def forward(self, x): output = self.layers(x) items = self.item_layer(output) items = self.nonlinearity(items) return items class MultVae(nn.Module): def __init__(self, item_dim, hidden_dim=600, latent_dim=200, n_enc_hidden_layers=1, n_dec_hidden_layers=1, dropout=0.5): super(MultVae, self).__init__() self.item_dim = item_dim self.encoder = MultVAE_encoder(item_dim=item_dim, hidden_dim= hidden_dim, latent_dim=latent_dim, n_hidden_layers= n_enc_hidden_layers, dropout=0.5, nonlinearity=nn.Tanh) self.decoder = MultVAE_decoder(item_dim=item_dim, hidden_dim= hidden_dim, latent_dim=latent_dim, n_hidden_layers= n_dec_hidden_layers, nonlinearity=nn.Tanh) self.softmax = nn.Softmax(dim=2) def reparameterize(self, mu, logvar): if self.training: std = torch.exp(0.5 * logvar) eps = torch.randn_like(std) return eps.mul(std).add_(mu) else: return mu def forward(self, x): enc_mu, enc_logvar = self.encoder(x) z = self.reparameterize(enc_mu, enc_logvar) items = self.decoder(z) items = self.softmax(items) total_int = torch.count_nonzero(x, dim=2).unsqueeze(dim=1) items = items * total_int.expand(-1, -1, self.item_dim) return items, enc_mu, enc_logvar def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'item_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.sparse 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 = 9600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 600 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused__softmax_tanh_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 = libdevice.tanh(tmp0) tmp3 = libdevice.tanh(tmp2) tmp5 = libdevice.tanh(tmp4) tmp6 = triton_helpers.maximum(tmp3, tmp5) tmp8 = libdevice.tanh(tmp7) tmp9 = triton_helpers.maximum(tmp6, tmp8) tmp11 = libdevice.tanh(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__softmax_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 4 x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + 4 * x4, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x4), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x4), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x4), xmask, eviction_policy='evict_last') tmp9 = 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') tmp17 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tmp10 = 0.0 tmp11 = tmp9 != tmp10 tmp12 = tmp11.to(tl.int64) tmp14 = tmp13 != tmp10 tmp15 = tmp14.to(tl.int64) tmp16 = tmp12 + tmp15 tmp18 = tmp17 != tmp10 tmp19 = tmp18.to(tl.int64) tmp20 = tmp16 + tmp19 tmp22 = tmp21 != tmp10 tmp23 = tmp22.to(tl.int64) tmp24 = tmp20 + tmp23 tmp25 = tmp24.to(tl.float32) tmp26 = tmp8 * tmp25 tl.store(out_ptr0 + x3, tmp26, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (600, 4), (4, 1)) assert_size_stride(primals_3, (600,), (1,)) assert_size_stride(primals_4, (600, 600), (600, 1)) assert_size_stride(primals_5, (600,), (1,)) assert_size_stride(primals_6, (200, 600), (600, 1)) assert_size_stride(primals_7, (200,), (1,)) assert_size_stride(primals_8, (200, 600), (600, 1)) assert_size_stride(primals_9, (200,), (1,)) assert_size_stride(primals_10, (600, 200), (200, 1)) assert_size_stride(primals_11, (600,), (1,)) assert_size_stride(primals_12, (600, 600), (600, 1)) assert_size_stride(primals_13, (600,), (1,)) assert_size_stride(primals_14, (4, 600), (600, 1)) assert_size_stride(primals_15, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 600), (600, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 600), (1, 4), 0), out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 600), (2400, 600, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(9600)](buf1, primals_3, 9600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((16, 600), (600, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (16, 600), (600, 1), 0), reinterpret_tensor(primals_4, (600, 600), (1, 600), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 600), (2400, 600, 1), 0) del buf2 triton_poi_fused_tanh_0[grid(9600)](buf3, primals_5, 9600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((16, 200), (200, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (16, 600), (600, 1), 0), reinterpret_tensor(primals_6, (600, 200), (1, 600 ), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((16, 200), (200, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf3, (16, 600), (600, 1), 0), reinterpret_tensor(primals_8, (600, 200), (1, 600 ), 0), alpha=1, beta=1, out=buf5) del primals_9 buf6 = empty_strided_cuda((16, 600), (600, 1), torch.float32) extern_kernels.mm(buf4, reinterpret_tensor(primals_10, (200, 600), (1, 200), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 600), (2400, 600, 1), 0) del buf6 triton_poi_fused_tanh_0[grid(9600)](buf7, primals_11, 9600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_11 buf8 = empty_strided_cuda((16, 600), (600, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (16, 600), (600, 1), 0), reinterpret_tensor(primals_12, (600, 600), (1, 600), 0), out=buf8) buf9 = reinterpret_tensor(buf8, (4, 4, 600), (2400, 600, 1), 0) del buf8 triton_poi_fused_tanh_0[grid(9600)](buf9, primals_13, 9600, XBLOCK= 128, num_warps=4, num_stages=1) del primals_13 buf10 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_15, reinterpret_tensor(buf9, (16, 600), (600, 1), 0), reinterpret_tensor(primals_14, (600, 4), (1, 600), 0), alpha=1, beta=1, out=buf10) del primals_15 buf11 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_tanh_1[grid(64)](buf10, buf11, 64, XBLOCK =64, num_warps=1, num_stages=1) buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__softmax_mul_2[grid(64)](buf11, primals_1, buf12, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf11 return (buf12, reinterpret_tensor(buf4, (4, 4, 200), (800, 200, 1), 0), reinterpret_tensor(buf5, (4, 4, 200), (800, 200, 1), 0), primals_1, buf1, buf3, buf4, buf7, buf9, buf10, primals_14, primals_12, primals_10, primals_8, primals_6, primals_4) class MultVAE_encoder(nn.Module): def __init__(self, item_dim: 'int', hidden_dim=600, latent_dim=200, n_hidden_layers=1, dropout=0.5, nonlinearity=nn.Tanh): super(MultVAE_encoder, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nn.Tanh() self.layers = nn.Sequential() self.layers.add_module('input_dropout', nn.Dropout(dropout)) self.layers.add_module('linear_enc_1', nn.Linear(in_features= item_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_enc_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_enc_{}'.format(i + 2), self. nonlinearity) self.mu = nn.Linear(in_features=hidden_dim, out_features=latent_dim) self.logvar = nn.Linear(in_features=hidden_dim, out_features=latent_dim ) def forward(self, x): output = self.layers(x) mu = self.mu(output) logvar = self.logvar(output) return mu, logvar class MultVAE_decoder(nn.Module): def __init__(self, item_dim, hidden_dim=600, latent_dim=200, n_hidden_layers=1, nonlinearity=nn.Tanh): super(MultVAE_decoder, self).__init__() self.item_dim = item_dim self.latent_dim = latent_dim self.nonlinearity = nonlinearity() self.layers = nn.Sequential() self.layers.add_module('linear_dec_1', nn.Linear(in_features= latent_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_dec_1', self.nonlinearity) if n_hidden_layers > 0: for i in range(n_hidden_layers): self.layers.add_module('hidden_dec_{}'.format(i + 1), nn. Linear(in_features=hidden_dim, out_features=hidden_dim)) self.layers.add_module('Tanh_dec_{}'.format(i + 2), self. nonlinearity) self.item_layer = nn.Linear(in_features=hidden_dim, out_features= item_dim) def forward(self, x): output = self.layers(x) items = self.item_layer(output) items = self.nonlinearity(items) return items class MultVaeNew(nn.Module): def __init__(self, item_dim, hidden_dim=600, latent_dim=200, n_enc_hidden_layers=1, n_dec_hidden_layers=1, dropout=0.5): super(MultVaeNew, self).__init__() self.item_dim = item_dim self.encoder = MultVAE_encoder(item_dim=item_dim, hidden_dim= hidden_dim, latent_dim=latent_dim, n_hidden_layers= n_enc_hidden_layers, dropout=0.5, nonlinearity=nn.Tanh) self.decoder = MultVAE_decoder(item_dim=item_dim, hidden_dim= hidden_dim, latent_dim=latent_dim, n_hidden_layers= n_dec_hidden_layers, nonlinearity=nn.Tanh) self.softmax = nn.Softmax(dim=2) def reparameterize(self, mu, logvar): if self.training: std = torch.exp(0.5 * logvar) eps = torch.randn_like(std) return eps.mul(std).add_(mu) else: return mu def forward(self, input_0): primals_2 = self.encoder.layers.linear_enc_1.weight primals_3 = self.encoder.layers.linear_enc_1.bias primals_4 = self.encoder.layers.hidden_enc_1.weight primals_5 = self.encoder.layers.hidden_enc_1.bias primals_6 = self.encoder.mu.weight primals_7 = self.encoder.mu.bias primals_8 = self.encoder.logvar.weight primals_9 = self.encoder.logvar.bias primals_10 = self.decoder.layers.linear_dec_1.weight primals_11 = self.decoder.layers.linear_dec_1.bias primals_12 = self.decoder.layers.hidden_dec_1.weight primals_13 = self.decoder.layers.hidden_dec_1.bias primals_14 = self.decoder.item_layer.weight primals_15 = self.decoder.item_layer.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15]) return output[0], output[1], output[2]
EricHe98/sad_final_project
MultVae
false
17,269
[ "MIT" ]
3
4b2b57e44f939840eede6f134493c5f8d809b1a7
https://github.com/EricHe98/sad_final_project/tree/4b2b57e44f939840eede6f134493c5f8d809b1a7
CrossEntropyLoss
import torch import torch.nn as nn import torch.nn.functional as F class CrossEntropyLoss(nn.Module): """ cross entropy loss """ def __init__(self): super().__init__() def forward(self, logits, labels): return F.cross_entropy(logits, labels, reduction='none') def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_mul_neg_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 % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp8 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp13 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask) tmp16 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask) tmp20 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask) tmp24 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask) tmp1 = tl_math.exp(tmp0) tmp3 = tl_math.exp(tmp2) tmp4 = tmp1 + tmp3 tmp6 = tl_math.exp(tmp5) tmp7 = tmp4 + tmp6 tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp11 = tl_math.log(tmp10) tmp12 = tmp0 - tmp11 tmp14 = tmp12 * tmp13 tmp15 = tmp2 - tmp11 tmp17 = tmp15 * tmp16 tmp18 = tmp14 + tmp17 tmp19 = tmp5 - tmp11 tmp21 = tmp19 * tmp20 tmp22 = tmp18 + tmp21 tmp23 = tmp8 - tmp11 tmp25 = tmp23 * tmp24 tmp26 = tmp22 + tmp25 tmp27 = -tmp26 tl.store(out_ptr0 + x2, tmp27, 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__log_softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused__log_softmax_mul_neg_sum_1[grid(64)](buf0, arg0_1, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del buf0 return buf1, class CrossEntropyLossNew(nn.Module): """ cross entropy loss """ 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]
Equationliu/GA-Attack
CrossEntropyLoss
false
17,270
[ "MIT" ]
8
b0280674a211f6451774ec6b1d4cee2fc19a4de6
https://github.com/Equationliu/GA-Attack/tree/b0280674a211f6451774ec6b1d4cee2fc19a4de6
MultiHeadAttn
import math import torch from torch import nn import torch.nn.functional as F class MultiHeadAttn(nn.Module): def __init__(self, d_model, n_head, dropout=0.1, scale=False): super().__init__() assert d_model % n_head == 0 self.n_head = n_head self.qkv_linear = nn.Linear(d_model, 3 * d_model) self.fc = nn.Linear(d_model, d_model) self.dropout_layer = nn.Dropout(dropout) if scale: self.scale = math.sqrt(d_model // n_head) else: self.scale = 1 def forward(self, x, mask): """ :param x: bsz x max_len x d_model :param mask: bsz x max_len :return: """ batch_size, max_len, _d_model = x.size() x = self.qkv_linear(x) q, k, v = torch.chunk(x, 3, dim=-1) q = q.view(batch_size, max_len, self.n_head, -1).transpose(1, 2) k = k.view(batch_size, max_len, self.n_head, -1).permute(0, 2, 3, 1) v = v.view(batch_size, max_len, self.n_head, -1).transpose(1, 2) attn = torch.matmul(q, k) attn = attn / self.scale attn.masked_fill_(mask=mask[:, None, None].eq(0), value=float('-inf')) attn = F.softmax(attn, dim=-1) attn = self.dropout_layer(attn) v = torch.matmul(attn, v) v = v.transpose(1, 2).reshape(batch_size, max_len, -1) v = self.fc(v) return v def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'n_head': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import 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_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_1(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (4 + y0), ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_eq_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 tl.store(out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused__softmax_div_masked_fill_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 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last').to(tl .int1) tmp1 = tl.load(in_ptr1 + 4 * x2, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp7 = tl.load(in_ptr1 + (1 + 4 * x2), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp12 = tl.load(in_ptr1 + (2 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = float('-inf') tmp5 = tl.where(tmp0, tmp4, tmp3) tmp8 = tmp7 * tmp2 tmp9 = tl.where(tmp6, tmp4, tmp8) tmp10 = triton_helpers.maximum(tmp5, tmp9) tmp13 = tmp12 * tmp2 tmp14 = tl.where(tmp11, tmp4, tmp13) tmp15 = triton_helpers.maximum(tmp10, tmp14) tmp18 = tmp17 * tmp2 tmp19 = tl.where(tmp16, tmp4, tmp18) tmp20 = triton_helpers.maximum(tmp15, tmp19) tmp21 = tmp5 - tmp20 tmp22 = tl_math.exp(tmp21) tmp23 = tmp9 - tmp20 tmp24 = tl_math.exp(tmp23) tmp25 = tmp22 + tmp24 tmp26 = tmp14 - tmp20 tmp27 = tl_math.exp(tmp26) tmp28 = tmp25 + tmp27 tmp29 = tmp19 - tmp20 tmp30 = tl_math.exp(tmp29) tmp31 = tmp28 + tmp30 tl.store(out_ptr0 + x2, tmp20, xmask) tl.store(out_ptr1 + x2, tmp31, xmask) @triton.jit def triton_poi_fused__softmax_div_masked_fill_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex // 64 x3 = xindex x4 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ).to(tl.int1) tmp1 = tl.load(in_out_ptr0 + x3, xmask) tmp6 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = float('-inf') tmp5 = tl.where(tmp0, tmp4, tmp3) tmp7 = tmp5 - tmp6 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 / tmp9 tl.store(in_out_ptr0 + x3, tmp10, xmask) @triton.jit def triton_poi_fused_clone_5(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (8 + y0), ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_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 + (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_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) 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, (12, 4), (4, 1)) assert_size_stride(primals_3, (12,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 12), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_3, buf1, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32) triton_poi_fused_clone_1[grid(16, 4)](buf0, primals_3, buf2, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf2, (16, 1, 4), (4, 0, 1), 0), out=buf3) buf4 = empty_strided_cuda((4, 1, 1, 4), (4, 4, 4, 1), torch.bool) triton_poi_fused_eq_2[grid(16)](primals_4, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_div_masked_fill_3[grid(64)](buf4, buf3, buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf3 triton_poi_fused__softmax_div_masked_fill_4[grid(256)](buf7, buf4, buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf8 = reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf6 triton_poi_fused_clone_5[grid(16, 4)](buf0, primals_3, buf8, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del buf0 del primals_3 buf9 = reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 1), 0) del buf5 extern_kernels.bmm(reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf8, (16, 4, 1), (4, 1, 0), 0), out=buf9) buf10 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_6[grid(16, 4)](buf9, buf10, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf11 = reinterpret_tensor(buf9, (16, 4), (4, 1), 0) del buf9 extern_kernels.mm(reinterpret_tensor(buf10, (16, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf11) buf12 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0) del buf11 triton_poi_fused_add_7[grid(64)](buf12, primals_6, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_6 return buf12, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0 ), buf4, buf7, reinterpret_tensor(buf10, (16, 4), (4, 1), 0 ), primals_5, reinterpret_tensor(buf8, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf1, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 4), 0) class MultiHeadAttnNew(nn.Module): def __init__(self, d_model, n_head, dropout=0.1, scale=False): super().__init__() assert d_model % n_head == 0 self.n_head = n_head self.qkv_linear = nn.Linear(d_model, 3 * d_model) self.fc = nn.Linear(d_model, d_model) self.dropout_layer = nn.Dropout(dropout) if scale: self.scale = math.sqrt(d_model // n_head) else: self.scale = 1 def forward(self, input_0, input_1): primals_2 = self.qkv_linear.weight primals_3 = self.qkv_linear.bias primals_4 = self.fc.weight primals_6 = self.fc.bias primals_1 = input_0 primals_5 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
EmanuelaBoros/stacked-ner
MultiHeadAttn
false
17,271
[ "MIT" ]
4
b57e4fcf777a5ad2519ffa7223364e383975bf7d
https://github.com/EmanuelaBoros/stacked-ner/tree/b57e4fcf777a5ad2519ffa7223364e383975bf7d
KLLoss
import torch import torch.nn as nn import torch.utils.data class KLLoss(nn.Module): def __init__(self, size_average=False): super().__init__() self.size_average = size_average def forward(self, mu, logvar): loss = 0.5 * (mu.pow(2) + logvar.exp() - logvar - 1) if self.size_average: loss = loss.mean() else: loss = loss.sum() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 @triton.jit def triton_per_fused_add_exp_mul_pow_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp2 = tl.load(in_ptr1 + r0, None) tmp1 = tmp0 * tmp0 tmp3 = tl_math.exp(tmp2) tmp4 = tmp1 + tmp3 tmp5 = tmp4 - tmp2 tmp6 = 1.0 tmp7 = tmp5 - tmp6 tmp8 = 0.5 tmp9 = tmp7 * tmp8 tmp10 = tl.broadcast_to(tmp9, [RBLOCK]) tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0)) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp12, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_add_exp_mul_pow_sub_sum_0[grid(1)](arg0_1, arg1_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf0, class KLLossNew(nn.Module): def __init__(self, size_average=False): super().__init__() self.size_average = size_average def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
ForrestPi/VAEGAN
KLLoss
false
17,272
[ "MIT" ]
8
c2cfeedcc2dcfad6258468611536d9a8222eb8a3
https://github.com/ForrestPi/VAEGAN/tree/c2cfeedcc2dcfad6258468611536d9a8222eb8a3
AttentionHead
import math import torch import torch.utils.data import torch.nn as nn class AttentionHead(nn.Module): def __init__(self, d_model, d_k, d_v, device): super(AttentionHead, self).__init__() self.dk = math.sqrt(d_k) self.query_layer = nn.Linear(d_model, d_k) self.key_layer = nn.Linear(d_model, d_k) self.value_layer = nn.Linear(d_model, d_v) self def forward(self, input_query, input_key, input_value): query = self.query_layer(input_query) key = torch.transpose(self.key_layer(input_key), 1, 2) value = self.value_layer(input_value) score = torch.matmul(query, key) score = torch.nn.functional.softmax(score, dim=2) z = torch.matmul(score, value) return z def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 4, 'd_k': 4, 'd_v': 4, 'device': 0}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import math import torch.utils.data import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tmp1 = 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__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4, 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(256)](buf1, primals_5, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0) del buf1 extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1), 0), out=buf4) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) buf7 = reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0) del buf5 extern_kernels.bmm(reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf7) return reinterpret_tensor(buf7, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_6, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0 ), buf6, reinterpret_tensor(buf2, (16, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf0, (16, 4, 4), (16, 1, 4), 0 ), reinterpret_tensor(buf3, (16, 4, 4), (16, 1, 4), 0) class AttentionHeadNew(nn.Module): def __init__(self, d_model, d_k, d_v, device): super(AttentionHeadNew, self).__init__() self.dk = math.sqrt(d_k) self.query_layer = nn.Linear(d_model, d_k) self.key_layer = nn.Linear(d_model, d_k) self.value_layer = nn.Linear(d_model, d_v) self def forward(self, input_0, input_1, input_2): primals_1 = self.query_layer.weight primals_2 = self.query_layer.bias primals_4 = self.key_layer.weight primals_5 = self.key_layer.bias primals_7 = self.value_layer.weight primals_8 = self.value_layer.bias primals_3 = 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]) return output[0]
ErikHumphrey/sustain-seq2seq
AttentionHead
false
17,273
[ "Apache-2.0" ]
4
c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
https://github.com/ErikHumphrey/sustain-seq2seq/tree/c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
AdditiveAttention
import torch import torch.utils.data import torch.nn as nn class AdditiveAttention(nn.Module): def __init__(self, enc_hidden_dim, dec_hidden_dim): super(AdditiveAttention, self).__init__() self.attention_w1 = nn.Linear(enc_hidden_dim, enc_hidden_dim) self.attention_w2 = nn.Linear(dec_hidden_dim, enc_hidden_dim) self.attention_v = nn.Linear(enc_hidden_dim, 1) self.softmax = nn.Softmax(dim=1) self.enc_hidden_dim = enc_hidden_dim self.should_print = False self.att_mat = [] def forward(self, encoder_outputs, decoder_output): w2_decoder_output = self.attention_w2(decoder_output) w1_transformed_encoder_outputs = self.attention_w1(encoder_outputs) w1_w2_sum = w1_transformed_encoder_outputs + w2_decoder_output w1_w2_sum_tanh = w1_w2_sum.tanh() attention_weights = self.attention_v(w1_w2_sum_tanh) softmax_attention_weights = self.softmax(attention_weights.squeeze(2)) if self.should_print: to_cpu = softmax_attention_weights.cpu() row = to_cpu[0].data.numpy() self.att_mat.append(row) weighted_encoder_outputs = (encoder_outputs * softmax_attention_weights.unsqueeze(2).expand(-1, -1, self. enc_hidden_dim)) context = weighted_encoder_outputs.sum(dim=1) return context def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'enc_hidden_dim': 4, 'dec_hidden_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.utils.data import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_tanh_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x4 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = libdevice.tanh(tmp6) tl.store(in_out_ptr0 + x3, tmp7, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_mul_sum_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask) tmp14 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask) tmp18 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask) tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp1 / tmp7 tmp9 = tmp0 * tmp8 tmp11 = tmp2 / tmp7 tmp12 = tmp10 * tmp11 tmp13 = tmp9 + tmp12 tmp15 = tmp4 / tmp7 tmp16 = tmp14 * tmp15 tmp17 = tmp13 + tmp16 tmp19 = tmp6 / tmp7 tmp20 = tmp18 * tmp19 tmp21 = tmp17 + tmp20 tl.store(out_ptr0 + x2, tmp21, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_7, (1, 4), (4, 1)) assert_size_stride(primals_8, (1,), (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_3, reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 get_raw_stream(0) triton_poi_fused_add_tanh_0[grid(64)](buf2, primals_5, buf0, primals_2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_2 del primals_5 buf4 = reinterpret_tensor(buf0, (16, 1), (1, 1), 0) del buf0 extern_kernels.addmm(primals_8, reinterpret_tensor(buf2, (16, 4), ( 4, 1), 0), reinterpret_tensor(primals_7, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_8 buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_1[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_mul_sum_2[grid(16)](primals_6, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf5 return buf6, primals_3, primals_6, buf2, buf4, primals_7 class AdditiveAttentionNew(nn.Module): def __init__(self, enc_hidden_dim, dec_hidden_dim): super(AdditiveAttentionNew, self).__init__() self.attention_w1 = nn.Linear(enc_hidden_dim, enc_hidden_dim) self.attention_w2 = nn.Linear(dec_hidden_dim, enc_hidden_dim) self.attention_v = nn.Linear(enc_hidden_dim, 1) self.softmax = nn.Softmax(dim=1) self.enc_hidden_dim = enc_hidden_dim self.should_print = False self.att_mat = [] def forward(self, input_0, input_1): primals_1 = self.attention_w1.weight primals_2 = self.attention_w1.bias primals_3 = self.attention_w2.weight primals_5 = self.attention_w2.bias primals_7 = self.attention_v.weight primals_8 = self.attention_v.bias primals_6 = 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]
ErikHumphrey/sustain-seq2seq
AdditiveAttention
false
17,274
[ "Apache-2.0" ]
4
c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
https://github.com/ErikHumphrey/sustain-seq2seq/tree/c4787f0ca1047d01385e4fa4ffde59c6a8ab4cc4
SimpleLoss
import torch class SimpleLoss(torch.nn.Module): def forward(self, output, target): return output / target def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 / tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleLossNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
FranciscoShi/piepline
SimpleLoss
false
17,276
[ "MIT" ]
5
6105788339fc18bab39ea07625b5fd26ad687254
https://github.com/FranciscoShi/piepline/tree/6105788339fc18bab39ea07625b5fd26ad687254
ScaledDotProductAttention
import torch import torch.nn as nn import torch.optim import torch.autograd import torch.nn import torch.nn.init class ScaledDotProductAttention(nn.Module): def __init__(self, d_model, attention_dropout=0.1): super(ScaledDotProductAttention, self).__init__() self.temper = d_model ** 0.5 self.dropout = nn.Dropout(attention_dropout) self.softmax = nn.Softmax(dim=-1) def forward(self, q, k, v, attn_mask=None): attn = torch.bmm(q, k.transpose(1, 2)) / self.temper if attn_mask is not None: assert attn_mask.size() == attn.size( ), 'Attention mask shape {} mismatch with Attention logit tensor shape {}.'.format( attn_mask.size(), attn.size()) attn.data.masked_fill_(attn_mask, -float('inf')) attn = self.softmax(attn) attn = self.dropout(attn) output = torch.bmm(attn, v) return output, attn def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]) ] def get_init_inputs(): return [[], {'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.optim import torch.autograd import torch.nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = tl_math.exp(tmp16) tl.store(out_ptr0 + x2, tmp17, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), ( 16, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = buf0 del buf0 triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf3 = buf1 del buf1 extern_kernels.bmm(buf2, arg2_1, out=buf3) del arg2_1 return buf3, buf2 class ScaledDotProductAttentionNew(nn.Module): def __init__(self, d_model, attention_dropout=0.1): super(ScaledDotProductAttentionNew, self).__init__() self.temper = d_model ** 0.5 self.dropout = nn.Dropout(attention_dropout) self.softmax = nn.Softmax(dim=-1) def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0], output[1]
FilippoC/-deep-syntactic-dependency-parsing-release
ScaledDotProductAttention
false
17,277
[ "MIT" ]
4
30e2571ea930c2fd81559f5a2a971e3738cc6d39
https://github.com/FilippoC/-deep-syntactic-dependency-parsing-release/tree/30e2571ea930c2fd81559f5a2a971e3738cc6d39
ConcatELU
import torch import torch.nn as nn import torch.nn.functional as F class ConcatELU(nn.Module): """ Activation function that applies ELU in both direction (inverted and plain). Allows non-linearity while providing strong gradients for any input (important for final convolution) """ def forward(self, x): return torch.cat([F.elu(x), F.elu(-x)], dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import 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_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = 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], 8, tl.int64) tmp18 = tl.load(in_ptr0 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp15 & xmask, other=0.0) tmp19 = -tmp18 tmp20 = tmp19 > tmp6 tmp21 = tmp19 * tmp8 tmp22 = libdevice.expm1(tmp21) tmp23 = tmp22 * tmp8 tmp24 = tl.where(tmp20, tmp21, tmp23) tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp15, tmp24, tmp25) tmp27 = tl.where(tmp4, tmp14, tmp26) tl.store(out_ptr0 + x3, 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, 8, 4, 4), (128, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(512)](arg0_1, buf0, 512, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class ConcatELUNew(nn.Module): """ Activation function that applies ELU in both direction (inverted and plain). Allows non-linearity while providing strong gradients for any input (important for final convolution) """ def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
GBATZOLIS/CAFLOW
ConcatELU
false
17,278
[ "MIT" ]
6
ea33f84c424bd8e46999be59cd5d52bd8f0a3a77
https://github.com/GBATZOLIS/CAFLOW/tree/ea33f84c424bd8e46999be59cd5d52bd8f0a3a77
HDRLoss
import torch import torch.nn as nn class HDRLoss(nn.Module): def __init__(self): super().__init__() def forward(self, out_img, ref_img): return torch.mean((out_img - ref_img) ** 2) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_mean_pow_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp8, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_pow_sub_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class HDRLossNew(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]
Galaxies99/NHDRRNet-pytorch
HDRLoss
false
17,279
[ "MIT" ]
10
b20aae987e586a6cf9c9c52fc07b0884ce6fdf37
https://github.com/Galaxies99/NHDRRNet-pytorch/tree/b20aae987e586a6cf9c9c52fc07b0884ce6fdf37
LayerNorm
import torch import torch.nn as nn import torch.optim import torch.autograd import torch.nn import torch.nn.init class LayerNorm(nn.Module): def __init__(self, dim, mean=0.0, std=1.0, fixed=False, eps=1e-06, ball =False): super(LayerNorm, self).__init__() self.eps = eps self.ball = ball if fixed: self.target_mean = mean self.target_std = std else: self.target_mean = nn.Parameter(torch.empty(dim).fill_(mean)) self.target_std = nn.Parameter(torch.empty(dim).fill_(std)) def forward(self, x): mean = x.mean(-1, keepdim=True) std = torch.sqrt(torch.mean((x - mean).pow(2), dim=-1, keepdim=True ) + self.eps) if self.ball: std = std.clamp(1.0) return self.target_std * (x - mean) / std + self.target_mean def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.optim import torch.autograd import torch.nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mean_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = 4.0 tmp9 = tmp7 / tmp8 tmp10 = tmp0 - tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_pow_sqrt_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 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) tmp3 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp20 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp4 + tmp6 tmp9 = tmp8 * tmp8 tmp10 = tmp7 + tmp9 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = 4.0 tmp15 = tmp13 / tmp14 tmp16 = 1e-06 tmp17 = tmp15 + tmp16 tmp18 = libdevice.sqrt(tmp17) tmp19 = tmp2 / tmp18 tmp21 = tmp19 + tmp20 tl.store(out_ptr0 + x2, tmp21, 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_mean_sub_0[grid(256)](primals_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_pow_sqrt_1[grid(256)](primals_2, buf0, primals_3, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 del primals_3 return buf1, primals_1 class LayerNormNew(nn.Module): def __init__(self, dim, mean=0.0, std=1.0, fixed=False, eps=1e-06, ball =False): super(LayerNormNew, self).__init__() self.eps = eps self.ball = ball if fixed: self.target_mean = mean self.target_std = std else: self.target_mean = nn.Parameter(torch.empty(dim).fill_(mean)) self.target_std = nn.Parameter(torch.empty(dim).fill_(std)) def forward(self, input_0): primals_2 = self.target_mean primals_3 = self.target_std primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
FilippoC/-deep-syntactic-dependency-parsing-release
LayerNorm
false
17,280
[ "MIT" ]
4
30e2571ea930c2fd81559f5a2a971e3738cc6d39
https://github.com/FilippoC/-deep-syntactic-dependency-parsing-release/tree/30e2571ea930c2fd81559f5a2a971e3738cc6d39
FencepostModule
import torch import torch.nn as nn import torch.optim import torch.autograd import torch.nn import torch.nn.init class FencepostModule(nn.Module): def __init__(self, input_dim, repr_dim, n_labels, disentangle=False, label_bias=True, span_bias=False, activation='tanh'): super(FencepostModule, self).__init__() self.disentangle = disentangle self.activation_name = activation if activation == 'tanh': self.activation = torch.tanh elif activation == 'relu': self.activation = torch.relu elif activation == 'leaky_relu': self.activation = torch.nn.LeakyReLU() else: raise RuntimeError('Unknown activation function: %s' % self. activation_name) self.label_bias = label_bias self.span_bias = span_bias self.label_output_mlp = nn.Linear(input_dim, repr_dim, bias=True) self.label_output_projection = torch.nn.Parameter(data=torch.Tensor (repr_dim, n_labels)) if self.span_bias: self.span_output_mlp = nn.Linear(input_dim, repr_dim, bias=True) self.span_output_projection = torch.nn.Parameter(data=torch. Tensor(repr_dim, 1)) if self.label_bias: self.output_bias = torch.nn.Parameter(data=torch.Tensor(1, n_labels)) self.initialize_parameters() def initialize_parameters(self): with torch.no_grad(): if self.activation_name == 'tanh': torch.nn.init.xavier_uniform_(self.label_output_mlp.weight) else: torch.nn.init.kaiming_normal_(self.label_output_mlp.weight, nonlinearity=self.activation_name) torch.nn.init.zeros_(self.label_output_mlp.bias) torch.nn.init.xavier_uniform_(self.label_output_projection) if self.span_bias: if self.activation_name == 'tanh': torch.nn.init.xavier_uniform_(self.span_output_mlp.weight) else: torch.nn.init.kaiming_uniform_(self.span_output_mlp. weight, nonlinearity=self.activation_name) torch.nn.init.zeros_(self.span_output_mlp.bias) torch.nn.init.xavier_uniform_(self.span_output_projection) if self.label_bias: self.output_bias.fill_(0.0) """ Input dimension is: (n_words + 2, input_repr) """ def forward(self, input): n_words = input.size()[0] input_repr = input.size()[1] if self.disentangle: input = torch.cat([input[:, 0::2], input[:, 1::2]], 1) fencepost_annotations = torch.cat([input[:-1, :input_repr // 2], - input[1:, input_repr // 2:]], 1) span_features = torch.unsqueeze(fencepost_annotations, 0 ) - torch.unsqueeze(fencepost_annotations, 1) n_words = span_features.size()[0] span_features = span_features.view(n_words * n_words, -1) output = self.activation(self.label_output_mlp(span_features) ) @ self.label_output_projection if self.span_bias: output = output + self.activation(self.span_output_mlp( span_features)) @ self.span_output_projection if self.label_bias: output = output + self.output_bias output = output.view(n_words, n_words, -1) return output def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'repr_dim': 4, 'n_labels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.optim import torch.autograd import torch.nn import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sub_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 36 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 3 x2 = xindex // 12 x3 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 2, 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], 4, tl.int64) tmp9 = tl.load(in_ptr0 + (6 + 4 * x1 + (-2 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = -tmp9 tmp11 = tl.full(tmp10.shape, 0.0, tmp10.dtype) tmp12 = tl.where(tmp6, tmp10, tmp11) tmp13 = tl.where(tmp4, tmp5, tmp12) tmp14 = tl.load(in_ptr0 + (4 * x2 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp15 = tl.load(in_ptr0 + (6 + 4 * x2 + (-2 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = -tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp6, tmp16, tmp17) tmp19 = tl.where(tmp4, tmp14, tmp18) tmp20 = tmp13 - tmp19 tl.store(out_ptr0 + x3, tmp20, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 36 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, 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, (1, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((3, 3, 4), (12, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sub_0[grid(36)](primals_1, buf0, 36, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((9, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (9, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = buf1 del buf1 triton_poi_fused_tanh_1[grid(36)](buf2, primals_3, 36, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 buf3 = empty_strided_cuda((9, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, buf2, primals_4, alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (3, 3, 4), (12, 4, 1), 0 ), reinterpret_tensor(buf0, (9, 4), (4, 1), 0 ), buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4), 0) class FencepostModuleNew(nn.Module): def __init__(self, input_dim, repr_dim, n_labels, disentangle=False, label_bias=True, span_bias=False, activation='tanh'): super(FencepostModuleNew, self).__init__() self.disentangle = disentangle self.activation_name = activation if activation == 'tanh': self.activation = torch.tanh elif activation == 'relu': self.activation = torch.relu elif activation == 'leaky_relu': self.activation = torch.nn.LeakyReLU() else: raise RuntimeError('Unknown activation function: %s' % self. activation_name) self.label_bias = label_bias self.span_bias = span_bias self.label_output_mlp = nn.Linear(input_dim, repr_dim, bias=True) self.label_output_projection = torch.nn.Parameter(data=torch.Tensor (repr_dim, n_labels)) if self.span_bias: self.span_output_mlp = nn.Linear(input_dim, repr_dim, bias=True) self.span_output_projection = torch.nn.Parameter(data=torch. Tensor(repr_dim, 1)) if self.label_bias: self.output_bias = torch.nn.Parameter(data=torch.Tensor(1, n_labels)) self.initialize_parameters() def initialize_parameters(self): with torch.no_grad(): if self.activation_name == 'tanh': torch.nn.init.xavier_uniform_(self.label_output_mlp.weight) else: torch.nn.init.kaiming_normal_(self.label_output_mlp.weight, nonlinearity=self.activation_name) torch.nn.init.zeros_(self.label_output_mlp.bias) torch.nn.init.xavier_uniform_(self.label_output_projection) if self.span_bias: if self.activation_name == 'tanh': torch.nn.init.xavier_uniform_(self.span_output_mlp.weight) else: torch.nn.init.kaiming_uniform_(self.span_output_mlp. weight, nonlinearity=self.activation_name) torch.nn.init.zeros_(self.span_output_mlp.bias) torch.nn.init.xavier_uniform_(self.span_output_projection) if self.label_bias: self.output_bias.fill_(0.0) """ Input dimension is: (n_words + 2, input_repr) """ def forward(self, input_0): primals_1 = self.label_output_projection primals_5 = self.output_bias primals_2 = self.label_output_mlp.weight primals_3 = self.label_output_mlp.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
FilippoC/-deep-syntactic-dependency-parsing-release
FencepostModule
false
17,281
[ "MIT" ]
4
30e2571ea930c2fd81559f5a2a971e3738cc6d39
https://github.com/FilippoC/-deep-syntactic-dependency-parsing-release/tree/30e2571ea930c2fd81559f5a2a971e3738cc6d39
CenterCosineSimilarity
import torch import torch.nn as nn class CenterCosineSimilarity(nn.Module): def __init__(self, feat_dim, num_centers, eps=1e-08): super(CenterCosineSimilarity, self).__init__() self.centers = nn.Parameter(torch.randn(num_centers, feat_dim)) self.eps = eps def forward(self, feat): norm_f = torch.norm(feat, p=2, dim=-1, keepdim=True) feat_normalized = torch.div(feat, norm_f) norm_c = torch.norm(self.centers, p=2, dim=-1, keepdim=True) center_normalized = torch.div(self.centers, norm_c) return torch.mm(feat_normalized, center_normalized.t()) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'feat_dim': 4, 'num_centers': 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_div_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = tmp0 / tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_linalg_vector_norm_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_linalg_vector_norm_0[grid(16)](primals_2, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2) del buf1 return buf2, primals_2, buf0 class CenterCosineSimilarityNew(nn.Module): def __init__(self, feat_dim, num_centers, eps=1e-08): super(CenterCosineSimilarityNew, self).__init__() self.centers = nn.Parameter(torch.randn(num_centers, feat_dim)) self.eps = eps def forward(self, input_0): primals_1 = self.centers primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
GT-RIPL/DistillMatch-SSCL
CenterCosineSimilarity
false
17,282
[ "MIT" ]
9
e572671fd6994b3c43ad6e46e9efb3588804524c
https://github.com/GT-RIPL/DistillMatch-SSCL/tree/e572671fd6994b3c43ad6e46e9efb3588804524c
BBoxTransform
import torch import torch.nn as nn class BBoxTransform(nn.Module): def forward(self, anchors, regression): """ decode_box_outputs adapted from https://github.com/google/automl/blob/master/efficientdet/anchors.py Args: anchors: [batchsize, boxes, (y1, x1, y2, x2)] regression: [batchsize, boxes, (dy, dx, dh, dw)] Returns: """ y_centers_a = (anchors[..., 0] + anchors[..., 2]) / 2 x_centers_a = (anchors[..., 1] + anchors[..., 3]) / 2 ha = anchors[..., 2] - anchors[..., 0] wa = anchors[..., 3] - anchors[..., 1] w = regression[..., 3].exp() * wa h = regression[..., 2].exp() * ha y_centers = regression[..., 0] * ha + y_centers_a x_centers = regression[..., 1] * wa + x_centers_a ymin = y_centers - h / 2.0 xmin = x_centers - w / 2.0 ymax = y_centers + h / 2.0 xmax = x_centers + w / 2.0 return torch.stack([xmin, ymin, xmax, ymax], dim=2) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_stack_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (1 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp8 = tmp6 - tmp7 tmp9 = tmp5 * tmp8 tmp10 = tmp7 + tmp6 tmp11 = 0.5 tmp12 = tmp10 * tmp11 tmp13 = tmp9 + tmp12 tmp14 = tl.load(in_ptr0 + (3 + 4 * x0 + 16 * x1), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl_math.exp(tmp14) tmp16 = tmp15 * tmp8 tmp17 = tmp16 * tmp11 tmp18 = tmp13 - tmp17 tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp4, tmp18, tmp19) tmp21 = tmp0 >= tmp3 tmp22 = tl.full([1], 8, tl.int64) tmp23 = tmp0 < tmp22 tmp24 = tmp21 & tmp23 tmp25 = tl.load(in_ptr0 + (4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp26 = tl.load(in_ptr1 + (2 + 4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp27 = tl.load(in_ptr1 + (4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tmp26 - tmp27 tmp29 = tmp25 * tmp28 tmp30 = tmp27 + tmp26 tmp31 = tmp30 * tmp11 tmp32 = tmp29 + tmp31 tmp33 = tl.load(in_ptr0 + (2 + 4 * (-4 + x0) + 16 * x1), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp34 = tl_math.exp(tmp33) tmp35 = tmp34 * tmp28 tmp36 = tmp35 * tmp11 tmp37 = tmp32 - tmp36 tmp38 = tl.full(tmp37.shape, 0.0, tmp37.dtype) tmp39 = tl.where(tmp24, tmp37, tmp38) tmp40 = tmp0 >= tmp22 tmp41 = tl.full([1], 12, tl.int64) tmp42 = tmp0 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tl.load(in_ptr0 + (1 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp45 = tl.load(in_ptr1 + (3 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp46 = tl.load(in_ptr1 + (1 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp47 = tmp45 - tmp46 tmp48 = tmp44 * tmp47 tmp49 = tmp46 + tmp45 tmp50 = tmp49 * tmp11 tmp51 = tmp48 + tmp50 tmp52 = tl.load(in_ptr0 + (3 + 4 * (-8 + x0) + 16 * x1), tmp43 & xmask, eviction_policy='evict_last', other=0.0) tmp53 = tl_math.exp(tmp52) tmp54 = tmp53 * tmp47 tmp55 = tmp54 * tmp11 tmp56 = tmp51 + tmp55 tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype) tmp58 = tl.where(tmp43, tmp56, tmp57) tmp59 = tmp0 >= tmp41 tl.full([1], 16, tl.int64) tmp62 = tl.load(in_ptr0 + (4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp63 = tl.load(in_ptr1 + (2 + 4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp64 = tl.load(in_ptr1 + (4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp65 = tmp63 - tmp64 tmp66 = tmp62 * tmp65 tmp67 = tmp64 + tmp63 tmp68 = tmp67 * tmp11 tmp69 = tmp66 + tmp68 tmp70 = tl.load(in_ptr0 + (2 + 4 * (-12 + x0) + 16 * x1), tmp59 & xmask, eviction_policy='evict_last', other=0.0) tmp71 = tl_math.exp(tmp70) tmp72 = tmp71 * tmp65 tmp73 = tmp72 * tmp11 tmp74 = tmp69 + tmp73 tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype) tmp76 = tl.where(tmp59, tmp74, tmp75) tmp77 = tl.where(tmp43, tmp58, tmp76) tmp78 = tl.where(tmp24, tmp39, tmp77) tmp79 = tl.where(tmp4, tmp20, tmp78) tl.store(out_ptr0 + x2, tmp79, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0), class BBoxTransformNew(nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
DerryHub/the-TaobaoLive-Commodity-Identify-Competition
BBoxTransform
false
17,283
[ "MIT" ]
4
7e5e5c4fbddd9949fe01810d58bd7994889c007c
https://github.com/DerryHub/the-TaobaoLive-Commodity-Identify-Competition/tree/7e5e5c4fbddd9949fe01810d58bd7994889c007c
SmoothCrossEntropyLoss
import torch from torch.nn.modules.loss import _WeightedLoss import torch.nn.functional as F class SmoothCrossEntropyLoss(_WeightedLoss): """ Smooth labelling for pytorch. Source: https://stackoverflow.com/questions/55681502/label-smoothing-in-pytorch """ def __init__(self, weight=None, reduction='mean', smoothing=0.0): super().__init__(weight=weight, reduction=reduction) self.smoothing = smoothing self.weight = weight self.reduction = reduction @staticmethod def _smooth_one_hot(targets: 'torch.Tensor', n_classes: 'int', smoothing=0.0): assert 0 <= smoothing < 1 with torch.no_grad(): targets = torch.empty(size=(targets.size(0), n_classes), device =targets.device).fill_(smoothing / (n_classes - 1)).scatter_( 1, targets.data.unsqueeze(1), 1.0 - smoothing) return targets def forward(self, inputs, targets): targets = SmoothCrossEntropyLoss._smooth_one_hot(targets, inputs. size(-1), self.smoothing) lsm = F.log_softmax(inputs, -1) if self.weight is not None: lsm = lsm * self.weight.unsqueeze(0) loss = -(targets * lsm).sum(-1) if self.reduction == 'sum': loss = loss.sum() elif self.reduction == 'mean': loss = loss.mean() return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.ones([4], dtype=torch.int64)] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch.nn.modules.loss import _WeightedLoss assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__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_per_fused__log_softmax_mean_mul_neg_scatter_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 4 r2 = rindex tmp0 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last') tmp6 = tl.load(in_ptr1 + 4 * r2, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (1 + 4 * r2), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr1 + (2 + 4 * r2), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr1 + (3 + 4 * r2), None, eviction_policy='evict_last') tmp1 = tl.full([1, 1], 0, tl.int64) tmp2 = tmp0 == tmp1 tmp3 = 1.0 tmp4 = 0.0 tmp5 = tl.where(tmp2, tmp3, tmp4) tmp7 = tl_math.exp(tmp6) tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp12 = tl_math.exp(tmp11) tmp13 = tmp10 + tmp12 tmp15 = tl_math.exp(tmp14) tmp16 = tmp13 + tmp15 tmp17 = tl_math.log(tmp16) tmp18 = tmp6 - tmp17 tmp19 = tmp5 * tmp18 tmp20 = tl.full([1, 1], 1, tl.int64) tmp21 = tmp0 == tmp20 tmp22 = tl.where(tmp21, tmp3, tmp4) tmp23 = tmp8 - tmp17 tmp24 = tmp22 * tmp23 tmp25 = tmp19 + tmp24 tmp26 = tl.full([1, 1], 2, tl.int64) tmp27 = tmp0 == tmp26 tmp28 = tl.where(tmp27, tmp3, tmp4) tmp29 = tmp11 - tmp17 tmp30 = tmp28 * tmp29 tmp31 = tmp25 + tmp30 tmp32 = tl.full([1, 1], 3, tl.int64) tmp33 = tmp0 == tmp32 tmp34 = tl.where(tmp33, tmp3, tmp4) tmp35 = tmp14 - tmp17 tmp36 = tmp34 * tmp35 tmp37 = tmp31 + tmp36 tmp38 = -tmp37 tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK]) tmp41 = tl.sum(tmp39, 1)[:, None] tmp42 = 64.0 tmp43 = tmp41 / tmp42 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4,), (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_softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 triton_per_fused__log_softmax_mean_mul_neg_scatter_sum_1[grid(1)](buf3, arg1_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg1_1 del buf0 return buf3, class SmoothCrossEntropyLossNew(_WeightedLoss): """ Smooth labelling for pytorch. Source: https://stackoverflow.com/questions/55681502/label-smoothing-in-pytorch """ def __init__(self, weight=None, reduction='mean', smoothing=0.0): super().__init__(weight=weight, reduction=reduction) self.smoothing = smoothing self.weight = weight self.reduction = reduction @staticmethod def _smooth_one_hot(targets: 'torch.Tensor', n_classes: 'int', smoothing=0.0): assert 0 <= smoothing < 1 with torch.no_grad(): targets = torch.empty(size=(targets.size(0), n_classes), device =targets.device).fill_(smoothing / (n_classes - 1)).scatter_( 1, targets.data.unsqueeze(1), 1.0 - smoothing) return targets def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Fuminides/athena
SmoothCrossEntropyLoss
false
17,284
[ "MIT" ]
10
78ad7ad5236dc8f12adc0401c52add3931292e69
https://github.com/Fuminides/athena/tree/78ad7ad5236dc8f12adc0401c52add3931292e69
LinearExcitability
import math import torch from torch import nn from torch.nn.parameter import Parameter def linearExcitability(input, weight, excitability=None, bias=None): """ Applies a linear transformation to the incoming data: :math:`y = c(xA^T) + b`. Shape: - input: :math:`(N, *, in\\_features)` - weight: :math:`(out\\_features, in\\_features)` - excitability: :math:`(out\\_features)` - bias: :math:`(out\\_features)` - output: :math:`(N, *, out\\_features)` (NOTE: `*` means any number of additional dimensions) """ if excitability is not None: output = input.matmul(weight.t()) * excitability else: output = input.matmul(weight.t()) if bias is not None: output += bias return output class LinearExcitability(nn.Module): """Applies a linear transformation to the incoming data: :math:`y = c(Ax) + b` Args: in_features: size of each input sample out_features: size of each output sample bias: if 'False', layer will not learn an additive bias-parameter (DEFAULT=True) excitability: if 'False', layer will not learn a multiplicative excitability-parameter (DEFAULT=True) Shape: - input: :math:`(N, *, in\\_features)` where `*` means any number of additional dimensions - output: :math:`(N, *, out\\_features)` where all but the last dimension are the same shape as the input. Attributes: weight: the learnable weights of the module of shape (out_features x in_features) excitability: the learnable multiplication terms (out_features) bias: the learnable bias of the module of shape (out_features) excit_buffer: fixed multiplication variable (out_features) Examples:: >>> m = LinearExcitability(20, 30) >>> input = autograd.Variable(torch.randn(128, 20)) >>> output = m(input) >>> print(output.size()) """ def __init__(self, in_features, out_features, bias=True, excitability= False, excit_buffer=False): super(LinearExcitability, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if excitability: self.excitability = Parameter(torch.Tensor(out_features)) else: self.register_parameter('excitability', None) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) if excit_buffer: buffer = torch.Tensor(out_features).uniform_(1, 1) self.register_buffer('excit_buffer', buffer) else: self.register_buffer('excit_buffer', None) self.reset_parameters() def reset_parameters(self): """Modifies the parameters "in-place" to reset them at appropriate initialization values""" stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.excitability is not None: self.excitability.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def forward(self, input): """Running this model's forward step requires/returns: INPUT: -[input]: [batch_size]x[...]x[in_features] OUTPUT: -[output]: [batch_size]x[...]x[hidden_features]""" if self.excit_buffer is None: excitability = self.excitability elif self.excitability is None: excitability = self.excit_buffer else: excitability = self.excitability * self.excit_buffer return linearExcitability(input, self.weight, excitability, self.bias) def __repr__(self): return self.__class__.__name__ + '(' + 'in_features=' + str(self. in_features) + ', out_features=' + str(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 math from torch import nn from torch.nn.parameter import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_view_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x4, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 buf2 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_add_view_0[grid(256)](buf2, primals_2, 256, XBLOCK =128, num_warps=4, num_stages=1) del primals_2 return buf2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0) def linearExcitability(input, weight, excitability=None, bias=None): """ Applies a linear transformation to the incoming data: :math:`y = c(xA^T) + b`. Shape: - input: :math:`(N, *, in\\_features)` - weight: :math:`(out\\_features, in\\_features)` - excitability: :math:`(out\\_features)` - bias: :math:`(out\\_features)` - output: :math:`(N, *, out\\_features)` (NOTE: `*` means any number of additional dimensions) """ if excitability is not None: output = input.matmul(weight.t()) * excitability else: output = input.matmul(weight.t()) if bias is not None: output += bias return output class LinearExcitabilityNew(nn.Module): """Applies a linear transformation to the incoming data: :math:`y = c(Ax) + b` Args: in_features: size of each input sample out_features: size of each output sample bias: if 'False', layer will not learn an additive bias-parameter (DEFAULT=True) excitability: if 'False', layer will not learn a multiplicative excitability-parameter (DEFAULT=True) Shape: - input: :math:`(N, *, in\\_features)` where `*` means any number of additional dimensions - output: :math:`(N, *, out\\_features)` where all but the last dimension are the same shape as the input. Attributes: weight: the learnable weights of the module of shape (out_features x in_features) excitability: the learnable multiplication terms (out_features) bias: the learnable bias of the module of shape (out_features) excit_buffer: fixed multiplication variable (out_features) Examples:: >>> m = LinearExcitability(20, 30) >>> input = autograd.Variable(torch.randn(128, 20)) >>> output = m(input) >>> print(output.size()) """ def __init__(self, in_features, out_features, bias=True, excitability= False, excit_buffer=False): super(LinearExcitabilityNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight = Parameter(torch.Tensor(out_features, in_features)) if excitability: self.excitability = Parameter(torch.Tensor(out_features)) else: self.register_parameter('excitability', None) if bias: self.bias = Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) if excit_buffer: buffer = torch.Tensor(out_features).uniform_(1, 1) self.register_buffer('excit_buffer', buffer) else: self.register_buffer('excit_buffer', None) self.reset_parameters() def reset_parameters(self): """Modifies the parameters "in-place" to reset them at appropriate initialization values""" stdv = 1.0 / math.sqrt(self.weight.size(1)) self.weight.data.uniform_(-stdv, stdv) if self.excitability is not None: self.excitability.data.uniform_(1, 1) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def __repr__(self): return self.__class__.__name__ + '(' + 'in_features=' + str(self. in_features) + ', out_features=' + str(self.out_features) + ')' def forward(self, input_0): primals_1 = self.weight primals_2 = self.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GMvandeVen/progressive-learning-pytorch
LinearExcitability
false
17,285
[ "MIT" ]
4
165645b2d7595d94d036f765c9a311d505e667a3
https://github.com/GMvandeVen/progressive-learning-pytorch/tree/165645b2d7595d94d036f765c9a311d505e667a3
LSGanLoss
import torch from torch import nn import torch.optim class LSGanLoss(nn.Module): def __init__(self, layer=3): super(LSGanLoss, self).__init__() self.layer = layer def forward(self, real, fake): loss_G = 0 loss_D = 0 for i in range(self.layer): loss_G = loss_G + torch.mean((fake[i] - torch.ones_like(fake[i] )) ** 2) loss_D = loss_D + 0.5 * (torch.mean((fake[i] - torch.zeros_like (fake[i])) ** 2) + torch.mean((real[i] - torch.ones_like( real[i])) ** 2)) return loss_G, loss_D def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.optim 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_ones_like_pow_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp11 = tl.load(in_ptr1 + r0, None) tmp17 = tl.load(in_ptr0 + (64 + r0), None) tmp27 = tl.load(in_ptr1 + (64 + r0), None) tmp33 = tl.load(in_ptr0 + (128 + r0), None) tmp43 = tl.load(in_ptr1 + (128 + r0), None) tmp1 = 1.0 tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.sum(tmp4, 1)[:, None] tmp7 = tmp0 * tmp0 tmp8 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK]) tmp10 = tl.sum(tmp8, 1)[:, None] tmp12 = tmp11 - tmp1 tmp13 = tmp12 * tmp12 tmp14 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK]) tmp16 = tl.sum(tmp14, 1)[:, None] tmp18 = tmp17 - tmp1 tmp19 = tmp18 * tmp18 tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK]) tmp22 = tl.sum(tmp20, 1)[:, None] tmp23 = tmp17 * tmp17 tmp24 = tl.broadcast_to(tmp23, [XBLOCK, RBLOCK]) tmp26 = tl.sum(tmp24, 1)[:, None] tmp28 = tmp27 - tmp1 tmp29 = tmp28 * tmp28 tmp30 = tl.broadcast_to(tmp29, [XBLOCK, RBLOCK]) tmp32 = tl.sum(tmp30, 1)[:, None] tmp34 = tmp33 - tmp1 tmp35 = tmp34 * tmp34 tmp36 = tl.broadcast_to(tmp35, [XBLOCK, RBLOCK]) tmp38 = tl.sum(tmp36, 1)[:, None] tmp39 = tmp33 * tmp33 tmp40 = tl.broadcast_to(tmp39, [XBLOCK, RBLOCK]) tmp42 = tl.sum(tmp40, 1)[:, None] tmp44 = tmp43 - tmp1 tmp45 = tmp44 * tmp44 tmp46 = tl.broadcast_to(tmp45, [XBLOCK, RBLOCK]) tmp48 = tl.sum(tmp46, 1)[:, None] tmp49 = 64.0 tmp50 = tmp10 / tmp49 tmp51 = tmp16 / tmp49 tmp52 = tmp50 + tmp51 tmp53 = 0.5 tmp54 = tmp52 * tmp53 tmp55 = 0.0 tmp56 = tmp54 + tmp55 tmp57 = tmp26 / tmp49 tmp58 = tmp32 / tmp49 tmp59 = tmp57 + tmp58 tmp60 = tmp59 * tmp53 tmp61 = tmp56 + tmp60 tmp62 = tmp42 / tmp49 tmp63 = tmp48 / tmp49 tmp64 = tmp62 + tmp63 tmp65 = tmp64 * tmp53 tmp66 = tmp61 + tmp65 tmp67 = tmp6 / tmp49 tmp68 = tmp67 + tmp55 tmp69 = tmp22 / tmp49 tmp70 = tmp68 + tmp69 tmp71 = tmp38 / tmp49 tmp72 = tmp70 + tmp71 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp66, None) tl.debug_barrier() tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp72, 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 = empty_strided_cuda((), (), torch.float32) buf10 = buf3 del buf3 buf9 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_mean_mul_ones_like_pow_sub_0[grid(1)](buf10, buf9, arg0_1, arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf9, buf10 class LSGanLossNew(nn.Module): def __init__(self, layer=3): super(LSGanLossNew, self).__init__() self.layer = layer 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]
ForrestPi/faceSwapProjects
LSGanLoss
false
17,286
[ "MIT" ]
5
daf2649a2791a25aa541c4d6d3b7e1d6552be5d7
https://github.com/ForrestPi/faceSwapProjects/tree/daf2649a2791a25aa541c4d6d3b7e1d6552be5d7
conv_layer
import torch from torch import nn class conv_layer(nn.Module): """Standard convolutional layer. Possible to return pre-activations.""" def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, padding=1, drop=0, batch_norm=False, nl=nn.ReLU(), bias=True, gated =False): super().__init__() if drop > 0: self.dropout = nn.Dropout2d(drop) self.conv = nn.Conv2d(in_planes, out_planes, stride=stride, kernel_size=kernel_size, padding=padding, bias=bias) if batch_norm: self.bn = nn.BatchNorm2d(out_planes) if gated: self.gate = nn.Conv2d(in_planes, out_planes, stride=stride, kernel_size=kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() if isinstance(nl, nn.Module): self.nl = nl elif not nl == 'none': self.nl = nn.ReLU() if nl == 'relu' else nn.LeakyReLU( ) if nl == 'leakyrelu' else modules.Identity() def forward(self, x, return_pa=False): input = self.dropout(x) if hasattr(self, 'dropout') else x pre_activ = self.bn(self.conv(input)) if hasattr(self, 'bn' ) else self.conv(input) gate = self.sigmoid(self.gate(x)) if hasattr(self, 'gate') else None gated_pre_activ = gate * pre_activ if hasattr(self, 'gate' ) else pre_activ output = self.nl(gated_pre_activ) if hasattr(self, 'nl' ) else gated_pre_activ return (output, gated_pre_activ) if return_pa else output def list_init_layers(self): """Return list of modules whose parameters could be initialized differently (i.e., conv- or fc-layers).""" return [self.conv] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_planes': 4, 'out_planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(256)](buf1, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf2 class conv_layerNew(nn.Module): """Standard convolutional layer. Possible to return pre-activations.""" def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, padding=1, drop=0, batch_norm=False, nl=nn.ReLU(), bias=True, gated =False): super().__init__() if drop > 0: self.dropout = nn.Dropout2d(drop) self.conv = nn.Conv2d(in_planes, out_planes, stride=stride, kernel_size=kernel_size, padding=padding, bias=bias) if batch_norm: self.bn = nn.BatchNorm2d(out_planes) if gated: self.gate = nn.Conv2d(in_planes, out_planes, stride=stride, kernel_size=kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() if isinstance(nl, nn.Module): self.nl = nl elif not nl == 'none': self.nl = nn.ReLU() if nl == 'relu' else nn.LeakyReLU( ) if nl == 'leakyrelu' else modules.Identity() def list_init_layers(self): """Return list of modules whose parameters could be initialized differently (i.e., conv- or fc-layers).""" return [self.conv] def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GMvandeVen/progressive-learning-pytorch
conv_layer
false
17,288
[ "MIT" ]
4
165645b2d7595d94d036f765c9a311d505e667a3
https://github.com/GMvandeVen/progressive-learning-pytorch/tree/165645b2d7595d94d036f765c9a311d505e667a3
Downsample
import torch import torch.nn as nn def conv_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D convolution module. """ if dims == 1: return nn.Conv1d(*args, **kwargs) elif dims == 2: return nn.Conv2d(*args, **kwargs) elif dims == 3: return nn.Conv3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') def avg_pool_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D average pooling module. """ if dims == 1: return nn.AvgPool1d(*args, **kwargs) elif dims == 2: return nn.AvgPool2d(*args, **kwargs) elif dims == 3: return nn.AvgPool3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') class Downsample(nn.Module): """ A downsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then downsampling occurs in the inner-two dimensions. """ def __init__(self, channels, use_conv, dims=2, out_channels=None): super().__init__() self.channels = channels self.out_channels = out_channels or channels self.use_conv = use_conv self.dims = dims stride = 2 if dims != 3 else (1, 2, 2) if use_conv: self.op = conv_nd(dims, self.channels, self.out_channels, 3, stride=stride, padding=1) else: assert self.channels == self.out_channels self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride) def forward(self, x): assert x.shape[1] == self.channels return self.op(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4, 'use_conv': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, 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 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(64)](buf1, primals_3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf1, primals_1, primals_2 def conv_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D convolution module. """ if dims == 1: return nn.Conv1d(*args, **kwargs) elif dims == 2: return nn.Conv2d(*args, **kwargs) elif dims == 3: return nn.Conv3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') def avg_pool_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D average pooling module. """ if dims == 1: return nn.AvgPool1d(*args, **kwargs) elif dims == 2: return nn.AvgPool2d(*args, **kwargs) elif dims == 3: return nn.AvgPool3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') class DownsampleNew(nn.Module): """ A downsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then downsampling occurs in the inner-two dimensions. """ def __init__(self, channels, use_conv, dims=2, out_channels=None): super().__init__() self.channels = channels self.out_channels = out_channels or channels self.use_conv = use_conv self.dims = dims stride = 2 if dims != 3 else (1, 2, 2) if use_conv: self.op = conv_nd(dims, self.channels, self.out_channels, 3, stride=stride, padding=1) else: assert self.channels == self.out_channels self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride) def forward(self, input_0): primals_2 = self.op.weight primals_3 = self.op.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GastonMazzei/escher-project-website
Downsample
false
17,289
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
CPUForgetMult
import torch import torch.nn.init class CPUForgetMult(torch.nn.Module): def __init__(self): super(CPUForgetMult, self).__init__() def forward(self, f, x, hidden_init=None): result = [] forgets = f.split(1, dim=0) prev_h = hidden_init for i, h in enumerate((f * x).split(1, dim=0)): if prev_h is not None: h = h + (1 - forgets[i]) * prev_h h = h.view(h.size()[1:]) result.append(h) prev_h = h return torch.stack(result) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn.init assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_rsub_stack_0(in_ptr0, in_ptr1, out_ptr1, out_ptr2, out_ptr3, out_ptr4, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + (128 + x0), xmask) tmp1 = tl.load(in_ptr1 + (128 + x0), xmask) tmp5 = tl.load(in_ptr0 + (64 + x0), xmask) tmp6 = tl.load(in_ptr1 + (64 + x0), xmask) tmp9 = tl.load(in_ptr0 + x0, xmask) tmp10 = tl.load(in_ptr1 + x0, xmask) tmp16 = tl.load(in_ptr0 + (192 + x0), xmask) tmp17 = tl.load(in_ptr1 + (192 + x0), xmask) tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp7 = tmp5 * tmp6 tmp8 = tmp3 - tmp5 tmp11 = tmp9 * tmp10 tmp12 = tmp8 * tmp11 tmp13 = tmp7 + tmp12 tmp14 = tmp4 * tmp13 tmp15 = tmp2 + tmp14 tmp18 = tmp16 * tmp17 tmp19 = tmp3 - tmp16 tmp20 = tmp19 * tmp15 tmp21 = tmp18 + tmp20 tl.store(out_ptr1 + x0, tmp13, xmask) tl.store(out_ptr2 + x0, tmp11, xmask) tl.store(out_ptr3 + x0, tmp15, xmask) tl.store(out_ptr4 + x0, tmp21, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) buf2 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 64) buf1 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0) buf3 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 128) buf4 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 192) get_raw_stream(0) triton_poi_fused_add_mul_rsub_stack_0[grid(64)](arg0_1, arg1_1, buf2, buf1, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 return reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0), class CPUForgetMultNew(torch.nn.Module): def __init__(self): super(CPUForgetMultNew, 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]
FurKan7/resim_renklendirme-colorizing-of-picture-
CPUForgetMult
false
17,290
[ "MIT" ]
8
a431a42cd00a60f85948795bc872a272897fbc76
https://github.com/FurKan7/resim_renklendirme-colorizing-of-picture-/tree/a431a42cd00a60f85948795bc872a272897fbc76
MLP
import torch import torch.nn as nn class MLP(nn.Module): def __init__(self, width): super().__init__() self.width = width self.c_fc = nn.Linear(width, width * 4) self.c_proj = nn.Linear(width * 4, width) self.gelu = nn.GELU() def forward(self, x): return self.c_proj(self.gelu(self.c_fc(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'width': 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_gelu_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 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) 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.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch. float32) get_raw_stream(0) triton_poi_fused_gelu_0[grid(1024)](buf0, buf1, 1024, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 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 ), buf0, reinterpret_tensor(buf1, (64, 16), (16, 1), 0), primals_4 class MLPNew(nn.Module): def __init__(self, width): super().__init__() self.width = width self.c_fc = nn.Linear(width, width * 4) self.c_proj = nn.Linear(width * 4, width) self.gelu = nn.GELU() def forward(self, input_0): primals_1 = self.c_fc.weight primals_2 = self.c_fc.bias primals_4 = self.c_proj.weight primals_5 = self.c_proj.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
GastonMazzei/escher-project-website
MLP
false
17,291
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
rSoftMax
import torch import torch.nn as nn import torch.nn.functional as F from torch.functional import F class rSoftMax(nn.Module): def __init__(self, radix, cardinality): super().__init__() self.radix = radix self.cardinality = cardinality def forward(self, x): batch = x.size(0) if self.radix > 1: x = x.view(batch, self.cardinality, self.radix, -1).transpose(1, 2) x = F.softmax(x, dim=1) x = x.reshape(batch, -1) else: x = torch.sigmoid(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'radix': 4, 'cardinality': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 4 x2 = xindex // 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 % 4 x3 = xindex // 64 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x3), xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (4 + x0 + 16 * x1 + 64 * x3), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (8 + x0 + 16 * x1 + 64 * x3), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (12 + x0 + 16 * x1 + 64 * x3), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x4, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 4, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 return reinterpret_tensor(buf1, (4, 64), (64, 1), 0), class rSoftMaxNew(nn.Module): def __init__(self, radix, cardinality): super().__init__() self.radix = radix self.cardinality = cardinality def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
DerryHub/the-TaobaoLive-Commodity-Identify-Competition
rSoftMax
false
17,292
[ "MIT" ]
4
7e5e5c4fbddd9949fe01810d58bd7994889c007c
https://github.com/DerryHub/the-TaobaoLive-Commodity-Identify-Competition/tree/7e5e5c4fbddd9949fe01810d58bd7994889c007c
GroupNorm32
import torch import torch.nn.functional as F import torch.nn as nn class GroupNorm32(nn.GroupNorm): def __init__(self, num_groups, num_channels, swish, eps=1e-05): super().__init__(num_groups=num_groups, num_channels=num_channels, eps=eps) self.swish = swish def forward(self, x): y = super().forward(x.float()) if self.swish == 1.0: y = F.silu(y) elif self.swish: y = y * F.sigmoid(y * float(self.swish)) return y def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_groups': 1, 'num_channels': 4, 'swish': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mul_native_group_norm_sigmoid_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex r3 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp24 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last') tmp26 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 64, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = 64.0 tmp18 = tmp16 / tmp17 tmp19 = 1e-05 tmp20 = tmp18 + tmp19 tmp21 = libdevice.rsqrt(tmp20) tmp22 = tmp0 - tmp10 tmp23 = tmp22 * tmp21 tmp25 = tmp23 * tmp24 tmp27 = tmp25 + tmp26 tmp28 = 4.0 tmp29 = tmp27 * tmp28 tmp30 = tl.sigmoid(tmp29) tmp31 = tmp27 * tmp30 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp21, xmask) tl.store(in_out_ptr1 + (r1 + 64 * x0), tmp31, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32) buf1 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf3 = reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf5 = buf4 del buf4 get_raw_stream(0) triton_per_fused_mul_native_group_norm_sigmoid_0[grid(4)](buf3, buf5, primals_1, primals_2, primals_3, buf0, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) return buf5, primals_1, primals_2, primals_3, buf0, buf3 class GroupNorm32New(nn.GroupNorm): def __init__(self, num_groups, num_channels, swish, eps=1e-05): super().__init__(num_groups=num_groups, num_channels=num_channels, eps=eps) self.swish = swish def forward(self, input_0): primals_2 = self.weight primals_3 = self.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GastonMazzei/escher-project-website
GroupNorm32
false
17,293
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
downsampleLayer
import torch import torch.nn as nn class downsampleLayer(nn.Module): """ A downsample layer of UNet. LeakyReLU is used as the activation func. """ def __init__(self, infeature, outfeature, kernelSize, strides=2, paddings=1, bn=False): super(downsampleLayer, self).__init__() self.conv = nn.Conv2d(infeature, outfeature, kernelSize, stride= strides, padding=paddings) self.acti = nn.LeakyReLU(negative_slope=0.2) self.bn = None if bn: self.bn = nn.BatchNorm2d(outfeature, momentum=0.8) def forward(self, x): y = self.acti(self.conv(x)) if self.bn is not None: y = self.bn(y) return y def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'infeature': 4, 'outfeature': 4, 'kernelSize': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): 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 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr1 + x3, tmp7, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(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((4, 4, 2, 2), (16, 4, 2, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_leaky_relu_0[grid(64)](buf0, primals_2, buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del primals_2 return buf2, primals_1, primals_3, buf1 class downsampleLayerNew(nn.Module): """ A downsample layer of UNet. LeakyReLU is used as the activation func. """ def __init__(self, infeature, outfeature, kernelSize, strides=2, paddings=1, bn=False): super(downsampleLayerNew, self).__init__() self.conv = nn.Conv2d(infeature, outfeature, kernelSize, stride= strides, padding=paddings) self.acti = nn.LeakyReLU(negative_slope=0.2) self.bn = None if bn: self.bn = nn.BatchNorm2d(outfeature, momentum=0.8) 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]
GentleDell/DEBOR
downsampleLayer
false
17,294
[ "BSD-3-Clause" ]
4
cd566f173599fe7419e7baf312f63830c28d5de2
https://github.com/GentleDell/DEBOR/tree/cd566f173599fe7419e7baf312f63830c28d5de2
GraphLinear
import torch import torch.nn as nn class GraphLinear(nn.Module): """ Generalization of 1x1 convolutions on Graphs """ def __init__(self, in_channels, out_channels): super(GraphLinear, self).__init__() self.in_channels = in_channels self.out_channels = out_channels self.W = nn.Parameter(torch.FloatTensor(out_channels, in_channels)) self.b = nn.Parameter(torch.FloatTensor(out_channels)) self.reset_parameters() def reset_parameters(self): w_stdv = 1 / (self.in_channels * self.out_channels) self.W.data.uniform_(-w_stdv, w_stdv) self.b.data.uniform_(-w_stdv, w_stdv) def forward(self, x): return torch.matmul(self.W[None, :], x) + self.b[None, :, None] 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 import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 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, 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((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(primals_1, (16, 4, 4), (0, 4, 1), 0), reinterpret_tensor(primals_2, (16, 4, 4), (16, 4, 1), 0 ), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf1, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf1, reinterpret_tensor(primals_2, (16, 4, 4), (16, 1, 4), 0) class GraphLinearNew(nn.Module): """ Generalization of 1x1 convolutions on Graphs """ def __init__(self, in_channels, out_channels): super(GraphLinearNew, self).__init__() self.in_channels = in_channels self.out_channels = out_channels self.W = nn.Parameter(torch.FloatTensor(out_channels, in_channels)) self.b = nn.Parameter(torch.FloatTensor(out_channels)) self.reset_parameters() def reset_parameters(self): w_stdv = 1 / (self.in_channels * self.out_channels) self.W.data.uniform_(-w_stdv, w_stdv) self.b.data.uniform_(-w_stdv, w_stdv) def forward(self, input_0): primals_1 = self.W primals_3 = self.b primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GentleDell/DEBOR
GraphLinear
false
17,295
[ "BSD-3-Clause" ]
4
cd566f173599fe7419e7baf312f63830c28d5de2
https://github.com/GentleDell/DEBOR/tree/cd566f173599fe7419e7baf312f63830c28d5de2
Upsample
import torch import torch.nn.functional as F import torch.nn as nn def conv_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D convolution module. """ if dims == 1: return nn.Conv1d(*args, **kwargs) elif dims == 2: return nn.Conv2d(*args, **kwargs) elif dims == 3: return nn.Conv3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') class Upsample(nn.Module): """ An upsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then upsampling occurs in the inner-two dimensions. """ def __init__(self, channels, use_conv, dims=2, out_channels=None): super().__init__() self.channels = channels self.out_channels = out_channels or channels self.use_conv = use_conv self.dims = dims if use_conv: self.conv = conv_nd(dims, self.channels, self.out_channels, 3, padding=1) def forward(self, x): assert x.shape[1] == self.channels if self.dims == 3: x = F.interpolate(x, (x.shape[2], x.shape[3] * 2, x.shape[4] * 2), mode='nearest') else: x = F.interpolate(x, scale_factor=2, mode='nearest') if self.use_conv: x = self.conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4, 'use_conv': 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__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 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=1, bias=None) assert_size_stride(buf1, (4, 4, 8, 8), (256, 64, 8, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(1024)](buf2, primals_3, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 def conv_nd(dims, *args, **kwargs): """ Create a 1D, 2D, or 3D convolution module. """ if dims == 1: return nn.Conv1d(*args, **kwargs) elif dims == 2: return nn.Conv2d(*args, **kwargs) elif dims == 3: return nn.Conv3d(*args, **kwargs) raise ValueError(f'unsupported dimensions: {dims}') class UpsampleNew(nn.Module): """ An upsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then upsampling occurs in the inner-two dimensions. """ def __init__(self, channels, use_conv, dims=2, out_channels=None): super().__init__() self.channels = channels self.out_channels = out_channels or channels self.use_conv = use_conv self.dims = dims if use_conv: self.conv = conv_nd(dims, self.channels, self.out_channels, 3, padding=1) def forward(self, input_0): primals_2 = self.conv.weight primals_3 = self.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GastonMazzei/escher-project-website
Upsample
false
17,296
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
upsampleLayer
import torch import torch.nn as nn class upsampleLayer(nn.Module): """ A upsample layer of UNet. ReLU is the activation func. The skip connection can be cutted if not given. Because RGB-UV is not a completion task but a image transition task. """ def __init__(self, infeature, outfeature, kernelSize, strides=1, paddings=1, bn=False, dropout_rate=0): super(upsampleLayer, self).__init__() self.upsp = nn.Upsample(scale_factor=2, mode='nearest') self.conv = nn.Conv2d(infeature, outfeature, kernelSize, stride= strides, padding=paddings) self.acti = nn.ReLU() self.drop = None if dropout_rate != 0: self.drop = nn.Dropout2d(p=dropout_rate) self.bn = None if bn: self.bn = nn.BatchNorm2d(outfeature, momentum=0.8) def forward(self, x, skip_input=None): y = self.conv(self.upsp(x)) if self.drop is not None: y = self.drop(y) if self.bn is not None: y = self.bn(y) if skip_input is not None: y = torch.cat((y, skip_input), 1) return y def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'infeature': 4, 'outfeature': 4, 'kernelSize': 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__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 49 % 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__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=1, bias=None) assert_size_stride(buf1, (4, 4, 7, 7), (196, 49, 7, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(784)](buf2, primals_3, 784, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class upsampleLayerNew(nn.Module): """ A upsample layer of UNet. ReLU is the activation func. The skip connection can be cutted if not given. Because RGB-UV is not a completion task but a image transition task. """ def __init__(self, infeature, outfeature, kernelSize, strides=1, paddings=1, bn=False, dropout_rate=0): super(upsampleLayerNew, self).__init__() self.upsp = nn.Upsample(scale_factor=2, mode='nearest') self.conv = nn.Conv2d(infeature, outfeature, kernelSize, stride= strides, padding=paddings) self.acti = nn.ReLU() self.drop = None if dropout_rate != 0: self.drop = nn.Dropout2d(p=dropout_rate) self.bn = None if bn: self.bn = nn.BatchNorm2d(outfeature, momentum=0.8) def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.conv.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
GentleDell/DEBOR
upsampleLayer
false
17,297
[ "BSD-3-Clause" ]
4
cd566f173599fe7419e7baf312f63830c28d5de2
https://github.com/GentleDell/DEBOR/tree/cd566f173599fe7419e7baf312f63830c28d5de2
Attention
import torch import torch.optim from torch import nn class Attention(nn.Module): """ Attention network for calculate attention value """ def __init__(self, encoder_dim, decoder_dim, attention_dim): """ :param encoder_dim: input size of encoder network :param decoder_dim: input size of decoder network :param attention_dim: input size of attention network """ super(Attention, self).__init__() self.encoder_att = nn.Linear(encoder_dim, attention_dim) self.decoder_att = nn.Linear(decoder_dim, attention_dim) self.full_att = nn.Linear(attention_dim, 1) self.relu = nn.ReLU() self.softmax = nn.Softmax(dim=1) def forward(self, encoder_out, decoder_hidden): att1 = self.encoder_att(encoder_out) att2 = self.decoder_att(decoder_hidden) att = self.full_att(self.relu(att1 + att2.unsqueeze(1))).squeeze(2) alpha = self.softmax(att) attention_weighted_encoding = (encoder_out * alpha.unsqueeze(2)).sum( dim=1) return attention_weighted_encoding, alpha def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'encoder_dim': 4, 'decoder_dim': 4, 'attention_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.optim from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_relu_threshold_backward_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x5 = xindex % 256 x0 = xindex % 4 x3 = xindex // 256 x6 = xindex % 64 x4 = xindex tmp0 = tl.load(in_ptr0 + x5, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x6 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.full([1], 0, tl.int32) tmp8 = triton_helpers.maximum(tmp7, tmp6) tmp9 = 0.0 tmp10 = tmp8 <= tmp9 tl.store(out_ptr0 + x4, tmp8, xmask) tl.store(out_ptr1 + x4, tmp10, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_mul_sum_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex % 256 x1 = xindex // 4 % 16 x3 = xindex // 256 x5 = xindex tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x1 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr1 + (16 + x1 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr1 + (32 + x1 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr1 + (48 + x1 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp0 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp0 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp0 * tmp9 tmp11 = tmp8 + tmp10 tl.store(out_ptr0 + x5, tmp11, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_7, (1, 4), (4, 1)) assert_size_stride(primals_8, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_add_relu_threshold_backward_0[grid(1024)](buf0, primals_2, buf1, primals_5, buf2, buf8, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_5 buf4 = reinterpret_tensor(buf1, (256, 1), (1, 1), 0) del buf1 extern_kernels.addmm(primals_8, reinterpret_tensor(buf2, (256, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_8 buf5 = reinterpret_tensor(buf0, (4, 4, 4, 4, 1), (64, 16, 4, 1, 256), 0 ) del buf0 triton_poi_fused__softmax_1[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4, 1), (64, 16, 4, 1, 1), 0) del buf4 triton_poi_fused__softmax_2[grid(256)](buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf5 buf7 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sum_3[grid(1024)](primals_3, buf6, buf7, 1024, XBLOCK=256, num_warps=4, num_stages=1) return buf7, buf6, primals_3, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(buf2, (256, 4), (4, 1), 0 ), buf6, primals_7, buf8 class AttentionNew(nn.Module): """ Attention network for calculate attention value """ def __init__(self, encoder_dim, decoder_dim, attention_dim): """ :param encoder_dim: input size of encoder network :param decoder_dim: input size of decoder network :param attention_dim: input size of attention network """ super(AttentionNew, self).__init__() self.encoder_att = nn.Linear(encoder_dim, attention_dim) self.decoder_att = nn.Linear(decoder_dim, attention_dim) self.full_att = nn.Linear(attention_dim, 1) self.relu = nn.ReLU() self.softmax = nn.Softmax(dim=1) def forward(self, input_0, input_1): primals_1 = self.encoder_att.weight primals_2 = self.encoder_att.bias primals_4 = self.decoder_att.weight primals_5 = self.decoder_att.bias primals_7 = self.full_att.weight primals_8 = self.full_att.bias primals_3 = input_0 primals_6 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0], output[1]
Fpiotro/MOLECULAR-TRANSLATION
Attention
false
17,298
[ "MIT" ]
5
050dd0c093ee4e68326c2404c5b4dbf53ca6c8a0
https://github.com/Fpiotro/MOLECULAR-TRANSLATION/tree/050dd0c093ee4e68326c2404c5b4dbf53ca6c8a0
USConv2d
import torch import torch.nn as nn import torch.utils def make_divisible(v, divisor=8, min_value=1): """ forked from slim: https://github.com/tensorflow/models/blob/ 0344c5503ee55e24f0de7f37336a6e08f10976fd/ research/slim/nets/mobilenet/mobilenet.py#L62-L69 """ if min_value is None: min_value = divisor new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) if new_v < 0.9 * v: new_v += divisor return new_v class USConv2d(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, depthwise=False, bias=True, width_mult_list=[1.0]): super(USConv2d, self).__init__(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.depthwise = depthwise self.in_channels_max = in_channels self.out_channels_max = out_channels self.width_mult_list = width_mult_list self.ratio = 1.0, 1.0 def set_ratio(self, ratio): self.ratio = ratio def forward(self, input): assert self.ratio[0] in self.width_mult_list, str(self.ratio[0] ) + ' in? ' + str(self.width_mult_list) self.in_channels = make_divisible(self.in_channels_max * self.ratio[0]) assert self.ratio[1] in self.width_mult_list, str(self.ratio[1] ) + ' in? ' + str(self.width_mult_list) self.out_channels = make_divisible(self.out_channels_max * self. ratio[1]) self.groups = self.in_channels if self.depthwise else 1 weight = self.weight[:self.out_channels, :self.in_channels, :, :] if self.bias is not None: bias = self.bias[:self.out_channels] else: bias = self.bias y = nn.functional.conv2d(input, weight, bias, self.stride, self. padding, self.dilation, self.groups) return y def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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, 1, 1), (4, 1, 1, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(16)](buf1, primals_2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_2 return buf1, primals_3, primals_1 def make_divisible(v, divisor=8, min_value=1): """ forked from slim: https://github.com/tensorflow/models/blob/ 0344c5503ee55e24f0de7f37336a6e08f10976fd/ research/slim/nets/mobilenet/mobilenet.py#L62-L69 """ if min_value is None: min_value = divisor new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) if new_v < 0.9 * v: new_v += divisor return new_v class USConv2dNew(nn.Conv2d): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, depthwise=False, bias=True, width_mult_list=[1.0]): super(USConv2dNew, self).__init__(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.depthwise = depthwise self.in_channels_max = in_channels self.out_channels_max = out_channels self.width_mult_list = width_mult_list self.ratio = 1.0, 1.0 def set_ratio(self, ratio): self.ratio = ratio def forward(self, input_0): primals_1 = self.weight primals_2 = self.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Gaussianer/FasterSeg
USConv2d
false
17,299
[ "MIT" ]
6
f2e102b433275ac9f3387a8c2ae8439b2687bfda
https://github.com/Gaussianer/FasterSeg/tree/f2e102b433275ac9f3387a8c2ae8439b2687bfda
GlobalAvgPool2d
import torch import torch.nn as nn import torch.utils class GlobalAvgPool2d(nn.Module): def __init__(self): """Global average pooling over the input's spatial dimensions""" super(GlobalAvgPool2d, self).__init__() def forward(self, inputs): in_size = inputs.size() inputs = inputs.view((in_size[0], in_size[1], -1)).mean(dim=2) inputs = inputs.view(in_size[0], in_size[1], 1, 1) return inputs def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.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_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, arg0_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del arg0_1 return reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0), class GlobalAvgPool2dNew(nn.Module): def __init__(self): """Global average pooling over the input's spatial dimensions""" super(GlobalAvgPool2dNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Gaussianer/FasterSeg
GlobalAvgPool2d
false
17,300
[ "MIT" ]
6
f2e102b433275ac9f3387a8c2ae8439b2687bfda
https://github.com/Gaussianer/FasterSeg/tree/f2e102b433275ac9f3387a8c2ae8439b2687bfda
TwoMLPHead
import torch from torchvision.transforms import functional as F from torch import nn import torch.nn.functional as F import torch.utils.data class TwoMLPHead(nn.Module): """ Standard heads for FPN-based models Arguments: in_channels (int): number of input channels representation_size (int): size of the intermediate representation """ def __init__(self, in_channels, representation_size): super(TwoMLPHead, self).__init__() self.fc6 = nn.Linear(in_channels, representation_size) self.fc7 = nn.Linear(representation_size, representation_size) def forward(self, x): x = x.flatten(start_dim=1) x = F.relu(self.fc6(x)) x = F.relu(self.fc7(x)) return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'representation_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn import torch.utils.data assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(16)](buf1, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf2) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(16)](buf3, primals_5, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return buf3, primals_1, buf1, buf4, primals_4 class TwoMLPHeadNew(nn.Module): """ Standard heads for FPN-based models Arguments: in_channels (int): number of input channels representation_size (int): size of the intermediate representation """ def __init__(self, in_channels, representation_size): super(TwoMLPHeadNew, self).__init__() self.fc6 = nn.Linear(in_channels, representation_size) self.fc7 = nn.Linear(representation_size, representation_size) def forward(self, input_0): primals_1 = self.fc6.weight primals_3 = self.fc6.bias primals_2 = self.fc7.weight primals_5 = self.fc7.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
BoChenYS/ROPE
TwoMLPHead
false
17,301
[ "BSD-3-Clause" ]
6
3e50f134259b555cf547e4a3ef8b14cf5cda4e00
https://github.com/BoChenYS/ROPE/tree/3e50f134259b555cf547e4a3ef8b14cf5cda4e00
F_fully_connected_leaky
import torch from torch import nn class F_fully_connected_leaky(nn.Module): """Fully connected tranformation, not reversible, but used below.""" def __init__(self, size_in, size, internal_size=None, dropout=0.0, batch_norm=False, leaky_slope=0.01): super(F_fully_connected_leaky, self).__init__() if not internal_size: internal_size = 2 * size self.d1 = nn.Dropout(p=dropout) self.d2 = nn.Dropout(p=dropout) self.d2b = nn.Dropout(p=dropout) self.fc1 = nn.Linear(size_in, internal_size) self.fc2 = nn.Linear(internal_size, internal_size) self.fc2b = nn.Linear(internal_size, internal_size) self.fc2d = nn.Linear(internal_size, internal_size) self.fc3 = nn.Linear(internal_size, size) self.nl1 = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2 = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2b = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2d = nn.ReLU() if batch_norm: self.bn1 = nn.BatchNorm1d(internal_size) self.bn1.weight.data.fill_(1) self.bn2 = nn.BatchNorm1d(internal_size) self.bn2.weight.data.fill_(1) self.bn2b = nn.BatchNorm1d(internal_size) self.bn2b.weight.data.fill_(1) self.batch_norm = batch_norm def forward(self, x): out = self.fc1(x) if self.batch_norm: out = self.bn1(out) out = self.nl1(self.d1(out)) out = self.fc2(out) if self.batch_norm: out = self.bn2(out) out = self.nl2(self.d2(out)) out = self.fc2b(out) if self.batch_norm: out = self.bn2b(out) out = self.nl2b(self.d2b(out)) out = self.fc2d(out) out = self.nl2d(out) out = self.fc3(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'size_in': 4, 'size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (8, 8), (8, 1)) assert_size_stride(primals_5, (8,), (1,)) assert_size_stride(primals_6, (8, 8), (8, 1)) assert_size_stride(primals_7, (8,), (1,)) assert_size_stride(primals_8, (8, 8), (8, 1)) assert_size_stride(primals_9, (8,), (1,)) assert_size_stride(primals_10, (4, 8), (8, 1)) assert_size_stride(primals_11, (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_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf2 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(512)](buf0, primals_2, buf1, buf2, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf3 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 8), (1, 8), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf5 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) triton_poi_fused_leaky_relu_0[grid(512)](buf3, primals_5, buf4, buf5, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = buf3 del buf3 extern_kernels.mm(reinterpret_tensor(buf5, (64, 8), (8, 1), 0), reinterpret_tensor(primals_6, (8, 8), (1, 8), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf8 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32) triton_poi_fused_leaky_relu_0[grid(512)](buf6, primals_7, buf7, buf8, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf9 = buf6 del buf6 extern_kernels.mm(reinterpret_tensor(buf8, (64, 8), (8, 1), 0), reinterpret_tensor(primals_8, (8, 8), (1, 8), 0), out=buf9) buf10 = reinterpret_tensor(buf9, (4, 4, 4, 8), (128, 32, 8, 1), 0) del buf9 buf12 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(512)](buf10, primals_9, buf12, 512, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf10, (64, 8), (8, 1), 0), reinterpret_tensor(primals_10, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf11) del primals_11 return reinterpret_tensor(buf11, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 8), (8, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 8), (8, 1), 0 ), buf7, reinterpret_tensor(buf8, (64, 8), (8, 1), 0 ), reinterpret_tensor(buf10, (64, 8), (8, 1), 0 ), primals_10, buf12, primals_8, primals_6, primals_4 class F_fully_connected_leakyNew(nn.Module): """Fully connected tranformation, not reversible, but used below.""" def __init__(self, size_in, size, internal_size=None, dropout=0.0, batch_norm=False, leaky_slope=0.01): super(F_fully_connected_leakyNew, self).__init__() if not internal_size: internal_size = 2 * size self.d1 = nn.Dropout(p=dropout) self.d2 = nn.Dropout(p=dropout) self.d2b = nn.Dropout(p=dropout) self.fc1 = nn.Linear(size_in, internal_size) self.fc2 = nn.Linear(internal_size, internal_size) self.fc2b = nn.Linear(internal_size, internal_size) self.fc2d = nn.Linear(internal_size, internal_size) self.fc3 = nn.Linear(internal_size, size) self.nl1 = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2 = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2b = nn.LeakyReLU(negative_slope=leaky_slope) self.nl2d = nn.ReLU() if batch_norm: self.bn1 = nn.BatchNorm1d(internal_size) self.bn1.weight.data.fill_(1) self.bn2 = nn.BatchNorm1d(internal_size) self.bn2.weight.data.fill_(1) self.bn2b = nn.BatchNorm1d(internal_size) self.bn2b.weight.data.fill_(1) self.batch_norm = batch_norm def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc2b.weight primals_7 = self.fc2b.bias primals_8 = self.fc2d.weight primals_9 = self.fc2d.bias primals_10 = self.fc3.weight primals_11 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
Goobley/Radynversion
F_fully_connected_leaky
false
17,302
[ "MIT" ]
7
f44edc77b6eb7ef2bdbd8e8aabda3bf9822d3695
https://github.com/Goobley/Radynversion/tree/f44edc77b6eb7ef2bdbd8e8aabda3bf9822d3695
SqueezeAndExcitation
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed class SqueezeAndExcitation(nn.Module): def __init__(self, planes, squeeze): super(SqueezeAndExcitation, self).__init__() self.squeeze = nn.Linear(planes, squeeze) self.expand = nn.Linear(squeeze, planes) self.relu = nn.ReLU(inplace=True) self.sigmoid = nn.Sigmoid() def forward(self, x): out = torch.mean(x.view(x.size(0), x.size(1), -1), 2) out = self.squeeze(out) out = self.relu(out) out = self.expand(out) out = self.sigmoid(out) out = out.unsqueeze(2).unsqueeze(3) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'planes': 4, 'squeeze': 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.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_sigmoid_sigmoid_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp4 = 1.0 tmp5 = tmp4 - tmp3 tmp6 = tmp3 * tmp5 tl.store(in_out_ptr0 + x2, tmp3, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_1 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_2, (4, 4), (1, 4 ), 0), out=buf2) del primals_2 buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(16)](buf3, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf3, reinterpret_tensor(primals_4, (4, 4), (1, 4 ), 0), out=buf4) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_sigmoid_sigmoid_backward_2[grid(16)](buf5, primals_5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return reinterpret_tensor(buf5, (4, 4, 1, 1), (4, 1, 1, 1), 0 ), buf1, buf3, buf6, primals_4 class SqueezeAndExcitationNew(nn.Module): def __init__(self, planes, squeeze): super(SqueezeAndExcitationNew, self).__init__() self.squeeze = nn.Linear(planes, squeeze) self.expand = nn.Linear(squeeze, planes) self.relu = nn.ReLU(inplace=True) self.sigmoid = nn.Sigmoid() def forward(self, input_0): primals_2 = self.squeeze.weight primals_3 = self.squeeze.bias primals_4 = self.expand.weight primals_5 = self.expand.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
FujitsuLaboratories/CAC
SqueezeAndExcitation
false
17,303
[ "Apache-2.0" ]
8
d12df8e47f61eaf7d7b0ed355e2d1aa296453f86
https://github.com/FujitsuLaboratories/CAC/tree/d12df8e47f61eaf7d7b0ed355e2d1aa296453f86
SigmoidFocalLoss
import torch import torch.nn as nn import torch.utils class SigmoidFocalLoss(nn.Module): def __init__(self, ignore_label, gamma=2.0, alpha=0.25, reduction='mean'): super(SigmoidFocalLoss, self).__init__() self.ignore_label = ignore_label self.gamma = gamma self.alpha = alpha self.reduction = reduction def forward(self, pred, target): b, _h, _w = target.size() pred = pred.view(b, -1, 1) pred_sigmoid = pred.sigmoid() target = target.view(b, -1).float() mask = target.ne(self.ignore_label).float() target = mask * target onehot = target.view(b, -1, 1) max_val = (-pred_sigmoid).clamp(min=0) pos_part = (1 - pred_sigmoid) ** self.gamma * (pred_sigmoid - pred_sigmoid * onehot) neg_part = pred_sigmoid ** self.gamma * (max_val + ((-max_val).exp( ) + (-pred_sigmoid - max_val).exp()).log()) loss = -(self.alpha * pos_part + (1 - self.alpha) * neg_part).sum(dim =-1) * mask if self.reduction == 'mean': loss = loss.mean() return loss def get_inputs(): return [torch.rand([4, 16]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'ignore_label': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.utils assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused__to_copy_add_clamp_exp_log_mean_mul_ne_neg_pow_rsub_sigmoid_sub_sum_0( in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp5 = tl.load(in_ptr1 + r0, None) tmp1 = tl.sigmoid(tmp0) tmp2 = 1.0 tmp3 = tmp2 - tmp1 tmp4 = tmp3 * tmp3 tmp6 = 4.0 tmp7 = tmp5 != tmp6 tmp8 = tmp7.to(tl.float32) tmp9 = tmp8 * tmp5 tmp10 = tmp1 * tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp4 * tmp11 tmp13 = 0.25 tmp14 = tmp12 * tmp13 tmp15 = tmp1 * tmp1 tmp16 = -tmp1 tmp17 = 0.0 tmp18 = triton_helpers.maximum(tmp16, tmp17) tmp19 = -tmp18 tmp20 = tl_math.exp(tmp19) tmp21 = tmp16 - tmp18 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tl_math.log(tmp23) tmp25 = tmp18 + tmp24 tmp26 = tmp15 * tmp25 tmp27 = 0.75 tmp28 = tmp26 * tmp27 tmp29 = tmp14 + tmp28 tmp30 = -tmp29 tmp31 = tmp30 * tmp8 tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK]) tmp34 = tl.sum(tmp32, 1)[:, None] tmp35 = 64.0 tmp36 = tmp34 / tmp35 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp36, None) 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, 16), (16, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 get_raw_stream(0) triton_per_fused__to_copy_add_clamp_exp_log_mean_mul_ne_neg_pow_rsub_sigmoid_sub_sum_0[ grid(1)](buf2, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class SigmoidFocalLossNew(nn.Module): def __init__(self, ignore_label, gamma=2.0, alpha=0.25, reduction='mean'): super(SigmoidFocalLossNew, self).__init__() self.ignore_label = ignore_label self.gamma = gamma self.alpha = alpha self.reduction = reduction def forward(self, input_0, input_1): arg1_1 = input_0 arg0_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
Gaussianer/FasterSeg
SigmoidFocalLoss
false
17,304
[ "MIT" ]
6
f2e102b433275ac9f3387a8c2ae8439b2687bfda
https://github.com/Gaussianer/FasterSeg/tree/f2e102b433275ac9f3387a8c2ae8439b2687bfda
PairwiseLoss
import torch import torch.nn as nn class PairwiseLoss(nn.Module): def __init__(self): super().__init__() self.m = 0 def forward(self, pos_out, neg_out): distance = 1 - pos_out + neg_out loss = torch.mean(torch.max(torch.tensor(0), distance)) 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_lift_fresh_maximum_mean_rsub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = triton_helpers.maximum(tmp5, tmp4) 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_lift_fresh_maximum_mean_rsub_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 PairwiseLossNew(nn.Module): def __init__(self): super().__init__() self.m = 0 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
GrantXie/wikidata-wikifier
PairwiseLoss
false
17,305
[ "MIT" ]
3
a65c9b71596e390999af9de7638eb8c8c13c1581
https://github.com/GrantXie/wikidata-wikifier/tree/a65c9b71596e390999af9de7638eb8c8c13c1581
MultiheadAttention
import math import torch import torch as th import torch.nn as nn class QKVMultiheadAttention(nn.Module): def __init__(self, n_heads: 'int', n_ctx: 'int'): super().__init__() self.n_heads = n_heads self.n_ctx = n_ctx def forward(self, qkv): bs, n_ctx, width = qkv.shape attn_ch = width // self.n_heads // 3 scale = 1 / math.sqrt(math.sqrt(attn_ch)) qkv = qkv.view(bs, n_ctx, self.n_heads, -1) q, k, v = th.split(qkv, attn_ch, dim=-1) weight = th.einsum('bthc,bshc->bhts', q * scale, k * scale) wdtype = weight.dtype weight = th.softmax(weight.float(), dim=-1).type(wdtype) return th.einsum('bhts,bshc->bthc', weight, v).reshape(bs, n_ctx, -1) class MultiheadAttention(nn.Module): def __init__(self, n_ctx, width, heads): super().__init__() self.n_ctx = n_ctx self.width = width self.heads = heads self.c_qkv = nn.Linear(width, width * 3) self.c_proj = nn.Linear(width, width) self.attention = QKVMultiheadAttention(heads, n_ctx) def forward(self, x): x = self.c_qkv(x) x = self.attention(x) x = self.c_proj(x) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'n_ctx': 4, 'width': 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 math import torch as th 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 = 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 + (1 + 3 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (1 + 3 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__softmax_mul_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 x3 = xindex // 16 tmp0 = tl.load(in_ptr0 + 3 * x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 3 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + (x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr2 + (4 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr2 + (8 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr2 + (12 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp4 * tmp7 tmp9 = triton_helpers.maximum(tmp6, tmp8) tmp11 = tmp4 * tmp10 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp14 = tmp4 * tmp13 tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp16 = tmp6 - tmp15 tmp17 = tl_math.exp(tmp16) tmp18 = tmp8 - tmp15 tmp19 = tl_math.exp(tmp18) tmp20 = tmp17 + tmp19 tmp21 = tmp11 - tmp15 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tmp14 - tmp15 tmp25 = tl_math.exp(tmp24) tmp26 = tmp23 + tmp25 tl.store(out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr1 + x4, tmp15, xmask) tl.store(out_ptr2 + x4, tmp26, xmask) @triton.jit def triton_poi_fused__softmax_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 x4 = xindex // 4 x0 = xindex % 4 x1 = xindex // 4 % 4 x3 = xindex // 64 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x1 + 4 * x0 + 16 * x3), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp7, xmask) @triton.jit def triton_poi_fused_clone_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 + 3 * x1 + 12 * x0 + 48 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (2 + 3 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (12, 4), (4, 1)) assert_size_stride(primals_2, (12,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 12), (12, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 12), (1, 4), 0), out=buf0) del primals_1 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(64)](buf0, primals_2, buf2, 64, XBLOCK= 64, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) triton_poi_fused__softmax_mul_1[grid(64)](buf0, primals_2, buf2, buf1, buf3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_2[grid(256)](buf1, buf2, buf3, buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 1, 1), (16, 4, 1, 1, 1), 0) del buf4 triton_poi_fused_clone_3[grid(64)](buf0, primals_2, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del primals_2 buf7 = reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 1), 0) del buf3 extern_kernels.bmm(reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf6, (16, 4, 1), (4, 1, 0), 0), out=buf7) buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_clone_4[grid(16, 4)](buf7, buf8, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf9 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0) del buf7 extern_kernels.mm(reinterpret_tensor(buf8, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf9) buf10 = reinterpret_tensor(buf9, (4, 4, 4), (16, 4, 1), 0) del buf9 triton_poi_fused_add_5[grid(64)](buf10, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 return buf10, reinterpret_tensor(primals_3, (16, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (4, 4, 4, 1, 1), (16, 1, 4, 1, 1), 0 ), reinterpret_tensor(buf2, (4, 4, 1, 4, 1), (16, 1, 1, 4, 1), 0 ), buf5, reinterpret_tensor(buf8, (16, 4), (4, 1), 0 ), primals_4, reinterpret_tensor(buf6, (16, 1, 4), (4, 1, 1), 0) class QKVMultiheadAttention(nn.Module): def __init__(self, n_heads: 'int', n_ctx: 'int'): super().__init__() self.n_heads = n_heads self.n_ctx = n_ctx def forward(self, qkv): bs, n_ctx, width = qkv.shape attn_ch = width // self.n_heads // 3 scale = 1 / math.sqrt(math.sqrt(attn_ch)) qkv = qkv.view(bs, n_ctx, self.n_heads, -1) q, k, v = th.split(qkv, attn_ch, dim=-1) weight = th.einsum('bthc,bshc->bhts', q * scale, k * scale) wdtype = weight.dtype weight = th.softmax(weight.float(), dim=-1).type(wdtype) return th.einsum('bhts,bshc->bthc', weight, v).reshape(bs, n_ctx, -1) class MultiheadAttentionNew(nn.Module): def __init__(self, n_ctx, width, heads): super().__init__() self.n_ctx = n_ctx self.width = width self.heads = heads self.c_qkv = nn.Linear(width, width * 3) self.c_proj = nn.Linear(width, width) self.attention = QKVMultiheadAttention(heads, n_ctx) def forward(self, input_0): primals_1 = self.c_qkv.weight primals_2 = self.c_qkv.bias primals_4 = self.c_proj.weight primals_5 = self.c_proj.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
GastonMazzei/escher-project-website
MultiheadAttention
false
17,306
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
PairwiseNetwork
import torch import torch.nn as nn import torch.nn.functional as F class PairwiseNetwork(nn.Module): def __init__(self, hidden_size): super().__init__() self.fc1 = nn.Linear(hidden_size, 2 * hidden_size) self.fc2 = nn.Linear(2 * hidden_size, hidden_size) self.fc3 = nn.Linear(hidden_size, hidden_size) self.fc4 = nn.Linear(hidden_size, 1) def forward(self, pos_features, neg_features): x = F.relu(self.fc1(pos_features)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) pos_out = torch.sigmoid(self.fc4(x)) x = F.relu(self.fc1(neg_features)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) neg_out = torch.sigmoid(self.fc4(x)) return pos_out, neg_out def predict(self, test_feat): x = F.relu(self.fc1(test_feat)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) test_out = torch.sigmoid(self.fc4(x)) return test_out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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_relu_threshold_backward_0(in_out_ptr0, in_out_ptr1, in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_out_ptr1 + 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 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) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_out_ptr1, 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 x0 = xindex % 4 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) 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 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) @triton.jit def triton_poi_fused_sigmoid_2(in_out_ptr0, in_out_ptr1, 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]) tmp5 = tl.load(in_out_ptr1 + x0, xmask) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tmp6 = tmp5 + tmp2 tmp7 = tl.sigmoid(tmp6) tl.store(in_out_ptr0 + x0, tmp4, xmask) tl.store(in_out_ptr1 + x0, tmp7, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10) = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 8), (8, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (1, 4), (4, 1)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf0) buf8 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_10, (64, 4), (4, 1), 0 ), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0), out=buf8) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0) del buf0 buf21 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) buf9 = reinterpret_tensor(buf8, (4, 4, 4, 8), (128, 32, 8, 1), 0) del buf8 buf18 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(512)](buf1, buf9, primals_2, buf21, buf18, 512, 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, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf2) buf10 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf9, (64, 8), (8, 1), 0), reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf10) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf20 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf11 = reinterpret_tensor(buf10, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf10 buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf3, buf11, primals_5, buf20, buf17, 256, XBLOCK=256, num_warps=4, num_stages=1 ) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf4) buf12 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf11, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf12) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 buf19 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf13 = reinterpret_tensor(buf12, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf12 buf16 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(256)](buf5, buf13, primals_7, buf19, buf16, 256, XBLOCK=256, num_warps=4, num_stages=1 ) del primals_7 buf6 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 1), (1, 4), 0), out=buf6) buf14 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf13, (64, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 1), (1, 4), 0), out=buf14) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf6 buf15 = reinterpret_tensor(buf14, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf14 triton_poi_fused_sigmoid_2[grid(64)](buf7, buf15, primals_9, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_9 return (buf7, buf15, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(buf1, (64, 8), (8, 1), 0), reinterpret_tensor( buf3, (64, 4), (4, 1), 0), reinterpret_tensor(buf5, (64, 4), (4, 1), 0), buf7, reinterpret_tensor(primals_10, (64, 4), (4, 1), 0), reinterpret_tensor(buf9, (64, 8), (8, 1), 0), reinterpret_tensor( buf11, (64, 4), (4, 1), 0), reinterpret_tensor(buf13, (64, 4), (4, 1), 0), buf15, primals_8, buf16, primals_6, buf17, primals_4, buf18, buf19, buf20, buf21) class PairwiseNetworkNew(nn.Module): def __init__(self, hidden_size): super().__init__() self.fc1 = nn.Linear(hidden_size, 2 * hidden_size) self.fc2 = nn.Linear(2 * hidden_size, hidden_size) self.fc3 = nn.Linear(hidden_size, hidden_size) self.fc4 = nn.Linear(hidden_size, 1) def predict(self, test_feat): x = F.relu(self.fc1(test_feat)) x = F.relu(self.fc2(x)) x = F.relu(self.fc3(x)) test_out = torch.sigmoid(self.fc4(x)) return test_out def forward(self, input_0, input_1): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_8 = self.fc4.weight primals_9 = self.fc4.bias primals_3 = input_0 primals_10 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10]) return output[0], output[1]
GrantXie/wikidata-wikifier
PairwiseNetwork
false
17,307
[ "MIT" ]
3
a65c9b71596e390999af9de7638eb8c8c13c1581
https://github.com/GrantXie/wikidata-wikifier/tree/a65c9b71596e390999af9de7638eb8c8c13c1581
SoftCrossEntropyLoss2d
import torch import torch.nn as nn import torch.nn.functional as F import torch.utils class SoftCrossEntropyLoss2d(nn.Module): def __init__(self): super(SoftCrossEntropyLoss2d, self).__init__() def forward(self, inputs, targets): loss = 0 inputs = -F.log_softmax(inputs, dim=1) for index in range(inputs.size()[0]): loss += F.conv2d(inputs[range(index, index + 1)], targets[range (index, index + 1)]) / (targets.size()[2] * targets.size()[3]) 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 from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_neg_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp14 = -tmp13 tl.store(out_ptr0 + x3, tmp14, xmask) @triton.jit def triton_poi_fused_index_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (x1 + 16 * y0), xmask & ymask, eviction_policy ='evict_last') tl.store(out_ptr0 + (y0 + 4 * x1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_index_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (64 + x1 + 16 * y0), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (y0 + 4 * x1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_index_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (128 + x1 + 16 * y0), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (y0 + 4 * x1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_index_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (192 + x1 + 16 * y0), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (y0 + 4 * x1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_div_6(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp6 = tl.load(in_ptr1 + 0) tmp7 = tl.broadcast_to(tmp6, [XBLOCK]) tmp10 = tl.load(in_out_ptr0 + 0) tmp11 = tl.broadcast_to(tmp10, [XBLOCK]) tmp14 = tl.load(in_ptr2 + 0) tmp15 = tl.broadcast_to(tmp14, [XBLOCK]) tmp2 = 0.0625 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = tmp3 + tmp4 tmp8 = tmp7 * tmp2 tmp9 = tmp5 + tmp8 tmp12 = tmp11 * tmp2 tmp13 = tmp9 + tmp12 tmp16 = tmp15 * tmp2 tmp17 = tmp13 + tmp16 tl.store(in_out_ptr0 + tl.full([XBLOCK], 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((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_neg_1[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 buf2 = empty_strided_cuda((1, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_index_2[grid(4, 16)](buf1, buf2, 4, 16, XBLOCK=16, YBLOCK=4, num_warps=1, num_stages=1) buf3 = empty_strided_cuda((1, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_index_2[grid(4, 16)](arg1_1, buf3, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) buf4 = extern_kernels.convolution(buf2, buf3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (1, 1, 1, 1), (1, 1, 1, 1)) buf5 = buf3 del buf3 triton_poi_fused_index_3[grid(4, 16)](buf1, buf5, 4, 16, XBLOCK=16, YBLOCK=4, num_warps=1, num_stages=1) buf6 = buf2 del buf2 triton_poi_fused_index_3[grid(4, 16)](arg1_1, buf6, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) buf7 = extern_kernels.convolution(buf5, buf6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (1, 1, 1, 1), (1, 1, 1, 1)) buf8 = buf6 del buf6 triton_poi_fused_index_4[grid(4, 16)](buf1, buf8, 4, 16, XBLOCK=16, YBLOCK=4, num_warps=1, num_stages=1) buf9 = buf5 del buf5 triton_poi_fused_index_4[grid(4, 16)](arg1_1, buf9, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) buf10 = extern_kernels.convolution(buf8, buf9, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (1, 1, 1, 1), (1, 1, 1, 1)) buf11 = buf9 del buf9 triton_poi_fused_index_5[grid(4, 16)](buf1, buf11, 4, 16, XBLOCK=16, YBLOCK=4, num_warps=1, num_stages=1) del buf1 buf12 = buf8 del buf8 triton_poi_fused_index_5[grid(4, 16)](arg1_1, buf12, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) del arg1_1 buf13 = extern_kernels.convolution(buf11, buf12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (1, 1, 1, 1), (1, 1, 1, 1)) del buf11 del buf12 buf14 = buf10 del buf10 triton_poi_fused_add_div_6[grid(1)](buf14, buf4, buf7, buf13, 1, XBLOCK=1, num_warps=1, num_stages=1) del buf13 del buf4 del buf7 return buf14, class SoftCrossEntropyLoss2dNew(nn.Module): def __init__(self): super(SoftCrossEntropyLoss2dNew, 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]
Gaussianer/FasterSeg
SoftCrossEntropyLoss2d
false
17,308
[ "MIT" ]
6
f2e102b433275ac9f3387a8c2ae8439b2687bfda
https://github.com/Gaussianer/FasterSeg/tree/f2e102b433275ac9f3387a8c2ae8439b2687bfda
Affine
import math import torch from torch import nn import torch.autograd from torch.nn import init class Affine(nn.Module): """ This module implements the affine parameters gamma and beta seen in Eq. 10 in Pezeshki et al. (2016). It differs from the way affine is used in batchnorm out of the box of PyTorch. Pytorch affine : y = bn(x)*gamma + beta Rasmus et al. (2015): y = gamma * (bn(x) + beta) """ def __init__(self, n_channels, map_size): super(Affine, self).__init__() self.map_size = map_size self.n_channels = n_channels self.gamma = nn.Parameter(torch.Tensor(self.n_channels, self. map_size, self.map_size)) self.beta = nn.Parameter(torch.Tensor(self.n_channels, self. map_size, self.map_size)) def forward(self, x): out = self.gamma * (x + self.beta) return out def reset_parameters(self) ->None: init.kaiming_uniform_(self.gamma, a=math.sqrt(5)) init.kaiming_uniform_(self.beta, a=math.sqrt(5)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_channels': 4, 'map_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math from torch import nn import torch.autograd 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 @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 % 64 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4), (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_1, primals_3, primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf0, primals_1, primals_2, primals_3 class AffineNew(nn.Module): """ This module implements the affine parameters gamma and beta seen in Eq. 10 in Pezeshki et al. (2016). It differs from the way affine is used in batchnorm out of the box of PyTorch. Pytorch affine : y = bn(x)*gamma + beta Rasmus et al. (2015): y = gamma * (bn(x) + beta) """ def __init__(self, n_channels, map_size): super(AffineNew, self).__init__() self.map_size = map_size self.n_channels = n_channels self.gamma = nn.Parameter(torch.Tensor(self.n_channels, self. map_size, self.map_size)) self.beta = nn.Parameter(torch.Tensor(self.n_channels, self. map_size, self.map_size)) def reset_parameters(self) ->None: init.kaiming_uniform_(self.gamma, a=math.sqrt(5)) init.kaiming_uniform_(self.beta, a=math.sqrt(5)) def forward(self, input_0): primals_1 = self.gamma primals_2 = self.beta primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Goschjann/ssltsc
Affine
false
17,309
[ "MIT" ]
5
08d6b1bf711bb1c8f19f9bfb66a98d4e423e932e
https://github.com/Goschjann/ssltsc/tree/08d6b1bf711bb1c8f19f9bfb66a98d4e423e932e
PositionEmbs
import torch from torch import nn class PositionEmbs(nn.Module): def __init__(self, num_patches, emb_dim, dropout_rate=0.1): super(PositionEmbs, self).__init__() self.pos_embedding = nn.Parameter(torch.randn(1, num_patches + 2, emb_dim)) if dropout_rate > 0: self.dropout = nn.Dropout(dropout_rate) else: self.dropout = None def forward(self, x): out = x + self.pos_embedding if self.dropout: out = self.dropout(out) return out def get_inputs(): return [torch.rand([4, 4, 6, 4])] def get_init_inputs(): return [[], {'num_patches': 4, 'emb_dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 384 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 24 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1, 6, 4), (24, 4, 1)) assert_size_stride(primals_2, (4, 4, 6, 4), (96, 24, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 4), (96, 24, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(384)](primals_2, primals_1, buf0, 384, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 del primals_2 return buf0, class PositionEmbsNew(nn.Module): def __init__(self, num_patches, emb_dim, dropout_rate=0.1): super(PositionEmbsNew, self).__init__() self.pos_embedding = nn.Parameter(torch.randn(1, num_patches + 2, emb_dim)) if dropout_rate > 0: self.dropout = nn.Dropout(dropout_rate) else: self.dropout = None def forward(self, input_0): primals_1 = self.pos_embedding primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
Graeme22/VisionTransformer-Pytorch
PositionEmbs
false
17,310
[ "Apache-2.0" ]
5
4e8abecf27e92dffd8d00f3d9b5ad4a21079cd0e
https://github.com/Graeme22/VisionTransformer-Pytorch/tree/4e8abecf27e92dffd8d00f3d9b5ad4a21079cd0e
DistilledLoss
import torch from torch import nn import torch.nn.functional as F class DistilledLoss(nn.Module): """ Intended for use with a DistillationTrainer. Combines vanilla cross entropy loss with a modified form of KL divergence loss. Attempts to minimize the KL divergence between the student and distilled logits while maintaining an emphasis on predicting the true labels with cross entropy. """ def __init__(self, alpha=0.5, temperature=1.0): super(DistilledLoss, self).__init__() self.alpha = alpha self.temperature = temperature def forward(self, teacher_logits, student_logits, distill_logits, labels): loss = F.cross_entropy(student_logits, labels) distill_loss = F.kl_div(F.log_softmax(distill_logits / self. temperature, dim=-1), F.softmax(teacher_logits / self. temperature, dim=-1).detach(), reduction='batchmean') distill_loss *= self.temperature ** 2 return loss * self.alpha + distill_loss * (1 - self.alpha) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__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 x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused__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) 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_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) tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = 1.0 tmp2 = tmp0 * tmp1 tmp4 = tmp3 * tmp1 tmp6 = tmp5 * tmp1 tmp7 = triton_helpers.maximum(tmp4, tmp6) tmp9 = tmp8 * tmp1 tmp10 = triton_helpers.maximum(tmp7, tmp9) tmp12 = tmp11 * tmp1 tmp13 = triton_helpers.maximum(tmp10, tmp12) tmp14 = tmp2 - tmp13 tmp15 = tmp14 * tmp1 tl.store(out_ptr0 + x2, tmp15, xmask) @triton.jit def triton_red_fused__log_softmax__softmax_add_div_mul_neg_sub_sum_xlogy_3( in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): rnumel = 256 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rbase = tl.arange(0, RBLOCK)[None, :] _tmp17 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) _tmp53 = tl.full([XBLOCK, RBLOCK], 0, tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r5 = rindex r0 = rindex % 16 r2 = rindex // 64 r4 = rindex // 4 tmp0 = tl.load(in_ptr0 + r5, rmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), rmask, eviction_policy= 'evict_last', other=0.0) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), rmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), rmask, eviction_policy='evict_last', other=0.0) tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), rmask, eviction_policy='evict_last', other=0.0) tmp14 = tl.load(in_ptr1 + r5, rmask, eviction_policy='evict_first', other=0.0) tmp19 = tl.load(in_ptr2 + r5, rmask, eviction_policy='evict_first', other=0.0) tmp20 = tl.load(in_ptr2 + 4 * r4, rmask, eviction_policy= 'evict_last', other=0.0) tmp21 = tl.load(in_ptr2 + (1 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp23 = tl.load(in_ptr2 + (2 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp25 = tl.load(in_ptr2 + (3 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp36 = tl.load(in_ptr3 + r5, rmask, eviction_policy='evict_first', other=0.0) tmp37 = tl.load(in_ptr3 + 4 * r4, rmask, eviction_policy= 'evict_last', other=0.0) tmp39 = tl.load(in_ptr3 + (1 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp42 = tl.load(in_ptr3 + (2 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp45 = tl.load(in_ptr3 + (3 + 4 * r4), rmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp15 = tmp13 * tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = _tmp17 + tmp16 _tmp17 = tl.where(rmask, tmp18, _tmp17) tmp22 = tmp20 + tmp21 tmp24 = tmp22 + tmp23 tmp26 = tmp24 + tmp25 tmp27 = tmp19 / tmp26 tmp28 = libdevice.isnan(tmp27).to(tl.int1) tmp29 = 0.0 tmp30 = tmp27 == tmp29 tmp31 = tl_math.log(tmp27) tmp32 = tmp27 * tmp31 tmp33 = tl.where(tmp30, tmp29, tmp32) tmp34 = float('nan') tmp35 = tl.where(tmp28, tmp34, tmp33) tmp38 = tl_math.exp(tmp37) tmp40 = tl_math.exp(tmp39) tmp41 = tmp38 + tmp40 tmp43 = tl_math.exp(tmp42) tmp44 = tmp41 + tmp43 tmp46 = tl_math.exp(tmp45) tmp47 = tmp44 + tmp46 tmp48 = tl_math.log(tmp47) tmp49 = tmp36 - tmp48 tmp50 = tmp27 * tmp49 tmp51 = tmp35 - tmp50 tmp52 = tl.broadcast_to(tmp51, [XBLOCK, RBLOCK]) tmp54 = _tmp53 + tmp52 _tmp53 = tl.where(rmask, tmp54, _tmp53) tmp17 = tl.sum(_tmp17, 1)[:, None] tmp53 = tl.sum(_tmp53, 1)[:, None] tmp55 = -tmp17 tmp56 = 0.015625 tmp57 = tmp55 * tmp56 tmp58 = 0.5 tmp59 = tmp57 * tmp58 tmp60 = 0.25 tmp61 = tmp53 * tmp60 tmp62 = 1.0 tmp63 = tmp61 * tmp62 tmp64 = tmp63 * tmp58 tmp65 = tmp59 + tmp64 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp65, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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)](arg1_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](arg3_1, buf2, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg3_1 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_2[grid(256)](arg2_1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg2_1 buf1 = empty_strided_cuda((), (), torch.float32) buf6 = buf1 del buf1 triton_red_fused__log_softmax__softmax_add_div_mul_neg_sub_sum_xlogy_3[ grid(1)](buf6, buf0, arg0_1, buf2, buf4, 1, 256, XBLOCK=1, RBLOCK=256, num_warps=8, num_stages=1) del arg0_1 del buf0 del buf2 del buf4 return buf6, class DistilledLossNew(nn.Module): """ Intended for use with a DistillationTrainer. Combines vanilla cross entropy loss with a modified form of KL divergence loss. Attempts to minimize the KL divergence between the student and distilled logits while maintaining an emphasis on predicting the true labels with cross entropy. """ def __init__(self, alpha=0.5, temperature=1.0): super(DistilledLossNew, self).__init__() self.alpha = alpha self.temperature = temperature def forward(self, input_0, input_1, input_2, input_3): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 output = call([arg0_1, arg1_1, arg2_1, arg3_1]) return output[0]
Graeme22/VisionTransformer-Pytorch
DistilledLoss
false
17,311
[ "Apache-2.0" ]
5
4e8abecf27e92dffd8d00f3d9b5ad4a21079cd0e
https://github.com/Graeme22/VisionTransformer-Pytorch/tree/4e8abecf27e92dffd8d00f3d9b5ad4a21079cd0e
APLayer
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed class ZIF(torch.autograd.Function): @staticmethod def forward(ctx, input, gama): out = (input > 0).float() L = torch.tensor([gama]) ctx.save_for_backward(input, out, L) return out @staticmethod def backward(ctx, grad_output): input, _out, others = ctx.saved_tensors gama = others[0].item() grad_input = grad_output.clone() tmp = 1 / gama * (1 / gama) * (gama - input.abs()).clamp(min=0) grad_input = grad_input * tmp return grad_input, None class LIFSpike(nn.Module): def __init__(self, thresh=1.0, tau=0.5, gama=1.0): super(LIFSpike, self).__init__() self.act = ZIF.apply self.thresh = thresh self.tau = tau self.gama = gama def forward(self, x): mem = 0 spike_pot = [] T = x.shape[1] for t in range(T): mem = mem * self.tau + x[:, t, ...] spike = self.act(mem - self.thresh, self.gama) mem = (1 - spike) * mem spike_pot.append(spike) return torch.stack(spike_pot, dim=1) class SeqToANNContainer(nn.Module): def __init__(self, *args): super().__init__() if len(args) == 1: self.module = args[0] else: self.module = nn.Sequential(*args) def forward(self, x_seq: 'torch.Tensor'): y_shape = [x_seq.shape[0], x_seq.shape[1]] y_seq = self.module(x_seq.flatten(0, 1).contiguous()) y_shape.extend(y_seq.shape[1:]) return y_seq.view(y_shape) class APLayer(nn.Module): def __init__(self, kernel_size): super(APLayer, self).__init__() self.fwd = SeqToANNContainer(nn.AvgPool2d(kernel_size)) self.act = LIFSpike() def forward(self, x): x = self.fwd(x) x = self.act(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp8 = tmp7 + tmp6 tmp10 = tmp9 + tmp8 tmp12 = tmp11 + tmp10 tmp14 = tmp13 + tmp12 tmp16 = tmp15 + tmp14 tmp18 = tmp17 + tmp16 tmp20 = tmp19 + tmp18 tmp22 = tmp21 + tmp20 tmp24 = tmp23 + tmp22 tmp26 = tmp25 + tmp24 tmp28 = tmp27 + tmp26 tmp30 = tmp29 + tmp28 tmp31 = 0.0625 tmp32 = tmp30 * tmp31 tl.store(out_ptr0 + x0, tmp32, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_avg_pool2d_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0), class ZIF(torch.autograd.Function): @staticmethod def forward(ctx, input, gama): out = (input > 0).float() L = torch.tensor([gama]) ctx.save_for_backward(input, out, L) return out @staticmethod def backward(ctx, grad_output): input, _out, others = ctx.saved_tensors gama = others[0].item() grad_input = grad_output.clone() tmp = 1 / gama * (1 / gama) * (gama - input.abs()).clamp(min=0) grad_input = grad_input * tmp return grad_input, None class LIFSpike(nn.Module): def __init__(self, thresh=1.0, tau=0.5, gama=1.0): super(LIFSpike, self).__init__() self.act = ZIF.apply self.thresh = thresh self.tau = tau self.gama = gama def forward(self, x): mem = 0 spike_pot = [] T = x.shape[1] for t in range(T): mem = mem * self.tau + x[:, t, ...] spike = self.act(mem - self.thresh, self.gama) mem = (1 - spike) * mem spike_pot.append(spike) return torch.stack(spike_pot, dim=1) class SeqToANNContainer(nn.Module): def __init__(self, *args): super().__init__() if len(args) == 1: self.module = args[0] else: self.module = nn.Sequential(*args) def forward(self, x_seq: 'torch.Tensor'): y_shape = [x_seq.shape[0], x_seq.shape[1]] y_seq = self.module(x_seq.flatten(0, 1).contiguous()) y_shape.extend(y_seq.shape[1:]) return y_seq.view(y_shape) class APLayerNew(nn.Module): def __init__(self, kernel_size): super(APLayerNew, self).__init__() self.fwd = SeqToANNContainer(nn.AvgPool2d(kernel_size)) self.act = LIFSpike() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
Gus-Lab/temporal_efficient_training
APLayer
false
17,312
[ "MIT" ]
5
f9bde4107ed653cc8dd3ee58689bf3b55f6b89ba
https://github.com/Gus-Lab/temporal_efficient_training/tree/f9bde4107ed653cc8dd3ee58689bf3b55f6b89ba
Conv2dSame
import torch from torchvision.transforms import * import torch.nn import torch import torch.nn as nn class Conv2dSame(torch.nn.Module): """2D convolution that pads to keep spatial dimensions equal. Cannot deal with stride. Only quadratic kernels (=scalar kernel_size). """ def __init__(self, in_channels, out_channels, kernel_size, bias=True, padding_layer=nn.ReflectionPad2d): """ :param in_channels: Number of input channels :param out_channels: Number of output channels :param kernel_size: Scalar. Spatial dimensions of kernel (only quadratic kernels supported). :param bias: Whether or not to use bias. :param padding_layer: Which padding to use. Default is reflection padding. """ super().__init__() ka = kernel_size // 2 kb = ka - 1 if kernel_size % 2 == 0 else ka self.net = nn.Sequential(padding_layer((ka, kb, ka, kb)), nn.Conv2d (in_channels, out_channels, kernel_size, bias=bias, stride=1)) self.weight = self.net[1].weight self.bias = self.net[1].bias def forward(self, x): return self.net(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math from torchvision.transforms import * import torch.nn 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_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 784 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 7 x1 = xindex // 7 % 7 x2 = xindex // 49 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-2 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-2 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(784)](primals_1, buf0, 784, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = buf1 del buf1 triton_poi_fused_convolution_1[grid(256)](buf2, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 return buf2, primals_2, buf0 class Conv2dSameNew(torch.nn.Module): """2D convolution that pads to keep spatial dimensions equal. Cannot deal with stride. Only quadratic kernels (=scalar kernel_size). """ def __init__(self, in_channels, out_channels, kernel_size, bias=True, padding_layer=nn.ReflectionPad2d): """ :param in_channels: Number of input channels :param out_channels: Number of output channels :param kernel_size: Scalar. Spatial dimensions of kernel (only quadratic kernels supported). :param bias: Whether or not to use bias. :param padding_layer: Which padding to use. Default is reflection padding. """ super().__init__() ka = kernel_size // 2 kb = ka - 1 if kernel_size % 2 == 0 else ka self.net = nn.Sequential(padding_layer((ka, kb, ka, kb)), nn.Conv2d (in_channels, out_channels, kernel_size, bias=bias, stride=1)) self.weight = self.net[1].weight self.bias = self.net[1].bias def forward(self, input_0): primals_1 = self.weight primals_3 = self.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
COMHTVM/lensless
Conv2dSame
false
17,313
[ "MIT" ]
6
0d67a310bab08551d7422fa792f3422a7ee7d9cb
https://github.com/COMHTVM/lensless/tree/0d67a310bab08551d7422fa792f3422a7ee7d9cb
Combinator
import torch from torch import nn import torch.autograd class Combinator(nn.Module): """ The vanilla combinator function g() that combines vertical and lateral connections as explained in Pezeshki et al. (2016). The weights are initialized as described in Eq. 17 and the g() is defined in Eq. 16. """ def __init__(self, n_channels, length, data_type='2d'): super(Combinator, self).__init__() if data_type == '2d': zeros = torch.zeros(n_channels, length, length) ones = torch.ones(n_channels, length, length) elif data_type == '1d': zeros = torch.zeros(n_channels, length) ones = torch.ones(n_channels, length) else: raise ValueError self.b0 = nn.Parameter(zeros) self.w0z = nn.Parameter(ones) self.w0u = nn.Parameter(zeros) self.w0zu = nn.Parameter(ones) self.b1 = nn.Parameter(zeros) self.w1z = nn.Parameter(ones) self.w1u = nn.Parameter(zeros) self.w1zu = nn.Parameter(zeros) self.wsig = nn.Parameter(ones) def forward(self, z_tilde, ulplus1): assert z_tilde.shape == ulplus1.shape out = self.b0 + z_tilde.mul(self.w0z) + ulplus1.mul(self.w0u ) + z_tilde.mul(ulplus1.mul(self.w0zu)) + self.wsig.mul(torch. sigmoid(self.b1 + z_tilde.mul(self.w1z) + ulplus1.mul(self.w1u) + z_tilde.mul(ulplus1.mul(self.w1zu)))) return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_channels': 4, 'length': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_sigmoid_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, in_ptr8, in_ptr9, in_ptr10, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 64 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x2, xmask) tmp6 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp13 = tl.load(in_ptr6 + x0, xmask, eviction_policy='evict_last') tmp14 = tl.load(in_ptr7 + x0, xmask, eviction_policy='evict_last') tmp15 = tl.load(in_ptr8 + x0, xmask, eviction_policy='evict_last') tmp18 = tl.load(in_ptr9 + x0, xmask, eviction_policy='evict_last') tmp21 = tl.load(in_ptr10 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 * tmp2 tmp4 = tmp0 + tmp3 tmp7 = tmp5 * tmp6 tmp8 = tmp4 + tmp7 tmp10 = tmp5 * tmp9 tmp11 = tmp1 * tmp10 tmp12 = tmp8 + tmp11 tmp16 = tmp1 * tmp15 tmp17 = tmp14 + tmp16 tmp19 = tmp5 * tmp18 tmp20 = tmp17 + tmp19 tmp22 = tmp5 * tmp21 tmp23 = tmp1 * tmp22 tmp24 = tmp20 + tmp23 tmp25 = tl.sigmoid(tmp24) tmp26 = tmp13 * tmp25 tmp27 = tmp12 + tmp26 tl.store(out_ptr0 + x2, tmp27, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_7, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_8, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_9, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_10, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_11, (4, 4, 4), (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_sigmoid_0[grid(256)](primals_3, primals_1, primals_4, primals_2, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) del primals_3 del primals_4 del primals_5 del primals_6 return (buf0, primals_1, primals_2, primals_7, primals_8, primals_9, primals_10, primals_11) class CombinatorNew(nn.Module): """ The vanilla combinator function g() that combines vertical and lateral connections as explained in Pezeshki et al. (2016). The weights are initialized as described in Eq. 17 and the g() is defined in Eq. 16. """ def __init__(self, n_channels, length, data_type='2d'): super(CombinatorNew, self).__init__() if data_type == '2d': zeros = torch.zeros(n_channels, length, length) ones = torch.ones(n_channels, length, length) elif data_type == '1d': zeros = torch.zeros(n_channels, length) ones = torch.ones(n_channels, length) else: raise ValueError self.b0 = nn.Parameter(zeros) self.w0z = nn.Parameter(ones) self.w0u = nn.Parameter(zeros) self.w0zu = nn.Parameter(ones) self.b1 = nn.Parameter(zeros) self.w1z = nn.Parameter(ones) self.w1u = nn.Parameter(zeros) self.w1zu = nn.Parameter(zeros) self.wsig = nn.Parameter(ones) def forward(self, input_0, input_1): primals_3 = self.b0 primals_4 = self.w0z primals_5 = self.w0u primals_6 = self.w0zu primals_7 = self.b1 primals_8 = self.w1z primals_9 = self.w1u primals_10 = self.w1zu primals_11 = self.wsig primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
Goschjann/ssltsc
Combinator
false
17,314
[ "MIT" ]
5
08d6b1bf711bb1c8f19f9bfb66a98d4e423e932e
https://github.com/Goschjann/ssltsc/tree/08d6b1bf711bb1c8f19f9bfb66a98d4e423e932e
ResidualAttentionBlock
import math import torch import torch as th import torch.nn as nn class LayerNorm(nn.LayerNorm): """ Implementation that supports fp16 inputs but fp32 gains/biases. """ def forward(self, x: 'th.Tensor'): return super().forward(x.float()) class QKVMultiheadAttention(nn.Module): def __init__(self, n_heads: 'int', n_ctx: 'int'): super().__init__() self.n_heads = n_heads self.n_ctx = n_ctx def forward(self, qkv): bs, n_ctx, width = qkv.shape attn_ch = width // self.n_heads // 3 scale = 1 / math.sqrt(math.sqrt(attn_ch)) qkv = qkv.view(bs, n_ctx, self.n_heads, -1) q, k, v = th.split(qkv, attn_ch, dim=-1) weight = th.einsum('bthc,bshc->bhts', q * scale, k * scale) wdtype = weight.dtype weight = th.softmax(weight.float(), dim=-1).type(wdtype) return th.einsum('bhts,bshc->bthc', weight, v).reshape(bs, n_ctx, -1) class MultiheadAttention(nn.Module): def __init__(self, n_ctx, width, heads): super().__init__() self.n_ctx = n_ctx self.width = width self.heads = heads self.c_qkv = nn.Linear(width, width * 3) self.c_proj = nn.Linear(width, width) self.attention = QKVMultiheadAttention(heads, n_ctx) def forward(self, x): x = self.c_qkv(x) x = self.attention(x) x = self.c_proj(x) return x class MLP(nn.Module): def __init__(self, width): super().__init__() self.width = width self.c_fc = nn.Linear(width, width * 4) self.c_proj = nn.Linear(width * 4, width) self.gelu = nn.GELU() def forward(self, x): return self.c_proj(self.gelu(self.c_fc(x))) class ResidualAttentionBlock(nn.Module): def __init__(self, n_ctx: 'int', width: 'int', heads: 'int'): super().__init__() self.attn = MultiheadAttention(n_ctx, width, heads) self.ln_1 = LayerNorm(width) self.mlp = MLP(width) self.ln_2 = LayerNorm(width) def forward(self, x: 'th.Tensor'): x = x + self.attn(self.ln_1(x)) x = x + self.mlp(self.ln_2(x)) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'n_ctx': 4, 'width': 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 libdevice, math as tl_math import math import torch as th 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_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + (1 + 3 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (1 + 3 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused__softmax_mul_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 4 x3 = xindex // 16 tmp0 = tl.load(in_ptr0 + 3 * x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 3 * x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + (x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp7 = tl.load(in_ptr2 + (4 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr2 + (8 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr2 + (12 + x0 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp4 * tmp7 tmp9 = triton_helpers.maximum(tmp6, tmp8) tmp11 = tmp4 * tmp10 tmp12 = triton_helpers.maximum(tmp9, tmp11) tmp14 = tmp4 * tmp13 tmp15 = triton_helpers.maximum(tmp12, tmp14) tmp16 = tmp6 - tmp15 tmp17 = tl_math.exp(tmp16) tmp18 = tmp8 - tmp15 tmp19 = tl_math.exp(tmp18) tmp20 = tmp17 + tmp19 tmp21 = tmp11 - tmp15 tmp22 = tl_math.exp(tmp21) tmp23 = tmp20 + tmp22 tmp24 = tmp14 - tmp15 tmp25 = tl_math.exp(tmp24) tmp26 = tmp23 + tmp25 tl.store(out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr1 + x4, tmp15, xmask) tl.store(out_ptr2 + x4, tmp26, xmask) @triton.jit def triton_poi_fused__softmax_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex // 4 x0 = xindex % 4 x1 = xindex // 4 % 4 x3 = xindex // 64 x2 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x1 + 4 * x0 + 16 * x3), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x4, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp4 = tmp2 - tmp3 tmp5 = tl_math.exp(tmp4) tmp7 = tmp5 / tmp6 tl.store(out_ptr0 + (x0 + 4 * x2 + 16 * x1 + 64 * x3), tmp7, xmask) @triton.jit def triton_poi_fused_clone_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 + 3 * x1 + 12 * x0 + 48 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (2 + 3 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + x3, tmp2, 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 + (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_7(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_8(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_9(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_10(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, primals_13) = 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, (12,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 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, 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) buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_mul_2[grid(64)](buf3, primals_5, buf5, 64, XBLOCK= 64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32) triton_poi_fused__softmax_mul_3[grid(64)](buf3, primals_5, buf5, buf4, buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_4[grid(256)](buf4, buf5, buf6, buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = reinterpret_tensor(buf7, (4, 4, 4, 1, 1), (16, 4, 1, 1, 1), 0) del buf7 triton_poi_fused_clone_5[grid(64)](buf3, primals_5, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf3 del primals_5 buf10 = reinterpret_tensor(buf6, (16, 4, 1), (4, 1, 1), 0) del buf6 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_6[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_6, (4, 4), (1, 4), 0), out=buf12) buf13 = buf1 del buf1 buf14 = buf0 del buf0 triton_poi_fused_add_native_layer_norm_7[grid(16)](primals_1, buf12, primals_7, 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_8[grid(64)](primals_1, buf12, primals_7, buf13, buf14, primals_8, primals_9, buf15, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf13 del buf14 del primals_9 buf16 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf15, (16, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 16), (1, 4), 0), alpha=1, beta=1, out=buf16) del primals_11 buf17 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_gelu_9[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_12, (16, 4), (1, 16), 0), out=buf18) buf19 = reinterpret_tensor(buf18, (4, 4, 4), (16, 4, 1), 0) del buf18 triton_poi_fused_add_10[grid(64)](buf19, primals_1, buf12, primals_7, primals_13, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_13 return buf19, primals_1, primals_7, primals_8, reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(buf4, (4, 4, 4, 1, 1), (16, 1, 4, 1, 1), 0), reinterpret_tensor(buf5, (4, 4, 1, 4, 1), (16, 1, 1, 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_12, primals_10, primals_6, reinterpret_tensor(buf9, (16, 1, 4), (4, 1, 1), 0), primals_4 class LayerNorm(nn.LayerNorm): """ Implementation that supports fp16 inputs but fp32 gains/biases. """ def forward(self, x: 'th.Tensor'): return super().forward(x.float()) class QKVMultiheadAttention(nn.Module): def __init__(self, n_heads: 'int', n_ctx: 'int'): super().__init__() self.n_heads = n_heads self.n_ctx = n_ctx def forward(self, qkv): bs, n_ctx, width = qkv.shape attn_ch = width // self.n_heads // 3 scale = 1 / math.sqrt(math.sqrt(attn_ch)) qkv = qkv.view(bs, n_ctx, self.n_heads, -1) q, k, v = th.split(qkv, attn_ch, dim=-1) weight = th.einsum('bthc,bshc->bhts', q * scale, k * scale) wdtype = weight.dtype weight = th.softmax(weight.float(), dim=-1).type(wdtype) return th.einsum('bhts,bshc->bthc', weight, v).reshape(bs, n_ctx, -1) class MultiheadAttention(nn.Module): def __init__(self, n_ctx, width, heads): super().__init__() self.n_ctx = n_ctx self.width = width self.heads = heads self.c_qkv = nn.Linear(width, width * 3) self.c_proj = nn.Linear(width, width) self.attention = QKVMultiheadAttention(heads, n_ctx) def forward(self, x): x = self.c_qkv(x) x = self.attention(x) x = self.c_proj(x) return x class MLP(nn.Module): def __init__(self, width): super().__init__() self.width = width self.c_fc = nn.Linear(width, width * 4) self.c_proj = nn.Linear(width * 4, width) self.gelu = nn.GELU() def forward(self, x): return self.c_proj(self.gelu(self.c_fc(x))) class ResidualAttentionBlockNew(nn.Module): def __init__(self, n_ctx: 'int', width: 'int', heads: 'int'): super().__init__() self.attn = MultiheadAttention(n_ctx, width, heads) self.ln_1 = LayerNorm(width) self.mlp = MLP(width) self.ln_2 = LayerNorm(width) def forward(self, input_0): primals_4 = self.attn.c_qkv.weight primals_5 = self.attn.c_qkv.bias primals_6 = self.attn.c_proj.weight primals_2 = self.attn.c_proj.bias primals_3 = self.ln_1.weight primals_7 = self.ln_1.bias primals_10 = self.mlp.c_fc.weight primals_11 = self.mlp.c_fc.bias primals_12 = self.mlp.c_proj.weight primals_8 = self.mlp.c_proj.bias primals_9 = self.ln_2.weight primals_13 = self.ln_2.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]
GastonMazzei/escher-project-website
ResidualAttentionBlock
false
17,315
[ "MIT" ]
5
b3861eeeca11a7c31502f539ded9ae718f3d9e2e
https://github.com/GastonMazzei/escher-project-website/tree/b3861eeeca11a7c31502f539ded9ae718f3d9e2e
BasicBlock
import torch import torch.nn as nn import torch.nn.functional as F class BasicBlock(nn.Module): def __init__(self, inplanes, planes, droprate=0.2, attention=None): super(BasicBlock, self).__init__() self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, padding=1, bias=False) self.in1 = nn.InstanceNorm2d(planes) self.relu = nn.ReLU(inplace=True) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False) self.in2 = nn.InstanceNorm2d(planes) self.attention = attention self.droprate = droprate def forward(self, x): skip = x out = self.conv1(x) out = self.in1(out) if self.droprate > 0: out = F.dropout(out, p=self.droprate, training=self.training) out = self.relu(out) out = self.conv2(out) out = self.in2(out) if self.droprate > 0: out = F.dropout(out, p=self.droprate, training=self.training) if self.attention is not None: out = self.attention(out) out += skip out = self.relu(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'inplanes': 4, 'planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__native_batch_norm_legit_relu_0(in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = tmp0 - tmp10 tmp18 = 16.0 tmp19 = tmp16 / tmp18 tmp20 = 1e-05 tmp21 = tmp19 + tmp20 tmp22 = libdevice.rsqrt(tmp21) tmp23 = tmp17 * tmp22 tmp24 = tl.full([1, 1], 0, tl.int32) tmp25 = triton_helpers.maximum(tmp24, tmp23) tl.store(out_ptr2 + (r1 + 16 * x0), tmp25, xmask) tl.store(out_ptr3 + x0, tmp22, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_add_relu_threshold_backward_1( in_ptr0, in_ptr1, out_ptr0, out_ptr2, out_ptr3, out_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp24 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tl.where(xmask, tmp1, 0) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tmp8 = tl.full([XBLOCK, 1], 16, tl.int32) tmp9 = tmp8.to(tl.float32) tmp10 = tmp7 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK]) tmp15 = tl.where(xmask, tmp13, 0) tmp16 = tl.sum(tmp15, 1)[:, None] tmp17 = tmp0 - tmp10 tmp18 = 16.0 tmp19 = tmp16 / tmp18 tmp20 = 1e-05 tmp21 = tmp19 + tmp20 tmp22 = libdevice.rsqrt(tmp21) tmp23 = tmp17 * tmp22 tmp25 = tmp23 + tmp24 tmp26 = tl.full([1, 1], 0, tl.int32) tmp27 = triton_helpers.maximum(tmp26, tmp25) tmp28 = 0.0 tmp29 = tmp27 <= tmp28 tl.store(out_ptr2 + (r1 + 16 * x0), tmp27, xmask) tl.store(out_ptr3 + (r1 + 16 * x0), tmp29, xmask) tl.store(out_ptr4 + x0, tmp22, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4, 4, 3, 3), (36, 9, 3, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_relu_0[grid(16)](buf0, buf1, buf5, buf4, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) buf6 = extern_kernels.convolution(buf5, primals_3, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1)) buf7 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf10 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_add_relu_threshold_backward_1[ grid(16)](buf6, primals_1, buf7, buf11, buf12, buf10, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) return buf11, primals_1, primals_2, primals_3, buf0, reinterpret_tensor( buf4, (16,), (1,), 0), buf5, buf6, reinterpret_tensor(buf10, (16,), (1,), 0), buf12, reinterpret_tensor(buf7, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf1, (1, 16, 1, 1), (16, 1, 1, 1), 0) class BasicBlockNew(nn.Module): def __init__(self, inplanes, planes, droprate=0.2, attention=None): super(BasicBlockNew, self).__init__() self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, padding=1, bias=False) self.in1 = nn.InstanceNorm2d(planes) self.relu = nn.ReLU(inplace=True) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False) self.in2 = nn.InstanceNorm2d(planes) self.attention = attention self.droprate = droprate def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv2.weight primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Galaxies99/alpha-protein
BasicBlock
false
17,316
[ "MIT" ]
4
db4b77ab48d5905ade5d4a66004f8387773718fa
https://github.com/Galaxies99/alpha-protein/tree/db4b77ab48d5905ade5d4a66004f8387773718fa
SpaceToDepth
import torch import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed class SpaceToDepth(nn.Module): def __init__(self, block_size=4): super().__init__() assert block_size == 4 self.bs = block_size def forward(self, x): N, C, H, W = x.size() x = x.view(N, C, H // self.bs, self.bs, W // self.bs, self.bs) x = x.permute(0, 3, 5, 1, 2, 4).contiguous() x = x.view(N, C * self.bs ** 2, H // self.bs, W // self.bs) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 16 y1 = yindex // 16 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 1, 1), (64, 16, 4, 1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64, 4)](arg0_1, buf0, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 64, 1, 1), (64, 1, 1, 1), 0), class SpaceToDepthNew(nn.Module): def __init__(self, block_size=4): super().__init__() assert block_size == 4 self.bs = block_size def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
GuillaumeAI/gia-labeling-ImageNet21K
SpaceToDepth
false
17,317
[ "MIT" ]
4
825ff49f1558f848fc8a798e2e393b708e75bb0e
https://github.com/GuillaumeAI/gia-labeling-ImageNet21K/tree/825ff49f1558f848fc8a798e2e393b708e75bb0e
PA
import torch from torch import nn class PA(nn.Module): def __init__(self, dim): super().__init__() self.pa_conv = nn.Conv2d(dim, dim, 3, 1, 1, groups=dim) def forward(self, x): return x * self.pa_conv(x).sigmoid() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_mul_sigmoid_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tl.sigmoid(tmp2) tmp5 = tmp3 * tmp4 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=4, 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_mul_sigmoid_0[grid(256)](buf1, primals_2, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf2, primals_1, primals_3, buf1 class PANew(nn.Module): def __init__(self, dim): super().__init__() self.pa_conv = nn.Conv2d(dim, dim, 3, 1, 1, groups=dim) def forward(self, input_0): primals_1 = self.pa_conv.weight primals_2 = self.pa_conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
Genevievekim/segformer
PA
false
17,318
[ "MIT" ]
10
4a0800746ade51101ec2573c683b06eccadb9683
https://github.com/Genevievekim/segformer/tree/4a0800746ade51101ec2573c683b06eccadb9683
DilatedBasicBlock
import torch import torch.nn as nn class DilatedBasicBlock(nn.Module): def __init__(self, inplanes, planes, kernel_size=3, dilation=1): super(DilatedBasicBlock, self).__init__() padding_size = kernel_size + (kernel_size - 1) * (dilation - 1) - 1 assert padding_size % 2 == 0 padding_size = int(padding_size / 2) self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=kernel_size, stride=1, padding=padding_size, dilation=dilation) self.in1 = nn.InstanceNorm2d(planes) self.relu = nn.ReLU(inplace=True) self.conv2 = nn.Conv2d(planes, planes, kernel_size=kernel_size, stride=1, padding=padding_size, dilation=dilation) self.in2 = nn.InstanceNorm2d(planes) if inplanes != planes: self.conv3 = nn.Conv2d(inplanes, planes, kernel_size=1, stride=1) self.in3 = nn.InstanceNorm2d(planes) else: self.conv3 = None self.in3 = None def forward(self, x): if self.conv3 is not None: skip = self.in3(self.conv3(x)) else: skip = x out = self.conv1(x) out = self.in1(out) out = self.relu(out) out = self.conv2(out) out = self.in2(out) out += skip out = self.relu(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'inplanes': 4, 'planes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused__native_batch_norm_legit_convolution_relu_0(in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr ): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = tmp2 - tmp12 tmp20 = 16.0 tmp21 = tmp18 / tmp20 tmp22 = 1e-05 tmp23 = tmp21 + tmp22 tmp24 = libdevice.rsqrt(tmp23) tmp25 = tmp19 * tmp24 tmp26 = tl.full([1, 1], 0, tl.int32) tmp27 = triton_helpers.maximum(tmp26, tmp25) tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask) tl.store(out_ptr2 + (r2 + 16 * x3), tmp27, xmask) tl.store(out_ptr3 + x3, tmp24, xmask) tl.store(out_ptr0 + x3, tmp12, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_convolution_relu_threshold_backward_1( in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr2, out_ptr3, out_ptr4, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x3 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp26 = tl.load(in_ptr1 + (r2 + 16 * x3), xmask, other=0.0) tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = tmp2 - tmp12 tmp20 = 16.0 tmp21 = tmp18 / tmp20 tmp22 = 1e-05 tmp23 = tmp21 + tmp22 tmp24 = libdevice.rsqrt(tmp23) tmp25 = tmp19 * tmp24 tmp27 = tmp25 + tmp26 tmp28 = tl.full([1, 1], 0, tl.int32) tmp29 = triton_helpers.maximum(tmp28, tmp27) tmp30 = 0.0 tmp31 = tmp29 <= tmp30 tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask) tl.store(out_ptr2 + (r2 + 16 * x3), tmp29, xmask) tl.store(out_ptr3 + (r2 + 16 * x3), tmp31, xmask) tl.store(out_ptr4 + x3, tmp24, xmask) tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) get_raw_stream(0) triton_per_fused__native_batch_norm_legit_convolution_relu_0[grid(16)]( buf1, primals_3, buf2, buf6, buf5, 16, 16, XBLOCK=8, num_warps= 2, num_stages=1) del primals_3 buf7 = extern_kernels.convolution(buf6, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 4, 4, 4), (64, 16, 4, 1)) buf8 = buf7 del buf7 buf9 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32 ) buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf12 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch. float32) triton_per_fused__native_batch_norm_legit_convolution_relu_threshold_backward_1[ grid(16)](buf8, primals_5, primals_1, buf9, buf13, buf14, buf12, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del primals_5 return buf13, primals_1, primals_2, primals_4, buf1, reinterpret_tensor( buf5, (16,), (1,), 0), buf6, buf8, reinterpret_tensor(buf12, (16,), (1,), 0), buf14, reinterpret_tensor(buf9, (1, 16, 1, 1), (16, 1, 1, 1), 0), reinterpret_tensor(buf2, (1, 16, 1, 1), (16, 1, 1, 1), 0) class DilatedBasicBlockNew(nn.Module): def __init__(self, inplanes, planes, kernel_size=3, dilation=1): super(DilatedBasicBlockNew, self).__init__() padding_size = kernel_size + (kernel_size - 1) * (dilation - 1) - 1 assert padding_size % 2 == 0 padding_size = int(padding_size / 2) self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=kernel_size, stride=1, padding=padding_size, dilation=dilation) self.in1 = nn.InstanceNorm2d(planes) self.relu = nn.ReLU(inplace=True) self.conv2 = nn.Conv2d(planes, planes, kernel_size=kernel_size, stride=1, padding=padding_size, dilation=dilation) self.in2 = nn.InstanceNorm2d(planes) if inplanes != planes: self.conv3 = nn.Conv2d(inplanes, planes, kernel_size=1, stride=1) self.in3 = nn.InstanceNorm2d(planes) else: self.conv3 = None self.in3 = None 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]
Galaxies99/alpha-protein
DilatedBasicBlock
false
17,319
[ "MIT" ]
4
db4b77ab48d5905ade5d4a66004f8387773718fa
https://github.com/Galaxies99/alpha-protein/tree/db4b77ab48d5905ade5d4a66004f8387773718fa