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
BayesConv2d
from torch.nn import Module import math import torch from torch.nn import Parameter import torch.nn.functional as F from torch.nn.modules.utils import _pair class _BayesConvNd(Module): """ Applies Bayesian Convolution Arguments: prior_mu (Float): mean of prior normal distribution. prior_sigma (Float): sigma of prior normal distribution. .. note:: other arguments are following conv of pytorch 1.2.0. https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py """ __constants__ = ['prior_mu', 'prior_sigma', 'stride', 'padding', 'dilation', 'groups', 'bias', 'padding_mode', 'output_padding', 'in_channels', 'out_channels', 'kernel_size'] def __init__(self, prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias, padding_mode): super(_BayesConvNd, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups self.padding_mode = padding_mode self.prior_mu = prior_mu self.prior_sigma = prior_sigma self.prior_log_sigma = math.log(prior_sigma) if transposed: self.weight_mu = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.weight_log_sigma = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.register_buffer('weight_eps', None) else: self.weight_mu = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.weight_log_sigma = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.register_buffer('weight_eps', None) if bias is None or bias is False: self.bias = False else: self.bias = True if self.bias: self.bias_mu = Parameter(torch.Tensor(out_channels)) self.bias_log_sigma = Parameter(torch.Tensor(out_channels)) self.register_buffer('bias_eps', None) else: self.register_parameter('bias_mu', None) self.register_parameter('bias_log_sigma', None) self.register_buffer('bias_eps', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels n *= self.kernel_size[0] ** 2 stdv = 1.0 / math.sqrt(n) self.weight_mu.data.uniform_(-stdv, stdv) self.weight_log_sigma.data.fill_(self.prior_log_sigma) if self.bias: self.bias_mu.data.uniform_(-stdv, stdv) self.bias_log_sigma.data.fill_(self.prior_log_sigma) def freeze(self): self.weight_eps = torch.randn_like(self.weight_log_sigma) if self.bias: self.bias_eps = torch.randn_like(self.bias_log_sigma) def unfreeze(self): self.weight_eps = None if self.bias: self.bias_eps = None def extra_repr(self): s = ( '{prior_mu}, {prior_sigma}, {in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is False: s += ', bias=False' return s.format(**self.__dict__) def __setstate__(self, state): super(_BayesConvNd, self).__setstate__(state) if not hasattr(self, 'padding_mode'): self.padding_mode = 'zeros' class BayesConv2d(_BayesConvNd): """ Applies Bayesian Convolution for 2D inputs Arguments: prior_mu (Float): mean of prior normal distribution. prior_sigma (Float): sigma of prior normal distribution. .. note:: other arguments are following conv of pytorch 1.2.0. https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py """ def __init__(self, prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros'): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(BayesConv2d, self).__init__(prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias, padding_mode) def conv2d_forward(self, input, weight): if self.bias: if self.bias_eps is None: bias = self.bias_mu + torch.exp(self.bias_log_sigma ) * torch.randn_like(self.bias_log_sigma) else: bias = self.bias_mu + torch.exp(self.bias_log_sigma ) * self.bias_eps else: bias = None if self.padding_mode == 'circular': expanded_padding = (self.padding[1] + 1) // 2, self.padding[1 ] // 2, (self.padding[0] + 1) // 2, self.padding[0] // 2 return F.conv2d(F.pad(input, expanded_padding, mode='circular'), weight, bias, self.stride, _pair(0), self.dilation, self.groups ) return F.conv2d(input, weight, bias, self.stride, self.padding, self.dilation, self.groups) def forward(self, input): """ Overriden. """ if self.weight_eps is None: weight = self.weight_mu + torch.exp(self.weight_log_sigma ) * torch.randn_like(self.weight_log_sigma) else: weight = self.weight_mu + torch.exp(self.weight_log_sigma ) * self.weight_eps return self.conv2d_forward(input, weight) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'prior_mu': 4, 'prior_sigma': 4, 'in_channels': 4, 'out_channels': 4, 'kernel_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 from torch.nn import Module import math from torch.nn import Parameter import torch.nn.functional as F from torch.nn.modules.utils import _pair assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_exp_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) tmp3 = tl.load(in_ptr2 + x0, xmask) tmp2 = tl_math.exp(tmp1) tmp4 = tmp2 * tmp3 tmp5 = tmp0 + tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_add_convolution_exp_mul_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp3 = tl.load(in_ptr2 + x0, xmask) tmp2 = tl_math.exp(tmp1) tmp4 = tmp2 * tmp3 tmp5 = tmp0 + tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_add_convolution_exp_mul_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (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, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.randn.default([4, 4, 4, 4], dtype=torch. float32, device=device(type='cuda', index=0), pin_memory=False) 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_add_exp_mul_0[grid(256)](primals_1, primals_2, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf3 = torch.ops.aten.randn.default([4], dtype=torch.float32, device=device(type='cuda', index=0), pin_memory=False) buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4,), (1,), torch.float32) triton_poi_fused_add_convolution_exp_mul_1[grid(4)](primals_3, primals_4, buf4, buf5, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf6 = extern_kernels.convolution(primals_5, buf2, 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, 1, 1), (4, 1, 1, 1)) buf7 = buf6 del buf6 triton_poi_fused_add_convolution_exp_mul_2[grid(16)](buf7, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf5 return buf7, primals_2, primals_4, primals_5, buf1, buf2, buf4 class _BayesConvNd(Module): """ Applies Bayesian Convolution Arguments: prior_mu (Float): mean of prior normal distribution. prior_sigma (Float): sigma of prior normal distribution. .. note:: other arguments are following conv of pytorch 1.2.0. https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py """ __constants__ = ['prior_mu', 'prior_sigma', 'stride', 'padding', 'dilation', 'groups', 'bias', 'padding_mode', 'output_padding', 'in_channels', 'out_channels', 'kernel_size'] def __init__(self, prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride, padding, dilation, transposed, output_padding, groups, bias, padding_mode): super(_BayesConvNd, self).__init__() if in_channels % groups != 0: raise ValueError('in_channels must be divisible by groups') if out_channels % groups != 0: raise ValueError('out_channels must be divisible by groups') self.in_channels = in_channels self.out_channels = out_channels self.kernel_size = kernel_size self.stride = stride self.padding = padding self.dilation = dilation self.transposed = transposed self.output_padding = output_padding self.groups = groups self.padding_mode = padding_mode self.prior_mu = prior_mu self.prior_sigma = prior_sigma self.prior_log_sigma = math.log(prior_sigma) if transposed: self.weight_mu = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.weight_log_sigma = Parameter(torch.Tensor(in_channels, out_channels // groups, *kernel_size)) self.register_buffer('weight_eps', None) else: self.weight_mu = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.weight_log_sigma = Parameter(torch.Tensor(out_channels, in_channels // groups, *kernel_size)) self.register_buffer('weight_eps', None) if bias is None or bias is False: self.bias = False else: self.bias = True if self.bias: self.bias_mu = Parameter(torch.Tensor(out_channels)) self.bias_log_sigma = Parameter(torch.Tensor(out_channels)) self.register_buffer('bias_eps', None) else: self.register_parameter('bias_mu', None) self.register_parameter('bias_log_sigma', None) self.register_buffer('bias_eps', None) self.reset_parameters() def reset_parameters(self): n = self.in_channels n *= self.kernel_size[0] ** 2 stdv = 1.0 / math.sqrt(n) self.weight_mu.data.uniform_(-stdv, stdv) self.weight_log_sigma.data.fill_(self.prior_log_sigma) if self.bias: self.bias_mu.data.uniform_(-stdv, stdv) self.bias_log_sigma.data.fill_(self.prior_log_sigma) def freeze(self): self.weight_eps = torch.randn_like(self.weight_log_sigma) if self.bias: self.bias_eps = torch.randn_like(self.bias_log_sigma) def unfreeze(self): self.weight_eps = None if self.bias: self.bias_eps = None def extra_repr(self): s = ( '{prior_mu}, {prior_sigma}, {in_channels}, {out_channels}, kernel_size={kernel_size}, stride={stride}' ) if self.padding != (0,) * len(self.padding): s += ', padding={padding}' if self.dilation != (1,) * len(self.dilation): s += ', dilation={dilation}' if self.output_padding != (0,) * len(self.output_padding): s += ', output_padding={output_padding}' if self.groups != 1: s += ', groups={groups}' if self.bias is False: s += ', bias=False' return s.format(**self.__dict__) def __setstate__(self, state): super(_BayesConvNd, self).__setstate__(state) if not hasattr(self, 'padding_mode'): self.padding_mode = 'zeros' class BayesConv2dNew(_BayesConvNd): """ Applies Bayesian Convolution for 2D inputs Arguments: prior_mu (Float): mean of prior normal distribution. prior_sigma (Float): sigma of prior normal distribution. .. note:: other arguments are following conv of pytorch 1.2.0. https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py """ def __init__(self, prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros'): kernel_size = _pair(kernel_size) stride = _pair(stride) padding = _pair(padding) dilation = _pair(dilation) super(BayesConv2dNew, self).__init__(prior_mu, prior_sigma, in_channels, out_channels, kernel_size, stride, padding, dilation, False, _pair(0), groups, bias, padding_mode) def conv2d_forward(self, input, weight): if self.bias: if self.bias_eps is None: bias = self.bias_mu + torch.exp(self.bias_log_sigma ) * torch.randn_like(self.bias_log_sigma) else: bias = self.bias_mu + torch.exp(self.bias_log_sigma ) * self.bias_eps else: bias = None if self.padding_mode == 'circular': expanded_padding = (self.padding[1] + 1) // 2, self.padding[1 ] // 2, (self.padding[0] + 1) // 2, self.padding[0] // 2 return F.conv2d(F.pad(input, expanded_padding, mode='circular'), weight, bias, self.stride, _pair(0), self.dilation, self.groups ) return F.conv2d(input, weight, bias, self.stride, self.padding, self.dilation, self.groups) def forward(self, input_0): primals_1 = self.weight_mu primals_2 = self.weight_log_sigma primals_3 = self.bias_mu primals_4 = self.bias_log_sigma primals_5 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
anaplasia29/Bayesian-Neural-Network
BayesConv2d
false
3,110
[ "MIT" ]
0
d98df8039e52cd2505dc8a94ed3cd474c2056d9a
https://github.com/anaplasia29/Bayesian-Neural-Network/tree/d98df8039e52cd2505dc8a94ed3cd474c2056d9a
QNetwork
import torch import torch.nn as nn import torch.nn.functional as F class QNetwork(nn.Module): """Actor (Policy) Model. Deep Net function approximator for q(s,a)""" def __init__(self, state_size, action_size, seed): """Initialize parameters and build model. Parameters: ========== state_size (int): This is the dimension of each state. action_size (int): This is the dimension of each action. seed (int): This gives the random seed. """ super(QNetwork, self).__init__() self.seed = torch.manual_seed(seed) self.fc1 = nn.Linear(state_size, 64) self.fc2 = nn.Linear(64, 32) self.fc3 = nn.Linear(32, 16) self.fc4 = nn.Linear(16, action_size) def forward(self, state): """This builds a network that maps a state to action values.""" state = self.fc1(state) state = F.relu(state) state = self.fc2(state) state = F.relu(state) state = self.fc3(state) state = F.relu(state) state = self.fc4(state) return state def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'action_size': 4, 'seed': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (32, 64), (64, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (16, 32), (32, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (4, 16), (16, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf0 buf9 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf1, primals_2, buf9, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 32), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 32), (512, 128, 32, 1), 0) del buf2 buf8 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(2048)](buf3, primals_5, buf8, 2048, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 32), (32, 1), 0), reinterpret_tensor(primals_6, (32, 16), (1, 32), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf4 buf7 = empty_strided_cuda((4, 4, 4, 16), (256, 64, 16, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(1024)](buf5, primals_7, buf7, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf5, (64, 16), (16, 1), 0), reinterpret_tensor(primals_8, (16, 4), (1, 16), 0), alpha=1, beta=1, out=buf6) del primals_9 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor( buf3, (64, 32), (32, 1), 0), reinterpret_tensor(buf5, (64, 16), (16, 1), 0), primals_8, buf7, primals_6, buf8, primals_4, buf9 class QNetworkNew(nn.Module): """Actor (Policy) Model. Deep Net function approximator for q(s,a)""" def __init__(self, state_size, action_size, seed): """Initialize parameters and build model. Parameters: ========== state_size (int): This is the dimension of each state. action_size (int): This is the dimension of each action. seed (int): This gives the random seed. """ super(QNetworkNew, self).__init__() self.seed = torch.manual_seed(seed) self.fc1 = nn.Linear(state_size, 64) self.fc2 = nn.Linear(64, 32) self.fc3 = nn.Linear(32, 16) self.fc4 = nn.Linear(16, action_size) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_8 = self.fc4.weight primals_9 = self.fc4.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]
andreaspts/DRL_LUNAR_LANDER
QNetwork
false
3,111
[ "MIT" ]
0
61f19b294ba7ed069795c70a3ceca4d9f7ff8a66
https://github.com/andreaspts/DRL_LUNAR_LANDER/tree/61f19b294ba7ed069795c70a3ceca4d9f7ff8a66
PreNet
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim.optimizer class PreNet(nn.Module): def __init__(self, in_dims, fc1_dims=256, fc2_dims=128, dropout=0.5): super().__init__() self.fc1 = nn.Linear(in_dims, fc1_dims) self.fc2 = nn.Linear(fc1_dims, fc2_dims) self.p = dropout def forward(self, x): x = self.fc1(x) x = F.relu(x) x = F.dropout(x, self.p, training=self.training) x = self.fc2(x) x = F.relu(x) x = F.dropout(x, self.p, training=self.training) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_dims': 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.optim.optimizer assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (128, 256), (256, 1)) assert_size_stride(primals_5, (128,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf1, primals_2, buf5, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 128), (1, 256), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf2 buf4 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf3, primals_5, buf4, 8192, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 256), (256, 1), 0 ), buf4, primals_4, buf5 class PreNetNew(nn.Module): def __init__(self, in_dims, fc1_dims=256, fc2_dims=128, dropout=0.5): super().__init__() self.fc1 = nn.Linear(in_dims, fc1_dims) self.fc2 = nn.Linear(fc1_dims, fc2_dims) self.p = dropout def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
anh/ForwardTacotron
PreNet
false
3,112
[ "MIT" ]
0
a58d9244844b4512f5655e154f08f934760c88b3
https://github.com/anh/ForwardTacotron/tree/a58d9244844b4512f5655e154f08f934760c88b3
RNN
import torch import torch.nn as nn class RNN(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int', output_size: 'int'): super(RNN, self).__init__() self.hidden_size = hidden_size self.i2h = nn.Linear(input_size + hidden_size, hidden_size) self.i2o = nn.Linear(input_size + hidden_size, output_size) self.softMax = nn.LogSoftmax(dim=1) def forward(self, _input, _hidden): combined = torch.cat((_input, _hidden), 1) hidden = self.i2h(combined) output = self.i2o(combined) output = self.softMax(output) return output, hidden def init_hidden(self): return torch.zeros(1, self.hidden_size) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4, 'output_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused__log_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 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 8), (8, 1)) assert_size_stride(primals_6, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, buf0, reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf1) del primals_3 del primals_4 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, buf0, reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf2) del primals_5 del primals_6 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = buf2 del buf2 triton_poi_fused__log_softmax_2[grid(16)](buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf3 return buf4, buf1, buf0, buf4 class RNNNew(nn.Module): def __init__(self, input_size: 'int', hidden_size: 'int', output_size: 'int'): super(RNNNew, self).__init__() self.hidden_size = hidden_size self.i2h = nn.Linear(input_size + hidden_size, hidden_size) self.i2o = nn.Linear(input_size + hidden_size, output_size) self.softMax = nn.LogSoftmax(dim=1) def init_hidden(self): return torch.zeros(1, self.hidden_size) def forward(self, input_0, input_1): primals_3 = self.i2h.weight primals_4 = self.i2h.bias primals_5 = self.i2o.weight primals_6 = self.i2o.bias primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0], output[1]
alimpk/names-classify
RNN
false
3,113
[ "MIT" ]
0
cfaff60cae504a8deceaa5b8641cbd9fc50ce705
https://github.com/alimpk/names-classify/tree/cfaff60cae504a8deceaa5b8641cbd9fc50ce705
RewardCriterion
import torch import torch.nn as nn from torch.autograd import * def to_contiguous(tensor): if tensor.is_contiguous(): return tensor else: return tensor.contiguous() class RewardCriterion(nn.Module): def __init__(self): super(RewardCriterion, self).__init__() def forward(self, input, seq, reward): input = to_contiguous(input).view(-1) reward = to_contiguous(reward).view(-1) mask = (seq > 0).float() mask = to_contiguous(torch.cat([mask.new(mask.size(0), 1).fill_(1), mask[:, :-1]], 1)).view(-1) output = -input * reward * mask output = torch.sum(output) / torch.sum(mask) return output def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn from torch.autograd import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_div_mul_neg_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp2 = tl.load(in_ptr1 + r0, None) tmp1 = -tmp0 tmp3 = tmp1 * tmp2 tmp4 = r0 % 4 tl.full([1, 1], 0, tl.int64) tmp7 = tl.full([1, 1], 1, tl.int64) tmp8 = tmp4 < tmp7 tmp9 = 1.0 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp8, tmp9, tmp10) tmp12 = tmp4 >= tmp7 tl.full([1, 1], 4, tl.int64) tmp15 = tl.load(in_ptr2 + tl.broadcast_to(4 * (r0 // 4) + (-1 + r0 % 4), [XBLOCK, RBLOCK]), tmp12, eviction_policy='evict_last', other=0.0) tmp16 = 0.0 tmp17 = tmp15 > tmp16 tmp18 = tmp17.to(tl.float32) tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp12, tmp18, tmp19) tmp21 = tl.where(tmp8, tmp11, tmp20) tmp22 = tmp3 * tmp21 tmp23 = tl.broadcast_to(tmp22, [XBLOCK, RBLOCK]) tmp25 = tl.sum(tmp23, 1)[:, None] tmp26 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp28 = tl.sum(tmp26, 1)[:, None] tmp29 = tmp25 / tmp28 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp29, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) assert_size_stride(arg2_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_div_mul_neg_sum_0[grid(1)](buf2, arg0_1, arg1_1, arg2_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, def to_contiguous(tensor): if tensor.is_contiguous(): return tensor else: return tensor.contiguous() class RewardCriterionNew(nn.Module): def __init__(self): super(RewardCriterionNew, self).__init__() def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
anonymous2021hello/transformer-cil
RewardCriterion
false
3,114
[ "MIT" ]
0
aed4017b61afaf4d9d21d40a078eefb4c7031cd1
https://github.com/anonymous2021hello/transformer-cil/tree/aed4017b61afaf4d9d21d40a078eefb4c7031cd1
PatchEmbedding
import torch import torch.nn as nn class PatchEmbedding(nn.Module): """PatchEmdedding class Args: image_size(int): size of the image. assume that image shape is square in_channels(int): input channel of the image, 3 for RGB color channel embed_size(int): output channel size. This is the latent vector size. and is constant throughout the transformer patch_size(int): size of the patch Attributes: n_patches(int): calculate the number of patches. patcher: convert image into patches. Basically a convolution layer with kernel size and stride as of the patch size """ def __init__(self, image_size=224, in_channels=3, embed_size=768, patch_size=16): super(PatchEmbedding, self).__init__() self.n_patches = (image_size // patch_size) ** 2 self.patcher = nn.Conv2d(in_channels, embed_size, patch_size, patch_size) def forward(self, x): out = self.patcher(x) out = out.flatten(2) out = out.transpose(1, 2) return out def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 2304 xnumel = 256 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 256 * y3), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 768 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 12 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 3 y1 = yindex // 3 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask) @triton.jit def triton_poi_fused_convolution_2(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 768 y1 = yindex // 768 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 768 * x2 + 12288 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (768, 3, 16, 16), (768, 256, 16, 1)) assert_size_stride(primals_2, (768,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((768, 3, 16, 16), (768, 1, 48, 3), torch. float32) get_raw_stream(0) triton_poi_fused_0[grid(2304, 256)](primals_1, buf0, 2304, 256, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch .float32) triton_poi_fused_1[grid(12, 4096)](primals_3, buf1, 12, 4096, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, buf0, stride=(16, 16), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 768, 4, 4), (12288, 1, 3072, 768)) buf3 = empty_strided_cuda((4, 768, 4, 4), (12288, 16, 4, 1), torch. float32) triton_poi_fused_convolution_2[grid(3072, 16)](buf2, primals_2, buf3, 3072, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del buf2 del primals_2 return reinterpret_tensor(buf3, (4, 16, 768), (12288, 1, 16), 0 ), buf0, buf1 class PatchEmbeddingNew(nn.Module): """PatchEmdedding class Args: image_size(int): size of the image. assume that image shape is square in_channels(int): input channel of the image, 3 for RGB color channel embed_size(int): output channel size. This is the latent vector size. and is constant throughout the transformer patch_size(int): size of the patch Attributes: n_patches(int): calculate the number of patches. patcher: convert image into patches. Basically a convolution layer with kernel size and stride as of the patch size """ def __init__(self, image_size=224, in_channels=3, embed_size=768, patch_size=16): super(PatchEmbeddingNew, self).__init__() self.n_patches = (image_size // patch_size) ** 2 self.patcher = nn.Conv2d(in_channels, embed_size, patch_size, patch_size) def forward(self, input_0): primals_1 = self.patcher.weight primals_2 = self.patcher.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
aiwizzard/vision-transformer
PatchEmbedding
false
3,115
[ "Apache-2.0" ]
0
f9dd2f720a595f02543aa9720204d8f8c6f58193
https://github.com/aiwizzard/vision-transformer/tree/f9dd2f720a595f02543aa9720204d8f8c6f58193
RnLU
import math import torch import torch.nn as nn from torch.autograd.function import InplaceFunction import torch.nn.parallel import torch.utils.data def birelu(x, inplace=False): return BiReLUFunction().apply(x, inplace) def rnlu(x, inplace=False, shift=0, scale_fix=(math.pi / 2) ** 0.5): x = birelu(x, inplace=inplace) pos, neg = (x + shift).chunk(2, dim=1) scale = (pos - neg).view(pos.size(0), -1).mean(1) * scale_fix + 1e-08 return x / scale.view(scale.size(0), *([1] * (x.dim() - 1))) class BiReLUFunction(InplaceFunction): @classmethod def forward(cls, ctx, input, inplace=False): if input.size(1) % 2 != 0: raise RuntimeError( 'dimension 1 of input must be multiple of 2, but got {}'. format(input.size(1))) ctx.inplace = inplace if ctx.inplace: ctx.mark_dirty(input) output = input else: output = input.clone() pos, neg = output.chunk(2, dim=1) pos.clamp_(min=0) neg.clamp_(max=0) ctx.save_for_backward(output) return output @staticmethod def backward(ctx, grad_output): output, = ctx.saved_variables grad_input = grad_output.masked_fill(output.eq(0), 0) return grad_input, None class RnLU(nn.Module): """docstring for RnLU.""" def __init__(self, inplace=False): super(RnLU, self).__init__() self.inplace = inplace def forward(self, x): return rnlu(x, inplace=self.inplace) 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 math import torch.nn as nn from torch.autograd.function import InplaceFunction import torch.nn.parallel 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_mean_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): xnumel = 4 RBLOCK: tl.constexpr = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp21 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp44 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0) tmp0 = r1 // 16 tmp1 = tl.full([1, 1], 2, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.broadcast_to(r1 // 16, [XBLOCK, RBLOCK]) tmp4 = tmp3 < tmp1 tmp5 = tmp4 & tmp2 tmp6 = tl.load(in_ptr0 + (r1 + 64 * x0), tmp5 & xmask, other=0.0) tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype) tmp10 = tl.where(tmp5, tmp8, tmp9) tmp11 = tl.load(in_ptr0 + (r1 + 64 * x0), tmp2 & xmask, other=0.0) tmp12 = tl.where(tmp4, tmp10, tmp11) tmp13 = triton_helpers.minimum(tmp12, tmp7) tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype) tmp15 = tl.where(tmp2, tmp13, tmp14) tmp16 = tmp0 < tmp1 tmp17 = tl.load(in_ptr0 + (r1 + 64 * x0), tmp16 & xmask, other=0.0) tmp18 = triton_helpers.maximum(tmp17, tmp7) tmp19 = tl.full(tmp18.shape, 0.0, tmp18.dtype) tmp20 = tl.where(tmp16, tmp18, tmp19) tmp22 = tl.where(tmp16, tmp20, tmp21) tmp23 = tl.where(tmp2, tmp15, tmp22) tmp24 = tmp23 + tmp7 tmp25 = 2 + r1 // 16 tmp26 = tmp25 >= tmp1 tmp27 = tl.broadcast_to(2 + r1 // 16, [XBLOCK, RBLOCK]) tmp28 = tmp27 < tmp1 tmp29 = tmp28 & tmp26 tmp30 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), tmp29 & xmask, other=0.0) tmp31 = triton_helpers.maximum(tmp30, tmp7) tmp32 = tl.full(tmp31.shape, 0.0, tmp31.dtype) tmp33 = tl.where(tmp29, tmp31, tmp32) tmp34 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), tmp26 & xmask, other=0.0) tmp35 = tl.where(tmp28, tmp33, tmp34) tmp36 = triton_helpers.minimum(tmp35, tmp7) tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype) tmp38 = tl.where(tmp26, tmp36, tmp37) tmp39 = tmp25 < tmp1 tmp40 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), tmp39 & xmask, other=0.0) tmp41 = triton_helpers.maximum(tmp40, tmp7) tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp39, tmp41, tmp42) tmp45 = tl.where(tmp39, tmp43, tmp44) tmp46 = tl.where(tmp26, tmp38, tmp45) tmp47 = tmp46 + tmp7 tmp48 = tmp24 - tmp47 tmp49 = tl.broadcast_to(tmp48, [XBLOCK, RBLOCK]) tmp51 = tl.where(xmask, tmp49, 0) tmp52 = tl.sum(tmp51, 1)[:, None] tl.store(out_ptr0 + x0, tmp52, xmask) @triton.jit def triton_poi_fused_clamp_div_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 4 x3 = xindex x2 = xindex // 64 tmp19 = tl.load(in_ptr0 + x3, xmask) tmp22 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp0 = x1 tmp1 = tl.full([1], 2, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tmp0 < tmp1 tmp4 = tmp3 & tmp2 tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, other=0.0) tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tl.load(in_ptr0 + x3, tmp2 & xmask, other=0.0) tmp11 = tl.where(tmp3, tmp9, tmp10) tmp12 = triton_helpers.minimum(tmp11, tmp6) tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp2, tmp12, tmp13) tmp15 = tl.load(in_ptr0 + x3, tmp3 & xmask, other=0.0) tmp16 = triton_helpers.maximum(tmp15, tmp6) tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp3, tmp16, tmp17) tmp20 = tl.where(tmp3, tmp18, tmp19) tmp21 = tl.where(tmp2, tmp14, tmp20) tmp23 = 32.0 tmp24 = tmp22 / tmp23 tmp25 = 1.2533141373155001 tmp26 = tmp24 * tmp25 tmp27 = 1e-08 tmp28 = tmp26 + tmp27 tmp29 = tmp21 / tmp28 tl.store(out_ptr0 + x3, tmp29, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_mean_0[grid(4)](arg0_1, buf0, 4, 32, XBLOCK=1, num_warps=2, num_stages=1) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clamp_div_1[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del buf0 return buf1, def birelu(x, inplace=False): return BiReLUFunction().apply(x, inplace) def rnlu(x, inplace=False, shift=0, scale_fix=(math.pi / 2) ** 0.5): x = birelu(x, inplace=inplace) pos, neg = (x + shift).chunk(2, dim=1) scale = (pos - neg).view(pos.size(0), -1).mean(1) * scale_fix + 1e-08 return x / scale.view(scale.size(0), *([1] * (x.dim() - 1))) class BiReLUFunction(InplaceFunction): @classmethod def forward(cls, ctx, input, inplace=False): if input.size(1) % 2 != 0: raise RuntimeError( 'dimension 1 of input must be multiple of 2, but got {}'. format(input.size(1))) ctx.inplace = inplace if ctx.inplace: ctx.mark_dirty(input) output = input else: output = input.clone() pos, neg = output.chunk(2, dim=1) pos.clamp_(min=0) neg.clamp_(max=0) ctx.save_for_backward(output) return output @staticmethod def backward(ctx, grad_output): output, = ctx.saved_variables grad_input = grad_output.masked_fill(output.eq(0), 0) return grad_input, None class RnLUNew(nn.Module): """docstring for RnLU.""" def __init__(self, inplace=False): super(RnLUNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
aparna-aketi/Low_Precision_DL
RnLU
false
3,116
[ "MIT" ]
0
5a2489cac5da8f43dd8490a9d871f1ce17f8e7f8
https://github.com/aparna-aketi/Low_Precision_DL/tree/5a2489cac5da8f43dd8490a9d871f1ce17f8e7f8
LanguageModelCriterion
import torch import torch.nn as nn from torch.autograd import * class LanguageModelCriterion(nn.Module): def __init__(self): super(LanguageModelCriterion, self).__init__() def forward(self, input, target, mask): target = target[:, :input.size(1)] mask = mask[:, :input.size(1)] output = -input.gather(2, target.unsqueeze(2)).squeeze(2) * mask output = torch.sum(output) / torch.sum(mask) return output def get_inputs(): return [torch.ones([4, 4, 4], dtype=torch.int64), torch.ones([4, 4], dtype=torch.int64), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn from torch.autograd import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_div_mul_neg_sum_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp9 = tl.load(in_ptr2 + r0, None) tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4), 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + (tmp4 + 4 * r0), None, eviction_policy= 'evict_last') tmp7 = -tmp6 tmp8 = tmp7.to(tl.float32) tmp10 = tmp8 * tmp9 tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp13 = tl.sum(tmp11, 1)[:, None] tmp14 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp16 = tl.sum(tmp14, 1)[:, None] tmp17 = tmp13 / tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp17, None) 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, 1)) assert_size_stride(arg2_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_div_mul_neg_sum_0[grid(1)](buf2, arg1_1, arg0_1, arg2_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf2, class LanguageModelCriterionNew(nn.Module): def __init__(self): super(LanguageModelCriterionNew, self).__init__() def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
anonymous2021hello/transformer-cil
LanguageModelCriterion
false
3,117
[ "MIT" ]
0
aed4017b61afaf4d9d21d40a078eefb4c7031cd1
https://github.com/anonymous2021hello/transformer-cil/tree/aed4017b61afaf4d9d21d40a078eefb4c7031cd1
DiceLoss
import torch import torch.nn as nn class DiceLoss(nn.Module): def __init__(self): super(DiceLoss, self).__init__() self.sigmoid = nn.Sigmoid() def forward(self, output, target): prediction = self.sigmoid(output) return 1 - 2 * torch.sum(prediction * target) / (torch.sum( prediction) + torch.sum(target) + 1e-07) 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_div_mul_rsub_sigmoid_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 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = tl.broadcast_to(tmp1, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = tl.broadcast_to(tmp2, [RBLOCK]) tmp12 = triton_helpers.promote_to_tensor(tl.sum(tmp10, 0)) tmp13 = 2.0 tmp14 = tmp6 * tmp13 tmp15 = tmp9 + tmp12 tmp16 = 1e-07 tmp17 = tmp15 + tmp16 tmp18 = tmp14 / tmp17 tmp19 = 1.0 tmp20 = tmp19 - tmp18 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp20, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf3 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_div_mul_rsub_sigmoid_sum_0[grid(1)](buf3, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf3, class DiceLossNew(nn.Module): def __init__(self): super(DiceLossNew, self).__init__() self.sigmoid = nn.Sigmoid() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
apyskir/steppy-toolkit
DiceLoss
false
3,118
[ "MIT" ]
0
3190054954aeab043ced1c079d87bdd3582bb232
https://github.com/apyskir/steppy-toolkit/tree/3190054954aeab043ced1c079d87bdd3582bb232
BiReLU
import torch import torch.nn as nn from torch.autograd.function import InplaceFunction import torch.nn.parallel import torch.utils.data def birelu(x, inplace=False): return BiReLUFunction().apply(x, inplace) class BiReLUFunction(InplaceFunction): @classmethod def forward(cls, ctx, input, inplace=False): if input.size(1) % 2 != 0: raise RuntimeError( 'dimension 1 of input must be multiple of 2, but got {}'. format(input.size(1))) ctx.inplace = inplace if ctx.inplace: ctx.mark_dirty(input) output = input else: output = input.clone() pos, neg = output.chunk(2, dim=1) pos.clamp_(min=0) neg.clamp_(max=0) ctx.save_for_backward(output) return output @staticmethod def backward(ctx, grad_output): output, = ctx.saved_variables grad_input = grad_output.masked_fill(output.eq(0), 0) return grad_input, None class BiReLU(nn.Module): """docstring for BiReLU.""" def __init__(self, inplace=False): super(BiReLU, self).__init__() self.inplace = inplace def forward(self, inputs): return birelu(inputs, inplace=self.inplace) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch.autograd.function import InplaceFunction import torch.nn.parallel 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 x1 = xindex // 16 % 4 x3 = xindex tmp19 = tl.load(in_ptr0 + x3, xmask) tmp0 = x1 tmp1 = tl.full([1], 2, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tmp0 < tmp1 tmp4 = tmp3 & tmp2 tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, other=0.0) tmp6 = 0.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tl.load(in_ptr0 + x3, tmp2 & xmask, other=0.0) tmp11 = tl.where(tmp3, tmp9, tmp10) tmp12 = triton_helpers.minimum(tmp11, tmp6) tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp2, tmp12, tmp13) tmp15 = tl.load(in_ptr0 + x3, tmp3 & xmask, other=0.0) tmp16 = triton_helpers.maximum(tmp15, tmp6) tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp3, tmp16, tmp17) tmp20 = tl.where(tmp3, tmp18, tmp19) tmp21 = tl.where(tmp2, tmp14, tmp20) tl.store(out_ptr0 + x3, tmp21, 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, def birelu(x, inplace=False): return BiReLUFunction().apply(x, inplace) class BiReLUFunction(InplaceFunction): @classmethod def forward(cls, ctx, input, inplace=False): if input.size(1) % 2 != 0: raise RuntimeError( 'dimension 1 of input must be multiple of 2, but got {}'. format(input.size(1))) ctx.inplace = inplace if ctx.inplace: ctx.mark_dirty(input) output = input else: output = input.clone() pos, neg = output.chunk(2, dim=1) pos.clamp_(min=0) neg.clamp_(max=0) ctx.save_for_backward(output) return output @staticmethod def backward(ctx, grad_output): output, = ctx.saved_variables grad_input = grad_output.masked_fill(output.eq(0), 0) return grad_input, None class BiReLUNew(nn.Module): """docstring for BiReLU.""" def __init__(self, inplace=False): super(BiReLUNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
aparna-aketi/Low_Precision_DL
BiReLU
false
3,119
[ "MIT" ]
0
5a2489cac5da8f43dd8490a9d871f1ce17f8e7f8
https://github.com/aparna-aketi/Low_Precision_DL/tree/5a2489cac5da8f43dd8490a9d871f1ce17f8e7f8
Network
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim class Network(nn.Module): def __init__(self, lr, input_dims, n_hidden=64, output_dims=4): super(Network, self).__init__() self.fc1 = nn.Linear(input_dims, n_hidden) self.fc2 = nn.Linear(n_hidden, n_hidden) self.pi = nn.Linear(n_hidden, output_dims) self.v = nn.Linear(n_hidden, 1) self.optimizer = optim.Adam(self.parameters(), lr=lr) def forward(self, state): x = F.relu(self.fc1(state)) x = F.relu(self.fc2(x)) pi = self.pi(x) v_s = self.v(x) return pi, v_s def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'lr': 4, 'input_dims': 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.optim as optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) 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, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (64, 64), (64, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 64), (64, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (1, 64), (64, 1)) assert_size_stride(primals_9, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf1, primals_2, buf8, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor(primals_4, (64, 64), (1, 64), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 64), (1024, 256, 64, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 64), (1024, 256, 64, 1), torch.bool ) triton_poi_fused_relu_threshold_backward_0[grid(4096)](buf3, primals_5, buf7, 4096, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 64), (64, 1), 0), reinterpret_tensor(primals_6, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf4) del primals_7 buf6 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf3, (64, 64), (64, 1), 0), reinterpret_tensor(primals_8, (64, 1), (1, 64), 0), alpha=1, beta=1, out=buf6) del primals_9 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf6, (4, 4, 4, 1), (16, 4, 1, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor( buf3, (64, 64), (64, 1), 0 ), primals_8, primals_6, buf7, primals_4, buf8 class NetworkNew(nn.Module): def __init__(self, lr, input_dims, n_hidden=64, output_dims=4): super(NetworkNew, self).__init__() self.fc1 = nn.Linear(input_dims, n_hidden) self.fc2 = nn.Linear(n_hidden, n_hidden) self.pi = nn.Linear(n_hidden, output_dims) self.v = nn.Linear(n_hidden, 1) self.optimizer = optim.Adam(self.parameters(), lr=lr) 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.pi.weight primals_7 = self.pi.bias primals_8 = self.v.weight primals_9 = self.v.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]
apoorvaish/mujoco-rl
Network
false
3,120
[ "MIT" ]
0
234bd7689990cdd63db458d0367e14ccd1b62c1f
https://github.com/apoorvaish/mujoco-rl/tree/234bd7689990cdd63db458d0367e14ccd1b62c1f
ConvertPointsToHomogeneous
import torch import torch.nn as nn def convert_points_to_homogeneous(points): """Function that converts points from Euclidean to homogeneous space. See :class:`~torchgeometry.ConvertPointsToHomogeneous` for details. Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> output = tgm.convert_points_to_homogeneous(input) # BxNx4 """ if not torch.is_tensor(points): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(points))) if len(points.shape) < 2: raise ValueError('Input must be at least a 2D tensor. Got {}'. format(points.shape)) return nn.functional.pad(points, (0, 1), 'constant', 1.0) class ConvertPointsToHomogeneous(nn.Module): """Creates a transformation to convert points from Euclidean to homogeneous space. Args: points (Tensor): tensor of N-dimensional points. Returns: Tensor: tensor of N+1-dimensional points. Shape: - Input: :math:`(B, D, N)` or :math:`(D, N)` - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)` Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> transform = tgm.ConvertPointsToHomogeneous() >>> output = transform(input) # BxNx4 """ def __init__(self): super(ConvertPointsToHomogeneous, self).__init__() def forward(self, input): return convert_points_to_homogeneous(input) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 320 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = x0 tmp1 = tl.full([1], 4, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.load(in_ptr0 + (x0 + 4 * x1), tmp2 & xmask, other=1.0) tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 5), (80, 20, 5, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(320)](arg0_1, buf0, 320, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, def convert_points_to_homogeneous(points): """Function that converts points from Euclidean to homogeneous space. See :class:`~torchgeometry.ConvertPointsToHomogeneous` for details. Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> output = tgm.convert_points_to_homogeneous(input) # BxNx4 """ if not torch.is_tensor(points): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(points))) if len(points.shape) < 2: raise ValueError('Input must be at least a 2D tensor. Got {}'. format(points.shape)) return nn.functional.pad(points, (0, 1), 'constant', 1.0) class ConvertPointsToHomogeneousNew(nn.Module): """Creates a transformation to convert points from Euclidean to homogeneous space. Args: points (Tensor): tensor of N-dimensional points. Returns: Tensor: tensor of N+1-dimensional points. Shape: - Input: :math:`(B, D, N)` or :math:`(D, N)` - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)` Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> transform = tgm.ConvertPointsToHomogeneous() >>> output = transform(input) # BxNx4 """ def __init__(self): super(ConvertPointsToHomogeneousNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
aravinho/frankmocap
ConvertPointsToHomogeneous
false
3,121
[ "BSD-3-Clause" ]
0
6a150a9cb96e9b32a60d8047eaa84d0c37e471f5
https://github.com/aravinho/frankmocap/tree/6a150a9cb96e9b32a60d8047eaa84d0c37e471f5
pg_model
import torch import torch.nn as nn import torch.nn.functional as F class pg_model(nn.Module): def __init__(self): super(pg_model, self).__init__() self.l1 = nn.Linear(4, 10) self.l2 = nn.Linear(10, 2) self.l3 = nn.Linear(2, 2) def forward(self, x): x = self.l1(x) x = F.relu(x) x = self.l2(x) x = F.relu(x) x = self.l3(x) x = F.softmax(x, dim=1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): 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) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 2 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused__softmax_2(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 x3 = xindex x0 = xindex % 8 x2 = xindex // 32 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (24 + x0 + 32 * 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 8 x2 = xindex // 32 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (24 + x0 + 32 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (10, 4), (4, 1)) assert_size_stride(primals_2, (10,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (2, 10), (10, 1)) assert_size_stride(primals_5, (2,), (1,)) assert_size_stride(primals_6, (2, 2), (2, 1)) assert_size_stride(primals_7, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 10), (10, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 10), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 10), (160, 40, 10, 1), 0) del buf0 buf8 = empty_strided_cuda((4, 4, 4, 10), (160, 40, 10, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(640)](buf1, primals_2, buf8, 640, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 10), (10, 1), 0), reinterpret_tensor(primals_4, (10, 2), (1, 10), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf2 buf7 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(128)](buf3, primals_5, buf7, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 2), ( 2, 1), 0), reinterpret_tensor(primals_6, (2, 2), (1, 2), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32) triton_poi_fused__softmax_2[grid(128)](buf4, buf5, 128, XBLOCK=128, num_warps=4, num_stages=1) buf6 = reinterpret_tensor(buf4, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf4 triton_poi_fused__softmax_3[grid(128)](buf5, buf6, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf5 return buf6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 10), (10, 1), 0), reinterpret_tensor( buf3, (64, 2), (2, 1), 0), buf6, primals_6, buf7, primals_4, buf8 class pg_modelNew(nn.Module): def __init__(self): super(pg_modelNew, self).__init__() self.l1 = nn.Linear(4, 10) self.l2 = nn.Linear(10, 2) self.l3 = nn.Linear(2, 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_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
anthonytec2/ssp-rl-final
pg_model
false
3,122
[ "MIT" ]
0
4004678f7b820989d69824bd492307b3ed227b7a
https://github.com/anthonytec2/ssp-rl-final/tree/4004678f7b820989d69824bd492307b3ed227b7a
DiagGaussian
import torch import numpy as np import torch.nn as nn import torch.utils.data class BaseDistribution(nn.Module): """ Base distribution of a flow-based model Parameters do not depend of target variable (as is the case for a VAE encoder) """ def __init__(self): super().__init__() def forward(self, num_samples=1): """ Samples from base distribution and calculates log probability :param num_samples: Number of samples to draw from the distriubtion :return: Samples drawn from the distribution, log probability """ raise NotImplementedError def log_prob(self, z): """ Calculate log probability of batch of samples :param z: Batch of random variables to determine log probability for :return: log probability for each batch element """ raise NotImplementedError class DiagGaussian(BaseDistribution): """ Multivariate Gaussian distribution with diagonal covariance matrix """ def __init__(self, d): """ Constructor :param d: Dimension of Gaussian distribution """ super().__init__() self.d = d self.loc = nn.Parameter(torch.zeros(1, self.d)) self.log_scale = nn.Parameter(torch.zeros(1, self.d)) def forward(self, num_samples=1): eps = torch.randn((num_samples, self.d), device=self.loc.device) z = self.loc + torch.exp(self.log_scale) * eps log_p = -0.5 * self.d * np.log(2 * np.pi) - torch.sum(self. log_scale + 0.5 * torch.pow(eps, 2), 1) return z, log_p def log_prob(self, z): log_p = -0.5 * self.d * np.log(2 * np.pi) - torch.sum(self. log_scale + 0.5 * torch.pow((z - self.loc) / torch.exp(self. log_scale), 2), 1) return log_p def get_inputs(): return [] def get_init_inputs(): return [[], {'d': 4}]
import torch from torch import device import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import numpy as np 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_out_ptr0, in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp3 = tl.load(in_ptr2 + r0, None) tmp2 = tl_math.exp(tmp1) tmp4 = tmp2 * tmp3 tmp5 = tmp0 + tmp4 tmp6 = tmp3 * tmp3 tmp7 = 0.5 tmp8 = tmp6 * tmp7 tmp9 = tmp1 + tmp8 tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp12 = tl.sum(tmp10, 1)[:, None] tmp13 = -3.6757541328186907 tmp14 = tmp13 - tmp12 tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp5, None) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp14, None) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = torch.ops.aten.randn.default([1, 4], device=device(type= 'cuda', index=0), pin_memory=False) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((1, 4), (4, 1), torch.float32) buf3 = empty_strided_cuda((1,), (1,), torch.float32) buf4 = buf3 del buf3 get_raw_stream(0) triton_per_fused_add_exp_mul_pow_sub_sum_0[grid(1)](buf4, primals_1, primals_2, buf1, buf2, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del primals_1 return buf2, buf4, primals_2, buf1 class BaseDistribution(nn.Module): """ Base distribution of a flow-based model Parameters do not depend of target variable (as is the case for a VAE encoder) """ def __init__(self): super().__init__() def forward(self, num_samples=1): """ Samples from base distribution and calculates log probability :param num_samples: Number of samples to draw from the distriubtion :return: Samples drawn from the distribution, log probability """ raise NotImplementedError def log_prob(self, z): """ Calculate log probability of batch of samples :param z: Batch of random variables to determine log probability for :return: log probability for each batch element """ raise NotImplementedError class DiagGaussianNew(BaseDistribution): """ Multivariate Gaussian distribution with diagonal covariance matrix """ def __init__(self, d): """ Constructor :param d: Dimension of Gaussian distribution """ super().__init__() self.d = d self.loc = nn.Parameter(torch.zeros(1, self.d)) self.log_scale = nn.Parameter(torch.zeros(1, self.d)) def log_prob(self, z): log_p = -0.5 * self.d * np.log(2 * np.pi) - torch.sum(self. log_scale + 0.5 * torch.pow((z - self.loc) / torch.exp(self. log_scale), 2), 1) return log_p def forward(self): primals_1 = self.loc primals_2 = self.log_scale output = call([primals_1, primals_2]) return output[0], output[1]
arc82/normalizing-flows
DiagGaussian
false
3,123
[ "MIT" ]
0
f43df979267eb69b066606177c61d3b2bad0a5b5
https://github.com/arc82/normalizing-flows/tree/f43df979267eb69b066606177c61d3b2bad0a5b5
ConvertPointsFromHomogeneous
import torch import torch.nn as nn def convert_points_from_homogeneous(points): """Function that converts points from homogeneous to Euclidean space. See :class:`~torchgeometry.ConvertPointsFromHomogeneous` for details. Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> output = tgm.convert_points_from_homogeneous(input) # BxNx2 """ if not torch.is_tensor(points): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(points))) if len(points.shape) < 2: raise ValueError('Input must be at least a 2D tensor. Got {}'. format(points.shape)) return points[..., :-1] / points[..., -1:] class ConvertPointsFromHomogeneous(nn.Module): """Creates a transformation that converts points from homogeneous to Euclidean space. Args: points (Tensor): tensor of N-dimensional points. Returns: Tensor: tensor of N-1-dimensional points. Shape: - Input: :math:`(B, D, N)` or :math:`(D, N)` - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)` Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> transform = tgm.ConvertPointsFromHomogeneous() >>> output = transform(input) # BxNx2 """ def __init__(self): super(ConvertPointsFromHomogeneous, self).__init__() def forward(self, input): return convert_points_from_homogeneous(input) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_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 x0 = xindex % 3 x1 = xindex // 3 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1), xmask) tmp1 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 / tmp1 tl.store(out_ptr0 + x2, 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, 3), (48, 12, 3, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_0[grid(192)](arg0_1, buf0, 192, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, def convert_points_from_homogeneous(points): """Function that converts points from homogeneous to Euclidean space. See :class:`~torchgeometry.ConvertPointsFromHomogeneous` for details. Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> output = tgm.convert_points_from_homogeneous(input) # BxNx2 """ if not torch.is_tensor(points): raise TypeError('Input type is not a torch.Tensor. Got {}'.format( type(points))) if len(points.shape) < 2: raise ValueError('Input must be at least a 2D tensor. Got {}'. format(points.shape)) return points[..., :-1] / points[..., -1:] class ConvertPointsFromHomogeneousNew(nn.Module): """Creates a transformation that converts points from homogeneous to Euclidean space. Args: points (Tensor): tensor of N-dimensional points. Returns: Tensor: tensor of N-1-dimensional points. Shape: - Input: :math:`(B, D, N)` or :math:`(D, N)` - Output: :math:`(B, D, N + 1)` or :math:`(D, N + 1)` Examples:: >>> input = torch.rand(2, 4, 3) # BxNx3 >>> transform = tgm.ConvertPointsFromHomogeneous() >>> output = transform(input) # BxNx2 """ def __init__(self): super(ConvertPointsFromHomogeneousNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
aravinho/frankmocap
ConvertPointsFromHomogeneous
false
3,124
[ "BSD-3-Clause" ]
0
6a150a9cb96e9b32a60d8047eaa84d0c37e471f5
https://github.com/aravinho/frankmocap/tree/6a150a9cb96e9b32a60d8047eaa84d0c37e471f5
value_model
import torch import torch.nn as nn import torch.nn.functional as F class value_model(nn.Module): def __init__(self): super(value_model, self).__init__() self.l1 = nn.Linear(4, 10) self.l2 = nn.Linear(10, 2) self.l3 = nn.Linear(2, 1) def forward(self, x): x = self.l1(x) x = F.relu(x) x = self.l2(x) x = F.relu(x) x = self.l3(x) x = F.softmax(x, dim=1) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): 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) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 2 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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) = args args.clear() assert_size_stride(primals_1, (10, 4), (4, 1)) assert_size_stride(primals_2, (10,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (2, 10), (10, 1)) assert_size_stride(primals_5, (2,), (1,)) assert_size_stride(primals_6, (1, 2), (2, 1)) assert_size_stride(primals_7, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 10), (10, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 10), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 10), (160, 40, 10, 1), 0) del buf0 buf9 = empty_strided_cuda((4, 4, 4, 10), (160, 40, 10, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(640)](buf1, primals_2, buf9, 640, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 10), (10, 1), 0), reinterpret_tensor(primals_4, (10, 2), (1, 10), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 2), (32, 8, 2, 1), 0) del buf2 buf8 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(128)](buf3, primals_5, buf8, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf5 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 2), ( 2, 1), 0), reinterpret_tensor(primals_6, (2, 1), (1, 2), 0), alpha=1, beta=1, out=buf5) del primals_7 buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_2[grid(64)](buf5, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = reinterpret_tensor(buf5, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf5 triton_poi_fused__softmax_3[grid(64)](buf6, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf6 return buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 10), (10, 1), 0), reinterpret_tensor( buf3, (64, 2), (2, 1), 0), buf7, primals_6, buf8, primals_4, buf9 class value_modelNew(nn.Module): def __init__(self): super(value_modelNew, self).__init__() self.l1 = nn.Linear(4, 10) self.l2 = nn.Linear(10, 2) self.l3 = nn.Linear(2, 1) def forward(self, input_0): primals_1 = self.l1.weight primals_2 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_6 = self.l3.weight primals_7 = self.l3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
anthonytec2/ssp-rl-final
value_model
false
3,125
[ "MIT" ]
0
4004678f7b820989d69824bd492307b3ed227b7a
https://github.com/anthonytec2/ssp-rl-final/tree/4004678f7b820989d69824bd492307b3ed227b7a
IntrinsicsModel
import torch import torch.nn.functional as F import torch.nn as nn class IntrinsicsModel(nn.Module): def __init__(self, n, H, W): super(IntrinsicsModel, self).__init__() self.skew_scale = 0.001 self.fc1 = nn.Linear(n, n) self.fc2 = nn.Linear(n, n) self.fc3 = nn.Linear(n, 5) self.H = H self.W = W def forward(self, x): x = F.elu(self.fc1(x)) x = F.tanh(self.fc2(x)) x = self.fc3(x) intrinsics = torch.cat((F.softplus(x[:, :1]) * self.W, F.softplus(x [:, 1:2]) * self.H, F.sigmoid(x[:, 2:3]) * self.W, F.sigmoid(x[ :, 3:4]) * self.H, x[:, 4:] * self.skew_scale), dim=1) return intrinsics def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n': 4, 'H': 4, 'W': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 320 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 20 % 4 x0 = xindex % 20 x2 = xindex // 80 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 + 80 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = 20.0 tmp7 = tmp5 > tmp6 tmp8 = tl_math.exp(tmp5) tmp9 = libdevice.log1p(tmp8) tmp10 = tl.where(tmp7, tmp5, tmp9) tmp11 = 4.0 tmp12 = tmp10 * tmp11 tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype) tmp14 = tl.where(tmp4, tmp12, tmp13) tmp15 = tmp0 >= tmp3 tmp16 = tl.full([1], 2, tl.int64) tmp17 = tmp0 < tmp16 tmp18 = tmp15 & tmp17 tmp19 = tl.load(in_ptr0 + (20 + x0 + 80 * x2), tmp18 & xmask, eviction_policy='evict_last', other=0.0) tmp20 = tmp19 > tmp6 tmp21 = tl_math.exp(tmp19) tmp22 = libdevice.log1p(tmp21) tmp23 = tl.where(tmp20, tmp19, tmp22) tmp24 = tmp23 * tmp11 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp18, tmp24, tmp25) tmp27 = tmp0 >= tmp16 tmp28 = tl.full([1], 3, tl.int64) tmp29 = tmp0 < tmp28 tmp30 = tmp27 & tmp29 tmp31 = tl.load(in_ptr0 + (40 + x0 + 80 * x2), tmp30 & xmask, eviction_policy='evict_last', other=0.0) tmp32 = tl.sigmoid(tmp31) tmp33 = tmp32 * tmp11 tmp34 = tl.full(tmp33.shape, 0.0, tmp33.dtype) tmp35 = tl.where(tmp30, tmp33, tmp34) tmp36 = tmp0 >= tmp28 tl.full([1], 4, tl.int64) tmp39 = tl.load(in_ptr0 + (60 + x0 + 80 * x2), tmp36 & xmask, eviction_policy='evict_last', other=0.0) tmp40 = tl.sigmoid(tmp39) tmp41 = tmp40 * tmp11 tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp36, tmp41, tmp42) tmp44 = tl.where(tmp30, tmp35, tmp43) tmp45 = tl.where(tmp18, tmp26, tmp44) tmp46 = tl.where(tmp4, tmp14, tmp45) tl.store(out_ptr0 + x3, tmp46, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (5, 4), (4, 1)) assert_size_stride(primals_7, (5,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.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_1[grid(256)](buf3, primals_5, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 5), (5, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 5), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 5), (80, 20, 5, 1), torch.float32) triton_poi_fused_cat_2[grid(320)](buf4, buf5, 320, XBLOCK=128, num_warps=4, num_stages=1) return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0 ), buf3, buf4, primals_6, primals_4 class IntrinsicsModelNew(nn.Module): def __init__(self, n, H, W): super(IntrinsicsModelNew, self).__init__() self.skew_scale = 0.001 self.fc1 = nn.Linear(n, n) self.fc2 = nn.Linear(n, n) self.fc3 = nn.Linear(n, 5) self.H = H self.W = W def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
apurvtwr/Jarvis
IntrinsicsModel
false
3,126
[ "Apache-2.0" ]
0
bdd25e059826a0403c6282a1ee206f9f4c3e9355
https://github.com/apurvtwr/Jarvis/tree/bdd25e059826a0403c6282a1ee206f9f4c3e9355
MotionModel
import torch import torch.nn.functional as F import torch.nn as nn class MotionModel(nn.Module): def __init__(self, n): super(MotionModel, self).__init__() self.rotation_scale = 0.01 self.fc1 = nn.Linear(n, n) self.fc2 = nn.Linear(n, n) self.fc3 = nn.Linear(n, n) self.rotation = nn.Linear(n, 3) self.translation = nn.Linear(n, 3) def forward(self, x): x = F.elu(self.fc1(x)) translation = F.tanh(self.translation(x)) x = F.elu(self.fc2(x)) x = F.tanh(self.fc3(x)) rotation = self.rotation(x) * self.rotation_scale return rotation, translation def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_elu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 1.0 tmp4 = tmp0 * tmp3 tmp5 = libdevice.expm1(tmp4) tmp6 = tmp5 * tmp3 tmp7 = tl.where(tmp2, tmp4, tmp6) tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 3 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) @triton.jit def triton_poi_fused_mul_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 3 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.01 tmp4 = tmp2 * tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = 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, (3, 4), (4, 1)) assert_size_stride(primals_5, (3,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (3, 4), (4, 1)) assert_size_stride(primals_11, (3,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 3), (3, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 3), (1, 4), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 3), (48, 12, 3, 1), 0) del buf2 triton_poi_fused_tanh_1[grid(192)](buf3, primals_5, 192, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_elu_0[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused_tanh_2[grid(256)](buf7, primals_9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf8 = empty_strided_cuda((64, 3), (3, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (64, 4), (4, 1), 0), reinterpret_tensor(primals_10, (4, 3), (1, 4), 0), out=buf8) buf9 = reinterpret_tensor(buf8, (4, 4, 4, 3), (48, 12, 3, 1), 0) del buf8 triton_poi_fused_mul_3[grid(192)](buf9, primals_11, 192, XBLOCK=256, num_warps=4, num_stages=1) del primals_11 return buf9, buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0 ), buf3, buf4, reinterpret_tensor(buf5, (64, 4), (4, 1), 0 ), buf7, primals_10, primals_8, primals_6, primals_4 class MotionModelNew(nn.Module): def __init__(self, n): super(MotionModelNew, self).__init__() self.rotation_scale = 0.01 self.fc1 = nn.Linear(n, n) self.fc2 = nn.Linear(n, n) self.fc3 = nn.Linear(n, n) self.rotation = nn.Linear(n, 3) self.translation = nn.Linear(n, 3) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_6 = self.fc2.weight primals_7 = self.fc2.bias primals_8 = self.fc3.weight primals_9 = self.fc3.bias primals_4 = self.rotation.weight primals_5 = self.rotation.bias primals_10 = self.translation.weight primals_11 = self.translation.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], output[1]
apurvtwr/Jarvis
MotionModel
false
3,127
[ "Apache-2.0" ]
0
bdd25e059826a0403c6282a1ee206f9f4c3e9355
https://github.com/apurvtwr/Jarvis/tree/bdd25e059826a0403c6282a1ee206f9f4c3e9355
GraphEncoder
import torch import numpy as np from torch import nn import torch.nn.functional as F from collections import OrderedDict from sklearn.cluster import KMeans class GraphEncoder(nn.Module): def __init__(self, layers, clusters): super(GraphEncoder, self).__init__() self.layers = nn.Sequential(OrderedDict({'lin1': nn.Linear(layers[0 ], layers[1]), 'sig1': nn.Sigmoid(), 'lin2': nn.Linear(layers[1 ], layers[2]), 'sig2': nn.Sigmoid(), 'lin3': nn.Linear(layers[2 ], layers[3]), 'sig3': nn.Sigmoid(), 'lin4': nn.Linear(layers[3 ], layers[4]), 'sig4': nn.Sigmoid()})) self.clusters = clusters self.outputs = {} self.layers[0].register_forward_hook(self.get_activation('lin1')) self.layers[2].register_forward_hook(self.get_activation('lin2')) self.layers[4].register_forward_hook(self.get_activation('lin3')) def get_activation(self, name): def hook(module, input, output): self.outputs[name] = output return hook def forward(self, x): output = self.layers(x) return output def layer_activations(self, layername): return torch.mean(torch.sigmoid(self.outputs[layername]), dim=0) def sparse_result(self, rho, layername): rho_hat = self.layer_activations(layername) return rho * np.log(rho) - rho * torch.log(rho_hat) + (1 - rho ) * np.log(1 - rho) - (1 - rho) * torch.log(1 - rho_hat) def kl_div(self, rho): first = torch.mean(self.sparse_result(rho, 'lin1')) second = torch.mean(self.sparse_result(rho, 'lin2')) return first + second def get_index_by_name(self, name): return list(dict(self.layers.named_children()).keys()).index(name) def loss(self, x_hat, x, beta, rho): loss = F.mse_loss(x_hat, x) + beta * self.kl_div(rho) return loss def get_cluster(self): kmeans = KMeans(n_clusters=self.clusters).fit(self.outputs['lin2']. detach().cpu().numpy()) self.centroids = kmeans.cluster_centers_ return kmeans.labels_ def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'layers': [4, 4, 4, 4, 4], 'clusters': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import numpy as np from torch import nn import torch.nn.functional as F from collections import OrderedDict from sklearn.cluster import KMeans assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sigmoid_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tl.store(out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(256)](buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_sigmoid_0[grid(256)](buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_sigmoid_0[grid(256)](buf4, buf5, 256, XBLOCK=256, num_warps=4, num_stages=1) buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf6) buf7 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused_sigmoid_1[grid(256)](buf7, primals_9, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 return buf7, reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, buf3, buf5, buf7, primals_8, primals_6, primals_4 class GraphEncoderNew(nn.Module): def __init__(self, layers, clusters): super(GraphEncoderNew, self).__init__() self.layers = nn.Sequential(OrderedDict({'lin1': nn.Linear(layers[0 ], layers[1]), 'sig1': nn.Sigmoid(), 'lin2': nn.Linear(layers[1 ], layers[2]), 'sig2': nn.Sigmoid(), 'lin3': nn.Linear(layers[2 ], layers[3]), 'sig3': nn.Sigmoid(), 'lin4': nn.Linear(layers[3 ], layers[4]), 'sig4': nn.Sigmoid()})) self.clusters = clusters self.outputs = {} self.layers[0].register_forward_hook(self.get_activation('lin1')) self.layers[2].register_forward_hook(self.get_activation('lin2')) self.layers[4].register_forward_hook(self.get_activation('lin3')) def get_activation(self, name): def hook(module, input, output): self.outputs[name] = output return hook def layer_activations(self, layername): return torch.mean(torch.sigmoid(self.outputs[layername]), dim=0) def sparse_result(self, rho, layername): rho_hat = self.layer_activations(layername) return rho * np.log(rho) - rho * torch.log(rho_hat) + (1 - rho ) * np.log(1 - rho) - (1 - rho) * torch.log(1 - rho_hat) def kl_div(self, rho): first = torch.mean(self.sparse_result(rho, 'lin1')) second = torch.mean(self.sparse_result(rho, 'lin2')) return first + second def get_index_by_name(self, name): return list(dict(self.layers.named_children()).keys()).index(name) def loss(self, x_hat, x, beta, rho): loss = F.mse_loss(x_hat, x) + beta * self.kl_div(rho) return loss def get_cluster(self): kmeans = KMeans(n_clusters=self.clusters).fit(self.outputs['lin2']. detach().cpu().numpy()) self.centroids = kmeans.cluster_centers_ return kmeans.labels_ def forward(self, input_0): primals_1 = self.layers.lin1.weight primals_2 = self.layers.lin1.bias primals_4 = self.layers.lin2.weight primals_5 = self.layers.lin2.bias primals_6 = self.layers.lin3.weight primals_7 = self.layers.lin3.bias primals_8 = self.layers.lin4.weight primals_9 = self.layers.lin4.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]
SusheendharVijay/ClusterEncoder
GraphEncoder
false
3,128
[ "MIT" ]
0
1ebdb4280027f88010cea2d3535b457cf648d311
https://github.com/SusheendharVijay/ClusterEncoder/tree/1ebdb4280027f88010cea2d3535b457cf648d311
Tanh2
import torch import torch.utils.data import torch.nn as nn import torch.nn.parallel import torch.optim class Tanh2(nn.Module): def __init__(self): super(Tanh2, self).__init__() self.tanh = nn.Tanh() def forward(self, x): return (self.tanh(x) + 1) / 2 def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.utils.data import torch.nn as nn import torch.nn.parallel 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_poi_fused_add_div_tanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tmp2 = 1.0 tmp3 = tmp1 + tmp2 tmp4 = 0.5 tmp5 = tmp3 * tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_tanh_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class Tanh2New(nn.Module): def __init__(self): super(Tanh2New, self).__init__() self.tanh = nn.Tanh() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ananiask8/FFWM
Tanh2
false
3,129
[ "MIT" ]
0
117f593783da67da9dc910a751910760497ef37f
https://github.com/ananiask8/FFWM/tree/117f593783da67da9dc910a751910760497ef37f
SimpleModel
import torch import torch.cuda from torch.nn.functional import * class SimpleModel(torch.nn.Module): def __init__(self, hidden_dim, empty_grad=False, rank=0): super(SimpleModel, self).__init__() self.linear = torch.nn.Linear(hidden_dim, hidden_dim) if empty_grad: self.linear2 = torch.nn.Linear(hidden_dim, hidden_dim) self.cross_entropy_loss = torch.nn.CrossEntropyLoss() self.rank = rank self.empty_grad = empty_grad def forward(self, x, y): hidden_dim = x if self.rank == 0 and self.empty_grad: hidden_dim = self.linear(hidden_dim) + self.linear2(hidden_dim) else: hidden_dim = self.linear(hidden_dim) return self.cross_entropy_loss(hidden_dim, y) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 math as tl_math import torch.cuda from torch.nn.functional import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__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_per_fused__log_softmax_div_mul_neg_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r3 = rindex r0 = rindex % 16 r2 = rindex // 64 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr1 + r3, None) tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tmp15 = tmp13 * tmp14 tmp16 = tl.broadcast_to(tmp15, [RBLOCK]) tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0)) tmp19 = -tmp18 tmp20 = 0.015625 tmp21 = tmp19 * tmp20 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 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_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(256)](buf0, buf1, 256, XBLOCK= 128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 triton_per_fused__log_softmax_div_mul_neg_sum_1[grid(1)](buf3, buf1, primals_4, 1, 256, num_warps=2, num_stages=1) del buf1 return buf3, primals_4, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), buf0 class SimpleModelNew(torch.nn.Module): def __init__(self, hidden_dim, empty_grad=False, rank=0): super(SimpleModelNew, self).__init__() self.linear = torch.nn.Linear(hidden_dim, hidden_dim) if empty_grad: self.linear2 = torch.nn.Linear(hidden_dim, hidden_dim) self.cross_entropy_loss = torch.nn.CrossEntropyLoss() self.rank = rank self.empty_grad = empty_grad def forward(self, input_0, input_1): primals_2 = self.linear.weight primals_3 = self.linear.bias primals_1 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
arashashari/DeepSpeed
SimpleModel
false
3,130
[ "MIT" ]
0
a2984d0a69640d4cfec4cf38fe22376dc8994a91
https://github.com/arashashari/DeepSpeed/tree/a2984d0a69640d4cfec4cf38fe22376dc8994a91
resblock
import torch import torch.utils.data import torch.nn as nn import torch.nn.parallel import torch.optim class mfm(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, type=1): super(mfm, self).__init__() self.out_channels = out_channels if type == 1: self.filter = nn.Conv2d(in_channels, 2 * out_channels, kernel_size=kernel_size, stride=stride, padding=padding) else: self.filter = nn.Linear(in_channels, 2 * out_channels) def forward(self, x): x = self.filter(x) out = torch.split(x, self.out_channels, 1) return torch.max(out[0], out[1]) class resblock(nn.Module): def __init__(self, in_channels, out_channels): super(resblock, self).__init__() self.conv1 = mfm(in_channels, out_channels, kernel_size=3, stride=1, padding=1) self.conv2 = mfm(in_channels, out_channels, kernel_size=3, stride=1, padding=1) def forward(self, x): res = x out = self.conv1(x) out = self.conv2(out) out = out + res return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.utils.data import torch.nn as nn import torch.nn.parallel 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_poi_fused_eq_gt_lt_maximum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 64 x3 = xindex % 64 x1 = xindex // 16 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 128 * x2), xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (64 + x3 + 128 * x2), xmask) tmp4 = tl.load(in_ptr1 + (4 + x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = triton_helpers.maximum(tmp2, tmp5) tmp7 = tmp2 == tmp5 tmp8 = tmp2 > tmp5 tmp9 = tmp2 < tmp5 tl.store(out_ptr0 + x4, tmp6, xmask) tl.store(out_ptr1 + x4, tmp7, xmask) tl.store(out_ptr2 + x4, tmp8, xmask) tl.store(out_ptr3 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_add_eq_gt_lt_maximum_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 64 x3 = xindex % 64 x1 = xindex // 16 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 128 * x2), xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (64 + x3 + 128 * x2), xmask) tmp4 = tl.load(in_ptr1 + (4 + x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr2 + x4, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = triton_helpers.maximum(tmp2, tmp5) tmp8 = tmp6 + tmp7 tmp9 = tmp2 == tmp5 tmp10 = tmp2 > tmp5 tmp11 = tmp2 < tmp5 tl.store(out_ptr0 + x4, tmp8, xmask) tl.store(out_ptr1 + x4, tmp9, xmask) tl.store(out_ptr2 + x4, tmp10, xmask) tl.store(out_ptr3 + x4, tmp11, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (8, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (8,), (1,)) assert_size_stride(primals_4, (8, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (8,), (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, 8, 4, 4), (128, 16, 4, 1)) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_eq_gt_lt_maximum_0[grid(256)](buf0, primals_3, buf1, buf7, buf8, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 8, 4, 4), (128, 16, 4, 1)) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_eq_gt_lt_maximum_1[grid(256)](buf2, primals_5, primals_1, buf3, buf4, buf5, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf2 del primals_5 return (buf3, primals_1, primals_2, primals_4, buf1, buf4, buf5, buf6, buf7, buf8, buf9) class mfm(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, type=1): super(mfm, self).__init__() self.out_channels = out_channels if type == 1: self.filter = nn.Conv2d(in_channels, 2 * out_channels, kernel_size=kernel_size, stride=stride, padding=padding) else: self.filter = nn.Linear(in_channels, 2 * out_channels) def forward(self, x): x = self.filter(x) out = torch.split(x, self.out_channels, 1) return torch.max(out[0], out[1]) class resblockNew(nn.Module): def __init__(self, in_channels, out_channels): super(resblockNew, self).__init__() self.conv1 = mfm(in_channels, out_channels, kernel_size=3, stride=1, padding=1) self.conv2 = mfm(in_channels, out_channels, kernel_size=3, stride=1, padding=1) def forward(self, input_0): primals_2 = self.conv1.filter.weight primals_3 = self.conv1.filter.bias primals_4 = self.conv2.filter.weight primals_5 = self.conv2.filter.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ananiask8/FFWM
resblock
false
3,131
[ "MIT" ]
0
117f593783da67da9dc910a751910760497ef37f
https://github.com/ananiask8/FFWM/tree/117f593783da67da9dc910a751910760497ef37f
GCN_classifier
from torch.nn import Module import math import torch import torch.nn.functional as F from torch.nn.modules.module import Module from torch.nn.parameter import Parameter from scipy.sparse import * class GraphConvolution(Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, bias=False, act=lambda x: x, dropout=0.0): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.dropout = dropout self.act = act self.weight = Parameter(torch.FloatTensor(in_features, out_features)) if bias: self.bias = Parameter(torch.FloatTensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) torch.nn.init.xavier_uniform_(self.weight) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def forward(self, input, adj): input = F.dropout(input, self.dropout, training=self.training) input = torch.squeeze(input) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) if self.bias is not None: output = output + self.bias return self.act(output) def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' class GCN_classifier(Module): def __init__(self, feature_dim, hidden_dim, out_dim, dropout=0.2): super(GCN_classifier, self).__init__() self.feature_dim = feature_dim self.hidden_dim = hidden_dim self.out_dim = out_dim self.dropout = dropout self.gc1 = GraphConvolution(self.feature_dim, self.hidden_dim, dropout=self.dropout, act=F.relu) self.gc2 = GraphConvolution(self.hidden_dim, self.out_dim) def forward(self, adj, X): hidden = self.gc1(X, adj) out = self.gc2(hidden, adj) return F.log_softmax(out, dim=1) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'feature_dim': 4, 'hidden_dim': 4, 'out_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch.nn import Module import math import torch.nn.functional as F from torch.nn.modules.module import Module from torch.nn.parameter import Parameter from scipy.sparse import * assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_squeeze_threshold_backward_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = 0.0 tmp4 = tmp2 <= tmp3 tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp4, xmask) @triton.jit def triton_poi_fused__log_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 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused__log_softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tl_math.exp(tmp1) tmp4 = tl_math.exp(tmp3) tmp5 = tmp2 + tmp4 tmp7 = tl_math.exp(tmp6) tmp8 = tmp5 + tmp7 tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp12 = tl_math.log(tmp11) tmp13 = tmp0 - tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (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, primals_2, out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, buf0, out=buf1) buf2 = buf0 del buf0 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_squeeze_threshold_backward_0[grid(16)](buf1, buf2, buf7, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = buf1 del buf1 extern_kernels.mm(buf2, primals_4, out=buf3) buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, buf3, out=buf4) buf5 = buf3 del buf3 triton_poi_fused__log_softmax_1[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) buf6 = buf4 del buf4 triton_poi_fused__log_softmax_2[grid(16)](buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf5 return buf6, buf6, reinterpret_tensor(primals_3, (4, 4), (1, 4), 0 ), reinterpret_tensor(buf2, (4, 4), (1, 4), 0), reinterpret_tensor( primals_4, (4, 4), (1, 4), 0), buf7, reinterpret_tensor(primals_1, (4, 4), (1, 4), 0) class GraphConvolution(Module): """ Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """ def __init__(self, in_features, out_features, bias=False, act=lambda x: x, dropout=0.0): super(GraphConvolution, self).__init__() self.in_features = in_features self.out_features = out_features self.dropout = dropout self.act = act self.weight = Parameter(torch.FloatTensor(in_features, out_features)) if bias: self.bias = Parameter(torch.FloatTensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.weight.size(1)) torch.nn.init.xavier_uniform_(self.weight) if self.bias is not None: self.bias.data.uniform_(-stdv, stdv) def forward(self, input, adj): input = F.dropout(input, self.dropout, training=self.training) input = torch.squeeze(input) support = torch.mm(input, self.weight) output = torch.spmm(adj, support) if self.bias is not None: output = output + self.bias return self.act(output) def __repr__(self): return self.__class__.__name__ + ' (' + str(self.in_features ) + ' -> ' + str(self.out_features) + ')' class GCN_classifierNew(Module): def __init__(self, feature_dim, hidden_dim, out_dim, dropout=0.2): super(GCN_classifierNew, self).__init__() self.feature_dim = feature_dim self.hidden_dim = hidden_dim self.out_dim = out_dim self.dropout = dropout self.gc1 = GraphConvolution(self.feature_dim, self.hidden_dim, dropout=self.dropout, act=F.relu) self.gc2 = GraphConvolution(self.hidden_dim, self.out_dim) def forward(self, input_0, input_1): primals_1 = self.gc1.weight primals_2 = self.gc2.weight primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
TTomatoZhang/GHGCN
GCN_classifier
false
3,132
[ "Apache-2.0" ]
0
09a07ff9e29e5889b912ca5feff74bb9308eda55
https://github.com/TTomatoZhang/GHGCN/tree/09a07ff9e29e5889b912ca5feff74bb9308eda55
Fuse
import torch import torch.nn as nn class Fuse(nn.Module): def __init__(self): super(Fuse, self).__init__() self.convolution = nn.Conv2d(32, 16, kernel_size=1, padding=0) self.relu = nn.ReLU(inplace=True) def forward(self, x): x = self.convolution(x) x = self.relu(x) return x def get_inputs(): return [torch.rand([4, 32, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 16 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, None) tl.store(out_ptr0 + x3, tmp6, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (16, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 32, 64, 64), (131072, 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, 16, 64, 64), (65536, 4096, 64, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 16, 64, 64), (65536, 4096, 64, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(262144)]( buf1, primals_2, buf2, 262144, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3, buf2 class FuseNew(nn.Module): def __init__(self): super(FuseNew, self).__init__() self.convolution = nn.Conv2d(32, 16, kernel_size=1, padding=0) self.relu = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.convolution.weight primals_2 = self.convolution.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
arsalasif/SalAR
Fuse
false
3,133
[ "MIT" ]
0
eee0855199233177df0fce80f2a0612b8774ac1f
https://github.com/arsalasif/SalAR/tree/eee0855199233177df0fce80f2a0612b8774ac1f
group
import torch import torch.utils.data import torch.nn as nn import torch.nn.parallel import torch.optim class mfm(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, type=1): super(mfm, self).__init__() self.out_channels = out_channels if type == 1: self.filter = nn.Conv2d(in_channels, 2 * out_channels, kernel_size=kernel_size, stride=stride, padding=padding) else: self.filter = nn.Linear(in_channels, 2 * out_channels) def forward(self, x): x = self.filter(x) out = torch.split(x, self.out_channels, 1) return torch.max(out[0], out[1]) class group(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, mid_channels=None): super(group, self).__init__() if mid_channels is None: mid_channels = in_channels self.conv_a = mfm(in_channels, mid_channels, 1, 1, 0) self.conv = mfm(mid_channels, out_channels, kernel_size, stride, padding) def forward(self, x): x = self.conv_a(x) x = self.conv(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4, 'stride': 1, 'padding': 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.utils.data import torch.nn as nn import torch.nn.parallel 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_poi_fused_eq_gt_lt_maximum_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 64 x3 = xindex % 64 x1 = xindex // 16 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 128 * x2), xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (64 + x3 + 128 * x2), xmask) tmp4 = tl.load(in_ptr1 + (4 + x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = triton_helpers.maximum(tmp2, tmp5) tmp7 = tmp2 == tmp5 tmp8 = tmp2 > tmp5 tmp9 = tmp2 < tmp5 tl.store(out_ptr0 + x4, tmp6, xmask) tl.store(out_ptr1 + x4, tmp7, xmask) tl.store(out_ptr2 + x4, tmp8, xmask) tl.store(out_ptr3 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_eq_gt_lt_maximum_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 1296 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 324 x3 = xindex % 324 x1 = xindex // 81 % 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x3 + 648 * x2), xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (324 + x3 + 648 * x2), xmask) tmp4 = tl.load(in_ptr1 + (4 + x1), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = triton_helpers.maximum(tmp2, tmp5) tmp7 = tmp2 == tmp5 tmp8 = tmp2 > tmp5 tmp9 = tmp2 < tmp5 tl.store(out_ptr0 + x4, tmp6, xmask) tl.store(out_ptr1 + x4, tmp7, xmask) tl.store(out_ptr2 + x4, tmp8, xmask) tl.store(out_ptr3 + x4, tmp9, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (8, 4, 1, 1), (4, 1, 1, 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, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (8,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 8, 4, 4), (128, 16, 4, 1)) buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_eq_gt_lt_maximum_0[grid(256)](buf0, primals_2, buf1, buf7, buf8, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(4, 4), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 8, 9, 9), (648, 81, 9, 1)) buf3 = empty_strided_cuda((4, 4, 9, 9), (324, 81, 9, 1), torch.float32) buf4 = empty_strided_cuda((4, 4, 9, 9), (324, 81, 9, 1), torch.bool) buf5 = empty_strided_cuda((4, 4, 9, 9), (324, 81, 9, 1), torch.bool) buf6 = empty_strided_cuda((4, 4, 9, 9), (324, 81, 9, 1), torch.bool) triton_poi_fused_eq_gt_lt_maximum_1[grid(1296)](buf2, primals_5, buf3, buf4, buf5, buf6, 1296, XBLOCK=256, num_warps=4, num_stages=1 ) del buf2 del primals_5 return (buf3, primals_1, primals_3, primals_4, buf1, buf4, buf5, buf6, buf7, buf8, buf9) class mfm(nn.Module): def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, padding=1, type=1): super(mfm, self).__init__() self.out_channels = out_channels if type == 1: self.filter = nn.Conv2d(in_channels, 2 * out_channels, kernel_size=kernel_size, stride=stride, padding=padding) else: self.filter = nn.Linear(in_channels, 2 * out_channels) def forward(self, x): x = self.filter(x) out = torch.split(x, self.out_channels, 1) return torch.max(out[0], out[1]) class groupNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride, padding, mid_channels=None): super(groupNew, self).__init__() if mid_channels is None: mid_channels = in_channels self.conv_a = mfm(in_channels, mid_channels, 1, 1, 0) self.conv = mfm(mid_channels, out_channels, kernel_size, stride, padding) def forward(self, input_0): primals_1 = self.conv_a.filter.weight primals_2 = self.conv_a.filter.bias primals_4 = self.conv.filter.weight primals_5 = self.conv.filter.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ananiask8/FFWM
group
false
3,134
[ "MIT" ]
0
117f593783da67da9dc910a751910760497ef37f
https://github.com/ananiask8/FFWM/tree/117f593783da67da9dc910a751910760497ef37f
MyEntropy
import torch import torch.nn as nn class MyEntropy(nn.Module): def __init__(self): super(MyEntropy, self).__init__() def forward(self, predictions, target): b_size = predictions.size(0) lsm_func = nn.LogSoftmax(dim=1) logsoftmax = lsm_func(predictions) loss = -logsoftmax[torch.arange(b_size), target] return loss.mean() 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 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_per_fused__log_softmax_index_mean_neg_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) r1 = rindex // 16 r0 = rindex % 16 tmp0 = tl.load(in_ptr0 + r1, None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (r0 + 64 * r1), None) tmp9 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp12 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp15 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tl.device_assert((0 <= tmp4) & (tmp4 < 4), 'index out of bounds: 0 <= tmp4 < 4') tmp6 = tl.load(in_ptr1 + (r0 + 16 * tmp4 + 64 * r1), None) tmp8 = tl_math.exp(tmp7) tmp10 = tl_math.exp(tmp9) tmp11 = tmp8 + tmp10 tmp13 = tl_math.exp(tmp12) tmp14 = tmp11 + tmp13 tmp16 = tl_math.exp(tmp15) tmp17 = tmp14 + tmp16 tmp18 = tl_math.log(tmp17) tmp19 = tmp6 - tmp18 tmp20 = -tmp19 tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK]) tmp23 = tl.sum(tmp21, 1)[:, None] tmp24 = 64.0 tmp25 = tmp23 / tmp24 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp25, 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=128, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused__log_softmax_index_mean_neg_1[grid(1)](buf2, arg1_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg1_1 del buf0 return buf2, class MyEntropyNew(nn.Module): def __init__(self): super(MyEntropyNew, 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]
atimashov/object_detection
MyEntropy
false
3,135
[ "MIT" ]
0
922cd88f429156fa4668c7d718b2665e4ab875fd
https://github.com/atimashov/object_detection/tree/922cd88f429156fa4668c7d718b2665e4ab875fd
CBAM_Module
import torch from typing import * import torch.nn as nn class CBAM_Module(nn.Module): def __init__(self, channels, reduction): super(CBAM_Module, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc1 = nn.Conv2d(channels, channels // reduction, kernel_size=1, padding=0) self.relu = nn.ReLU(inplace=True) self.fc2 = nn.Conv2d(channels // reduction, channels, kernel_size=1, padding=0) self.sigmoid_channel = nn.Sigmoid() self.conv_after_concat = nn.Conv2d(2, 1, kernel_size=3, stride=1, padding=1) self.sigmoid_spatial = nn.Sigmoid() def forward(self, x): module_input = x avg = self.avg_pool(x) mx = self.max_pool(x) avg = self.fc1(avg) mx = self.fc1(mx) avg = self.relu(avg) mx = self.relu(mx) avg = self.fc2(avg) mx = self.fc2(mx) x = avg + mx x = self.sigmoid_channel(x) x = module_input * x module_input = x avg = torch.mean(x, 1, True) mx, _ = torch.max(x, 1, True) x = torch.cat((avg, mx), 1) x = self.conv_after_concat(x) x = self.sigmoid_spatial(x) x = module_input * x return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'channels': 4, 'reduction': 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 typing import * import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda 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_adaptive_max_pool2d_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy= 'evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp8 = triton_helpers.maximum(tmp7, tmp6) tmp10 = triton_helpers.maximum(tmp9, tmp8) tmp12 = triton_helpers.maximum(tmp11, tmp10) tmp14 = triton_helpers.maximum(tmp13, tmp12) tmp16 = triton_helpers.maximum(tmp15, tmp14) tmp18 = triton_helpers.maximum(tmp17, tmp16) tmp20 = triton_helpers.maximum(tmp19, tmp18) tmp22 = triton_helpers.maximum(tmp21, tmp20) tmp24 = triton_helpers.maximum(tmp23, tmp22) tmp26 = triton_helpers.maximum(tmp25, tmp24) tmp28 = triton_helpers.maximum(tmp27, tmp26) tmp30 = triton_helpers.maximum(tmp29, tmp28) tl.store(out_ptr0 + x0, tmp30, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_out_ptr1, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp6 = tl.load(in_out_ptr1 + x0, xmask) tmp3 = tmp0 + tmp2 tmp4 = tl.full([1], 0, tl.int32) tmp5 = triton_helpers.maximum(tmp4, tmp3) tmp7 = tmp6 + tmp2 tmp8 = triton_helpers.maximum(tmp4, tmp7) tl.store(in_out_ptr0 + x0, tmp5, xmask) tl.store(in_out_ptr1 + x0, tmp8, xmask) @triton.jit def triton_poi_fused_add_convolution_sigmoid_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel 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 = tmp3 + tmp1 tmp5 = tmp2 + tmp4 tmp6 = tl.sigmoid(tmp5) tl.store(in_out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_cat_4(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 x1 = xindex // 16 % 2 x0 = xindex % 16 x2 = xindex // 32 x4 = 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_ptr1 + 4 * x2, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 * tmp6 tmp8 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp9 = tl.load(in_ptr1 + (1 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp10 = tmp8 * tmp9 tmp11 = tmp7 + tmp10 tmp12 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp13 = tl.load(in_ptr1 + (2 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp14 = tmp12 * tmp13 tmp15 = tmp11 + tmp14 tmp16 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp18 = tmp16 * tmp17 tmp19 = tmp15 + tmp18 tmp20 = 4.0 tmp21 = tmp19 / tmp20 tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype) tmp23 = tl.where(tmp4, tmp21, tmp22) tmp24 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp27 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp28 = tl.load(in_ptr1 + 4 * x2, tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp29 = tmp27 * tmp28 tmp30 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp31 = tl.load(in_ptr1 + (1 + 4 * x2), tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp32 = tmp30 * tmp31 tmp33 = triton_helpers.maximum(tmp29, tmp32) tmp34 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp35 = tl.load(in_ptr1 + (2 + 4 * x2), tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp36 = tmp34 * tmp35 tmp37 = triton_helpers.maximum(tmp33, tmp36) tmp38 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp24 & xmask, eviction_policy='evict_last', other=0.0) tmp39 = tl.load(in_ptr1 + (3 + 4 * x2), tmp24 & xmask, eviction_policy= 'evict_last', other=0.0) tmp40 = tmp38 * tmp39 tmp41 = triton_helpers.maximum(tmp37, tmp40) tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype) tmp43 = tl.where(tmp24, tmp41, tmp42) tmp44 = tl.where(tmp4, tmp23, tmp43) tl.store(out_ptr0 + x4, tmp44, xmask) @triton.jit def triton_poi_fused_convolution_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 x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_mul_sigmoid_6(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 16 x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 * tmp1 tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (1,), (1,)) assert_size_stride(primals_4, (4, 1, 1, 1), (1, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (1, 2, 3, 3), (18, 9, 3, 1)) assert_size_stride(primals_7, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf0 get_raw_stream(0) triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) buf2 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_adaptive_max_pool2d_1[grid(16)](primals_1, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) buf3 = 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(buf3, (4, 1, 1, 1), (1, 1, 1, 1)) buf4 = extern_kernels.convolution(buf2, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 1, 1, 1), (1, 1, 1, 1)) buf5 = buf3 del buf3 buf6 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(4)](buf5, buf6, primals_3, 4, XBLOCK=4, num_warps=1, num_stages=1) del primals_3 buf7 = extern_kernels.convolution(buf5, primals_4, 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 = extern_kernels.convolution(buf6, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1)) buf9 = buf7 del buf7 triton_poi_fused_add_convolution_sigmoid_3[grid(16)](buf9, primals_5, buf8, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf8 del primals_5 buf10 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32) triton_poi_fused_cat_4[grid(128)](primals_1, buf9, buf10, 128, XBLOCK=128, num_warps=4, num_stages=1) buf11 = extern_kernels.convolution(buf10, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 1, 4, 4), (16, 16, 4, 1)) buf12 = buf11 del buf11 triton_poi_fused_convolution_5[grid(64)](buf12, primals_7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_7 buf13 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_mul_sigmoid_6[grid(256)](primals_1, buf9, buf12, buf13, 256, XBLOCK=256, num_warps=4, num_stages=1) return (buf13, primals_1, primals_2, primals_4, primals_6, buf1, buf2, buf5, buf6, buf9, buf10, buf12) class CBAM_ModuleNew(nn.Module): def __init__(self, channels, reduction): super(CBAM_ModuleNew, self).__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.max_pool = nn.AdaptiveMaxPool2d(1) self.fc1 = nn.Conv2d(channels, channels // reduction, kernel_size=1, padding=0) self.relu = nn.ReLU(inplace=True) self.fc2 = nn.Conv2d(channels // reduction, channels, kernel_size=1, padding=0) self.sigmoid_channel = nn.Sigmoid() self.conv_after_concat = nn.Conv2d(2, 1, kernel_size=3, stride=1, padding=1) self.sigmoid_spatial = nn.Sigmoid() def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.conv_after_concat.weight primals_7 = self.conv_after_concat.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
artyompal/kaggle_quick_draw
CBAM_Module
false
3,136
[ "Apache-2.0" ]
0
227e228295479cd5e1af8dcde773f5efdacd62b8
https://github.com/artyompal/kaggle_quick_draw/tree/227e228295479cd5e1af8dcde773f5efdacd62b8
SeparableBlock
from torch.nn import Module import torch from torch.nn import Linear class SeparableBlock(Module): def __init__(self, input_size, kernel_channels_in, kernel_channels_out, kernel_size): super(SeparableBlock, self).__init__() self.input_size = input_size self.kernel_size = kernel_size self.kernel_channels_in = kernel_channels_in self.kernel_channels_out = kernel_channels_out self.make_kernel_in = Linear(input_size, kernel_size * kernel_size * kernel_channels_in) self.make_kernel_out = Linear(input_size, kernel_size * kernel_size * kernel_channels_out) self.kernel_linear_in = Linear(kernel_channels_in, kernel_channels_in) self.kernel_linear_out = Linear(kernel_channels_out, kernel_channels_out) def forward(self, features): features = features.view(-1, self.input_size) kernel_in = self.make_kernel_in(features).view(-1, self.kernel_size, self.kernel_size, 1, self.kernel_channels_in) kernel_out = self.make_kernel_out(features).view(-1, self. kernel_size, self.kernel_size, self.kernel_channels_out, 1) kernel = torch.matmul(kernel_out, kernel_in) kernel = self.kernel_linear_in(kernel).permute(0, 1, 2, 4, 3) kernel = self.kernel_linear_out(kernel) kernel = kernel.permute(0, 4, 3, 1, 2) return kernel def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'kernel_channels_in': 4, 'kernel_channels_out': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch.nn import Module from torch.nn import Linear assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, None) 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, (64, 4), (4, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (64, 4), (4, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 64), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_2 del primals_3 buf1 = empty_strided_cuda((64, 64), (64, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 64), (1, 4), 0), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((1024, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (1024, 4, 1), (4, 1, 1), 0), reinterpret_tensor(buf0, (1024, 1, 4), (4, 4, 1), 0), out=buf2) buf3 = empty_strided_cuda((4096, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (4096, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((64, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(4096, 4)](buf3, primals_7, buf4, 4096, 4, XBLOCK=4, YBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf5 = buf3 del buf3 extern_kernels.mm(reinterpret_tensor(buf4, (4096, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf5) buf6 = reinterpret_tensor(buf5, (64, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0) del buf5 triton_poi_fused_add_1[grid(16384)](buf6, primals_9, 16384, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 return reinterpret_tensor(buf6, (64, 4, 4, 4, 4), (256, 1, 4, 64, 16), 0 ), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf2, (4096, 4), (4, 1), 0), reinterpret_tensor( buf4, (4096, 4), (4, 1), 0), primals_8, primals_6, reinterpret_tensor( buf1, (1024, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf0, (1024, 4, 1), (4, 1, 4), 0) class SeparableBlockNew(Module): def __init__(self, input_size, kernel_channels_in, kernel_channels_out, kernel_size): super(SeparableBlockNew, self).__init__() self.input_size = input_size self.kernel_size = kernel_size self.kernel_channels_in = kernel_channels_in self.kernel_channels_out = kernel_channels_out self.make_kernel_in = Linear(input_size, kernel_size * kernel_size * kernel_channels_in) self.make_kernel_out = Linear(input_size, kernel_size * kernel_size * kernel_channels_out) self.kernel_linear_in = Linear(kernel_channels_in, kernel_channels_in) self.kernel_linear_out = Linear(kernel_channels_out, kernel_channels_out) def forward(self, input_0): primals_2 = self.make_kernel_in.weight primals_3 = self.make_kernel_in.bias primals_4 = self.make_kernel_out.weight primals_5 = self.make_kernel_out.bias primals_6 = self.kernel_linear_in.weight primals_7 = self.kernel_linear_in.bias primals_8 = self.kernel_linear_out.weight primals_9 = self.kernel_linear_out.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]
andreasjansson/hyperstyle
SeparableBlock
false
3,137
[ "MIT" ]
0
d9847c76dd75da129a60bf995534ff6e71cbbaa6
https://github.com/andreasjansson/hyperstyle/tree/d9847c76dd75da129a60bf995534ff6e71cbbaa6
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]
augmentedstartups/EmotionDetectionYoloX
IOUloss
false
3,138
[ "Apache-2.0" ]
0
2b0e13b94486a0bd85628f1483a0b710503c2005
https://github.com/augmentedstartups/EmotionDetectionYoloX/tree/2b0e13b94486a0bd85628f1483a0b710503c2005
GaussianVAE2D
import torch import torch.utils.data import torch import torch.nn as nn from torch.autograd import Variable class GaussianVAE2D(nn.Module): def __init__(self, n_in, n_out, kernel_size, stride, padding=0): super(GaussianVAE2D, self).__init__() self.en_mu = nn.Conv2d(n_in, n_out, kernel_size, stride, padding) self.en_sigma = nn.Conv2d(n_in, n_out, kernel_size, stride, padding) self.softplus = nn.Softplus() self.reset_parameters() def reset_parameters(self): self.en_mu.weight.data.normal_(0, 0.002) self.en_mu.bias.data.normal_(0, 0.002) self.en_sigma.weight.data.normal_(0, 0.002) self.en_sigma.bias.data.normal_(0, 0.002) def forward(self, x): mu = self.en_mu(x) sd = self.softplus(self.en_sigma(x)) return mu, sd def sample(self, x): mu = self.en_mu(x) sd = self.softplus(self.en_sigma(x)) noise = Variable(torch.randn(mu.size(0), mu.size(1), mu.size(2), mu .size(3))) return mu + sd.mul(noise), mu, sd def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_in': 4, 'n_out': 4, 'kernel_size': 4, 'stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.utils.data import torch import torch.nn as nn from torch.autograd import Variable assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_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) @triton.jit def triton_poi_fused_convolution_softplus_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 = 1.0 tmp4 = tmp2 * tmp3 tmp5 = 20.0 tmp6 = tmp4 > tmp5 tmp7 = tl_math.exp(tmp4) tmp8 = libdevice.log1p(tmp7) tmp9 = tmp8 * tmp3 tmp10 = tl.where(tmp6, tmp2, tmp9) tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = 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)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(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 buf2 = extern_kernels.convolution(primals_3, 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, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_convolution_softplus_1[grid(16)](buf3, primals_5, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 return buf1, buf4, primals_1, primals_3, primals_4, buf3 class GaussianVAE2DNew(nn.Module): def __init__(self, n_in, n_out, kernel_size, stride, padding=0): super(GaussianVAE2DNew, self).__init__() self.en_mu = nn.Conv2d(n_in, n_out, kernel_size, stride, padding) self.en_sigma = nn.Conv2d(n_in, n_out, kernel_size, stride, padding) self.softplus = nn.Softplus() self.reset_parameters() def reset_parameters(self): self.en_mu.weight.data.normal_(0, 0.002) self.en_mu.bias.data.normal_(0, 0.002) self.en_sigma.weight.data.normal_(0, 0.002) self.en_sigma.bias.data.normal_(0, 0.002) def sample(self, x): mu = self.en_mu(x) sd = self.softplus(self.en_sigma(x)) noise = Variable(torch.randn(mu.size(0), mu.size(1), mu.size(2), mu .size(3))) return mu + sd.mul(noise), mu, sd def forward(self, input_0): primals_1 = self.en_mu.weight primals_2 = self.en_mu.bias primals_3 = self.en_sigma.weight primals_5 = self.en_sigma.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0], output[1]
ast0414/semit
GaussianVAE2D
false
3,139
[ "MIT" ]
0
c221222ba06f14611e3d030969cdb9f7c17ff98f
https://github.com/ast0414/semit/tree/c221222ba06f14611e3d030969cdb9f7c17ff98f
LearnedUpsampling1d
import torch from torch import nn class LearnedUpsampling1d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, bias=True): super().__init__() self.conv_t = nn.ConvTranspose1d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride= kernel_size, bias=False) if bias: self.bias = nn.Parameter(torch.FloatTensor(out_channels, kernel_size)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): self.conv_t.reset_parameters() nn.init.constant_(self.bias, 0) def forward(self, input): batch_size, _, length = input.size() kernel_size, = self.conv_t.kernel_size bias = self.bias.unsqueeze(0).unsqueeze(2).expand(batch_size, self. conv_t.out_channels, length, kernel_size).contiguous().view( batch_size, self.conv_t.out_channels, length * kernel_size) return self.conv_t(input) + bias def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (4 * x1 + x0 % 4), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_3, stride=(4,), padding=(0,), dilation=(1,), transposed=True, output_padding=(0 ,), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 16), (64, 16, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_add_0[grid(256)](buf1, primals_2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3 class LearnedUpsampling1dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, bias=True): super().__init__() self.conv_t = nn.ConvTranspose1d(in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride= kernel_size, bias=False) if bias: self.bias = nn.Parameter(torch.FloatTensor(out_channels, kernel_size)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): self.conv_t.reset_parameters() nn.init.constant_(self.bias, 0) def forward(self, input_0): primals_2 = self.bias primals_1 = self.conv_t.weight primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
austincap/samplernn-pytorch
LearnedUpsampling1d
false
3,140
[ "MIT" ]
0
d78399b899dcc116fd20823ae9e006ad8a6df4ea
https://github.com/austincap/samplernn-pytorch/tree/d78399b899dcc116fd20823ae9e006ad8a6df4ea
ConvTranspose2dBlock
import torch import torch.utils.data import torch from torch.nn import functional as F import torch.nn as nn class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign weight and bias before calling AdaIN!' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class ConvTranspose2dBlock(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, stride, padding= 0, output_padding=0, norm='none', activation='relu', pad_type='zero'): super(ConvTranspose2dBlock, self).__init__() self.use_bias = True norm_dim = output_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'ln': self.norm = LayerNorm(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(inplace=True) elif activation == 'prelu': self.activation = nn.PReLU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.dconv = nn.ConvTranspose2d(input_dim, output_dim, kernel_size, stride, padding, output_padding, bias=self.use_bias) def forward(self, x): x = self.dconv(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4, 'kernel_size': 4, 'stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.utils.data import torch from torch.nn import functional as F import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, 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 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 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,), (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=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 7, 7), (196, 49, 7, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(784)](buf1, primals_2, buf2, 784, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 return buf1, primals_1, primals_3, buf2 class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign weight and bias before calling AdaIN!' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-05, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = nn.Parameter(torch.Tensor(num_features).uniform_()) self.beta = nn.Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class ConvTranspose2dBlockNew(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, stride, padding= 0, output_padding=0, norm='none', activation='relu', pad_type='zero'): super(ConvTranspose2dBlockNew, self).__init__() self.use_bias = True norm_dim = output_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'ln': self.norm = LayerNorm(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(inplace=True) elif activation == 'prelu': self.activation = nn.PReLU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.dconv = nn.ConvTranspose2d(input_dim, output_dim, kernel_size, stride, padding, output_padding, bias=self.use_bias) def forward(self, input_0): primals_1 = self.dconv.weight primals_2 = self.dconv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ast0414/semit
ConvTranspose2dBlock
false
3,141
[ "MIT" ]
0
c221222ba06f14611e3d030969cdb9f7c17ff98f
https://github.com/ast0414/semit/tree/c221222ba06f14611e3d030969cdb9f7c17ff98f
LocallyConnected
import math import torch from torch import nn class LocallyConnected(nn.Module): """Local linear layer, i.e. Conv1dLocal() with filter size 1. Args: num_linear: num of local linear layers, i.e. in_features: m1 out_features: m2 bias: whether to include bias or not Shape: - Input: [n, d, m1] - Output: [n, d, m2] Attributes: weight: [d, m1, m2] bias: [d, m2] """ def __init__(self, num_linear, input_features, output_features, bias=True): super(LocallyConnected, self).__init__() self.num_linear = num_linear self.input_features = input_features self.output_features = output_features self.weight = nn.Parameter(torch.Tensor(num_linear, input_features, output_features)) if bias: self.bias = nn.Parameter(torch.Tensor(num_linear, output_features)) else: self.register_parameter('bias', None) 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) if self.bias is not None: nn.init.uniform_(self.bias, -bound, bound) def forward(self, input: 'torch.Tensor'): out = torch.matmul(input.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 extra_repr(self): return ('num_linear={}, in_features={}, out_features={}, bias={}'. format(self.num_linear, self.in_features, self.out_features, self.bias is not None)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 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) class LocallyConnectedNew(nn.Module): """Local linear layer, i.e. Conv1dLocal() with filter size 1. Args: num_linear: num of local linear layers, i.e. in_features: m1 out_features: m2 bias: whether to include bias or not Shape: - Input: [n, d, m1] - Output: [n, d, m2] Attributes: weight: [d, m1, m2] bias: [d, m2] """ def __init__(self, num_linear, input_features, output_features, bias=True): super(LocallyConnectedNew, self).__init__() self.num_linear = num_linear self.input_features = input_features self.output_features = output_features self.weight = nn.Parameter(torch.Tensor(num_linear, input_features, output_features)) if bias: self.bias = nn.Parameter(torch.Tensor(num_linear, output_features)) else: self.register_parameter('bias', None) 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) if self.bias is not None: nn.init.uniform_(self.bias, -bound, bound) def extra_repr(self): return ('num_linear={}, in_features={}, out_features={}, bias={}'. format(self.num_linear, self.in_features, self.out_features, self.bias is not None)) 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]
atong01/Graphical-modelling-continuous-time
LocallyConnected
false
3,142
[ "MIT" ]
0
f1c8d9bc30a44c38fd504e4cce2f7886fc352f92
https://github.com/atong01/Graphical-modelling-continuous-time/tree/f1c8d9bc30a44c38fd504e4cce2f7886fc352f92
TransposeConv2dLayer
import torch import torch.nn as nn from torch.nn import functional as F from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class TransposeConv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=False, scale_factor=2): super(TransposeConv2dLayer, self).__init__() self.scale_factor = scale_factor self.conv2d = Conv2dLayer(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest') x = self.conv2d(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.2 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x3, tmp7, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_1[grid(400) ](buf2, primals_3, buf3, 400, XBLOCK=128, num_warps=4, num_stages=1 ) del primals_3 return buf2, primals_2, buf0, buf3 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class TransposeConv2dLayerNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=False, scale_factor=2): super(TransposeConv2dLayerNew, self).__init__() self.scale_factor = scale_factor self.conv2d = Conv2dLayer(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, input_0): primals_1 = self.conv2d.conv2d.weight primals_3 = self.conv2d.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
autocomic/https-github.com-autocomic-DeepFillv2_Pytorch
TransposeConv2dLayer
false
3,143
[ "MIT" ]
0
7f6712a9b42dfd827879271f13856f1da5d6a032
https://github.com/autocomic/https-github.com-autocomic-DeepFillv2_Pytorch/tree/7f6712a9b42dfd827879271f13856f1da5d6a032
GatedTransition
import torch import torch.nn as nn class GatedTransition(nn.Module): """ Parameterizes the gaussian latent transition probability `p(z_t | z_{t-1} ,s)` """ def __init__(self, z_dim, static_dim, transition_dim): super().__init__() self.concat_dim = z_dim + static_dim self.lin_gate_z_to_hidden = nn.Linear(self.concat_dim, transition_dim) self.lin_gate_hidden_to_z = nn.Linear(transition_dim, z_dim) self.lin_proposed_mean_z_to_hidden = nn.Linear(self.concat_dim, transition_dim) self.lin_proposed_mean_hidden_to_z = nn.Linear(transition_dim, z_dim) self.lin_sig = nn.Linear(z_dim, z_dim) self.lin_z_to_loc = nn.Linear(z_dim, z_dim) self.lin_z_to_loc.weight.data = torch.eye(z_dim) self.lin_z_to_loc.bias.data = torch.zeros(z_dim) self.relu = nn.ReLU() self.softplus = nn.Softplus() def forward(self, z_t_1, mini_batch_static): """ Given the latent `z_{t-1} and s` corresponding to the time step t-1 we return the mean and scale vectors that parameterize the (diagonal) gaussian distribution `p(z_t | z_{t-1}, s)` """ concat = torch.cat((z_t_1, mini_batch_static), dim=1) _gate = self.relu(self.lin_gate_z_to_hidden(concat)) gate = torch.sigmoid(self.lin_gate_hidden_to_z(_gate)) _proposed_mean = self.relu(self.lin_proposed_mean_z_to_hidden(concat)) proposed_mean = self.lin_proposed_mean_hidden_to_z(_proposed_mean) loc = (1 - gate) * self.lin_z_to_loc(z_t_1) + gate * proposed_mean scale = self.softplus(self.lin_sig(self.relu(proposed_mean))) return loc, scale def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'z_dim': 4, 'static_dim': 4, 'transition_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_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_mul_relu_rsub_sigmoid_2(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 + x0, xmask) tmp4 = tl.load(in_ptr1 + x0, xmask) tmp6 = tl.load(in_ptr2 + x0, xmask) tmp1 = tl.sigmoid(tmp0) tmp2 = 1.0 tmp3 = tmp2 - tmp1 tmp5 = tmp3 * tmp4 tmp7 = tmp1 * tmp6 tmp8 = tmp5 + tmp7 tmp9 = tl.full([1], 0, tl.int32) tmp10 = triton_helpers.maximum(tmp9, tmp6) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp10, xmask) @triton.jit def triton_poi_fused_softplus_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 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) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 8), (8, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 4), (4, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 4), (4, 1)) assert_size_stride(primals_14, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (8, 4), (1, 8 ), 0), out=buf1) del primals_3 buf2 = buf1 del buf1 triton_poi_fused_relu_1[grid(16)](buf2, primals_4, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_4 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, buf2, reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_6 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(primals_7, (8, 4), (1, 8 ), 0), out=buf4) del primals_7 buf5 = buf4 del buf4 triton_poi_fused_relu_1[grid(16)](buf5, primals_8, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_8 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_10, buf5, reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf6) del primals_10 buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_12, primals_1, reinterpret_tensor( primals_11, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf7) del primals_11 del primals_12 buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_relu_rsub_sigmoid_2[grid(16)](buf3, buf7, buf6, buf8, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_14, buf9, reinterpret_tensor( primals_13, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf10) del primals_14 buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_softplus_3[grid(16)](buf10, buf11, 16, XBLOCK=16, num_warps=1, num_stages=1) return (buf8, buf11, primals_1, buf0, buf2, buf3, buf5, buf6, buf7, buf9, buf10, primals_13, primals_9, primals_5) class GatedTransitionNew(nn.Module): """ Parameterizes the gaussian latent transition probability `p(z_t | z_{t-1} ,s)` """ def __init__(self, z_dim, static_dim, transition_dim): super().__init__() self.concat_dim = z_dim + static_dim self.lin_gate_z_to_hidden = nn.Linear(self.concat_dim, transition_dim) self.lin_gate_hidden_to_z = nn.Linear(transition_dim, z_dim) self.lin_proposed_mean_z_to_hidden = nn.Linear(self.concat_dim, transition_dim) self.lin_proposed_mean_hidden_to_z = nn.Linear(transition_dim, z_dim) self.lin_sig = nn.Linear(z_dim, z_dim) self.lin_z_to_loc = nn.Linear(z_dim, z_dim) self.lin_z_to_loc.weight.data = torch.eye(z_dim) self.lin_z_to_loc.bias.data = torch.zeros(z_dim) self.relu = nn.ReLU() self.softplus = nn.Softplus() def forward(self, input_0, input_1): primals_3 = self.lin_gate_z_to_hidden.weight primals_4 = self.lin_gate_z_to_hidden.bias primals_1 = self.lin_gate_hidden_to_z.weight primals_6 = self.lin_gate_hidden_to_z.bias primals_7 = self.lin_proposed_mean_z_to_hidden.weight primals_8 = self.lin_proposed_mean_z_to_hidden.bias primals_2 = self.lin_proposed_mean_hidden_to_z.weight primals_10 = self.lin_proposed_mean_hidden_to_z.bias primals_5 = self.lin_sig.weight primals_12 = self.lin_sig.bias primals_9 = self.lin_z_to_loc.weight primals_14 = self.lin_z_to_loc.bias primals_11 = input_0 primals_13 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14]) return output[0], output[1]
autodidact-m/Projects
GatedTransition
false
3,144
[ "Apache-2.0" ]
0
f4c0473adba42f3a629b62eb09d3b1df91982f46
https://github.com/autodidact-m/Projects/tree/f4c0473adba42f3a629b62eb09d3b1df91982f46
Combiner
import torch import torch.nn as nn class Combiner(nn.Module): """ Parameterizes `q(z_t | z_{t-1}, x_{t:T}, m{t:T}, s)`, which is the basic building block of the guide (i.e. the variational distribution). The dependence on `x_{t:T} and m_{t:T}` is through the hidden state of the RNN (see the PyTorch module `rnn` below) """ def __init__(self, z_dim, static_dim, rnn_dim): super().__init__() self.concat_dim = z_dim + static_dim self.lin_z_to_hidden = nn.Linear(self.concat_dim, rnn_dim) self.lin_hidden_to_loc = nn.Linear(rnn_dim, z_dim) self.lin_hidden_to_scale = nn.Linear(rnn_dim, z_dim) self.tanh = nn.Tanh() self.softplus = nn.Softplus() def forward(self, z_t_1, mini_batch_static, h_rnn): """ parameterize the (diagonal) gaussian distribution `q(z_t | z_{t-1}, x_{t:T}, m{t:T}, s)` """ concat = torch.cat((z_t_1, mini_batch_static), dim=1) h_combined = 0.5 * (self.tanh(self.lin_z_to_hidden(concat)) + h_rnn) loc = self.lin_hidden_to_loc(h_combined) scale = self.softplus(self.lin_hidden_to_scale(h_combined)) return loc, scale def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'z_dim': 4, 'static_dim': 4, 'rnn_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, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_poi_fused_add_mul_tanh_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tmp3 = tmp1 + tmp2 tmp4 = 0.5 tmp5 = tmp3 * tmp4 tl.store(out_ptr0 + x0, tmp5, xmask) @triton.jit def triton_poi_fused_softplus_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 = 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) 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, 4), (4, 1)) assert_size_stride(primals_3, (4, 8), (8, 1)) assert_size_stride(primals_4, (4,), (1,)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, buf0, reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf1) del primals_3 del primals_4 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_tanh_1[grid(16)](buf1, primals_5, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, buf2, reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf3) del primals_7 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, buf2, reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_9 buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_softplus_2[grid(16)](buf4, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf3, buf5, buf0, buf1, buf2, buf4, primals_8, primals_6 class CombinerNew(nn.Module): """ Parameterizes `q(z_t | z_{t-1}, x_{t:T}, m{t:T}, s)`, which is the basic building block of the guide (i.e. the variational distribution). The dependence on `x_{t:T} and m_{t:T}` is through the hidden state of the RNN (see the PyTorch module `rnn` below) """ def __init__(self, z_dim, static_dim, rnn_dim): super().__init__() self.concat_dim = z_dim + static_dim self.lin_z_to_hidden = nn.Linear(self.concat_dim, rnn_dim) self.lin_hidden_to_loc = nn.Linear(rnn_dim, z_dim) self.lin_hidden_to_scale = nn.Linear(rnn_dim, z_dim) self.tanh = nn.Tanh() self.softplus = nn.Softplus() def forward(self, input_0, input_1, input_2): primals_3 = self.lin_z_to_hidden.weight primals_4 = self.lin_z_to_hidden.bias primals_1 = self.lin_hidden_to_loc.weight primals_7 = self.lin_hidden_to_loc.bias primals_2 = self.lin_hidden_to_scale.weight primals_9 = self.lin_hidden_to_scale.bias primals_5 = input_0 primals_6 = input_1 primals_8 = 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], output[1]
autodidact-m/Projects
Combiner
false
3,145
[ "Apache-2.0" ]
0
f4c0473adba42f3a629b62eb09d3b1df91982f46
https://github.com/autodidact-m/Projects/tree/f4c0473adba42f3a629b62eb09d3b1df91982f46
Net
import torch import numpy as np from torch.autograd import Variable class Net(torch.nn.Module): def __init__(self, n_in, n_hidden, n_out): super(Net, self).__init__() self.w1 = torch.nn.Linear(n_in, n_hidden) self.w2 = torch.nn.Linear(n_hidden, n_out) def forward(self, x): x = torch.tanh(self.w1(x)) x = self.w2(x) return x def my_train(self, xtrain, ytrain, num_epochs): """ Train the network Parameters ---------- xtrain : np.ndarray Inputs ytrain : np.ndarray Corresponding desired outputs """ xtrain = Variable(torch.FloatTensor(xtrain)) ytrain = Variable(torch.FloatTensor(ytrain)) criterion = torch.nn.MSELoss(reduction='sum') optimizer = torch.optim.SGD(self.parameters(), lr=1e-05) for t in range(num_epochs): optimizer.zero_grad() y_pred = self(xtrain) loss = criterion(y_pred, ytrain) loss.backward() optimizer.step() None def call_numpy(self, x: 'np.ndarray'): """ Call the network with numpy input and output """ x_tensor = Variable(torch.FloatTensor(x)) out = self(x_tensor) return out.detach().numpy() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_in': 4, 'n_hidden': 4, 'n_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np from torch.autograd import Variable assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, 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=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1, primals_4 class NetNew(torch.nn.Module): def __init__(self, n_in, n_hidden, n_out): super(NetNew, self).__init__() self.w1 = torch.nn.Linear(n_in, n_hidden) self.w2 = torch.nn.Linear(n_hidden, n_out) def my_train(self, xtrain, ytrain, num_epochs): """ Train the network Parameters ---------- xtrain : np.ndarray Inputs ytrain : np.ndarray Corresponding desired outputs """ xtrain = Variable(torch.FloatTensor(xtrain)) ytrain = Variable(torch.FloatTensor(ytrain)) criterion = torch.nn.MSELoss(reduction='sum') optimizer = torch.optim.SGD(self.parameters(), lr=1e-05) for t in range(num_epochs): optimizer.zero_grad() y_pred = self(xtrain) loss = criterion(y_pred, ytrain) loss.backward() optimizer.step() None def call_numpy(self, x: 'np.ndarray'): """ Call the network with numpy input and output """ x_tensor = Variable(torch.FloatTensor(x)) out = self(x_tensor) return out.detach().numpy() def forward(self, input_0): primals_1 = self.w1.weight primals_2 = self.w1.bias primals_4 = self.w2.weight primals_5 = self.w2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
auckland-cosmo/LearnAsYouGoEmulator
Net
false
3,146
[ "Apache-2.0" ]
0
d29dfb0192d8050003ab4f7e7b18571e21776ba3
https://github.com/auckland-cosmo/LearnAsYouGoEmulator/tree/d29dfb0192d8050003ab4f7e7b18571e21776ba3
GatedConv2d
import torch import torch.nn as nn from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + x0) + -4 * tl_math .abs(-3 + x1) + 16 * x2), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_convolution_elu_mul_sigmoid_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x2, xmask) tmp4 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.0 tmp7 = tmp2 > tmp6 tmp8 = 1.0 tmp9 = tmp2 * tmp8 tmp10 = libdevice.expm1(tmp9) tmp11 = tmp10 * tmp8 tmp12 = tl.where(tmp7, tmp9, tmp11) tmp13 = tl.sigmoid(tmp5) tmp14 = tmp12 * tmp13 tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(in_out_ptr1 + x2, tmp5, xmask) tl.store(out_ptr0 + x2, tmp14, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_reflection_pad2d_0[grid(256)](primals_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = extern_kernels.convolution(buf0, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 4, 1, 1), (4, 1, 1, 1)) buf2 = buf1 del buf1 buf4 = buf3 del buf3 buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32) triton_poi_fused_convolution_elu_mul_sigmoid_1[grid(16)](buf2, buf4, primals_3, primals_5, buf5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 del primals_5 return buf5, primals_2, primals_4, buf0, buf2, buf4 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2dNew, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = self.mask_conv2d.weight primals_5 = self.mask_conv2d.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
autocomic/https-github.com-autocomic-DeepFillv2_Pytorch
GatedConv2d
false
3,147
[ "MIT" ]
0
7f6712a9b42dfd827879271f13856f1da5d6a032
https://github.com/autocomic/https-github.com-autocomic-DeepFillv2_Pytorch/tree/7f6712a9b42dfd827879271f13856f1da5d6a032
Conv1DHighwayLayer
import torch import torch.nn as nn class Conv1DHighwayLayer(nn.Module): def __init__(self, inchannels, outchannels, kernelsize, activation= 'relu', stride=1, bias=-1): super(Conv1DHighwayLayer, self).__init__() self.inchannels = inchannels self.outchannels = outchannels self.kernelsize = kernelsize if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.stride = stride self.padding = (self.kernelsize - 1) // 2 self.conv = nn.Conv1d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gate = nn.Conv1d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, x): H = self.activation(self.conv(x)) T = self.gateact(self.gate(x)) out = H * T + x * (1 - T) return out def get_inputs(): return [torch.rand([4, 2])] def get_init_inputs(): return [[], {'inchannels': 4, 'outchannels': 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 from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) @triton.jit def triton_poi_fused_add_mul_relu_rsub_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 2 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x2, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tmp7 = 1.0 tmp8 = tmp7 - tmp4 tmp9 = tmp6 * tmp8 tmp10 = tmp5 + tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 2), (2, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 2), (8, 2, 1), 0), primals_1, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 1), (4, 1, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(4)](buf1, primals_2, 4, XBLOCK= 4, num_warps=1, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 2), (8, 2, 1), 0), primals_4, stride=(1,), padding=(1,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 1), (4, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(4)](buf3, primals_5, 4, XBLOCK= 4, num_warps=1, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 2), (2, 1), torch.float32) triton_poi_fused_add_mul_relu_rsub_sigmoid_1[grid(8)](buf1, buf3, primals_3, buf4, 8, XBLOCK=8, num_warps=1, num_stages=1) return buf4, primals_1, primals_3, primals_4, buf1, buf3 class Conv1DHighwayLayerNew(nn.Module): def __init__(self, inchannels, outchannels, kernelsize, activation= 'relu', stride=1, bias=-1): super(Conv1DHighwayLayerNew, self).__init__() self.inchannels = inchannels self.outchannels = outchannels self.kernelsize = kernelsize if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.stride = stride self.padding = (self.kernelsize - 1) // 2 self.conv = nn.Conv1d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gate = nn.Conv1d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_4 = self.gate.weight primals_5 = self.gate.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
avinashsai/Highway-Networks
Conv1DHighwayLayer
false
3,148
[ "MIT" ]
0
fe30629e47b919776f981eaa2bea7d21e648a17f
https://github.com/avinashsai/Highway-Networks/tree/fe30629e47b919776f981eaa2bea7d21e648a17f
Conv2dLayer
import torch import torch.nn as nn from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayer(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayer, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, x): x = self.pad(x) x = self.conv2d(x) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_elu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 1.0 tmp6 = tmp2 * tmp5 tmp7 = libdevice.expm1(tmp6) tmp8 = tmp7 * tmp5 tmp9 = tl.where(tmp4, tmp6, tmp8) tl.store(in_out_ptr0 + x2, tmp9, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 1, 1), (4, 1, 1, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_elu_0[grid(16)](buf1, primals_3, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf1 def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class Conv2dLayerNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='elu', norm= 'none', sn=False): super(Conv2dLayerNew, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU(inplace=True) elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) def forward(self, input_0): primals_1 = self.conv2d.weight primals_3 = self.conv2d.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
autocomic/https-github.com-autocomic-DeepFillv2_Pytorch
Conv2dLayer
false
3,149
[ "MIT" ]
0
7f6712a9b42dfd827879271f13856f1da5d6a032
https://github.com/autocomic/https-github.com-autocomic-DeepFillv2_Pytorch/tree/7f6712a9b42dfd827879271f13856f1da5d6a032
HighwayFC
import torch import torch.nn as nn class HighwayFC(nn.Module): def __init__(self, indim, outdim, activation='relu', bias=-1): super(HighwayFC, self).__init__() self.indim = indim self.outdim = outdim if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.fc = nn.Linear(self.indim, self.outdim) self.gate = nn.Linear(self.indim, self.outdim) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, x): H = self.activation(self.fc(x)) T = self.gateact(self.gate(x)) out = H * T + x * (1 - T) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'indim': 4, 'outdim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mul_relu_rsub_sigmoid_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) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp6 = tl.load(in_ptr2 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tmp7 = 1.0 tmp8 = tmp7 - tmp4 tmp9 = tmp6 * tmp8 tmp10 = tmp5 + tmp9 tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_relu_rsub_sigmoid_0[grid(256)](buf0, buf1, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) return buf2, primals_3, buf0, buf1 class HighwayFCNew(nn.Module): def __init__(self, indim, outdim, activation='relu', bias=-1): super(HighwayFCNew, self).__init__() self.indim = indim self.outdim = outdim if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.fc = nn.Linear(self.indim, self.outdim) self.gate = nn.Linear(self.indim, self.outdim) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, input_0): primals_1 = self.fc.weight primals_2 = self.fc.bias primals_4 = self.gate.weight primals_5 = self.gate.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
avinashsai/Highway-Networks
HighwayFC
false
3,150
[ "MIT" ]
0
fe30629e47b919776f981eaa2bea7d21e648a17f
https://github.com/avinashsai/Highway-Networks/tree/fe30629e47b919776f981eaa2bea7d21e648a17f
VertexDirectEmbedder
import torch import torch.utils.data from torch import nn def normalize_embeddings(embeddings: 'torch.Tensor', epsilon: 'float'=1e-06 ) ->torch.Tensor: """ Normalize N D-dimensional embedding vectors arranged in a tensor [N, D] Args: embeddings (tensor [N, D]): N D-dimensional embedding vectors epsilon (float): minimum value for a vector norm Return: Normalized embeddings (tensor [N, D]), such that L2 vector norms are all equal to 1. """ return embeddings / torch.clamp(embeddings.norm(p=None, dim=1, keepdim= True), min=epsilon) class VertexDirectEmbedder(nn.Module): """ Class responsible for embedding vertices. Vertex embeddings take the form of a tensor of size [N, D], where N = number of vertices D = number of dimensions in the embedding space """ def __init__(self, num_vertices: 'int', embed_dim: 'int'): """ Initialize embedder, set random embeddings Args: num_vertices (int): number of vertices to embed embed_dim (int): number of dimensions in the embedding space """ super(VertexDirectEmbedder, self).__init__() self.embeddings = nn.Parameter(torch.Tensor(num_vertices, embed_dim)) self.reset_parameters() @torch.no_grad() def reset_parameters(self): """ Reset embeddings to random values """ torch.nn.init.uniform_(self.embeddings, a=-0.5, b=0.5) def forward(self) ->torch.Tensor: """ Produce vertex embeddings, a tensor of shape [N, D] where: N = number of vertices D = number of dimensions in the embedding space Return: Full vertex embeddings, a tensor of shape [N, D] """ return normalize_embeddings(self.embeddings) @torch.no_grad() def load(self, fpath: 'str'): """ Load data from a file Args: fpath (str): file path to load data from """ with PathManager.open(fpath, 'rb') as hFile: data = pickle.load(hFile) for name in ['embeddings']: if name in data: getattr(self, name).copy_(torch.tensor(data[name]).float()) def get_inputs(): return [] def get_init_inputs(): return [[], {'num_vertices': 4, 'embed_dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clamp_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 = 1e-06 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tl.store(out_ptr0 + x2, tmp15, xmask) def call(args): primals_1, = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_div_linalg_vector_norm_0[grid(16)](primals_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf0, primals_1 def normalize_embeddings(embeddings: 'torch.Tensor', epsilon: 'float'=1e-06 ) ->torch.Tensor: """ Normalize N D-dimensional embedding vectors arranged in a tensor [N, D] Args: embeddings (tensor [N, D]): N D-dimensional embedding vectors epsilon (float): minimum value for a vector norm Return: Normalized embeddings (tensor [N, D]), such that L2 vector norms are all equal to 1. """ return embeddings / torch.clamp(embeddings.norm(p=None, dim=1, keepdim= True), min=epsilon) class VertexDirectEmbedderNew(nn.Module): """ Class responsible for embedding vertices. Vertex embeddings take the form of a tensor of size [N, D], where N = number of vertices D = number of dimensions in the embedding space """ def __init__(self, num_vertices: 'int', embed_dim: 'int'): """ Initialize embedder, set random embeddings Args: num_vertices (int): number of vertices to embed embed_dim (int): number of dimensions in the embedding space """ super(VertexDirectEmbedderNew, self).__init__() self.embeddings = nn.Parameter(torch.Tensor(num_vertices, embed_dim)) self.reset_parameters() @torch.no_grad() def reset_parameters(self): """ Reset embeddings to random values """ torch.nn.init.uniform_(self.embeddings, a=-0.5, b=0.5) @torch.no_grad() def load(self, fpath: 'str'): """ Load data from a file Args: fpath (str): file path to load data from """ with PathManager.open(fpath, 'rb') as hFile: data = pickle.load(hFile) for name in ['embeddings']: if name in data: getattr(self, name).copy_(torch.tensor(data[name]).float()) def forward(self): primals_1 = self.embeddings output = call([primals_1]) return output[0]
av777x/detectron2
VertexDirectEmbedder
false
3,151
[ "Apache-2.0" ]
0
c1794881d6d2fac6af0b3206937d32628677469c
https://github.com/av777x/detectron2/tree/c1794881d6d2fac6af0b3206937d32628677469c
Conv2DHighwayLayer
import torch import torch.nn as nn class Conv2DHighwayLayer(nn.Module): def __init__(self, inchannels, outchannels, kernelsize, activation= 'relu', stride=1, bias=-1): super(Conv2DHighwayLayer, self).__init__() self.inchannels = inchannels self.outchannels = outchannels self.kernelsize = kernelsize if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.stride = stride self.padding = (self.kernelsize - 1) // 2 self.conv = nn.Conv2d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gate = nn.Conv2d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, x): H = self.activation(self.conv(x)) T = self.gateact(self.gate(x)) out = H * T + x * (1 - T) return out def get_inputs(): return [torch.rand([4, 4, 2, 2])] def get_init_inputs(): return [[], {'inchannels': 4, 'outchannels': 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 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_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) @triton.jit def triton_poi_fused_add_mul_relu_rsub_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + x2, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = tl.sigmoid(tmp3) tmp5 = tmp2 * tmp4 tmp7 = 1.0 tmp8 = tmp7 - tmp4 tmp9 = tmp6 * tmp8 tmp10 = tmp5 + tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 2, 2), (16, 4, 2, 1)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(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, 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 buf2 = extern_kernels.convolution(primals_3, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(16)](buf3, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) triton_poi_fused_add_mul_relu_rsub_sigmoid_1[grid(64)](buf1, buf3, primals_3, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf4, primals_1, primals_3, primals_4, buf1, buf3 class Conv2DHighwayLayerNew(nn.Module): def __init__(self, inchannels, outchannels, kernelsize, activation= 'relu', stride=1, bias=-1): super(Conv2DHighwayLayerNew, self).__init__() self.inchannels = inchannels self.outchannels = outchannels self.kernelsize = kernelsize if activation == 'selu': self.activation = nn.SELU() elif activation == 'elu': self.activation = nn.ELU() else: self.activation = nn.ReLU() self.stride = stride self.padding = (self.kernelsize - 1) // 2 self.conv = nn.Conv2d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gate = nn.Conv2d(self.inchannels, self.outchannels, self. kernelsize, stride=self.stride, padding=self.padding) self.gateact = nn.Sigmoid() self.gate.bias.data.fill_(bias) def forward(self, input_0): primals_1 = self.conv.weight primals_2 = self.conv.bias primals_4 = self.gate.weight primals_5 = self.gate.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
avinashsai/Highway-Networks
Conv2DHighwayLayer
false
3,152
[ "MIT" ]
0
fe30629e47b919776f981eaa2bea7d21e648a17f
https://github.com/avinashsai/Highway-Networks/tree/fe30629e47b919776f981eaa2bea7d21e648a17f
LayerNorm
import torch import torch.nn.init import torch.optim.lr_scheduler class LayerNorm(torch.nn.Module): """ An implementation of `Layer Normalization <https://www.semanticscholar.org/paper/Layer-Normalization-Ba-Kiros/97fb4e3d45bb098e27e0071448b6152217bd35a5>`_ . Layer Normalization stabilises the training of deep neural networks by normalising the outputs of neurons from a particular layer. It computes: output = (gamma * (tensor - mean) / (std + eps)) + beta Parameters ---------- dimension : ``int``, required. The dimension of the layer output to normalize. eps : ``float``, optional, (default = 1e-6) An epsilon to prevent dividing by zero in the case the layer has zero variance. Returns ------- The normalized layer output. """ def __init__(self, dimension: 'int', eps: 'float'=1e-06) ->None: super().__init__() self.gamma = torch.nn.Parameter(torch.ones(dimension)) self.beta = torch.nn.Parameter(torch.zeros(dimension)) self.eps = eps def forward(self, tensor: 'torch.Tensor'): mean = tensor.mean(-1, keepdim=True) std = tensor.std(-1, unbiased=False, keepdim=True) return self.gamma * (tensor - mean) / (std + self.eps) + self.beta def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dimension': 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.init import torch.optim.lr_scheduler assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp29 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp9 = 4.0 tmp10 = tmp8 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp0 * tmp11 tmp13 = tmp2 - tmp10 tmp14 = tmp13 * tmp13 tmp15 = tmp3 - tmp10 tmp16 = tmp15 * tmp15 tmp17 = tmp14 + tmp16 tmp18 = tmp5 - tmp10 tmp19 = tmp18 * tmp18 tmp20 = tmp17 + tmp19 tmp21 = tmp7 - tmp10 tmp22 = tmp21 * tmp21 tmp23 = tmp20 + tmp22 tmp24 = tmp23 / tmp9 tmp25 = libdevice.sqrt(tmp24) tmp26 = 1e-06 tmp27 = tmp25 + tmp26 tmp28 = tmp12 / tmp27 tmp30 = tmp28 + tmp29 tl.store(out_ptr0 + x2, tmp30, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mean_mul_std_sub_0[grid(256)](primals_2, primals_1, primals_3, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 del primals_3 return buf0, primals_1 class LayerNormNew(torch.nn.Module): """ An implementation of `Layer Normalization <https://www.semanticscholar.org/paper/Layer-Normalization-Ba-Kiros/97fb4e3d45bb098e27e0071448b6152217bd35a5>`_ . Layer Normalization stabilises the training of deep neural networks by normalising the outputs of neurons from a particular layer. It computes: output = (gamma * (tensor - mean) / (std + eps)) + beta Parameters ---------- dimension : ``int``, required. The dimension of the layer output to normalize. eps : ``float``, optional, (default = 1e-6) An epsilon to prevent dividing by zero in the case the layer has zero variance. Returns ------- The normalized layer output. """ def __init__(self, dimension: 'int', eps: 'float'=1e-06) ->None: super().__init__() self.gamma = torch.nn.Parameter(torch.ones(dimension)) self.beta = torch.nn.Parameter(torch.zeros(dimension)) 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]
azraelzhor/allen-nlp-rc
LayerNorm
false
3,153
[ "Apache-2.0" ]
0
b114c00a8f364b18e3c427c1a447be9c65ede551
https://github.com/azraelzhor/allen-nlp-rc/tree/b114c00a8f364b18e3c427c1a447be9c65ede551
SimpleResidualBlock
import torch import torch.nn as nn class SimpleResidualBlock(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=1) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=1) self.relu2 = nn.ReLU() def forward(self, x): out = self.conv1(x) out = self.relu1(out) out = self.conv2(out) return self.relu2(out) + x def get_inputs(): return [torch.rand([4, 3, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 3 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 3 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr2 + x3, None) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp4 + tmp5 tmp7 = 0.0 tmp8 = tmp4 <= tmp7 tl.store(out_ptr0 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp8, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (3, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (3,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (3, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_5, (3,), (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, 3, 64, 64), (12288, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(49152)](buf1, primals_2, 49152, XBLOCK=512, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 3, 64, 64), (12288, 4096, 64, 1)) buf3 = empty_strided_cuda((4, 3, 64, 64), (12288, 4096, 64, 1), torch.float32) buf4 = empty_strided_cuda((4, 3, 64, 64), (12288, 4096, 64, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(49152) ](buf2, primals_5, primals_3, buf3, buf4, 49152, XBLOCK=512, num_warps=4, num_stages=1) del buf2 del primals_5 return buf3, primals_1, primals_3, primals_4, buf1, buf4 class SimpleResidualBlockNew(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=1) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(in_channels=3, out_channels=3, kernel_size=3, stride=1, padding=1) self.relu2 = nn.ReLU() def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ayanch07/ResNet-cifar-10-pytorch
SimpleResidualBlock
false
3,154
[ "MIT" ]
0
bafc945a022a2e3ada689a831c7e57b5bdb0e8bd
https://github.com/ayanch07/ResNet-cifar-10-pytorch/tree/bafc945a022a2e3ada689a831c7e57b5bdb0e8bd
TransposeGatedConv2d
import torch import torch.nn as nn from torch.nn import functional as F from torch.nn import Parameter def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2d, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, x): x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest') x = self.gated_conv2d(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn import Parameter assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = x0 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x4, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_mv_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.load(in_ptr0 + (64 + r0), None) tmp5 = tl.load(in_ptr1 + 1) tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp9 = tl.load(in_ptr0 + (128 + r0), None) tmp10 = tl.load(in_ptr1 + 2) tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK]) tmp14 = tl.load(in_ptr0 + (192 + r0), None) tmp15 = tl.load(in_ptr1 + 3) tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp3 = tmp0 * tmp2 tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp12 = tmp9 * tmp11 tmp13 = tmp8 + tmp12 tmp17 = tmp14 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = tmp18 * tmp18 tmp20 = tl.broadcast_to(tmp19, [XBLOCK, RBLOCK]) tmp22 = tl.sum(tmp20, 1)[:, None] tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-12 tmp25 = tmp23 + tmp24 tmp26 = tmp18 / tmp25 tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp18, None) tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp25, None) tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp26, None) @triton.jit def triton_per_fused_div_mv_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp4 = tmp1 / tmp3 tmp5 = tmp0 * tmp4 tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tl.store(out_ptr0 + x0, tmp9, xmask) @triton.jit def triton_per_fused_add_div_linalg_vector_norm_3(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.sum(tmp2, 1)[:, None] tmp5 = libdevice.sqrt(tmp4) tmp6 = 1e-12 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp8, None) @triton.jit def triton_per_fused_dot_4(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 * tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp5 = tl.sum(tmp3, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None) @triton.jit def triton_poi_fused_div_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 / tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = 0.0 tmp7 = tmp2 > tmp6 tmp8 = 0.2 tmp9 = tmp2 * tmp8 tmp10 = tl.where(tmp7, tmp2, tmp9) tmp11 = tl.sigmoid(tmp5) tmp12 = tmp10 * tmp11 tl.store(in_out_ptr0 + x3, tmp2, xmask) tl.store(in_out_ptr1 + x3, tmp5, xmask) tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (64,), (1,)) assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64,), (1,), torch.float32) buf2 = empty_strided_cuda((), (), torch.float32) buf3 = buf2 del buf2 buf27 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf3, primals_4, primals_2, buf1, buf27, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_div_mv_2[grid(4)](primals_4, buf1, buf3, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf6 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf4, buf6, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf6, buf4, buf7, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_4, buf7, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf0, buf8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 4, 5, 5), (100, 25, 5, 1)) buf11 = empty_strided_cuda((64,), (1,), torch.float32) buf12 = empty_strided_cuda((), (), torch.float32) buf13 = buf12 del buf12 buf36 = empty_strided_cuda((64,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_mv_1[grid(1)](buf13, primals_8, primals_6, buf11, buf36, 1, 64, XBLOCK=1, num_warps= 2, num_stages=1) buf14 = buf4 del buf4 triton_per_fused_div_mv_2[grid(4)](primals_8, buf11, buf13, buf14, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf16 = empty_strided_cuda((4,), (1,), torch.float32) triton_per_fused_add_div_linalg_vector_norm_3[grid(1)](buf14, buf16, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) buf17 = empty_strided_cuda((), (), torch.float32) triton_per_fused_dot_4[grid(1)](buf16, buf14, buf17, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf14 buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_div_5[grid(256)](primals_8, buf17, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1) buf19 = extern_kernels.convolution(buf0, buf18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf19, (4, 4, 5, 5), (100, 25, 5, 1)) buf10 = buf9 del buf9 buf20 = buf19 del buf19 buf21 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.float32 ) triton_poi_fused_convolution_leaky_relu_mul_sigmoid_6[grid(400)](buf10, buf20, primals_5, primals_9, buf21, 400, XBLOCK=128, num_warps= 4, num_stages=1) del primals_5 del primals_9 buf22 = torch.ops.aten.set_.source_Tensor(primals_2, buf6) assert_size_stride(buf22, (4,), (1,)) del buf1 buf28 = torch.ops.aten.set_.source_Tensor(primals_3, buf27) assert_size_stride(buf28, (64,), (1,)) del primals_3 buf31 = torch.ops.aten.set_.source_Tensor(primals_6, buf16) assert_size_stride(buf31, (4,), (1,)) del buf11 buf37 = torch.ops.aten.set_.source_Tensor(primals_7, buf36) assert_size_stride(buf37, (64,), (1,)) del primals_7 return (buf21, buf8, buf18, primals_2, primals_4, primals_6, primals_8, buf0, buf3, buf6, buf7, buf8, buf10, buf13, buf16, buf17, buf18, buf20) def l2normalize(v, eps=1e-12): return v / (v.norm() + eps) class LayerNorm(nn.Module): def __init__(self, num_features, eps=1e-08, affine=True): super(LayerNorm, self).__init__() self.num_features = num_features self.affine = affine self.eps = eps if self.affine: self.gamma = Parameter(torch.Tensor(num_features).uniform_()) self.beta = Parameter(torch.zeros(num_features)) def forward(self, x): shape = [-1] + [1] * (x.dim() - 1) if x.size(0) == 1: mean = x.view(-1).mean().view(*shape) std = x.view(-1).std().view(*shape) else: mean = x.view(x.size(0), -1).mean(1).view(*shape) std = x.view(x.size(0), -1).std(1).view(*shape) x = (x - mean) / (std + self.eps) if self.affine: shape = [1, -1] + [1] * (x.dim() - 2) x = x * self.gamma.view(*shape) + self.beta.view(*shape) return x class SpectralNorm(nn.Module): def __init__(self, module, name='weight', power_iterations=1): super(SpectralNorm, self).__init__() self.module = module self.name = name self.power_iterations = power_iterations if not self._made_params(): self._make_params() def _update_u_v(self): u = getattr(self.module, self.name + '_u') v = getattr(self.module, self.name + '_v') w = getattr(self.module, self.name + '_bar') height = w.data.shape[0] for _ in range(self.power_iterations): v.data = l2normalize(torch.mv(torch.t(w.view(height, -1).data), u.data)) u.data = l2normalize(torch.mv(w.view(height, -1).data, v.data)) sigma = u.dot(w.view(height, -1).mv(v)) setattr(self.module, self.name, w / sigma.expand_as(w)) def _made_params(self): try: getattr(self.module, self.name + '_u') getattr(self.module, self.name + '_v') getattr(self.module, self.name + '_bar') return True except AttributeError: return False def _make_params(self): w = getattr(self.module, self.name) height = w.data.shape[0] width = w.view(height, -1).data.shape[1] u = Parameter(w.data.new(height).normal_(0, 1), requires_grad=False) v = Parameter(w.data.new(width).normal_(0, 1), requires_grad=False) u.data = l2normalize(u.data) v.data = l2normalize(v.data) w_bar = Parameter(w.data) del self.module._parameters[self.name] self.module.register_parameter(self.name + '_u', u) self.module.register_parameter(self.name + '_v', v) self.module.register_parameter(self.name + '_bar', w_bar) def forward(self, *args): self._update_u_v() return self.module.forward(*args) class GatedConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='reflect', activation='elu', norm= 'none', sn=False): super(GatedConv2d, self).__init__() if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) if norm == 'bn': self.norm = nn.BatchNorm2d(out_channels) elif norm == 'in': self.norm = nn.InstanceNorm2d(out_channels) elif norm == 'ln': self.norm = LayerNorm(out_channels) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=True) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=True) elif activation == 'elu': self.activation = nn.ELU() elif activation == 'selu': self.activation = nn.SELU(inplace=True) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'sigmoid': self.activation = nn.Sigmoid() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) if sn: self.conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation)) self.mask_conv2d = SpectralNorm(nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation= dilation)) else: self.conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.mask_conv2d = nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=0, dilation=dilation) self.sigmoid = torch.nn.Sigmoid() def forward(self, x): x = self.pad(x) conv = self.conv2d(x) mask = self.mask_conv2d(x) gated_mask = self.sigmoid(mask) if self.activation: conv = self.activation(conv) x = conv * gated_mask return x class TransposeGatedConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, pad_type='zero', activation='lrelu', norm= 'none', sn=True, scale_factor=2): super(TransposeGatedConv2dNew, self).__init__() self.scale_factor = scale_factor self.gated_conv2d = GatedConv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, pad_type, activation, norm, sn) def forward(self, input_0): primals_2 = self.gated_conv2d.conv2d.module.bias primals_5 = self.gated_conv2d.conv2d.module.weight_u primals_3 = self.gated_conv2d.conv2d.module.weight_v primals_1 = self.gated_conv2d.conv2d.module.weight_bar primals_6 = self.gated_conv2d.mask_conv2d.module.bias primals_9 = self.gated_conv2d.mask_conv2d.module.weight_u primals_7 = self.gated_conv2d.mask_conv2d.module.weight_v primals_4 = self.gated_conv2d.mask_conv2d.module.weight_bar primals_8 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9]) return output[0]
autocomic/https-github.com-autocomic-DeepFillv2_Pytorch
TransposeGatedConv2d
false
3,155
[ "MIT" ]
0
7f6712a9b42dfd827879271f13856f1da5d6a032
https://github.com/autocomic/https-github.com-autocomic-DeepFillv2_Pytorch/tree/7f6712a9b42dfd827879271f13856f1da5d6a032
SimpleNet
import torch import torch.nn as nn from torch.functional import F import torch.nn.functional as F class SimpleNet(nn.Module): """ Simple Neural Net model """ def __init__(self): """ Creates layers as class attributes. """ super(SimpleNet, self).__init__() self.fc1 = nn.Linear(2048, 256) self.fc2 = nn.Linear(256, 64) self.fc3 = nn.Linear(64, 2) def forward(self, x): """ Forward pass of the network. :param x: :return: """ x = x.view(-1, 2048) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = F.softmax(self.fc3(x), dim=1) return x def get_inputs(): return [torch.rand([4, 2048])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_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 % 64 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__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 8 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 2 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp4 = tmp0 - tmp3 tmp5 = tl_math.exp(tmp4) tmp6 = tmp1 - tmp3 tmp7 = tl_math.exp(tmp6) tmp8 = tmp2 - tmp3 tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp11 = tmp5 / tmp10 tl.store(out_ptr0 + x2, tmp11, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 2048), (2048, 1)) assert_size_stride(primals_2, (256, 2048), (2048, 1)) assert_size_stride(primals_3, (256,), (1,)) assert_size_stride(primals_4, (64, 256), (256, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (2, 64), (64, 1)) assert_size_stride(primals_7, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 256), (256, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (2048, 256), (1, 2048), 0), out=buf0) del primals_2 buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_relu_0[grid(1024)](buf1, primals_3, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (256, 64), (1, 256), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(256)](buf3, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (64, 2), (1, 64), 0), alpha=1, beta=1, out=buf4) del primals_7 buf5 = empty_strided_cuda((4, 2), (2, 1), torch.float32) triton_poi_fused__softmax_2[grid(8)](buf4, buf5, 8, XBLOCK=8, num_warps=1, num_stages=1) del buf4 return buf5, primals_1, buf1, buf3, buf5, primals_6, primals_4 class SimpleNetNew(nn.Module): """ Simple Neural Net model """ def __init__(self): """ Creates layers as class attributes. """ super(SimpleNetNew, self).__init__() self.fc1 = nn.Linear(2048, 256) self.fc2 = nn.Linear(256, 64) self.fc3 = nn.Linear(64, 2) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
avizyt/PytorchMLDLStudy
SimpleNet
false
3,156
[ "MIT" ]
0
ccb552809e7ab4438576e6d3b7cd7ca3b73235ed
https://github.com/avizyt/PytorchMLDLStudy/tree/ccb552809e7ab4438576e6d3b7cd7ca3b73235ed
FFN
import torch import torch.nn as nn class FFN(nn.Module): def __init__(self, input_dim, num_class): super().__init__() self.layer1 = nn.Linear(input_dim, 256) self.layer2 = nn.Linear(256, 128) self.layer3 = nn.Linear(128, 128) self.out = nn.Linear(128, num_class) self.dropout = nn.Dropout(0.5) def forward(self, x): x = self.dropout(torch.relu(self.layer1(x))) x = self.dropout(torch.relu(self.layer2(x))) x = self.dropout(torch.relu(self.layer3(x))) x = self.out(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'num_class': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (256, 4), (4, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (128, 256), (256, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (128, 128), (128, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (4, 128), (128, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 256), (4096, 1024, 256, 1), 0 ) del buf0 buf9 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf1, primals_2, buf9, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (64, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 128), (1, 256), 0), out=buf2) buf3 = reinterpret_tensor(buf2, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf2 buf8 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf3, primals_5, buf8, 8192, 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, 128), (128, 1), 0), reinterpret_tensor(primals_6, (128, 128), (1, 128), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf4 buf7 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf5, primals_7, buf7, 8192, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf5, (64, 128), (128, 1), 0), reinterpret_tensor(primals_8, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf6) del primals_9 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 256), (256, 1), 0 ), reinterpret_tensor(buf3, (64, 128), (128, 1), 0 ), reinterpret_tensor(buf5, (64, 128), (128, 1), 0 ), primals_8, buf7, primals_6, buf8, primals_4, buf9 class FFNNew(nn.Module): def __init__(self, input_dim, num_class): super().__init__() self.layer1 = nn.Linear(input_dim, 256) self.layer2 = nn.Linear(256, 128) self.layer3 = nn.Linear(128, 128) self.out = nn.Linear(128, num_class) self.dropout = nn.Dropout(0.5) def forward(self, input_0): primals_1 = self.layer1.weight primals_2 = self.layer1.bias primals_4 = self.layer2.weight primals_5 = self.layer2.bias primals_6 = self.layer3.weight primals_7 = self.layer3.bias primals_8 = self.out.weight primals_9 = self.out.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]
baburamShapure/federatedGraphConv
FFN
false
3,157
[ "MIT" ]
0
015e502fcf1b911ab23572b00c547591a4bdf378
https://github.com/baburamShapure/federatedGraphConv/tree/015e502fcf1b911ab23572b00c547591a4bdf378
TreeStandardize
import torch from torch import nn import torch.utils.data class TreeStandardize(nn.Module): def forward(self, trees): mu = torch.mean(trees[0], dim=(1, 2)).unsqueeze(1).unsqueeze(1) s = torch.std(trees[0], dim=(1, 2)).unsqueeze(1).unsqueeze(1) standardized = (trees[0] - mu) / (s + 1e-05) return standardized, trees[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 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_per_fused_add_div_mean_std_sub_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.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 = tmp0 - tmp20 tmp22 = 15.0 tmp23 = tmp18 / tmp22 tmp24 = libdevice.sqrt(tmp23) tmp25 = 1e-05 tmp26 = tmp24 + tmp25 tmp27 = tmp21 / tmp26 tl.store(out_ptr2 + (r1 + 16 * x0), 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) buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_std_sub_0[grid(4)](arg0_1, buf4, 4, 16, XBLOCK=1, num_warps=2, num_stages=1) return buf4, reinterpret_tensor(arg0_1, (4, 4, 4), (16, 4, 1), 64) class TreeStandardizeNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0], output[1]
balsa-project/balsa
TreeStandardize
false
3,158
[ "Apache-2.0" ]
0
36f3fb35d33589928d761b89de52367d18d08fd8
https://github.com/balsa-project/balsa/tree/36f3fb35d33589928d761b89de52367d18d08fd8
TreeMaxPool
import torch from torch import nn import torch.utils.data class TreeMaxPool(nn.Module): def forward(self, trees): return trees[0].max(dim=2).values def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch 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 @triton.jit def triton_poi_fused_max_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp6 = triton_helpers.maximum(tmp4, tmp5) tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_max_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf0, class TreeMaxPoolNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
balsa-project/balsa
TreeMaxPool
false
3,159
[ "Apache-2.0" ]
0
36f3fb35d33589928d761b89de52367d18d08fd8
https://github.com/balsa-project/balsa/tree/36f3fb35d33589928d761b89de52367d18d08fd8
MetricLoss
import torch import torch.nn as nn import torch.jit import torch.nn class MetricLoss(nn.Module): """Loss designed to train a true metric, as opposed to a sigmoid classifier. """ def __init__(self): super(MetricLoss, self).__init__() def forward(self, input, target): weight = 1.0 - target weight /= weight.sum() weight += target / target.sum() tensor_result = weight * (input - target) ** 2 return tensor_result.sum() 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 import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_div_mul_pow_rsub_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) tmp12 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp3 = tl.broadcast_to(tmp2, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.broadcast_to(tmp0, [RBLOCK]) tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0)) tmp9 = tmp2 / tmp5 tmp10 = tmp0 / tmp8 tmp11 = tmp9 + tmp10 tmp13 = tmp12 - tmp0 tmp14 = tmp13 * tmp13 tmp15 = tmp11 * tmp14 tmp16 = tl.broadcast_to(tmp15, [RBLOCK]) tmp18 = triton_helpers.promote_to_tensor(tl.sum(tmp16, 0)) tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_div_mul_pow_rsub_sub_sum_0[grid(1)](buf2, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class MetricLossNew(nn.Module): """Loss designed to train a true metric, as opposed to a sigmoid classifier. """ def __init__(self): super(MetricLossNew, 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]
ankmathur96/torchsupport
MetricLoss
false
3,160
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
NotNorm
import torch import torch.nn as nn import torch.jit import torch.nn class NotNorm(nn.Module): def __init__(self, in_size): super().__init__() self.in_size = in_size def forward(self, inputs): [1] * (inputs.dim() - 2) out = inputs.view(inputs.size(0), inputs.size(1), -1) mean = out.mean(dim=-1, keepdim=True) std = out.std(dim=-1, keepdim=True) normed = (out - mean.detach()) / std.detach() out = std * normed + mean return out.view(inputs.shape) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_std_sub_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) 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 = 15.0 tmp20 = tmp18 / tmp19 tmp21 = libdevice.sqrt(tmp20) tmp22 = 16.0 tmp23 = tmp4 / tmp22 tmp24 = tmp0 - tmp23 tmp25 = tmp24 / tmp21 tmp26 = tmp21 * tmp25 tmp27 = tmp26 + tmp23 tl.store(out_ptr2 + (r1 + 16 * x0), 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) buf4 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_std_sub_0[grid(16)](arg0_1, buf4, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del arg0_1 return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0), class NotNormNew(nn.Module): def __init__(self, in_size): super().__init__() self.in_size = in_size def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ankmathur96/torchsupport
NotNorm
false
3,162
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
AdaptiveInstanceNorm
import torch import torch.nn as nn import torch.jit import torch.nn class AdaptiveInstanceNorm(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNorm, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, inputs, style): in_view = inputs.view(inputs.size(0), inputs.size(1), 1, 1, -1) mean = in_view.mean(dim=-1) std = in_view.std(dim=-1) scale = self.scale(style).view(style.size(0), -1, 1, 1) bias = self.bias(style).view(style.size(0), -1, 1, 1) return scale * (inputs - mean) / (std + 1e-06) + bias def get_inputs(): return [torch.rand([4, 64, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'ada_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.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_std_sub_0(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp26 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr2 + x0 % 4, xmask, eviction_policy='evict_last') tmp32 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp33 = tl.load(in_ptr4 + x0 % 4, 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 = libdevice.sqrt(tmp22) tmp24 = 1e-06 tmp25 = tmp23 + tmp24 tmp28 = tmp26 + tmp27 tmp29 = tmp0 - tmp20 tmp30 = tmp28 * tmp29 tmp31 = tmp30 / tmp25 tmp34 = tmp32 + tmp33 tmp35 = tmp31 + tmp34 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp35, 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, 64, 4, 4), (1024, 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) buf5 = 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=buf5) del primals_2 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf6) del primals_5 buf0 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 256, 256), torch. float32) buf3 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 256, 256), torch. float32) buf1 = reinterpret_tensor(buf0, (4, 64, 1, 1), (64, 1, 1, 1), 0) del buf0 buf7 = reinterpret_tensor(buf3, (4, 64, 1, 1), (64, 1, 1, 1), 0) del buf3 buf8 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch. float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_std_sub_0[grid(256)](buf1, buf7, primals_1, buf5, primals_3, buf6, primals_6, buf8, 256, 16, XBLOCK=32, num_warps=4, num_stages=1) del buf5 del buf6 del primals_3 del primals_6 return buf8, primals_1, buf1, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), buf7 class AdaptiveInstanceNormNew(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNormNew, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, input_0, input_1): primals_2 = self.scale.weight primals_3 = self.scale.bias primals_5 = self.bias.weight primals_6 = self.bias.bias 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]
ankmathur96/torchsupport
AdaptiveInstanceNorm
false
3,163
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
DCCWeightedELoss
import torch import numpy as np import torch.nn as nn import torch.jit import torch.nn class DCCWeightedELoss(nn.Module): def __init__(self, size_average=True): super(DCCWeightedELoss, self).__init__() self.size_average = size_average def forward(self, inputs, outputs, weights): out = (inputs - outputs).view(len(inputs), -1) out = torch.sum(weights * torch.norm(out, p=2, dim=1) ** 2) assert np.isfinite(out.data.cpu().numpy()).all(), 'Nan found in data' if self.size_average: out = out / inputs.nelement() return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_linalg_vector_norm_0(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tl.store(out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_per_fused_div_linalg_vector_norm_mul_pow_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex r0 = rindex % 4 tmp0 = tl.load(in_ptr0 + r2, None) tmp1 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last') tmp2 = libdevice.sqrt(tmp1) tmp3 = tmp2 * tmp2 tmp4 = tmp0 * tmp3 tmp5 = tl.broadcast_to(tmp4, [RBLOCK]) tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0)) tmp8 = 0.00390625 tmp9 = tmp7 * tmp8 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp9, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_per_fused_linalg_vector_norm_0[grid(4)](arg0_1, arg1_1, buf0, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_div_linalg_vector_norm_mul_pow_sum_1[grid(1)](buf2, arg2_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg2_1 del buf0 return buf2, class DCCWeightedELossNew(nn.Module): def __init__(self, size_average=True): super(DCCWeightedELossNew, self).__init__() self.size_average = size_average 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]
ankmathur96/torchsupport
DCCWeightedELoss
false
3,164
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
AdaptiveLayerNorm
import torch import torch.nn as nn import torch.jit import torch.nn class AdaptiveLayerNorm(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveLayerNorm, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, inputs, style): expand = [1] * (inputs.dim() - 2) mean = inputs.mean(dim=1, keepdim=True) std = inputs.std(dim=1, keepdim=True) scale = self.scale(style).view(style.size(0), -1, *expand) scale = scale - scale.mean(dim=1, keepdim=True) + 1 bias = self.bias(style).view(style.size(0), -1, *expand) bias = bias - bias.mean(dim=1, keepdim=True) return scale * (inputs - mean) / (std + 1e-06) + bias def get_inputs(): return [torch.rand([4, 64, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'ada_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.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_mean_std_0(in_out_ptr0, in_out_ptr1, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 16 x1 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 1024 * x1), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp4 / tmp19 tmp21 = 63.0 tmp22 = tmp18 / tmp21 tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-06 tmp25 = tmp23 + tmp24 tl.debug_barrier() tl.store(in_out_ptr0 + x3, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp25, xmask) @triton.jit def triton_per_fused_mean_1(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl. constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tl.store(out_ptr0 + x0, tmp4, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_sub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex // 16 x2 = xindex // 1024 x4 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + x3, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr2 + x4, None) tmp8 = tl.load(in_ptr3 + (x0 + 16 * x2), None, eviction_policy='evict_last' ) tmp11 = tl.load(in_ptr4 + (x0 + 16 * x2), None, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr5 + x3, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr6 + x2, None, eviction_policy='evict_last') tmp2 = 64.0 tmp3 = tmp1 / tmp2 tmp4 = tmp0 - tmp3 tmp5 = 1.0 tmp6 = tmp4 + tmp5 tmp9 = tmp7 - tmp8 tmp10 = tmp6 * tmp9 tmp12 = tmp10 / tmp11 tmp15 = tmp14 / tmp2 tmp16 = tmp13 - tmp15 tmp17 = tmp12 + tmp16 tl.store(out_ptr0 + x4, tmp17, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 64, 4, 4), (1024, 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((4, 1, 4, 4), (16, 64, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 16, 4, 1), 0) del buf0 buf9 = reinterpret_tensor(buf3, (4, 1, 4, 4), (16, 16, 4, 1), 0) del buf3 get_raw_stream(0) triton_per_fused_add_mean_std_0[grid(64)](buf1, buf9, primals_1, 64, 64, XBLOCK=32, num_warps=8, num_stages=1) buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf5) del primals_2 del primals_3 buf6 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) triton_per_fused_mean_1[grid(4)](buf5, buf6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf7 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf7) del primals_5 del primals_6 buf8 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) triton_per_fused_mean_1[grid(4)](buf7, buf8, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) buf10 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch. float32) triton_poi_fused_add_div_mean_mul_sub_2[grid(4096)](buf5, buf6, primals_1, buf1, buf9, buf7, buf8, buf10, 4096, XBLOCK=128, num_warps=4, num_stages=1) del buf5 del buf6 del buf7 del buf8 return buf10, primals_1, buf1, reinterpret_tensor(primals_4, (64, 4), ( 4, 1), 0), buf9 class AdaptiveLayerNormNew(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveLayerNormNew, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, input_0, input_1): primals_2 = self.scale.weight primals_3 = self.scale.bias primals_5 = self.bias.weight primals_6 = self.bias.bias 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]
ankmathur96/torchsupport
AdaptiveLayerNorm
false
3,165
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
ConvMeanPool
import torch from torch import nn from matplotlib import pyplot as pyplot class MyConvo2d(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, he_init=True, stride=1, bias=True): super(MyConvo2d, self).__init__() self.he_init = he_init self.padding = int((kernel_size - 1) / 2) self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=self.padding, bias=bias) def forward(self, input): output = self.conv(input) return output class ConvMeanPool(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, he_init=True): super(ConvMeanPool, self).__init__() self.he_init = he_init self.conv = MyConvo2d(input_dim, output_dim, kernel_size, he_init= self.he_init) def forward(self, input): output = self.conv(input) output = (output[:, :, ::2, ::2] + output[:, :, 1::2, ::2] + output [:, :, ::2, 1::2] + output[:, :, 1::2, 1::2]) / 4 return output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'output_dim': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch import nn from matplotlib import pyplot as pyplot assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 % 2 x4 = xindex // 4 x2 = xindex // 4 % 4 x6 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 6 * x1 + 9 * x4), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (3 + 2 * x0 + 9 * x4), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (1 + 6 * x1 + 9 * x4), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (4 + 9 * x4), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp3 + tmp1 tmp5 = tmp2 + tmp4 tmp7 = tmp6 + tmp1 tmp8 = tmp5 + tmp7 tmp10 = tmp9 + tmp1 tmp11 = tmp8 + tmp10 tmp12 = 0.25 tmp13 = tmp11 * tmp12 tl.store(out_ptr0 + x6, tmp13, 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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 3, 3), (36, 9, 3, 1)) buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_0[grid(64)](buf0, primals_2, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf0 del primals_2 return buf1, primals_1, primals_3 class MyConvo2d(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, he_init=True, stride=1, bias=True): super(MyConvo2d, self).__init__() self.he_init = he_init self.padding = int((kernel_size - 1) / 2) self.conv = nn.Conv2d(input_dim, output_dim, kernel_size, stride=1, padding=self.padding, bias=bias) def forward(self, input): output = self.conv(input) return output class ConvMeanPoolNew(nn.Module): def __init__(self, input_dim, output_dim, kernel_size, he_init=True): super(ConvMeanPoolNew, self).__init__() self.he_init = he_init self.conv = MyConvo2d(input_dim, output_dim, kernel_size, he_init= self.he_init) def forward(self, input_0): primals_1 = self.conv.conv.weight primals_2 = self.conv.conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ameya005/Conn_InvNet
ConvMeanPool
false
3,166
[ "MIT" ]
0
848a90e45808e540d3047d92b8d0a220da1bc5e7
https://github.com/ameya005/Conn_InvNet/tree/848a90e45808e540d3047d92b8d0a220da1bc5e7
ProposalNet
import torch from torch import nn import torch.utils.data class ProposalNet(nn.Module): def __init__(self): super(ProposalNet, self).__init__() self.down1 = nn.Conv2d(2048, 128, 3, 1, 1) self.down2 = nn.Conv2d(128, 128, 3, 2, 1) self.down3 = nn.Conv2d(128, 128, 3, 2, 1) self.ReLU = nn.ReLU() self.tidy1 = nn.Conv2d(128, 6, 1, 1, 0) self.tidy2 = nn.Conv2d(128, 6, 1, 1, 0) self.tidy3 = nn.Conv2d(128, 9, 1, 1, 0) def forward(self, x): batch_size = x.size(0) d1 = self.ReLU(self.down1(x)) d2 = self.ReLU(self.down2(d1)) d3 = self.ReLU(self.down3(d2)) t1 = self.tidy1(d1).view(batch_size, -1) t2 = self.tidy2(d2).view(batch_size, -1) t3 = self.tidy3(d3).view(batch_size, -1) return torch.cat((t1, t2, t3), dim=1) def get_inputs(): return [torch.rand([4, 2048, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn 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_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1024 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 256 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 132096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 33024 x1 = xindex // 33024 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 24576, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (24576 * x1 + x0 % 24576), tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0 // 4096 % 6, tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tmp11 = tl.full([1], 30720, tl.int64) tmp12 = tmp0 < tmp11 tmp13 = tmp10 & tmp12 tmp14 = tl.load(in_ptr2 + (6144 * x1 + (-24576 + x0) % 6144), tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp15 = tl.load(in_ptr3 + (-24576 + x0) // 1024 % 6, tmp13 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tmp14 + tmp15 tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype) tmp18 = tl.where(tmp13, tmp16, tmp17) tmp19 = tmp0 >= tmp11 tl.full([1], 33024, tl.int64) tmp22 = tl.load(in_ptr4 + (2304 * x1 + (-30720 + x0) % 2304), tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp23 = tl.load(in_ptr5 + (-30720 + x0) // 256 % 9, tmp19 & xmask, eviction_policy='evict_last', other=0.0) tmp24 = tmp22 + tmp23 tmp25 = tl.full(tmp24.shape, 0.0, tmp24.dtype) tmp26 = tl.where(tmp19, tmp24, tmp25) tmp27 = tl.where(tmp13, tmp18, tmp26) tmp28 = tl.where(tmp4, tmp9, tmp27) tl.store(out_ptr0 + x2, tmp28, 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, 2048, 64, 64), (8388608, 4096, 64, 1)) assert_size_stride(primals_2, (128, 2048, 3, 3), (18432, 9, 3, 1)) assert_size_stride(primals_3, (128,), (1,)) assert_size_stride(primals_4, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (6, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_9, (6,), (1,)) assert_size_stride(primals_10, (6, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_11, (6,), (1,)) assert_size_stride(primals_12, (9, 128, 1, 1), (128, 1, 1, 1)) assert_size_stride(primals_13, (9,), (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, 128, 64, 64), (524288, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(2097152)](buf1, primals_3, 2097152, XBLOCK=1024, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 128, 32, 32), (131072, 1024, 32, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(524288)](buf3, primals_5, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 buf4 = extern_kernels.convolution(buf3, primals_6, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 128, 16, 16), (32768, 256, 16, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(131072)](buf5, primals_7, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf6 = extern_kernels.convolution(buf1, 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, 6, 64, 64), (24576, 4096, 64, 1)) buf7 = extern_kernels.convolution(buf3, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 6, 32, 32), (6144, 1024, 32, 1)) buf8 = extern_kernels.convolution(buf5, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 9, 16, 16), (2304, 256, 16, 1)) buf9 = empty_strided_cuda((4, 33024), (33024, 1), torch.float32) triton_poi_fused_cat_3[grid(132096)](buf6, primals_9, buf7, primals_11, buf8, primals_13, buf9, 132096, XBLOCK=512, num_warps=8, num_stages=1) del buf6 del buf7 del buf8 del primals_11 del primals_13 del primals_9 return (buf9, primals_1, primals_2, primals_4, primals_6, primals_8, primals_10, primals_12, buf1, buf3, buf5) class ProposalNetNew(nn.Module): def __init__(self): super(ProposalNetNew, self).__init__() self.down1 = nn.Conv2d(2048, 128, 3, 1, 1) self.down2 = nn.Conv2d(128, 128, 3, 2, 1) self.down3 = nn.Conv2d(128, 128, 3, 2, 1) self.ReLU = nn.ReLU() self.tidy1 = nn.Conv2d(128, 6, 1, 1, 0) self.tidy2 = nn.Conv2d(128, 6, 1, 1, 0) self.tidy3 = nn.Conv2d(128, 9, 1, 1, 0) def forward(self, input_0): primals_2 = self.down1.weight primals_3 = self.down1.bias primals_4 = self.down2.weight primals_5 = self.down2.bias primals_6 = self.down3.weight primals_7 = self.down3.bias primals_8 = self.tidy1.weight primals_9 = self.tidy1.bias primals_10 = self.tidy2.weight primals_11 = self.tidy2.bias primals_12 = self.tidy3.weight primals_13 = self.tidy3.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]
Syderny/NTS-Net
ProposalNet
false
3,167
[ "MIT" ]
0
02d29e8e46aca7698c3102626eec33b12ddd7669
https://github.com/Syderny/NTS-Net/tree/02d29e8e46aca7698c3102626eec33b12ddd7669
AdaptiveFilterResponseNorm
import torch import torch.nn as nn import torch.nn.functional as func import torch.jit import torch.nn class AdaptiveFilterResponseNorm(nn.Module): def __init__(self, in_size, ada_size, eps=1e-16): super().__init__() self.eps = eps self.in_size = in_size self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) self.threshold = nn.Linear(ada_size, in_size) def forward(self, inputs, condition): out = inputs.view(inputs.size(0), inputs.size(1), -1) nu2 = out.mean(dim=-1) extension = [1] * (inputs.dim() - 2) denominator = torch.sqrt(nu2 + self.eps) denominator = denominator.view(inputs.size(0), inputs.size(1), * extension) out = inputs / denominator scale = self.scale(condition) bias = self.bias(condition) threshold = self.threshold(condition) out = func.relu(scale * out + bias - threshold) + threshold return out def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'ada_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_relu_sqrt_sub_threshold_backward_0( in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, 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 r2 = rindex % 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp10 = tl.load(in_out_ptr1 + (r1 + 16 * x0), xmask, other=0.0) tmp11 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last') tmp15 = tl.load(in_ptr2 + (r1 + 16 * x0), xmask, other=0.0) tmp16 = tl.load(in_ptr3 + r2, None, eviction_policy='evict_last') tmp19 = tl.load(in_ptr4 + (r1 + 16 * x0), xmask, other=0.0) tmp20 = tl.load(in_ptr5 + r2, None, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tmp7 = 1e-16 tmp8 = tmp6 + tmp7 tmp9 = libdevice.sqrt(tmp8) tmp12 = tmp10 + tmp11 tmp13 = tmp0 / tmp9 tmp14 = tmp12 * tmp13 tmp17 = tmp15 + tmp16 tmp18 = tmp14 + tmp17 tmp21 = tmp19 + tmp20 tmp22 = tmp18 - tmp21 tmp23 = tl.full([1, 1], 0, tl.int32) tmp24 = triton_helpers.maximum(tmp23, tmp22) tmp25 = tmp24 + tmp21 tmp26 = 0.0 tmp27 = tmp24 <= tmp26 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp9, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp25, xmask) tl.store(out_ptr1 + (r1 + 16 * x0), tmp27, 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, 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,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = 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=buf2) del primals_2 buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf3) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf4) del primals_7 buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 buf5 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_per_fused_add_div_mean_mul_relu_sqrt_sub_threshold_backward_0[ grid(16)](buf1, buf5, primals_1, primals_3, buf3, primals_6, buf4, primals_8, buf6, buf7, 16, 16, XBLOCK=8, num_warps=2, num_stages=1) del buf3 del buf4 del buf5 del primals_3 del primals_6 del primals_8 return buf6, primals_1, reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0), reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), buf7 class AdaptiveFilterResponseNormNew(nn.Module): def __init__(self, in_size, ada_size, eps=1e-16): super().__init__() self.eps = eps self.in_size = in_size self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) self.threshold = nn.Linear(ada_size, in_size) def forward(self, input_0, input_1): primals_2 = self.scale.weight primals_3 = self.scale.bias primals_5 = self.bias.weight primals_6 = self.bias.bias primals_7 = self.threshold.weight primals_8 = self.threshold.bias primals_1 = 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]
ankmathur96/torchsupport
AdaptiveFilterResponseNorm
false
3,168
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
DepthWiseSeparableConv1d
import torch import torch.nn as nn import torch.jit import torch.nn class DepthWiseSeparableConv1d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, bias=True): """Depthwise separable 1D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv1d` for details. """ super(DepthWiseSeparableConv1d, self).__init__() self.depth_conv = nn.Conv1d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv1d(in_channels, out_channels, 1) def forward(self, input): return self.point_conv(self.depth_conv(input)) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x0, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_1, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 1), (4, 1, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(4)](buf1, primals_2, 4, XBLOCK= 4, num_warps=1, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (1, 4, 1 ), (0, 1, 0), 0), primals_4, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 1), (4, 1, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(4)](buf3, primals_5, 4, XBLOCK= 4, num_warps=1, num_stages=1) del primals_5 return reinterpret_tensor(buf3, (4, 1), (1, 1), 0 ), primals_1, primals_4, reinterpret_tensor(primals_3, (1, 4, 4), ( 16, 4, 1), 0), buf1 class DepthWiseSeparableConv1dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, bias=True): """Depthwise separable 1D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv1d` for details. """ super(DepthWiseSeparableConv1dNew, self).__init__() self.depth_conv = nn.Conv1d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv1d(in_channels, out_channels, 1) def forward(self, input_0): primals_1 = self.depth_conv.weight primals_2 = self.depth_conv.bias primals_4 = self.point_conv.weight primals_5 = self.point_conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ankmathur96/torchsupport
DepthWiseSeparableConv1d
false
3,169
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
SemiNorm
import torch import torch.nn as nn from torch.nn.utils import spectral_norm import torch.jit import torch.nn from torch.nn.utils.spectral_norm import spectral_norm class SemiNorm(nn.Module): def __init__(self, in_size, normalization=None): super().__init__() normalization = normalization or spectral_norm self.norm = nn.Linear(2 * in_size, in_size) self.bn = nn.LayerNorm(in_size) def forward(self, inputs): out = inputs.view(inputs.size(0), inputs.size(1), -1) mean = out.mean(dim=-1) std = out.std(dim=-1) out = self.bn(inputs) out = out.view(out.size(0), out.size(1), -1) features = self.norm(torch.cat((mean, std), dim=1)) out = out + features.unsqueeze(-1) return out.view(inputs.shape) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn.utils import spectral_norm import torch.jit import torch.nn from torch.nn.utils.spectral_norm import spectral_norm assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_mean_std_0(in_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 x2 = xindex % 4 x3 = xindex // 4 tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 16, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 16.0 tmp20 = tmp4 / tmp19 tmp21 = 15.0 tmp22 = tmp18 / tmp21 tmp23 = libdevice.sqrt(tmp22) tl.store(out_ptr2 + (x2 + 8 * x3), tmp20, xmask) tl.store(out_ptr3 + (x2 + 8 * x3), tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_add_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x4 = xindex // 16 x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x3 // 4, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x3 // 4, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x3 % 4, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x3 % 4, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr5 + x4, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr6 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tmp11 = tmp9 + tmp10 tmp12 = tmp8 + tmp11 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,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 8), (8, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf8 = empty_strided_cuda((4, 8), (8, 1), torch.float32) buf6 = reinterpret_tensor(buf8, (4, 4), (8, 1), 0) buf7 = reinterpret_tensor(buf8, (4, 4), (8, 1), 4) get_raw_stream(0) triton_per_fused_mean_std_0[grid(16)](primals_1, buf6, buf7, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused_native_layer_norm_1[grid(64)](primals_1, buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf8, reinterpret_tensor(primals_4, (8, 4), (1, 8 ), 0), out=buf9) del primals_4 buf10 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) triton_poi_fused_add_2[grid(256)](primals_1, buf4, buf5, primals_2, primals_3, buf9, primals_5, buf10, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf4 del buf5 del buf9 del primals_2 del primals_3 del primals_5 return reinterpret_tensor(buf10, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, buf8 class SemiNormNew(nn.Module): def __init__(self, in_size, normalization=None): super().__init__() normalization = normalization or spectral_norm self.norm = nn.Linear(2 * in_size, in_size) self.bn = nn.LayerNorm(in_size) def forward(self, input_0): primals_4 = self.norm.weight primals_2 = self.norm.bias primals_3 = self.bn.weight primals_5 = self.bn.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ankmathur96/torchsupport
SemiNorm
false
3,170
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
ScaleNorm
import torch import torch.nn as nn import torch.jit import torch.nn class ScaleNorm(nn.Module): def __init__(self, *args): super().__init__() self.scale = nn.Parameter(torch.tensor(1.0, dtype=torch.float)) def forward(self, inputs): out = inputs.view(inputs.size(0), -1) norm = out.norm(dim=1, keepdim=True) out = self.scale * out / (norm + 1e-16) return out.view(*inputs.shape) 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 import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_linalg_vector_norm_mul_0(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp9 = tl.load(in_ptr1 + 0) tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK]) tmp1 = tmp0 * tmp0 tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp4 = tl.where(xmask, tmp2, 0) tmp5 = tl.sum(tmp4, 1)[:, None] tmp6 = libdevice.sqrt(tmp5) tmp7 = 1e-16 tmp8 = tmp6 + tmp7 tmp11 = tmp10 * tmp0 tmp12 = tmp11 / tmp8 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr0 + (r1 + 64 * x0), tmp12, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (), ()) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32) buf1 = reinterpret_tensor(buf0, (4, 1), (1, 1), 0) del buf0 buf2 = empty_strided_cuda((4, 64), (64, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_linalg_vector_norm_mul_0[grid(4)](buf1, primals_1, primals_2, buf2, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_2 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), primals_1, buf1 class ScaleNormNew(nn.Module): def __init__(self, *args): super().__init__() self.scale = nn.Parameter(torch.tensor(1.0, dtype=torch.float)) def forward(self, input_0): primals_2 = self.scale primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
ankmathur96/torchsupport
ScaleNorm
false
3,171
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
AuxiliaryConvolutions
import torch import torch.utils.data from torch import nn import torch.nn.functional as F from itertools import product as product import torch.optim class AuxiliaryConvolutions(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutions, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, conv7_feats): """ Forward propagation. :param conv7_feats: lower-level conv7 feature map, a tensor of dimensions (N, 1024, 19, 19) :return: higher-level feature maps conv8_2, conv9_2, conv10_2, and conv11_2 """ out = F.relu(self.conv8_1(conv7_feats)) out = F.relu(self.conv8_2(out)) conv8_2_feats = out out = F.relu(self.conv9_1(out)) out = F.relu(self.conv9_2(out)) conv9_2_feats = out out = F.relu(self.conv10_1(out)) out = F.relu(self.conv10_2(out)) conv10_2_feats = out out = F.relu(self.conv11_1(out)) conv11_2_feats = F.relu(self.conv11_2(out)) return conv8_2_feats, conv9_2_feats, conv10_2_feats, conv11_2_feats def get_inputs(): return [torch.rand([4, 1024, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.utils.data from torch import nn from itertools import product as product import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, YBLOCK], True, tl.int1) x2 = xindex y3 = yindex y0 = yindex % 1024 y1 = yindex // 1024 tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), None) tl.store(out_ptr0 + (y0 + 1024 * x2 + 4194304 * y1), tmp0, None) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1) ) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 256 y1 = yindex // 256 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): xnumel = 9 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 128 y1 = yindex // 128 tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last' ) tl.store(out_ptr0 + (y0 + 128 * x2 + 1152 * y1), tmp0, xmask) @triton.jit def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 1024 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 512 y1 = yindex // 512 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 512 * x2 + 524288 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x2 + 1024 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 512 * x2 + 524288 * y1), tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_6(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 256 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 256 y1 = yindex // 256 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 65536 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x2 + 256 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 256 * x2 + 65536 * y1), tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_8(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 196 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 256 y1 = yindex // 256 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 50176 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x2 + 196 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 256 * x2 + 50176 * y1), tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_10(in_ptr0, in_ptr1, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): xnumel = 144 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] tl.full([XBLOCK, YBLOCK], True, tl.int1) xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 256 y1 = yindex // 256 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 36864 * y1), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1, 1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x2 + 144 * y3), tmp4, xmask) tl.store(out_ptr1 + (y0 + 256 * x2 + 36864 * y1), tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17) = args args.clear() assert_size_stride(primals_1, (256, 1024, 1, 1), (1024, 1, 1, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 1024, 64, 64), (4194304, 4096, 64, 1)) assert_size_stride(primals_4, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_5, (512,), (1,)) assert_size_stride(primals_6, (128, 512, 1, 1), (512, 1, 1, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (256,), (1,)) assert_size_stride(primals_10, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_11, (128,), (1,)) assert_size_stride(primals_12, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (128, 256, 1, 1), (256, 1, 1, 1)) assert_size_stride(primals_15, (128,), (1,)) assert_size_stride(primals_16, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_17, (256,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1024, 64, 64), (4194304, 1, 65536, 1024), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(4096, 4096)](primals_3, buf0, 4096, 4096, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del primals_3 buf1 = empty_strided_cuda((512, 256, 3, 3), (2304, 1, 768, 256), torch.float32) triton_poi_fused_1[grid(131072, 9)](primals_4, buf1, 131072, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_2[grid(32768, 9)](primals_8, buf2, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_8 buf3 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_2[grid(32768, 9)](primals_12, buf3, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_12 buf4 = empty_strided_cuda((256, 128, 3, 3), (1152, 1, 384, 128), torch.float32) triton_poi_fused_2[grid(32768, 9)](primals_16, buf4, 32768, 9, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1) del primals_16 buf5 = extern_kernels.convolution(buf0, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 256, 64, 64), (1048576, 1, 16384, 256)) buf6 = buf5 del buf5 triton_poi_fused_convolution_relu_3[grid(4194304)](buf6, primals_2, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf7 = extern_kernels.convolution(buf6, buf1, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 512, 32, 32), (524288, 1, 16384, 512)) buf8 = empty_strided_cuda((4, 512, 32, 32), (524288, 1024, 32, 1), torch.float32) buf9 = empty_strided_cuda((4, 512, 32, 32), (524288, 1, 16384, 512), torch.float32) triton_poi_fused_convolution_relu_4[grid(2048, 1024)](buf7, primals_5, buf8, buf9, 2048, 1024, XBLOCK=64, YBLOCK=64, num_warps=8, num_stages=1) del buf7 del primals_5 buf10 = extern_kernels.convolution(buf9, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf10, (4, 128, 32, 32), (131072, 1, 4096, 128)) del buf9 buf11 = buf10 del buf10 triton_poi_fused_convolution_relu_5[grid(524288)](buf11, primals_7, 524288, XBLOCK=1024, num_warps=4, num_stages=1) del primals_7 buf12 = extern_kernels.convolution(buf11, buf2, stride=(2, 2), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 256, 16, 16), (65536, 1, 4096, 256)) buf13 = empty_strided_cuda((4, 256, 16, 16), (65536, 256, 16, 1), torch.float32) buf14 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256), torch.float32) triton_poi_fused_convolution_relu_6[grid(1024, 256)](buf12, primals_9, buf13, buf14, 1024, 256, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf12 del primals_9 buf15 = extern_kernels.convolution(buf14, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 128, 16, 16), (32768, 1, 2048, 128)) del buf14 buf16 = buf15 del buf15 triton_poi_fused_convolution_relu_7[grid(131072)](buf16, primals_11, 131072, XBLOCK=512, num_warps=8, num_stages=1) del primals_11 buf17 = extern_kernels.convolution(buf16, buf3, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf17, (4, 256, 14, 14), (50176, 1, 3584, 256)) buf18 = empty_strided_cuda((4, 256, 14, 14), (50176, 196, 14, 1), torch.float32) buf19 = empty_strided_cuda((4, 256, 14, 14), (50176, 1, 3584, 256), torch.float32) triton_poi_fused_convolution_relu_8[grid(1024, 196)](buf17, primals_13, buf18, buf19, 1024, 196, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1) del buf17 del primals_13 buf20 = extern_kernels.convolution(buf19, primals_14, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 128, 14, 14), (25088, 1, 1792, 128)) del buf19 buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_9[grid(100352)](buf21, primals_15, 100352, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf22 = extern_kernels.convolution(buf21, buf4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 256, 12, 12), (36864, 1, 3072, 256)) buf23 = empty_strided_cuda((4, 256, 12, 12), (36864, 144, 12, 1), torch.float32) buf24 = empty_strided_cuda((4, 256, 12, 12), (36864, 1, 3072, 256), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_10[grid(1024, 144) ](buf22, primals_17, buf23, buf24, 1024, 144, XBLOCK=64, YBLOCK =64, num_warps=8, num_stages=1) del buf22 del primals_17 return (buf8, buf13, buf18, buf23, primals_1, buf0, buf1, primals_6, buf2, primals_10, buf3, primals_14, buf4, buf6, buf8, buf11, buf13, buf16, buf18, buf21, buf24) class AuxiliaryConvolutionsNew(nn.Module): """ Additional convolutions to produce higher-level feature maps. """ def __init__(self): super(AuxiliaryConvolutionsNew, self).__init__() self.conv8_1 = nn.Conv2d(1024, 256, kernel_size=1, padding=0) self.conv8_2 = nn.Conv2d(256, 512, kernel_size=3, stride=2, padding=1) self.conv9_1 = nn.Conv2d(512, 128, kernel_size=1, padding=0) self.conv9_2 = nn.Conv2d(128, 256, kernel_size=3, stride=2, padding=1) self.conv10_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv10_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.conv11_1 = nn.Conv2d(256, 128, kernel_size=1, padding=0) self.conv11_2 = nn.Conv2d(128, 256, kernel_size=3, padding=0) self.init_conv2d() def init_conv2d(self): """ Initialize convolution parameters. """ for c in self.children(): if isinstance(c, nn.Conv2d): nn.init.xavier_uniform_(c.weight) nn.init.constant_(c.bias, 0.0) def forward(self, input_0): primals_1 = self.conv8_1.weight primals_2 = self.conv8_1.bias primals_4 = self.conv8_2.weight primals_5 = self.conv8_2.bias primals_6 = self.conv9_1.weight primals_7 = self.conv9_1.bias primals_8 = self.conv9_2.weight primals_9 = self.conv9_2.bias primals_10 = self.conv10_1.weight primals_11 = self.conv10_1.bias primals_12 = self.conv10_2.weight primals_13 = self.conv10_2.bias primals_14 = self.conv11_1.weight primals_15 = self.conv11_1.bias primals_16 = self.conv11_2.weight primals_17 = self.conv11_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17]) return output[0], output[1], output[2], output[3]
adityag6994/pytorch_ssd_training
AuxiliaryConvolutions
false
3,172
[ "MIT" ]
0
404f3cbef815e314337ec2c1b4f06a2403a7ce03
https://github.com/adityag6994/pytorch_ssd_training/tree/404f3cbef815e314337ec2c1b4f06a2403a7ce03
neuralNet
import torch import torch.nn as nn import torch.nn.functional as F class neuralNet(nn.Module): def __init__(self): super(neuralNet, self).__init__() self.conv1 = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5) self.conv2 = nn.Conv2d(in_channels=6, out_channels=12, kernel_size=5) self.conv3 = nn.Conv2d(in_channels=12, out_channels=24, kernel_size=5) self.conv4 = nn.Conv2d(in_channels=24, out_channels=48, kernel_size=5) self.fc1 = nn.Linear(in_features=48 * 12 * 12, out_features=240) self.fc2 = nn.Linear(in_features=240, out_features=120) self.out = nn.Linear(in_features=120, out_features=17) def forward(self, t): t = t t = self.conv1(t) t = F.relu(t) t = F.max_pool2d(t, kernel_size=2, stride=2) t = self.conv2(t) t = F.relu(t) t = F.max_pool2d(t, kernel_size=2, stride=2) t = self.conv3(t) t = F.relu(t) t = F.max_pool2d(t, kernel_size=2, stride=2) t = self.conv4(t) t = F.relu(t) t = F.max_pool2d(t, kernel_size=2, stride=2) t = t.reshape(-1, 48 * 12 * 12) t = self.fc1(t) t = F.relu(t) t = self.fc2(t) t = F.relu(t) t = self.out(t) return t def get_inputs(): return [torch.rand([4, 3, 256, 256])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1524096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 63504 % 6 x0 = xindex % 63504 x4 = xindex // 63504 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 63520 * x4), tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 381024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 126 x1 = xindex // 126 % 126 x2 = xindex // 15876 x3 = xindex % 15876 tmp0 = tl.load(in_ptr0 + (2 * x0 + 504 * x1 + 63520 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 504 * x1 + 63520 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (252 + 2 * x0 + 504 * x1 + 63520 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (253 + 2 * x0 + 504 * x1 + 63520 * x2), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x3 + 15904 * x2), tmp6, xmask) tl.store(out_ptr1 + (x3 + 16000 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 714432 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 14884 % 12 x0 = xindex % 14884 x4 = xindex // 14884 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 14912 * x4), tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 178608 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 61 x1 = xindex // 61 % 61 x2 = xindex // 3721 x3 = xindex % 3721 tmp0 = tl.load(in_ptr0 + (2 * x0 + 244 * x1 + 14912 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 244 * x1 + 14912 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (122 + 2 * x0 + 244 * x1 + 14912 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (123 + 2 * x0 + 244 * x1 + 14912 * x2), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x3 + 3744 * x2), tmp6, xmask) tl.store(out_ptr1 + (x3 + 3840 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 311904 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3249 % 24 x0 = xindex % 3249 x4 = xindex // 3249 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(out_ptr0 + (x0 + 3264 * x4), tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 75264 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 28 x1 = xindex // 28 % 28 x2 = xindex // 784 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 114 * x1 + 3264 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 114 * x1 + 3264 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (57 + 2 * x0 + 114 * x1 + 3264 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (58 + 2 * x0 + 114 * x1 + 3264 * x2), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr1 + x3, tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 576 % 48 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_7(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 27648 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 12 x1 = xindex // 12 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 48 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 48 * x1), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (24 + 2 * x0 + 48 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (25 + 2 * x0 + 48 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x2, tmp15, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_relu_8(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 960 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 240 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_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 480 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 120 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15) = args args.clear() assert_size_stride(primals_1, (4, 3, 256, 256), (196608, 65536, 256, 1)) assert_size_stride(primals_2, (6, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_3, (6,), (1,)) assert_size_stride(primals_4, (12, 6, 5, 5), (150, 25, 5, 1)) assert_size_stride(primals_5, (12,), (1,)) assert_size_stride(primals_6, (24, 12, 5, 5), (300, 25, 5, 1)) assert_size_stride(primals_7, (24,), (1,)) assert_size_stride(primals_8, (48, 24, 5, 5), (600, 25, 5, 1)) assert_size_stride(primals_9, (48,), (1,)) assert_size_stride(primals_10, (240, 6912), (6912, 1)) assert_size_stride(primals_11, (240,), (1,)) assert_size_stride(primals_12, (120, 240), (240, 1)) assert_size_stride(primals_13, (120,), (1,)) assert_size_stride(primals_14, (17, 120), (120, 1)) assert_size_stride(primals_15, (17,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 6, 252, 252), (381024, 63504, 252, 1)) buf1 = empty_strided_cuda((4, 6, 252, 252), (381120, 63520, 252, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(1524096)](buf0, primals_3, buf1, 1524096, XBLOCK=1024, num_warps=4, num_stages=1) del buf0 del primals_3 buf2 = empty_strided_cuda((4, 6, 126, 126), (95424, 15904, 126, 1), torch.float32) buf3 = empty_strided_cuda((4, 6, 126, 126), (96000, 16000, 126, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(381024)](buf1, buf2, buf3, 381024, XBLOCK=512, num_warps=8, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 12, 122, 122), (178608, 14884, 122, 1)) buf5 = empty_strided_cuda((4, 12, 122, 122), (178944, 14912, 122, 1 ), torch.float32) triton_poi_fused_convolution_relu_2[grid(714432)](buf4, primals_5, buf5, 714432, XBLOCK=512, num_warps=8, num_stages=1) del buf4 del primals_5 buf6 = empty_strided_cuda((4, 12, 61, 61), (44928, 3744, 61, 1), torch.float32) buf7 = empty_strided_cuda((4, 12, 61, 61), (46080, 3840, 61, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_3[grid(178608)](buf5, buf6, buf7, 178608, XBLOCK=512, num_warps=8, num_stages=1) buf8 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 24, 57, 57), (77976, 3249, 57, 1)) buf9 = empty_strided_cuda((4, 24, 57, 57), (78336, 3264, 57, 1), torch.float32) triton_poi_fused_convolution_relu_4[grid(311904)](buf8, primals_7, buf9, 311904, XBLOCK=512, num_warps=8, num_stages=1) del buf8 del primals_7 buf10 = empty_strided_cuda((4, 24, 28, 28), (18816, 784, 28, 1), torch.float32) buf11 = empty_strided_cuda((4, 24, 28, 28), (18816, 784, 28, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(75264)](buf9, buf10, buf11, 75264, XBLOCK=512, num_warps=8, num_stages=1) buf12 = extern_kernels.convolution(buf10, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 48, 24, 24), (27648, 576, 24, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_6[grid(110592)](buf13, primals_9, 110592, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf14 = empty_strided_cuda((4, 48, 12, 12), (6912, 144, 12, 1), torch.int8) buf15 = empty_strided_cuda((4, 48, 12, 12), (6912, 144, 12, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_7[grid(27648)](buf13, buf14, buf15, 27648, XBLOCK=256, num_warps=4, num_stages=1) buf16 = empty_strided_cuda((4, 240), (240, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf15, (4, 6912), (6912, 1), 0 ), reinterpret_tensor(primals_10, (6912, 240), (1, 6912), 0), out=buf16) buf17 = buf16 del buf16 triton_poi_fused_relu_8[grid(960)](buf17, primals_11, 960, XBLOCK= 256, num_warps=4, num_stages=1) del primals_11 buf18 = empty_strided_cuda((4, 120), (120, 1), torch.float32) extern_kernels.mm(buf17, reinterpret_tensor(primals_12, (240, 120), (1, 240), 0), out=buf18) buf19 = buf18 del buf18 triton_poi_fused_relu_9[grid(480)](buf19, primals_13, 480, XBLOCK= 256, num_warps=4, num_stages=1) del primals_13 buf20 = empty_strided_cuda((4, 17), (17, 1), torch.float32) extern_kernels.addmm(primals_15, buf19, reinterpret_tensor( primals_14, (120, 17), (1, 120), 0), alpha=1, beta=1, out=buf20) del primals_15 return (buf20, primals_1, primals_2, primals_4, primals_6, primals_8, buf1, buf2, buf3, buf5, buf6, buf7, buf9, buf10, buf11, buf13, buf14, reinterpret_tensor(buf15, (4, 6912), (6912, 1), 0), buf17, buf19, primals_14, primals_12, primals_10) class neuralNetNew(nn.Module): def __init__(self): super(neuralNetNew, self).__init__() self.conv1 = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5) self.conv2 = nn.Conv2d(in_channels=6, out_channels=12, kernel_size=5) self.conv3 = nn.Conv2d(in_channels=12, out_channels=24, kernel_size=5) self.conv4 = nn.Conv2d(in_channels=24, out_channels=48, kernel_size=5) self.fc1 = nn.Linear(in_features=48 * 12 * 12, out_features=240) self.fc2 = nn.Linear(in_features=240, out_features=120) self.out = nn.Linear(in_features=120, out_features=17) def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.conv3.weight primals_7 = self.conv3.bias primals_8 = self.conv4.weight primals_9 = self.conv4.bias primals_10 = self.fc1.weight primals_11 = self.fc1.bias primals_12 = self.fc2.weight primals_13 = self.fc2.bias primals_14 = self.out.weight primals_15 = self.out.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]
ayushmaan02/Plant-Disease-Detection
neuralNet
false
3,173
[ "MIT" ]
0
35e5b8112e933fd558a80a1e5350df541c29bd6b
https://github.com/ayushmaan02/Plant-Disease-Detection/tree/35e5b8112e933fd558a80a1e5350df541c29bd6b
Splitter
import torch import numpy as np class Splitter(torch.nn.Module): """ An implementation of "Splitter: Learning Node Representations that Capture Multiple Social Contexts" (WWW 2019). Paper: http://epasto.org/papers/www2019splitter.pdf """ def __init__(self, dimensions, lambd, base_node_count, node_count, device): """ Splitter set up. :param dimensions: Dimension of embedding vectors :param lambd: Parameter that determine how much personas spread from original embedding :param base_node_count: Number of nodes in the source graph. :param node_count: Number of nodes in the persona graph. :param device: Device which torch use """ super(Splitter, self).__init__() self.dimensions = dimensions self.lambd = lambd self.base_node_count = base_node_count self.node_count = node_count self.device = device def create_weights(self): """ Creating weights for embedding. """ self.base_node_embedding = torch.nn.Embedding(self.base_node_count, self.dimensions, padding_idx=0) self.node_embedding = torch.nn.Embedding(self.node_count, self. dimensions, padding_idx=0) def initialize_weights(self, base_node_embedding, mapping, str2idx): """ Using the base embedding and the persona mapping for initializing the embedding matrices. :param base_node_embedding: Node embedding of the source graph. :param mapping: Mapping of personas to nodes. :param str2idx: Mapping string of original network to index in original network """ persona_embedding = np.array([base_node_embedding[str2idx[ original_node]] for node, original_node in mapping.items()]) self.node_embedding.weight.data = torch.nn.Parameter(torch.Tensor( persona_embedding)) self.base_node_embedding.weight.data = torch.nn.Parameter(torch. Tensor(base_node_embedding), requires_grad=False) def calculate_main_loss(self, node_f, feature_f, targets): """ Calculating the main loss which is used to learning based on persona random walkers It will be act likes centrifugal force from the base embedding :param node_f: Embedding vectors of source nodes :param feature_f: Embedding vectors of target nodes to predict :param targets: Boolean vector whether negative samples or not """ node_f = torch.nn.functional.normalize(node_f, p=2, dim=1) feature_f = torch.nn.functional.normalize(feature_f, p=2, dim=1) scores = torch.sum(node_f * feature_f, dim=1) scores = torch.sigmoid(scores) main_loss = targets * torch.log(scores) + (1 - targets) * torch.log( 1 - scores) main_loss = -torch.mean(main_loss) return main_loss def calculate_regularization(self, source_f, original_f): """ Calculating the main loss which is used to learning based on persona random walkers It will be act likes centripetal force from the base embedding :param source_f: Embedding vectors of source nodes :param original_f: Embedding vectors of base embedding of source nodes """ source_f = torch.nn.functional.normalize(source_f, p=2, dim=1) original_f = torch.nn.functional.normalize(original_f, p=2, dim=1) scores = torch.sum(source_f * original_f, dim=1) scores = torch.sigmoid(scores) regularization_loss = -torch.mean(torch.log(scores)) return regularization_loss def forward(self, node_f, feature_f, targets, source_f, original_f): """ 1.main loss part :param node_f: Embedding vectors of source nodes :param feature_f: Embedding vectors of target nodes to predict :param targets: Boolean vector whether negative samples or not 2.regularization part :param source_f: Embedding vectors of source nodes :param original_f: Embedding vectors of base embedding of source nodes """ main_loss = self.calculate_main_loss(node_f, feature_f, targets) regularization_loss = self.calculate_regularization(source_f, original_f) loss = main_loss + self.lambd * regularization_loss return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dimensions': 4, 'lambd': 4, 'base_node_count': 4, 'node_count': 4, 'device': 0}]
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 numpy as np assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_div_mul_0(in_ptr0, 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 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') tmp16 = tl.load(in_ptr1 + x3, xmask) tmp17 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp22 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp25 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = libdevice.sqrt(tmp11) tmp13 = 1e-12 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = tmp0 / tmp14 tmp18 = tmp17 * tmp17 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = libdevice.sqrt(tmp27) tmp29 = triton_helpers.maximum(tmp28, tmp13) tmp30 = tmp16 / tmp29 tmp31 = tmp15 * tmp30 tl.store(out_ptr0 + x3, tmp31, xmask) @triton.jit def triton_per_fused_add_log_mean_mul_rsub_sigmoid_sum_1(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) r3 = rindex r0 = rindex % 16 r1 = rindex // 16 % 4 tmp0 = tl.load(in_ptr0 + r3, None) tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None, eviction_policy='evict_last' ) tmp2 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tl.sigmoid(tmp7) tmp9 = tl_math.log(tmp8) tmp10 = tmp0 * tmp9 tmp11 = 1.0 tmp12 = tmp11 - tmp0 tmp13 = tmp11 - tmp8 tmp14 = tl_math.log(tmp13) tmp15 = tmp12 * tmp14 tmp16 = tmp10 + tmp15 tmp17 = tl.broadcast_to(tmp16, [RBLOCK]) tmp19 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0)) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp19, None) @triton.jit def triton_per_fused_add_log_mean_mul_neg_rsub_sigmoid_sum_2(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex % 16 r1 = rindex // 16 tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None) tmp1 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp3 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp5 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp12 = tl.load(in_out_ptr0 + 0) tmp13 = tl.broadcast_to(tmp12, [XBLOCK, 1]) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp8 = tl_math.log(tmp7) tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.sum(tmp9, 1)[:, None] tmp14 = 256.0 tmp15 = tmp13 / tmp14 tmp16 = -tmp15 tmp17 = 64.0 tmp18 = tmp11 / tmp17 tmp19 = -tmp18 tmp20 = 4.0 tmp21 = tmp19 * tmp20 tmp22 = tmp16 + tmp21 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp22, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1, arg4_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg4_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_mul_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) triton_per_fused_add_log_mean_mul_rsub_sigmoid_sum_1[grid(1)](arg2_1, buf0, buf1, 1, 256, num_warps=2, num_stages=1) del arg2_1 buf2 = buf0 del buf0 triton_poi_fused_div_mul_0[grid(256)](arg3_1, arg4_1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg3_1 del arg4_1 buf4 = buf1 del buf1 triton_per_fused_add_log_mean_mul_neg_rsub_sigmoid_sum_2[grid(1)](buf4, buf2, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf2 return buf4, class SplitterNew(torch.nn.Module): """ An implementation of "Splitter: Learning Node Representations that Capture Multiple Social Contexts" (WWW 2019). Paper: http://epasto.org/papers/www2019splitter.pdf """ def __init__(self, dimensions, lambd, base_node_count, node_count, device): """ Splitter set up. :param dimensions: Dimension of embedding vectors :param lambd: Parameter that determine how much personas spread from original embedding :param base_node_count: Number of nodes in the source graph. :param node_count: Number of nodes in the persona graph. :param device: Device which torch use """ super(SplitterNew, self).__init__() self.dimensions = dimensions self.lambd = lambd self.base_node_count = base_node_count self.node_count = node_count self.device = device def create_weights(self): """ Creating weights for embedding. """ self.base_node_embedding = torch.nn.Embedding(self.base_node_count, self.dimensions, padding_idx=0) self.node_embedding = torch.nn.Embedding(self.node_count, self. dimensions, padding_idx=0) def initialize_weights(self, base_node_embedding, mapping, str2idx): """ Using the base embedding and the persona mapping for initializing the embedding matrices. :param base_node_embedding: Node embedding of the source graph. :param mapping: Mapping of personas to nodes. :param str2idx: Mapping string of original network to index in original network """ persona_embedding = np.array([base_node_embedding[str2idx[ original_node]] for node, original_node in mapping.items()]) self.node_embedding.weight.data = torch.nn.Parameter(torch.Tensor( persona_embedding)) self.base_node_embedding.weight.data = torch.nn.Parameter(torch. Tensor(base_node_embedding), requires_grad=False) def calculate_main_loss(self, node_f, feature_f, targets): """ Calculating the main loss which is used to learning based on persona random walkers It will be act likes centrifugal force from the base embedding :param node_f: Embedding vectors of source nodes :param feature_f: Embedding vectors of target nodes to predict :param targets: Boolean vector whether negative samples or not """ node_f = torch.nn.functional.normalize(node_f, p=2, dim=1) feature_f = torch.nn.functional.normalize(feature_f, p=2, dim=1) scores = torch.sum(node_f * feature_f, dim=1) scores = torch.sigmoid(scores) main_loss = targets * torch.log(scores) + (1 - targets) * torch.log( 1 - scores) main_loss = -torch.mean(main_loss) return main_loss def calculate_regularization(self, source_f, original_f): """ Calculating the main loss which is used to learning based on persona random walkers It will be act likes centripetal force from the base embedding :param source_f: Embedding vectors of source nodes :param original_f: Embedding vectors of base embedding of source nodes """ source_f = torch.nn.functional.normalize(source_f, p=2, dim=1) original_f = torch.nn.functional.normalize(original_f, p=2, dim=1) scores = torch.sum(source_f * original_f, dim=1) scores = torch.sigmoid(scores) regularization_loss = -torch.mean(torch.log(scores)) return regularization_loss def forward(self, input_0, input_1, input_2, input_3, input_4): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 arg4_1 = input_4 output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1]) return output[0]
balla2081/SpliiterPytorch
Splitter
false
3,174
[ "MIT" ]
0
366742166470dc730fe761bae081779d737e1315
https://github.com/balla2081/SpliiterPytorch/tree/366742166470dc730fe761bae081779d737e1315
DecoderLayer
import math import torch import torch.nn as nn import torch.nn.functional as F class MultiHeadAttention(nn.Module): def __init__(self, heads, d_model, dropout=0.1): super().__init__() self.d_model = d_model self.d_k = d_model // heads self.h = heads self.q_linear = nn.Linear(d_model, d_model) self.v_linear = nn.Linear(d_model, d_model) self.k_linear = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.out = nn.Linear(d_model, d_model) def forward(self, q, k, v, mask=None): bs = q.size(0) k = self.k_linear(k).view(bs, -1, self.h, self.d_k) q = self.q_linear(q).view(bs, -1, self.h, self.d_k) v = self.v_linear(v).view(bs, -1, self.h, self.d_k) k = k.transpose(1, 2) q = q.transpose(1, 2) v = v.transpose(1, 2) scores = self.attention(q, k, v, self.d_k, mask, self.dropout) concat = scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model) output = self.out(concat) return output def attention(self, q, k, v, d_k, mask=None, dropout=None): scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k) if mask is not None: mask = mask.unsqueeze(1) scores = scores.masked_fill(mask == 0, -1000000000.0) scores = F.softmax(scores, dim=-1) if dropout is not None: scores = dropout(scores) output = torch.matmul(scores, v) return output class Norm(nn.Module): def __init__(self, d_model, eps=1e-06): super().__init__() self.size = d_model self.alpha = nn.Parameter(torch.ones(self.size)) self.bias = nn.Parameter(torch.zeros(self.size)) self.eps = eps def forward(self, x): norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim =-1, keepdim=True) + self.eps) + self.bias return norm class FeedForward(nn.Module): def __init__(self, d_model, d_ff=2048, dropout=0.1): super().__init__() self.linear_1 = nn.Linear(d_model, d_ff) self.dropout = nn.Dropout(dropout) self.linear_2 = nn.Linear(d_ff, d_model) def forward(self, x): x = self.dropout(F.relu(self.linear_1(x))) x = self.linear_2(x) return x class DecoderLayer(nn.Module): def __init__(self, d_model, heads, dropout=0.1): super().__init__() self.norm_1 = Norm(d_model) self.norm_2 = Norm(d_model) self.norm_3 = Norm(d_model) self.dropout_1 = nn.Dropout(dropout) self.dropout_2 = nn.Dropout(dropout) self.dropout_3 = nn.Dropout(dropout) self.attn_1 = MultiHeadAttention(heads, d_model, dropout) self.attn_2 = MultiHeadAttention(heads, d_model, dropout) self.ff = FeedForward(d_model) def forward(self, x, e_outputs, src_mask, tgt_mask): x2 = self.norm_1(x) x = x + self.dropout_1(self.attn_1(x2, x2, x2, tgt_mask)) x2 = self.norm_2(x) x = x + self.dropout_2(self.attn_2(x2, e_outputs, e_outputs, src_mask)) x2 = self.norm_3(x) x = x + self.dropout_3(self.ff(x2)) return x def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'d_model': 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.nn as nn import torch.nn.functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_div_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp30 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp8 = tmp6 + tmp7 tmp9 = 4.0 tmp10 = tmp8 / tmp9 tmp11 = tmp1 - tmp10 tmp12 = tmp0 * tmp11 tmp13 = tmp2 - tmp10 tmp14 = tmp13 * tmp13 tmp15 = tmp3 - tmp10 tmp16 = tmp15 * tmp15 tmp17 = tmp14 + tmp16 tmp18 = tmp5 - tmp10 tmp19 = tmp18 * tmp18 tmp20 = tmp17 + tmp19 tmp21 = tmp7 - tmp10 tmp22 = tmp21 * tmp21 tmp23 = tmp20 + tmp22 tmp24 = 3.0 tmp25 = tmp23 / tmp24 tmp26 = libdevice.sqrt(tmp25) tmp27 = 1e-06 tmp28 = tmp26 + tmp27 tmp29 = tmp12 / tmp28 tmp31 = tmp29 + tmp30 tl.store(out_ptr0 + x2, tmp31, xmask) @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 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_eq_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.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 x0 = xindex % 4 x2 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (4 * x0 + 16 * x2), xmask, eviction_policy= 'evict_last').to(tl.int1) tmp1 = tl.load(in_ptr1 + 4 * x3, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy ='evict_last').to(tl.int1) tmp7 = tl.load(in_ptr1 + (1 + 4 * x3), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last').to(tl.int1) tmp12 = tl.load(in_ptr1 + (2 + 4 * x3), xmask, eviction_policy='evict_last' ) tmp16 = tl.load(in_ptr0 + (3 + 4 * x0 + 16 * x2), xmask, eviction_policy='evict_last').to(tl.int1) tmp17 = tl.load(in_ptr1 + (3 + 4 * x3), xmask, eviction_policy='evict_last' ) tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = -1000000000.0 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 + x3, tmp20, xmask) tl.store(out_ptr1 + x3, 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 x3 = xindex // 64 x4 = xindex % 16 x5 = xindex x6 = xindex // 4 tmp0 = tl.load(in_ptr0 + (x4 + 16 * x3), xmask, eviction_policy= 'evict_last').to(tl.int1) tmp1 = tl.load(in_out_ptr0 + x5, xmask) tmp6 = tl.load(in_ptr1 + x6, xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr2 + x6, xmask, eviction_policy='evict_last') tmp2 = 1.0 tmp3 = tmp1 * tmp2 tmp4 = -1000000000.0 tmp5 = tl.where(tmp0, tmp4, tmp3) tmp7 = tmp5 - tmp6 tmp8 = tl_math.exp(tmp7) tmp10 = tmp8 / tmp9 tl.store(in_out_ptr0 + x5, tmp10, xmask) @triton.jit def triton_poi_fused_clone_5(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_mean_std_6(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = 3.0 tmp29 = tmp27 / tmp28 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(in_out_ptr0 + x0, tmp29, xmask) @triton.jit def triton_poi_fused_add_div_mean_mul_std_sub_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp2 = tl.load(in_ptr2 + x2, xmask) tmp4 = 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') tmp3 = tmp1 + tmp2 tmp5 = tmp3 - tmp4 tmp6 = tmp0 * tmp5 tmp8 = libdevice.sqrt(tmp7) tmp9 = 1e-06 tmp10 = tmp8 + tmp9 tmp11 = tmp6 / tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) @triton.jit def triton_poi_fused_add_8(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_out_ptr0 + x2, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tl.store(in_out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_9(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 % 2048 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) 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_add_10(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_out_ptr0 + x2, xmask) tmp2 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x2, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30) = args args.clear() assert_size_stride(primals_1, (4,), (1,)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) assert_size_stride(primals_8, (4, 4), (4, 1)) assert_size_stride(primals_9, (4,), (1,)) assert_size_stride(primals_10, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_11, (4, 4), (4, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4,), (1,)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (4, 4), (4, 1)) assert_size_stride(primals_16, (4,), (1,)) assert_size_stride(primals_17, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_18, (4, 4), (4, 1)) assert_size_stride(primals_19, (4,), (1,)) assert_size_stride(primals_20, (4, 4), (4, 1)) assert_size_stride(primals_21, (4,), (1,)) assert_size_stride(primals_22, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_23, (4, 4), (4, 1)) assert_size_stride(primals_24, (4,), (1,)) assert_size_stride(primals_25, (4,), (1,)) assert_size_stride(primals_26, (4,), (1,)) assert_size_stride(primals_27, (2048, 4), (4, 1)) assert_size_stride(primals_28, (2048,), (1,)) assert_size_stride(primals_29, (4, 2048), (2048, 1)) assert_size_stride(primals_30, (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_add_div_mean_mul_std_sub_0[grid(64)](primals_1, primals_2, primals_3, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 del primals_3 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf2) buf3 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf3) buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_1[grid(16, 4)](buf2, primals_7, buf4, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_7 buf5 = reinterpret_tensor(buf2, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf2 triton_poi_fused_clone_1[grid(16, 4)](buf1, primals_5, buf5, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_5 buf6 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 0), out=buf6) buf7 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.bool) triton_poi_fused_eq_2[grid(64)](primals_10, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_10 buf8 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf1 buf9 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_div_masked_fill_3[grid(64)](buf7, buf6, buf8, buf9, 64, XBLOCK=64, num_warps=1, num_stages=1) buf10 = reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf6 triton_poi_fused__softmax_div_masked_fill_4[grid(256)](buf10, buf7, buf8, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1) buf11 = reinterpret_tensor(buf9, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf9 triton_poi_fused_clone_1[grid(16, 4)](buf3, primals_9, buf11, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_9 buf12 = reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 1), 0) del buf3 extern_kernels.bmm(reinterpret_tensor(buf10, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf11, (16, 4, 1), (4, 1, 0), 0), out=buf12) buf13 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf8 triton_poi_fused_clone_5[grid(16, 4)](buf12, buf13, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf14 = reinterpret_tensor(buf12, (16, 4), (4, 1), 0) del buf12 extern_kernels.addmm(primals_12, reinterpret_tensor(buf13, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf14) del primals_12 buf15 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf16 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf17 = buf16 del buf16 triton_poi_fused_add_mean_std_6[grid(16)](buf17, primals_2, buf14, buf15, 16, XBLOCK=16, num_warps=1, num_stages=1) buf18 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_17, (16, 4), (4, 1), 0 ), reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), out=buf18) del primals_15 buf19 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_std_sub_7[grid(64)](primals_13, primals_2, buf14, buf15, buf17, primals_14, buf19, 64, XBLOCK= 64, num_warps=1, num_stages=1) del buf15 del buf17 del primals_14 buf20 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf19, (16, 4), (4, 1), 0), reinterpret_tensor(primals_18, (4, 4), (1, 4), 0), out=buf20) buf21 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_17, (16, 4), (4, 1), 0 ), reinterpret_tensor(primals_20, (4, 4), (1, 4), 0), out=buf21) del primals_20 buf22 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_1[grid(16, 4)](buf20, primals_19, buf22, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_19 buf23 = reinterpret_tensor(buf20, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf20 triton_poi_fused_clone_1[grid(16, 4)](buf18, primals_16, buf23, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_16 buf24 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf22, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf23, (16, 1, 4), (4, 0, 1), 0), out=buf24) buf25 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.bool) triton_poi_fused_eq_2[grid(64)](primals_22, buf25, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_22 buf26 = reinterpret_tensor(buf18, (4, 4, 4, 1), (16, 4, 1, 64), 0) del buf18 buf27 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) triton_poi_fused__softmax_div_masked_fill_3[grid(64)](buf25, buf24, buf26, buf27, 64, XBLOCK=64, num_warps=1, num_stages=1) buf28 = reinterpret_tensor(buf24, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf24 triton_poi_fused__softmax_div_masked_fill_4[grid(256)](buf28, buf25, buf26, buf27, 256, XBLOCK=128, num_warps=4, num_stages=1) buf29 = reinterpret_tensor(buf27, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf27 triton_poi_fused_clone_1[grid(16, 4)](buf21, primals_21, buf29, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del primals_21 buf30 = reinterpret_tensor(buf21, (16, 4, 1), (4, 1, 1), 0) del buf21 extern_kernels.bmm(reinterpret_tensor(buf28, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf29, (16, 4, 1), (4, 1, 0), 0), out=buf30) buf31 = reinterpret_tensor(buf26, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf26 triton_poi_fused_clone_5[grid(16, 4)](buf30, buf31, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf32 = reinterpret_tensor(buf30, (16, 4), (4, 1), 0) del buf30 extern_kernels.mm(reinterpret_tensor(buf31, (16, 4), (4, 1), 0), reinterpret_tensor(primals_23, (4, 4), (1, 4), 0), out=buf32) buf33 = reinterpret_tensor(buf32, (4, 4, 4), (16, 4, 1), 0) del buf32 triton_poi_fused_add_8[grid(64)](buf33, primals_2, buf14, primals_24, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_24 buf34 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_div_mean_mul_std_sub_0[grid(64)](primals_25, buf33, primals_26, buf34, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_26 buf35 = empty_strided_cuda((16, 2048), (2048, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf34, (16, 4), (4, 1), 0), reinterpret_tensor(primals_27, (4, 2048), (1, 4), 0), out=buf35) buf36 = reinterpret_tensor(buf35, (4, 4, 2048), (8192, 2048, 1), 0) del buf35 buf39 = empty_strided_cuda((4, 4, 2048), (8192, 2048, 1), torch.bool) triton_poi_fused_relu_threshold_backward_9[grid(32768)](buf36, primals_28, buf39, 32768, XBLOCK=256, num_warps=4, num_stages=1) del primals_28 buf37 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf36, (16, 2048), (2048, 1), 0), reinterpret_tensor(primals_29, (2048, 4), (1, 2048), 0), out=buf37) buf38 = reinterpret_tensor(buf37, (4, 4, 4), (16, 4, 1), 0) del buf37 triton_poi_fused_add_10[grid(64)](buf38, buf33, primals_30, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_30 return buf38, primals_2, primals_13, primals_25, reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf7, buf10, reinterpret_tensor(buf13, (16, 4), (4, 1), 0), buf14, reinterpret_tensor(primals_17, (16, 4), (4, 1), 0 ), reinterpret_tensor(buf19, (16, 4), (4, 1), 0 ), buf25, buf28, reinterpret_tensor(buf31, (16, 4), (4, 1), 0 ), buf33, reinterpret_tensor(buf34, (16, 4), (4, 1), 0 ), reinterpret_tensor(buf36, (16, 2048), (2048, 1), 0 ), primals_29, buf39, primals_27, primals_23, reinterpret_tensor(buf29, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf22, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf23, (16, 4, 1), (4, 1, 4), 0 ), primals_18, primals_11, reinterpret_tensor(buf11, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 1, 1), 0 ), reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0 ), primals_8, primals_6, primals_4 class MultiHeadAttention(nn.Module): def __init__(self, heads, d_model, dropout=0.1): super().__init__() self.d_model = d_model self.d_k = d_model // heads self.h = heads self.q_linear = nn.Linear(d_model, d_model) self.v_linear = nn.Linear(d_model, d_model) self.k_linear = nn.Linear(d_model, d_model) self.dropout = nn.Dropout(dropout) self.out = nn.Linear(d_model, d_model) def forward(self, q, k, v, mask=None): bs = q.size(0) k = self.k_linear(k).view(bs, -1, self.h, self.d_k) q = self.q_linear(q).view(bs, -1, self.h, self.d_k) v = self.v_linear(v).view(bs, -1, self.h, self.d_k) k = k.transpose(1, 2) q = q.transpose(1, 2) v = v.transpose(1, 2) scores = self.attention(q, k, v, self.d_k, mask, self.dropout) concat = scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model) output = self.out(concat) return output def attention(self, q, k, v, d_k, mask=None, dropout=None): scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k) if mask is not None: mask = mask.unsqueeze(1) scores = scores.masked_fill(mask == 0, -1000000000.0) scores = F.softmax(scores, dim=-1) if dropout is not None: scores = dropout(scores) output = torch.matmul(scores, v) return output class Norm(nn.Module): def __init__(self, d_model, eps=1e-06): super().__init__() self.size = d_model self.alpha = nn.Parameter(torch.ones(self.size)) self.bias = nn.Parameter(torch.zeros(self.size)) self.eps = eps def forward(self, x): norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim =-1, keepdim=True) + self.eps) + self.bias return norm class FeedForward(nn.Module): def __init__(self, d_model, d_ff=2048, dropout=0.1): super().__init__() self.linear_1 = nn.Linear(d_model, d_ff) self.dropout = nn.Dropout(dropout) self.linear_2 = nn.Linear(d_ff, d_model) def forward(self, x): x = self.dropout(F.relu(self.linear_1(x))) x = self.linear_2(x) return x class DecoderLayerNew(nn.Module): def __init__(self, d_model, heads, dropout=0.1): super().__init__() self.norm_1 = Norm(d_model) self.norm_2 = Norm(d_model) self.norm_3 = Norm(d_model) self.dropout_1 = nn.Dropout(dropout) self.dropout_2 = nn.Dropout(dropout) self.dropout_3 = nn.Dropout(dropout) self.attn_1 = MultiHeadAttention(heads, d_model, dropout) self.attn_2 = MultiHeadAttention(heads, d_model, dropout) self.ff = FeedForward(d_model) def forward(self, input_0, input_1, input_2, input_3): primals_1 = self.norm_1.alpha primals_3 = self.norm_1.bias primals_5 = self.norm_2.alpha primals_7 = self.norm_2.bias primals_9 = self.norm_3.alpha primals_12 = self.norm_3.bias primals_4 = self.attn_1.q_linear.weight primals_13 = self.attn_1.q_linear.bias primals_6 = self.attn_1.v_linear.weight primals_14 = self.attn_1.v_linear.bias primals_8 = self.attn_1.k_linear.weight primals_16 = self.attn_1.k_linear.bias primals_11 = self.attn_1.out.weight primals_19 = self.attn_1.out.bias primals_15 = self.attn_2.q_linear.weight primals_21 = self.attn_2.q_linear.bias primals_18 = self.attn_2.v_linear.weight primals_24 = self.attn_2.v_linear.bias primals_20 = self.attn_2.k_linear.weight primals_25 = self.attn_2.k_linear.bias primals_23 = self.attn_2.out.weight primals_26 = self.attn_2.out.bias primals_27 = self.ff.linear_1.weight primals_28 = self.ff.linear_1.bias primals_29 = self.ff.linear_2.weight primals_30 = self.ff.linear_2.bias primals_2 = input_0 primals_10 = input_1 primals_17 = input_2 primals_22 = input_3 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30]) return output[0]
b19e93n/PLC-Pyramid
DecoderLayer
false
3,175
[ "MIT" ]
0
6d5b57be6995a94ef7402144cee965862713b031
https://github.com/b19e93n/PLC-Pyramid/tree/6d5b57be6995a94ef7402144cee965862713b031
StandardWNetDown
import torch import torch.nn as nn import torch.jit import torch.nn class DepthWiseSeparableConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True): """Depthwise separable 2D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv2d` for details. """ super(DepthWiseSeparableConv2d, self).__init__() self.depth_conv = nn.Conv2d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv2d(in_channels, out_channels, 1) def forward(self, input): return self.point_conv(self.depth_conv(input)) class StandardWNetDown(nn.Module): def __init__(self, in_channels, out_channels, position, activation=nn. ReLU()): """ Default down convolution block for the WNet. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. position (int): position of the block within the WNet. """ super(StandardWNetDown, self).__init__() self.activation = activation if position == 0: self.block_0 = nn.Conv2d(in_channels, out_channels, 3) self.block_1 = nn.Conv2d(in_channels, out_channels, 3) else: self.block_0 = DepthWiseSeparableConv2d(in_channels, out_channels, 3) self.block_1 = DepthWiseSeparableConv2d(out_channels, out_channels, 3) def forward(self, input): return self.activation(self.block_1(self.activation(self.block_0( input)))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'position': 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.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @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_relu_threshold_backward_2(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x3, tmp4, xmask) tl.store(out_ptr0 + x3, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, 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, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 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=(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_0[grid(256)](buf1, primals_2, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_0[grid(256)](buf5, primals_7, 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 = buf6 del buf6 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_2[grid(256)](buf7, primals_9, buf8, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 return (buf7, primals_1, primals_3, primals_4, primals_6, primals_8, buf1, buf3, buf5, buf8) class DepthWiseSeparableConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True): """Depthwise separable 2D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv2d` for details. """ super(DepthWiseSeparableConv2d, self).__init__() self.depth_conv = nn.Conv2d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv2d(in_channels, out_channels, 1) def forward(self, input): return self.point_conv(self.depth_conv(input)) class StandardWNetDownNew(nn.Module): def __init__(self, in_channels, out_channels, position, activation=nn. ReLU()): """ Default down convolution block for the WNet. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. position (int): position of the block within the WNet. """ super(StandardWNetDownNew, self).__init__() self.activation = activation if position == 0: self.block_0 = nn.Conv2d(in_channels, out_channels, 3) self.block_1 = nn.Conv2d(in_channels, out_channels, 3) else: self.block_0 = DepthWiseSeparableConv2d(in_channels, out_channels, 3) self.block_1 = DepthWiseSeparableConv2d(out_channels, out_channels, 3) def forward(self, input_0): primals_1 = self.block_0.depth_conv.weight primals_2 = self.block_0.depth_conv.bias primals_4 = self.block_0.point_conv.weight primals_5 = self.block_0.point_conv.bias primals_6 = self.block_1.depth_conv.weight primals_7 = self.block_1.depth_conv.bias primals_8 = self.block_1.point_conv.weight primals_9 = self.block_1.point_conv.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]
ankmathur96/torchsupport
StandardWNetDown
false
3,176
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
AdaptiveInstanceNormPP
import torch import torch.nn as nn import torch.jit import torch.nn class AdaptiveInstanceNorm(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNorm, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, inputs, style): in_view = inputs.view(inputs.size(0), inputs.size(1), 1, 1, -1) mean = in_view.mean(dim=-1) std = in_view.std(dim=-1) scale = self.scale(style).view(style.size(0), -1, 1, 1) bias = self.bias(style).view(style.size(0), -1, 1, 1) return scale * (inputs - mean) / (std + 1e-06) + bias class AdaptiveInstanceNormPP(AdaptiveInstanceNorm): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNormPP, self).__init__(in_size, ada_size) self.mean_scale = nn.Linear(ada_size, in_size) def forward(self, inputs, style): in_view = inputs.view(inputs.size(0), inputs.size(1), 1, 1, -1) mean = in_view.mean(dim=-1) mean_mean = mean.mean(dim=1, keepdim=True) std = in_view.std(dim=-1) mean_std = mean.std(dim=1, keepdim=True) scale = self.scale(style).view(style.size(0), -1, 1, 1) mean_scale = self.mean_scale(style).view(style.size(0), -1, 1, 1) bias = self.bias(style).view(style.size(0), -1, 1, 1) result = scale * (inputs - mean) / (std + 1e-06) + bias correction = mean_scale * (mean - mean_mean) / (mean_std + 1e-06) return result + correction def get_inputs(): return [torch.rand([4, 64, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'ada_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.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_mean_std_0(in_out_ptr0, in_out_ptr1, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 256 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0) tmp1 = tl.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 = libdevice.sqrt(tmp22) tmp24 = 1e-06 tmp25 = tmp23 + tmp24 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) @triton.jit def triton_per_fused_add_div_mean_mul_std_sub_1(in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, in_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) tmp26 = tl.load(in_out_ptr2 + (r1 + 64 * x0), xmask, other=0.0) tmp27 = tl.load(in_ptr1 + r1 % 4, None, eviction_policy='evict_last') tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(xmask, tmp1, 0) tmp4 = tl.sum(tmp3, 1)[:, None] tmp6 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp8 = tl.where(xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 64, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp1 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 64.0 tmp20 = tmp4 / tmp19 tmp21 = 63.0 tmp22 = tmp18 / tmp21 tmp23 = libdevice.sqrt(tmp22) tmp24 = 1e-06 tmp25 = tmp23 + tmp24 tmp28 = tmp26 + tmp27 tmp29 = tmp0 - tmp20 tmp30 = tmp28 * tmp29 tmp31 = tmp30 / tmp25 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp20, xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x0, tmp25, xmask) tl.store(in_out_ptr2 + (r1 + 64 * x0), tmp31, xmask) @triton.jit def triton_poi_fused_add_div_mul_sub_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex // 16 x4 = xindex tmp0 = tl.load(in_ptr0 + x3, None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x4 // 16 % 64 % 4, None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + x4, None) tmp4 = tl.load(in_ptr3 + x3, None, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x3, None, eviction_policy='evict_last') tmp9 = tl.load(in_ptr5 + x3, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr6 + x4 // 16 % 64 % 4, None, eviction_policy= 'evict_last') tmp13 = tl.load(in_ptr7 + x3, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp5 = tmp3 - tmp4 tmp6 = tmp2 * tmp5 tmp8 = tmp6 / tmp7 tmp11 = tmp9 + tmp10 tmp12 = tmp8 + tmp11 tmp14 = tmp12 + tmp13 tl.store(out_ptr0 + x4, tmp14, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8) = args args.clear() assert_size_stride(primals_1, (4, 64, 4, 4), (1024, 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,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 256, 256), torch. float32) buf5 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 256, 256), torch. float32) buf1 = reinterpret_tensor(buf0, (4, 64, 1, 1), (64, 1, 1, 1), 0) del buf0 buf13 = reinterpret_tensor(buf5, (4, 64, 1, 1), (64, 1, 1, 1), 0) del buf5 get_raw_stream(0) triton_per_fused_add_mean_std_0[grid(256)](buf1, buf13, primals_1, 256, 16, XBLOCK=8, num_warps=2, num_stages=1) buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf11) del primals_5 buf2 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf8 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32) buf3 = reinterpret_tensor(buf2, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf2 buf14 = reinterpret_tensor(buf8, (4, 1, 1, 1), (1, 1, 1, 1), 0) del buf8 buf15 = reinterpret_tensor(buf11, (4, 64, 1, 1), (64, 1, 256, 256), 0) del buf11 triton_per_fused_add_div_mean_mul_std_sub_1[grid(4)](buf3, buf14, buf15, buf1, primals_6, 4, 64, XBLOCK=1, num_warps=2, num_stages=1) del primals_6 buf10 = 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=buf10) del primals_2 buf12 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf12) del primals_7 buf16 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch. float32) triton_poi_fused_add_div_mul_sub_2[grid(4096)](buf10, primals_3, primals_1, buf1, buf13, buf12, primals_8, buf15, buf16, 4096, XBLOCK=128, num_warps=4, num_stages=1) del buf10 del buf12 del buf15 del primals_3 del primals_8 return buf16, primals_1, buf1, buf3, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), buf13, buf14 class AdaptiveInstanceNorm(nn.Module): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNorm, self).__init__() self.scale = nn.Linear(ada_size, in_size) self.bias = nn.Linear(ada_size, in_size) def forward(self, inputs, style): in_view = inputs.view(inputs.size(0), inputs.size(1), 1, 1, -1) mean = in_view.mean(dim=-1) std = in_view.std(dim=-1) scale = self.scale(style).view(style.size(0), -1, 1, 1) bias = self.bias(style).view(style.size(0), -1, 1, 1) return scale * (inputs - mean) / (std + 1e-06) + bias class AdaptiveInstanceNormPPNew(AdaptiveInstanceNorm): def __init__(self, in_size, ada_size): super(AdaptiveInstanceNormPPNew, self).__init__(in_size, ada_size) self.mean_scale = nn.Linear(ada_size, in_size) def forward(self, input_0, input_1): primals_2 = self.scale.weight primals_3 = self.scale.bias primals_5 = self.bias.weight primals_6 = self.bias.bias primals_7 = self.mean_scale.weight primals_8 = self.mean_scale.bias primals_1 = 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]
ankmathur96/torchsupport
AdaptiveInstanceNormPP
false
3,177
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
NonLocal
import torch import torch.nn as nn import torch.nn.functional as func import torch.jit import torch.nn class NonLocal(nn.Module): def __init__(self, in_size, attention_size=32, size=None, scale=None): super(NonLocal, self).__init__() self.size = size self.scale = scale self.attention_size = attention_size self.query = nn.Conv2d(in_size, attention_size, 1) self.key = nn.Conv2d(in_size, attention_size, 1) self.value = nn.Conv2d(in_size, attention_size, 1) self.project = nn.Conv2d(attention_size, in_size, 1) def forward(self, inputs): scaled_inputs = None if self.scale: scaled_inputs = func.max_pool2d(inputs, self.scale) elif self.size: scaled_inputs = func.adaptive_max_pool2d(inputs, self.size) else: scaled_inputs = inputs query = self.query(inputs).view(inputs.size(0), self.attention_size, -1 ) key = self.key(scaled_inputs).view(scaled_inputs.size(0), self. attention_size, -1) value = self.value(scaled_inputs).view(scaled_inputs.size(0), self. attention_size, -1) key = key.permute(0, 2, 1) assignment = (key @ query).softmax(dim=1) result = value @ assignment result = result.view(inputs.size(0), self.attention_size, *inputs. shape[2:]) return self.project(result) + inputs def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_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 // 16 % 32 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_per_fused__softmax_1(in_ptr0, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x0 = xindex % 16 x1 = xindex // 16 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * r2 + 256 * 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_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 256 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 - tmp1 tmp3 = tl_math.exp(tmp2) tmp5 = tmp3 / tmp4 tl.store(in_out_ptr0 + x3, tmp5, xmask) @triton.jit def triton_poi_fused_add_convolution_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (32, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_3, (32,), (1,)) assert_size_stride(primals_4, (32, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (32, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_7, (32,), (1,)) assert_size_stride(primals_8, (4, 32, 1, 1), (32, 1, 1, 1)) assert_size_stride(primals_9, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 4, 4), (512, 16, 4, 1)) buf1 = extern_kernels.convolution(primals_1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 32, 4, 4), (512, 16, 4, 1)) buf2 = extern_kernels.convolution(primals_1, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 32, 4, 4), (512, 16, 4, 1)) buf3 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_convolution_0[grid(2048)](buf3, primals_5, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = buf0 del buf0 triton_poi_fused_convolution_0[grid(2048)](buf4, primals_3, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf5 = empty_strided_cuda((4, 16, 16), (256, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (4, 16, 32), (512, 1, 16), 0), reinterpret_tensor(buf4, (4, 32, 16), (512, 16, 1), 0), out=buf5) buf6 = empty_strided_cuda((4, 1, 16), (16, 64, 1), torch.float32) buf7 = empty_strided_cuda((4, 1, 16), (16, 64, 1), torch.float32) triton_per_fused__softmax_1[grid(64)](buf5, buf6, buf7, 64, 16, XBLOCK=32, num_warps=4, num_stages=1) buf8 = buf5 del buf5 triton_poi_fused__softmax_2[grid(1024)](buf8, buf6, buf7, 1024, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del buf7 buf9 = buf2 del buf2 triton_poi_fused_convolution_0[grid(2048)](buf9, primals_7, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 32, 16), (512, 16, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf9, (4, 32, 16), (512, 16, 1), 0), buf8, out=buf10) buf11 = extern_kernels.convolution(reinterpret_tensor(buf10, (4, 32, 4, 4), (512, 16, 4, 1), 0), primals_8, stride=(1, 1), padding=( 0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 4, 4, 4), (64, 16, 4, 1)) buf12 = buf11 del buf11 triton_poi_fused_add_convolution_3[grid(256)](buf12, primals_9, primals_1, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 return (buf12, primals_1, primals_2, primals_4, primals_6, primals_8, buf8, reinterpret_tensor(buf10, (4, 32, 4, 4), (512, 16, 4, 1), 0), reinterpret_tensor(buf9, (4, 16, 32), (512, 1, 16), 0), reinterpret_tensor(buf3, (4, 32, 16), (512, 16, 1), 0), reinterpret_tensor(buf4, (4, 16, 32), (512, 1, 16), 0)) class NonLocalNew(nn.Module): def __init__(self, in_size, attention_size=32, size=None, scale=None): super(NonLocalNew, self).__init__() self.size = size self.scale = scale self.attention_size = attention_size self.query = nn.Conv2d(in_size, attention_size, 1) self.key = nn.Conv2d(in_size, attention_size, 1) self.value = nn.Conv2d(in_size, attention_size, 1) self.project = nn.Conv2d(attention_size, in_size, 1) def forward(self, input_0): primals_2 = self.query.weight primals_3 = self.query.bias primals_4 = self.key.weight primals_5 = self.key.bias primals_6 = self.value.weight primals_7 = self.value.bias primals_8 = self.project.weight primals_9 = self.project.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]
ankmathur96/torchsupport
NonLocal
false
3,178
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
MultiheadSimilarity
import torch import torch.utils.data from torch import nn class MultiheadSimilarity(nn.Module): def __init__(self, d_model, num_head, seq_len): super().__init__() self.num_head = num_head self.seq_len = seq_len self.d_head = d_model // num_head self.q_in_proj = nn.Linear(d_model, seq_len * d_model, bias=True) self.q_proj = nn.Linear(d_model, d_model, bias=True) self.k_proj = nn.Linear(d_model, d_model, bias=True) self.v_proj = nn.Linear(d_model, d_model, bias=True) self.out_proj = nn.Linear(seq_len * d_model, d_model, bias=True) def forward(self, q, kv): bs, d_model = q.shape nbs = bs * self.num_head q_ = self.q_in_proj(q) q_ = q_.contiguous().view(bs, self.seq_len, d_model).transpose(0, 1) kv = q_ + kv q = self.q_proj(q) q = q.contiguous().view(nbs, self.d_head).unsqueeze(-1) k = self.k_proj(kv) k = k.contiguous().view(self.seq_len, nbs, self.d_head).transpose(0, 1) similarity = torch.bmm(k, q) * float(self.d_head) ** -0.5 v = self.v_proj(kv) v = v.contiguous().view(self.seq_len, nbs, self.d_head).transpose(0, 1) v = (v * similarity).view(bs, self.num_head, self.seq_len, self.d_head) output = self.out_proj(v.flatten(1)) return output def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4, 1])] def get_init_inputs(): return [[], {'d_model': 4, 'num_head': 4, 'seq_len': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.utils.data from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_clone_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 % 4 x2 = xindex // 16 x3 = xindex // 4 x4 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask) tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last' ) tmp3 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tl.store(out_ptr0 + x4, tmp4, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) @triton.jit def triton_poi_fused_clone_2(in_ptr0, in_ptr1, in_ptr2, 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 y3 = yindex y0 = yindex % 4 tmp0 = tl.load(in_ptr0 + (y3 + 16 * x2), xmask & ymask, eviction_policy ='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (x2 + 4 * y3), xmask & ymask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp4 = 1.0 tmp5 = tmp3 * tmp4 tmp6 = tmp2 * tmp5 tl.store(out_ptr0 + (x2 + 4 * y3), tmp6, xmask & ymask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12 ) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (16, 4), (4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (4, 4, 1), (4, 1, 1)) assert_size_stride(primals_5, (4, 4), (4, 1)) assert_size_stride(primals_6, (4,), (1,)) assert_size_stride(primals_7, (4, 4), (4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4), (4, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 16), (16, 1)) assert_size_stride(primals_12, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 16), (16, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf0) del primals_2 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_6, primals_1, reinterpret_tensor( primals_5, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1) del primals_5 del primals_6 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_clone_0[grid(64)](buf0, primals_3, primals_4, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 del primals_4 buf3 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0) del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4), (16, 4, 1), 0) del buf3 triton_poi_fused_add_1[grid(64)](buf4, primals_8, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_8 buf5 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf4, (16, 4, 1), (1, 16, 0), 0), reinterpret_tensor(buf1, (16, 1, 1), (1, 1, 1), 0), out=buf5) buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf2, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf6) buf7 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_2[grid(16, 4)](buf6, primals_10, buf5, buf7, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_12, reinterpret_tensor(buf7, (4, 16), (16, 1), 0), reinterpret_tensor(primals_11, (16, 4), (1, 16), 0 ), alpha=1, beta=1, out=buf8) del primals_12 return buf8, primals_1, primals_10, reinterpret_tensor(buf2, (16, 4), ( 4, 1), 0), buf5, buf6, reinterpret_tensor(buf7, (4, 16), (16, 1), 0 ), primals_11, primals_9, reinterpret_tensor(buf4, (16, 1, 4), (1, 1, 16), 0), reinterpret_tensor(buf1, (16, 1, 1), (1, 1, 1), 0 ), primals_7 class MultiheadSimilarityNew(nn.Module): def __init__(self, d_model, num_head, seq_len): super().__init__() self.num_head = num_head self.seq_len = seq_len self.d_head = d_model // num_head self.q_in_proj = nn.Linear(d_model, seq_len * d_model, bias=True) self.q_proj = nn.Linear(d_model, d_model, bias=True) self.k_proj = nn.Linear(d_model, d_model, bias=True) self.v_proj = nn.Linear(d_model, d_model, bias=True) self.out_proj = nn.Linear(seq_len * d_model, d_model, bias=True) def forward(self, input_0, input_1): primals_2 = self.q_in_proj.weight primals_3 = self.q_in_proj.bias primals_1 = self.q_proj.weight primals_6 = self.q_proj.bias primals_5 = self.k_proj.weight primals_8 = self.k_proj.bias primals_7 = self.v_proj.weight primals_10 = self.v_proj.bias primals_11 = self.out_proj.weight primals_12 = self.out_proj.bias primals_9 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12]) return output[0]
bearcatt/SimpleBaseline
MultiheadSimilarity
false
3,179
[ "MIT" ]
0
9ae38f289688c0e671efb50985d3b8fe2da47d69
https://github.com/bearcatt/SimpleBaseline/tree/9ae38f289688c0e671efb50985d3b8fe2da47d69
ContrastivePairwiseEmbeddingLoss
import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastivePairwiseEmbeddingLoss(nn.Module): """ ContrastivePairwiseEmbeddingLoss – proof of concept criterion. Still work in progress. """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastivePairwiseEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, embeddings_pred, embeddings_true): """ Work in progress. Args: embeddings_pred: predicted embeddings embeddings_true: true embeddings Returns: loss """ device = embeddings_pred.device pairwise_similarity = torch.einsum('se,ae->sa', embeddings_pred, embeddings_true) bs = embeddings_pred.shape[0] batch_idx = torch.arange(bs, device=device) loss = F.cross_entropy(pairwise_similarity, batch_idx, reduction= self.reduction) return loss def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_per_fused_arange_nll_loss_forward_1(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp6 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last') tmp8 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last') tmp0 = r0 tmp1 = tl.full([1, 1], -100, tl.int64) tmp2 = tmp0 != tmp1 tmp3 = tl.full([1, 1], 0, tl.int64) tmp4 = tl.where(tmp2, tmp0, tmp3) tmp5 = tl.load(in_ptr0 + (tmp4 + 4 * r0), None, eviction_policy= 'evict_last') tmp7 = tl_math.exp(tmp6) tmp9 = tl_math.exp(tmp8) tmp10 = tmp7 + tmp9 tmp12 = tl_math.exp(tmp11) tmp13 = tmp10 + tmp12 tmp15 = tl_math.exp(tmp14) tmp16 = tmp13 + tmp15 tmp17 = tl_math.log(tmp16) tmp18 = tmp5 - tmp17 tmp19 = -tmp18 tmp20 = 0.0 tmp21 = tl.where(tmp2, tmp19, tmp20) tmp22 = tl.broadcast_to(tmp21, [XBLOCK, RBLOCK]) tmp24 = tl.sum(tmp22, 1)[:, None] tmp25 = tmp2.to(tl.int64) tmp26 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK]) tmp28 = tl.sum(tmp26, 1)[:, None] tmp29 = tmp28.to(tl.float32) tmp30 = tmp24 / tmp29 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp30, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (1, 4, 4), (16, 4, 1), 0), reinterpret_tensor(arg1_1, (1, 4, 4), (0, 1, 4), 0), out=buf0) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 buf2 = empty_strided_cuda((), (), torch.float32) buf4 = buf2 del buf2 triton_per_fused_arange_nll_loss_forward_1[grid(1)](buf4, buf1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf1 return buf4, class ContrastivePairwiseEmbeddingLossNew(nn.Module): """ ContrastivePairwiseEmbeddingLoss – proof of concept criterion. Still work in progress. """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastivePairwiseEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
bbradt/catalyst
ContrastivePairwiseEmbeddingLoss
false
3,180
[ "Apache-2.0" ]
0
38a503c8af040906e377b7485d7fe15a7bc1de19
https://github.com/bbradt/catalyst/tree/38a503c8af040906e377b7485d7fe15a7bc1de19
NormalizedDistance
import torch import torch.nn as nn import torch.jit import torch.nn def normalized_distance(data, distance): data = data.view(data.size(0), -1) reference = data[:, None] comparison = data[None, :] result = distance(reference, comparison) result = result / result.sum(dim=1, keepdim=True).detach() return result class NormalizedDistance(nn.Module): def __init__(self, distance=None): super().__init__() self.distance = distance if self.distance is None: self.distance = lambda x, y: (x - y).norm(dim=-1) def forward(self, data): return normalized_distance(data, self.distance) 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 import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_linalg_vector_norm_sub_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r2 = rindex x1 = xindex // 4 x0 = xindex % 4 x3 = xindex tmp0 = tl.load(in_ptr0 + (r2 + 64 * x1), xmask, eviction_policy= 'evict_last', other=0.0) tmp1 = tl.load(in_ptr0 + (r2 + 64 * x0), xmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp6 = tl.where(xmask, tmp4, 0) tmp7 = tl.sum(tmp6, 1)[:, None] tl.store(out_ptr0 + x3, tmp7, xmask) @triton.jit def triton_poi_fused_div_linalg_vector_norm_sum_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) 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.sqrt(tmp0) tmp3 = libdevice.sqrt(tmp2) tmp5 = libdevice.sqrt(tmp4) tmp6 = tmp3 + tmp5 tmp8 = libdevice.sqrt(tmp7) tmp9 = tmp6 + tmp8 tmp11 = libdevice.sqrt(tmp10) tmp12 = tmp9 + tmp11 tmp13 = tmp1 / tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_per_fused_linalg_vector_norm_sub_0[grid(16)](arg0_1, buf0, 16, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_div_linalg_vector_norm_sum_1[grid(16)](buf0, buf1, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf0 return buf1, def normalized_distance(data, distance): data = data.view(data.size(0), -1) reference = data[:, None] comparison = data[None, :] result = distance(reference, comparison) result = result / result.sum(dim=1, keepdim=True).detach() return result class NormalizedDistanceNew(nn.Module): def __init__(self, distance=None): super().__init__() self.distance = distance if self.distance is None: self.distance = lambda x, y: (x - y).norm(dim=-1) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ankmathur96/torchsupport
NormalizedDistance
false
3,181
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
ContrastiveDistanceLoss
import torch import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastiveDistanceLoss(nn.Module): """ Contrastive distance loss """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveDistanceLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, distance_pred, distance_true): """ Forward propagation method for the contrastive loss. Args: distance_pred: predicted distances distance_true: true distances Returns: loss """ bs = len(distance_true) margin_distance = self.margin - distance_pred margin_distance_ = torch.clamp(margin_distance, min=0.0) loss = (1 - distance_true) * torch.pow(distance_pred, 2 ) + distance_true * torch.pow(margin_distance_, 2) if self.reduction == 'mean': loss = torch.sum(loss) / 2.0 / bs elif self.reduction == 'sum': loss = torch.sum(loss) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_clamp_div_mul_pow_rsub_sum_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp3 * tmp3 tmp5 = tmp2 * tmp4 tmp6 = tmp1 - tmp3 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8 * tmp8 tmp10 = tmp0 * tmp9 tmp11 = tmp5 + tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = 0.25 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_clamp_div_mul_pow_rsub_sum_0[grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class ContrastiveDistanceLossNew(nn.Module): """ Contrastive distance loss """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveDistanceLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
bbradt/catalyst
ContrastiveDistanceLoss
false
3,182
[ "Apache-2.0" ]
0
38a503c8af040906e377b7485d7fe15a7bc1de19
https://github.com/bbradt/catalyst/tree/38a503c8af040906e377b7485d7fe15a7bc1de19
ContrastiveEmbeddingLoss
import torch import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed class ContrastiveEmbeddingLoss(nn.Module): """ Contrastive embedding loss paper: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, embeddings_left, embeddings_right, distance_true): """ Forward propagation method for the contrastive loss. Args: embeddings_left: left objects embeddings embeddings_right: right objects embeddings distance_true: true distances Returns: loss """ diff = embeddings_left - embeddings_right distance_pred = torch.sqrt(torch.sum(torch.pow(diff, 2), 1)) bs = len(distance_true) margin_distance = self.margin - distance_pred margin_distance_ = torch.clamp(margin_distance, min=0.0) loss = (1 - distance_true) * torch.pow(distance_pred, 2 ) + distance_true * torch.pow(margin_distance_, 2) if self.reduction == 'mean': loss = torch.sum(loss) / 2.0 / bs elif self.reduction == 'sum': loss = torch.sum(loss) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand( [4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.nn.modules.loss import * from torch.nn.modules import * from torch.optim import * from torch.optim.lr_scheduler import * import torch.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_pow_sqrt_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask) tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask) tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask) tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask) tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask) tmp2 = tmp0 - tmp1 tmp3 = tmp2 * tmp2 tmp6 = tmp4 - tmp5 tmp7 = tmp6 * tmp6 tmp8 = tmp3 + tmp7 tmp11 = tmp9 - tmp10 tmp12 = tmp11 * tmp11 tmp13 = tmp8 + tmp12 tmp16 = tmp14 - tmp15 tmp17 = tmp16 * tmp16 tmp18 = tmp13 + tmp17 tmp19 = libdevice.sqrt(tmp18) tl.store(out_ptr0 + x2, tmp19, xmask) @triton.jit def triton_per_fused_add_clamp_div_mul_pow_rsub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r2 = rindex r0 = rindex % 64 tmp0 = tl.load(in_ptr0 + r2, None) tmp3 = tl.load(in_ptr1 + r0, None, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tmp3 * tmp3 tmp5 = tmp2 * tmp4 tmp6 = tmp1 - tmp3 tmp7 = 0.0 tmp8 = triton_helpers.maximum(tmp6, tmp7) tmp9 = tmp8 * tmp8 tmp10 = tmp0 * tmp9 tmp11 = tmp5 + tmp10 tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 0.5 tmp16 = tmp14 * tmp15 tmp17 = 0.25 tmp18 = tmp16 * tmp17 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp18, None) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_pow_sqrt_sub_sum_0[grid(64)](arg0_1, arg1_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 del arg1_1 buf1 = empty_strided_cuda((), (), torch.float32) buf2 = buf1 del buf1 triton_per_fused_add_clamp_div_mul_pow_rsub_sum_1[grid(1)](buf2, arg2_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg2_1 del buf0 return buf2, class ContrastiveEmbeddingLossNew(nn.Module): """ Contrastive embedding loss paper: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf """ def __init__(self, margin=1.0, reduction='mean'): """ Constructor method for the ContrastiveEmbeddingLoss class. Args: margin: margin parameter. reduction: criterion reduction type. """ super().__init__() self.margin = margin self.reduction = reduction or 'none' def forward(self, input_0, input_1, input_2): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
bbradt/catalyst
ContrastiveEmbeddingLoss
false
3,183
[ "Apache-2.0" ]
0
38a503c8af040906e377b7485d7fe15a7bc1de19
https://github.com/bbradt/catalyst/tree/38a503c8af040906e377b7485d7fe15a7bc1de19
FiLMNetwork
import torch import torch.nn as nn class FiLMNetwork(nn.Module): def __init__(self, in_sz, out_sz): super(FiLMNetwork, self).__init__() self.f = nn.Linear(in_sz, out_sz) self.h = nn.Linear(in_sz, out_sz) def forward(self, inputs, features): gamma = self.f(inputs).unsqueeze(1) beta = self.h(inputs).unsqueeze(1) return features * gamma + beta def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_sz': 4, 'out_sz': 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_mul_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, 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 x3 = xindex // 256 x5 = xindex % 64 x0 = xindex % 4 x6 = xindex tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x5 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + (x5 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 * tmp3 tmp7 = tmp5 + tmp6 tmp8 = tmp4 + tmp7 tl.store(out_ptr0 + x6, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (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 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (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) get_raw_stream(0) triton_poi_fused_add_mul_0[grid(1024)](primals_6, buf0, primals_2, buf1, primals_5, buf2, 1024, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del buf1 del primals_2 del primals_5 return buf2, primals_6, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0) class FiLMNetworkNew(nn.Module): def __init__(self, in_sz, out_sz): super(FiLMNetworkNew, self).__init__() self.f = nn.Linear(in_sz, out_sz) self.h = nn.Linear(in_sz, out_sz) def forward(self, input_0, input_1): primals_1 = self.f.weight primals_2 = self.f.bias primals_4 = self.h.weight primals_5 = self.h.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]
bblinn2017/IM-NET-pytorch
FiLMNetwork
false
3,184
[ "MIT" ]
0
82ff646aaf2f93ae1560debb40fe05f1420ff655
https://github.com/bblinn2017/IM-NET-pytorch/tree/82ff646aaf2f93ae1560debb40fe05f1420ff655
MLP_FiLM
import torch import torch.nn as nn class FiLMNetwork(nn.Module): def __init__(self, in_sz, out_sz): super(FiLMNetwork, self).__init__() self.f = nn.Linear(in_sz, out_sz) self.h = nn.Linear(in_sz, out_sz) def forward(self, inputs, features): gamma = self.f(inputs).unsqueeze(1) beta = self.h(inputs).unsqueeze(1) return features * gamma + beta class MLP_FiLM(nn.Module): def __init__(self, cdim, fdim): super(MLP_FiLM, self).__init__() self.l1 = nn.Linear(fdim, fdim) self.l2 = nn.Linear(fdim, fdim) self.l3 = nn.Linear(fdim, fdim) self.f1 = FiLMNetwork(cdim, fdim) self.f2 = FiLMNetwork(cdim, fdim) def forward(self, c, x): x = self.f1(c, self.l1(x)).tanh() x = self.f2(c, self.l2(x)).tanh() return self.l3(x) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'cdim': 4, 'fdim': 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_mul_tanh_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 x3 = xindex // 256 x5 = xindex % 64 x0 = xindex % 4 x6 = xindex tmp0 = tl.load(in_ptr0 + x4, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (x5 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (x5 + 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 = libdevice.tanh(tmp6) tl.store(out_ptr0 + x6, tmp7, xmask) @triton.jit def triton_poi_fused_add_mul_tanh_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 x3 = xindex // 256 x5 = xindex % 64 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr1 + (x5 + 64 * x3), xmask, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr2 + (x5 + 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 = libdevice.tanh(tmp6) tl.store(out_ptr0 + x4, 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, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16) = 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, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 4), (4, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 4), (4, 1)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (4, 4), (4, 1)) assert_size_stride(primals_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.addmm(primals_5, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_4 del primals_5 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2) del primals_7 buf3 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_tanh_0[grid(1024)](buf0, buf1, buf2, primals_8, buf3, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_8 buf4 = empty_strided_cuda((256, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_10, reinterpret_tensor(buf3, (256, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf4) del primals_10 buf5 = buf2 del buf2 extern_kernels.addmm(primals_12, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf5) del primals_11 del primals_12 buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0), reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf6) del primals_13 buf7 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) triton_poi_fused_add_mul_tanh_1[grid(1024)](buf4, buf5, buf6, primals_14, buf7, 1024, XBLOCK=256, num_warps=4, num_stages=1) del buf6 del primals_14 buf8 = empty_strided_cuda((256, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_16, reinterpret_tensor(buf7, (256, 4), (4, 1), 0), reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf8) del primals_16 return reinterpret_tensor(buf8, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf0, reinterpret_tensor(primals_6, (64, 4), (4, 1), 0 ), buf1, buf3, buf4, buf5, buf7, primals_15, primals_9 class FiLMNetwork(nn.Module): def __init__(self, in_sz, out_sz): super(FiLMNetwork, self).__init__() self.f = nn.Linear(in_sz, out_sz) self.h = nn.Linear(in_sz, out_sz) def forward(self, inputs, features): gamma = self.f(inputs).unsqueeze(1) beta = self.h(inputs).unsqueeze(1) return features * gamma + beta class MLP_FiLMNew(nn.Module): def __init__(self, cdim, fdim): super(MLP_FiLMNew, self).__init__() self.l1 = nn.Linear(fdim, fdim) self.l2 = nn.Linear(fdim, fdim) self.l3 = nn.Linear(fdim, fdim) self.f1 = FiLMNetwork(cdim, fdim) self.f2 = FiLMNetwork(cdim, fdim) def forward(self, input_0, input_1): primals_1 = self.l1.weight primals_2 = self.l1.bias primals_4 = self.l2.weight primals_5 = self.l2.bias primals_7 = self.l3.weight primals_8 = self.l3.bias primals_9 = self.f1.f.weight primals_10 = self.f1.f.bias primals_11 = self.f1.h.weight primals_12 = self.f1.h.bias primals_13 = self.f2.f.weight primals_14 = self.f2.f.bias primals_15 = self.f2.h.weight primals_16 = self.f2.h.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, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16]) return output[0]
bblinn2017/IM-NET-pytorch
MLP_FiLM
false
3,185
[ "MIT" ]
0
82ff646aaf2f93ae1560debb40fe05f1420ff655
https://github.com/bblinn2017/IM-NET-pytorch/tree/82ff646aaf2f93ae1560debb40fe05f1420ff655
CnnViewModel
import torch import torch.nn as nn class CnnViewModel(nn.Module): def __init__(self, out_dim=10): super(CnnViewModel, self).__init__() self.cnn1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=5, stride=1, padding=2) self.relu1 = nn.ReLU() self.maxpool1 = nn.MaxPool2d(kernel_size=2) self.cnn2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size= 5, stride=1, padding=2) self.relu2 = nn.ReLU() self.maxpool2 = nn.MaxPool2d(kernel_size=2) self.fc1 = nn.Linear(32 * 7 * 7, out_dim) def forward(self, X): X = X.view(-1, 1, 28, 28) out = self.cnn1(X) out = self.relu1(out) out = self.maxpool1(out) out = self.cnn2(out) out = self.relu2(out) out = self.maxpool2(out) out = out.view(out.size(0), -1) out = self.fc1(out) return out def get_inputs(): return [torch.rand([4, 1, 28, 28])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 50176 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 12544 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 14 x1 = xindex // 14 x4 = xindex x3 = xindex // 3136 x5 = xindex % 3136 tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x1), xmask, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x1), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x1), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x4, tmp6, xmask) tl.store(out_ptr1 + (x5 + 3200 * x3), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 25088 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 196 % 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 6272 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 7 x3 = xindex // 7 x2 = xindex // 1568 x4 = xindex % 1568 x5 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 28 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 28 * x3), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (14 + 2 * x0 + 28 * x3), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (15 + 2 * x0 + 28 * x3), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + (x4 + 1664 * x2), tmp15, xmask) tl.store(out_ptr1 + x5, tmp16, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 1, 28, 28), (784, 784, 28, 1)) assert_size_stride(primals_2, (16, 1, 5, 5), (25, 25, 5, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (32, 16, 5, 5), (400, 25, 5, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (10, 1568), (1568, 1)) assert_size_stride(primals_7, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 28, 28), (12544, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(50176)](buf1, primals_3, 50176, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf2 = empty_strided_cuda((4, 16, 14, 14), (3136, 196, 14, 1), torch.float32) buf3 = empty_strided_cuda((4, 16, 14, 14), (3200, 196, 14, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_1[grid(12544)](buf1, buf2, buf3, 12544, XBLOCK=256, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(2, 2), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 32, 14, 14), (6272, 196, 14, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(25088)](buf5, primals_5, 25088, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 32, 7, 7), (1664, 49, 7, 1), torch.int8) buf7 = empty_strided_cuda((4, 32, 7, 7), (1568, 49, 7, 1), torch. float32) triton_poi_fused_max_pool2d_with_indices_3[grid(6272)](buf5, buf6, buf7, 6272, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf7, (4, 1568), (1568, 1), 0), reinterpret_tensor(primals_6, (1568, 10), (1, 1568), 0), alpha=1, beta=1, out=buf8) del primals_7 return (buf8, primals_2, primals_4, primals_1, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 1568), (1568, 1), 0), primals_6) class CnnViewModelNew(nn.Module): def __init__(self, out_dim=10): super(CnnViewModelNew, self).__init__() self.cnn1 = nn.Conv2d(in_channels=1, out_channels=16, kernel_size=5, stride=1, padding=2) self.relu1 = nn.ReLU() self.maxpool1 = nn.MaxPool2d(kernel_size=2) self.cnn2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size= 5, stride=1, padding=2) self.relu2 = nn.ReLU() self.maxpool2 = nn.MaxPool2d(kernel_size=2) self.fc1 = nn.Linear(32 * 7 * 7, out_dim) def forward(self, input_0): primals_2 = self.cnn1.weight primals_3 = self.cnn1.bias primals_4 = self.cnn2.weight primals_5 = self.cnn2.bias primals_6 = self.fc1.weight primals_7 = self.fc1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
bbrighttaer/DCCA_demo
CnnViewModel
false
3,186
[ "MIT" ]
0
c5410f2e163c6538899bf8f5f9afe031a517408f
https://github.com/bbrighttaer/DCCA_demo/tree/c5410f2e163c6538899bf8f5f9afe031a517408f
FastestBlock
import torch import torch.nn as nn def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FastestBlock(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FastestBlock, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel // 2, kernel_size=3, stride=self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel // 2 else: temp_norm_cfg['num_channels'] = self._num_block_channel // 2 self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel // 2, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) def forward(self, x): identity = x out = self._conv1(x) if self._norm_cfg is not None: out = self._norm1(out) out = self._activation(out) out = self._conv2(out) if self._norm_cfg is not None: out = self._norm2(out) if self._downsample is not None: identity = self._downsample(x) out += identity out = self._activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_input_channels': 4, 'num_block_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 2 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = 0.0 tmp8 = tmp6 <= tmp7 tl.store(in_out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (2, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (2,), (1,)) assert_size_stride(primals_4, (4, 2, 3, 3), (18, 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, 2, 4, 4), (32, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(128)](buf1, primals_3, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(256)]( buf3, primals_5, primals_1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1, buf4 def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FastestBlockNew(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FastestBlockNew, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel // 2, kernel_size=3, stride=self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel // 2 else: temp_norm_cfg['num_channels'] = self._num_block_channel // 2 self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel // 2, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) 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]
becauseofAI/DemoHub
FastestBlock
false
3,187
[ "Apache-2.0" ]
0
2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
https://github.com/becauseofAI/DemoHub/tree/2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
Resize
import torch import torch.nn as nn import torch.nn.functional as F class Resize(nn.Module): def __init__(self, input_size=[224, 224]): super(Resize, self).__init__() self.input_size = input_size def forward(self, input): x = F.interpolate(input, size=self.input_size, mode='bilinear', align_corners=True) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_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) x1 = xindex // 224 % 224 x0 = xindex % 224 x2 = xindex // 50176 x4 = xindex tmp0 = x1 tmp1 = tmp0.to(tl.float32) tmp2 = 0.013452914798206279 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 3, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tmp11 = x0 tmp12 = tmp11.to(tl.float32) tmp13 = tmp12 * tmp2 tmp14 = triton_helpers.maximum(tmp13, tmp4) tmp15 = tmp14.to(tl.int32) tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2), None, eviction_policy='evict_last') tmp17 = tmp15 + tmp7 tmp18 = triton_helpers.minimum(tmp17, tmp9) tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), None, eviction_policy='evict_last') tmp20 = tmp19 - tmp16 tmp21 = tmp15.to(tl.float32) tmp22 = tmp14 - tmp21 tmp23 = triton_helpers.maximum(tmp22, tmp4) tmp24 = 1.0 tmp25 = triton_helpers.minimum(tmp23, tmp24) tmp26 = tmp20 * tmp25 tmp27 = tmp16 + tmp26 tmp28 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), None, eviction_policy='evict_last') tmp29 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), None, eviction_policy='evict_last') tmp30 = tmp29 - tmp28 tmp31 = tmp30 * tmp25 tmp32 = tmp28 + tmp31 tmp33 = tmp27 - tmp32 tmp34 = tmp6.to(tl.float32) tmp35 = tmp5 - tmp34 tmp36 = triton_helpers.maximum(tmp35, tmp4) tmp37 = triton_helpers.minimum(tmp36, tmp24) tmp38 = tmp33 * tmp37 tmp39 = tmp32 + tmp38 tl.store(in_out_ptr0 + x4, tmp39, None) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 224, 224), (200704, 50176, 224, 1), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid (802816)](buf1, arg0_1, 802816, XBLOCK=1024, num_warps=4, num_stages=1) del arg0_1 return buf1, class ResizeNew(nn.Module): def __init__(self, input_size=[224, 224]): super(ResizeNew, self).__init__() self.input_size = input_size def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
beibuwandeluori/Attack-ImageNet-tianchi
Resize
false
3,188
[ "MIT" ]
0
85294952ac1a190c26bba5e8f141b1c68e72668a
https://github.com/beibuwandeluori/Attack-ImageNet-tianchi/tree/85294952ac1a190c26bba5e8f141b1c68e72668a
ConvGRUCellNd
import torch import torch.nn as nn import torch.jit import torch.nn class ConvGRUCellNd(nn.Module): def __init__(self, in_size, out_size, kernel_size, N=1, **kwargs): super(ConvGRUCellNd, self).__init__() conv = eval(f'nn.Conv{N}d') self.conv_ir = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hr = conv(in_size, out_size, kernel_size, **kwargs) self.conv_iz = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hz = conv(in_size, out_size, kernel_size, **kwargs) self.conv_in = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hn = conv(in_size, out_size, kernel_size, **kwargs) def forward(self, inputs, state): r = torch.sigmoid(self.conv_ir(inputs) + self.conv_hr(state)) z = torch.sigmoid(self.conv_iz(inputs) + self.conv_hz(state)) n = torch.tanh(self.conv_in(inputs) + self.conv_hn(state * r)) return z * state + (1 - z) * n def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'in_size': 4, 'out_size': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_sigmoid_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tl.store(in_out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_add_mul_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp6 = tmp4 + tmp5 tmp7 = tmp3 + tmp6 tmp8 = tl.sigmoid(tmp7) tmp9 = tmp0 * tmp8 tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_add_tanh_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = libdevice.tanh(tmp6) tl.store(in_out_ptr0 + x0, tmp7, xmask) @triton.jit def triton_poi_fused_add_mul_rsub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x2, xmask) tmp5 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tl.store(out_ptr0 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_add_sigmoid_sigmoid_backward_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp4 = tl.load(in_ptr2 + x0, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp7 = tl.sigmoid(tmp6) tmp8 = 1.0 tmp9 = tmp8 - tmp7 tmp10 = tmp7 * tmp9 tl.store(in_out_ptr0 + x0, tmp10, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14) = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4), (4, 1)) assert_size_stride(primals_7, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_8, (4,), (1,)) assert_size_stride(primals_9, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_10, (4,), (1,)) assert_size_stride(primals_11, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_12, (4,), (1,)) assert_size_stride(primals_13, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_14, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_1, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf0, (1, 4, 1), (4, 1, 1)) buf1 = extern_kernels.convolution(reinterpret_tensor(primals_6, (1, 4, 4), (16, 4, 1), 0), primals_4, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf1, (1, 4, 1), (4, 1, 1)) buf2 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_7, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf2, (1, 4, 1), (4, 1, 1)) buf3 = extern_kernels.convolution(reinterpret_tensor(primals_6, (1, 4, 4), (16, 4, 1), 0), primals_9, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf3, (1, 4, 1), (4, 1, 1)) buf4 = reinterpret_tensor(buf2, (4, 1), (1, 1), 0) del buf2 get_raw_stream(0) triton_poi_fused_add_sigmoid_0[grid(4)](buf4, primals_8, buf3, primals_10, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf3 del primals_10 del primals_8 buf5 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1, 4, 4), (16, 4, 1), 0), primals_11, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf5, (1, 4, 1), (4, 1, 1)) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_sigmoid_1[grid(16)](primals_6, buf0, primals_2, buf1, primals_5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) buf7 = extern_kernels.convolution(reinterpret_tensor(buf6, (1, 4, 4 ), (0, 4, 1), 0), primals_13, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=(0,), groups=1, bias=None) assert_size_stride(buf7, (1, 4, 1), (4, 1, 1)) buf8 = reinterpret_tensor(buf5, (4, 1), (1, 1), 0) del buf5 triton_poi_fused_add_tanh_2[grid(4)](buf8, primals_12, buf7, primals_14, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf7 del primals_12 del primals_14 buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_mul_rsub_3[grid(16)](buf4, primals_6, buf8, buf9, 16, XBLOCK=16, num_warps=1, num_stages=1) buf10 = reinterpret_tensor(buf0, (4, 1), (1, 1), 0) del buf0 triton_poi_fused_add_sigmoid_sigmoid_backward_4[grid(4)](buf10, primals_2, buf1, primals_5, 4, XBLOCK=4, num_warps=1, num_stages=1) del buf1 del primals_2 del primals_5 return (buf9, primals_1, primals_4, primals_6, primals_7, primals_9, primals_11, primals_13, reinterpret_tensor(primals_3, (1, 4, 4), ( 16, 4, 1), 0), buf4, reinterpret_tensor(buf6, (1, 4, 4), (16, 4, 1), 0), buf8, buf10) class ConvGRUCellNdNew(nn.Module): def __init__(self, in_size, out_size, kernel_size, N=1, **kwargs): super(ConvGRUCellNdNew, self).__init__() conv = eval(f'nn.Conv{N}d') self.conv_ir = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hr = conv(in_size, out_size, kernel_size, **kwargs) self.conv_iz = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hz = conv(in_size, out_size, kernel_size, **kwargs) self.conv_in = conv(in_size, out_size, kernel_size, **kwargs) self.conv_hn = conv(in_size, out_size, kernel_size, **kwargs) def forward(self, input_0, input_1): primals_1 = self.conv_ir.weight primals_2 = self.conv_ir.bias primals_4 = self.conv_hr.weight primals_5 = self.conv_hr.bias primals_7 = self.conv_iz.weight primals_8 = self.conv_iz.bias primals_9 = self.conv_hz.weight primals_10 = self.conv_hz.bias primals_11 = self.conv_in.weight primals_12 = self.conv_in.bias primals_13 = self.conv_hn.weight primals_14 = self.conv_hn.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, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14]) return output[0]
ankmathur96/torchsupport
ConvGRUCellNd
false
3,189
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
Unet
import torch from torch import nn from torch.nn import functional as F class ContractingBlock(nn.Module): """ ContractingBlock Class Performs two convolutions followed by a max pool operation. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, in_channels, out_channels): super().__init__() self.conv3x3_0 = nn.Conv2d(in_channels, out_channels, kernel_size=3) self.conv3x3_1 = nn.Conv2d(out_channels, out_channels, kernel_size=3) def forward(self, x): """ Function for completing a forward pass of ContractingBlock: Given an image tensor, completes a contracting block and returns the transformed tensor. Parameters: x: image tensor of shape (batch size, channels, height, width) """ fx = F.relu(self.conv3x3_0(x)) fx = F.relu(self.conv3x3_1(fx)) return fx class ExpandingBlock(nn.Module): """ ExpandingBlock Performs an upsampling, a convolution, a concatenation of its two inputs, followed by two more convolutions. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, hid_channels): super(ExpandingBlock, self).__init__() self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) self.conv = nn.Conv2d(hid_channels, hid_channels // 2, kernel_size= 3, stride=1, padding=1) self.conv3x3_0 = nn.Conv2d(hid_channels, hid_channels // 2, kernel_size=3, stride=1) self.conv3x3_1 = nn.Conv2d(hid_channels // 2, hid_channels // 2, kernel_size=3, stride=1) @staticmethod def crop(x, shape=None): """ Function for cropping an image tensor: Given an image tensor and the new shape, crops to the center pixels (assumes that the input's size and the new size are even numbers). Parameters: image: image tensor of shape (batch size, channels, height, width) new_shape: a torch.Size object with the shape you want x to have """ _, _, h, w = x.shape _, _, h_new, w_new = shape ch, cw = h // 2, w // 2 ch_new, cw_new = h_new // 2, w_new // 2 x1 = int(cw - cw_new) y1 = int(ch - ch_new) x2 = int(x1 + w_new) y2 = int(y1 + h_new) return x[:, :, y1:y2, x1:x2] def forward(self, x, skip): """ Function for completing a forward pass of ExpandingBlock: Given an image tensor, completes an expanding block and returns the transformed tensor. Parameters: x: image tensor of shape (batch size, channels, height, width) skip_con_x: the image tensor from the contracting path (from the opposing block of x) for the skip connection """ up = self.upsample(x) upconv = self.conv(up) skip = self.crop(skip, upconv.shape) fx = torch.cat([upconv, skip], dim=1) fx = F.relu(self.conv3x3_0(fx)) fx = F.relu(self.conv3x3_1(fx)) return fx class FeatureMapBlock(nn.Module): """ FeatureMapBlock The final layer of a UNet - maps each pixel to a pixel with the correct number of output dimensions using a 1x1 convolution. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, in_channels, out_channels): super(FeatureMapBlock, self).__init__() self.conv1x1 = nn.Conv2d(in_channels, out_channels, kernel_size=1) def forward(self, x): """ Function for completing a forward pass of FeatureMapBlock: Given an image tensor, returns it mapped to the desired number of channels. Parameters: x: image tensor of shape (batch size, channels, height, width) """ fx = self.conv1x1(x) return fx class Unet(nn.Module): """ UNet Class A series of 4 contracting blocks followed by 4 expanding blocks to transform an input image into the corresponding paired image, with an upfeature layer at the start and a downfeature layer at the end Values: input_channels: the number of channels to expect from a given input output_channels: the number of channels to expect for a given output """ def __init__(self, in_channels=1, hid_channels=64, out_channels=1): super(Unet, self).__init__() self.contract1 = ContractingBlock(1, hid_channels) self.contract2 = ContractingBlock(hid_channels, hid_channels * 2) self.contract3 = ContractingBlock(hid_channels * 2, hid_channels * 4) self.contract4 = ContractingBlock(hid_channels * 4, hid_channels * 8) self.bottleneck = ContractingBlock(hid_channels * 8, hid_channels * 16) self.expand1 = ExpandingBlock(hid_channels * 16) self.expand2 = ExpandingBlock(hid_channels * 8) self.expand3 = ExpandingBlock(hid_channels * 4) self.expand4 = ExpandingBlock(hid_channels * 2) self.downfeature = FeatureMapBlock(hid_channels, out_channels) self.pool = nn.MaxPool2d(kernel_size=2, stride=2) def forward(self, x): """ Function for completing a forward pass of UNet: Given an image tensor, passes it through U-Net and returns the output. Parameters: x: image tensor of shape (batch size, channels, height, width) """ d1 = self.contract1(x) dp1 = self.pool(d1) d2 = self.contract2(dp1) dp2 = self.pool(d2) d3 = self.contract3(dp2) dp3 = self.pool(d3) d4 = self.contract4(dp3) dp4 = self.pool(d4) b = self.bottleneck(dp4) up1 = self.expand1(b, d4) up2 = self.expand2(up1, d3) up3 = self.expand3(up2, d2) up4 = self.expand4(up3, d1) xn = self.downfeature(up4) return xn def get_inputs(): return [torch.rand([4, 1, 256, 256])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn from torch.nn import functional as F assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16516096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 64516 % 64 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 63504 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4064256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 126 x3 = xindex // 126 x2 = xindex // 15876 x4 = xindex % 15876 tmp0 = tl.load(in_ptr0 + (2 * x0 + 504 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 504 * x3), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (252 + 2 * x0 + 504 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (253 + 2 * x0 + 504 * x3), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x4 + 15904 * x2), tmp6, xmask) tl.store(out_ptr1 + (x4 + 16000 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 15376 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 14884 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1905152 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 61 x3 = xindex // 61 x2 = xindex // 3721 x4 = xindex % 3721 tmp0 = tl.load(in_ptr0 + (2 * x0 + 244 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 244 * x3), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (122 + 2 * x0 + 244 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (123 + 2 * x0 + 244 * x3), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x4 + 3744 * x2), tmp6, xmask) tl.store(out_ptr1 + (x4 + 3840 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3564544 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3481 % 256 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3326976 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3249 % 256 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 28 x1 = xindex // 28 % 28 x2 = xindex // 784 x3 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 114 * x1 + 3249 * x2), None, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 114 * x1 + 3249 * x2), None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (57 + 2 * x0 + 114 * x1 + 3249 * x2), None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (58 + 2 * x0 + 114 * x1 + 3249 * x2), None, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x3, tmp6, None) tl.store(out_ptr1 + x3, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_9(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 676 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_relu_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 576 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_max_pool2d_with_indices_11(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 12 x1 = xindex // 12 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 48 * x1), None, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 48 * x1), None, eviction_policy= 'evict_last') tmp3 = tl.load(in_ptr0 + (24 + 2 * x0 + 48 * x1), None, eviction_policy ='evict_last') tmp5 = tl.load(in_ptr0 + (25 + 2 * x0 + 48 * x1), None, eviction_policy ='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + x2, tmp6, None) tl.store(out_ptr1 + x2, tmp16, None) @triton.jit def triton_poi_fused_convolution_relu_12(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 100 % 1024 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused__to_copy_13(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4666666666666667 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_14(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4666666666666667 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 7, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_15(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4666666666666667 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = 1.0 tmp11 = triton_helpers.minimum(tmp9, tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_16(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 16 % 16 x0 = xindex % 16 x6 = xindex // 256 x2 = xindex // 256 % 1024 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp25 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp39 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 8, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 8 * tmp4 + 64 * x6), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp15 = tmp14 + tmp1 tmp16 = tmp14 < 0 tmp17 = tl.where(tmp16, tmp15, tmp14) tmp18 = tl.load(in_ptr2 + (tmp17 + 8 * tmp4 + 64 * x6), None, eviction_policy='evict_last') tmp19 = tmp18 + tmp10 tmp20 = triton_helpers.maximum(tmp12, tmp19) tmp21 = tmp20 - tmp13 tmp23 = tmp21 * tmp22 tmp24 = tmp13 + tmp23 tmp26 = tmp25 + tmp1 tmp27 = tmp25 < 0 tmp28 = tl.where(tmp27, tmp26, tmp25) tmp29 = tl.load(in_ptr2 + (tmp8 + 8 * tmp28 + 64 * x6), None, eviction_policy='evict_last') tmp30 = tmp29 + tmp10 tmp31 = triton_helpers.maximum(tmp12, tmp30) tmp32 = tl.load(in_ptr2 + (tmp17 + 8 * tmp28 + 64 * x6), None, eviction_policy='evict_last') tmp33 = tmp32 + tmp10 tmp34 = triton_helpers.maximum(tmp12, tmp33) tmp35 = tmp34 - tmp31 tmp36 = tmp35 * tmp22 tmp37 = tmp31 + tmp36 tmp38 = tmp37 - tmp24 tmp40 = tmp38 * tmp39 tmp41 = tmp24 + tmp40 tl.store(in_out_ptr0 + x4, tmp41, None) @triton.jit def triton_poi_fused_cat_17(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 256 % 1024 x3 = xindex // 262144 x4 = xindex % 256 x0 = xindex % 16 x1 = xindex // 16 % 16 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 512, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 256 * x2 + 131072 * x3), tmp4, other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tl.full([1], 1024, tl.int64) tmp13 = tl.load(in_ptr2 + (100 + x0 + 24 * x1 + 576 * (-512 + x2) + 294912 * x3), tmp10, other=0.0) tmp14 = tl.where(tmp4, tmp9, tmp13) tl.store(out_ptr0 + x5, tmp14, None) @triton.jit def triton_poi_fused_convolution_relu_18(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 196 % 512 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused__to_copy_19(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 24 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4782608695652174 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_20(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 24 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4782608695652174 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 11, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_21(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 24 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.4782608695652174 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = 1.0 tmp11 = triton_helpers.minimum(tmp9, tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_22(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 24 % 24 x0 = xindex % 24 x6 = xindex // 576 x2 = xindex // 576 % 512 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp25 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp39 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 12, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 12 * tmp4 + 144 * x6), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp15 = tmp14 + tmp1 tmp16 = tmp14 < 0 tmp17 = tl.where(tmp16, tmp15, tmp14) tmp18 = tl.load(in_ptr2 + (tmp17 + 12 * tmp4 + 144 * x6), None, eviction_policy='evict_last') tmp19 = tmp18 + tmp10 tmp20 = triton_helpers.maximum(tmp12, tmp19) tmp21 = tmp20 - tmp13 tmp23 = tmp21 * tmp22 tmp24 = tmp13 + tmp23 tmp26 = tmp25 + tmp1 tmp27 = tmp25 < 0 tmp28 = tl.where(tmp27, tmp26, tmp25) tmp29 = tl.load(in_ptr2 + (tmp8 + 12 * tmp28 + 144 * x6), None, eviction_policy='evict_last') tmp30 = tmp29 + tmp10 tmp31 = triton_helpers.maximum(tmp12, tmp30) tmp32 = tl.load(in_ptr2 + (tmp17 + 12 * tmp28 + 144 * x6), None, eviction_policy='evict_last') tmp33 = tmp32 + tmp10 tmp34 = triton_helpers.maximum(tmp12, tmp33) tmp35 = tmp34 - tmp31 tmp36 = tmp35 * tmp22 tmp37 = tmp31 + tmp36 tmp38 = tmp37 - tmp24 tmp40 = tmp38 * tmp39 tmp41 = tmp24 + tmp40 tl.store(in_out_ptr0 + x4, tmp41, None) @triton.jit def triton_poi_fused_cat_23(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 576 % 512 x3 = xindex // 294912 x4 = xindex % 576 x0 = xindex % 24 x1 = xindex // 24 % 24 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 256, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 576 * x2 + 147456 * x3), tmp4, other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tl.full([1], 512, tl.int64) tmp13 = tl.load(in_ptr2 + (928 + x0 + 57 * x1 + 3249 * (-256 + x2) + 831744 * x3), tmp10, other=0.0) tmp14 = tl.where(tmp4, tmp9, tmp13) tl.store(out_ptr0 + x5, tmp14, None) @triton.jit def triton_poi_fused_convolution_relu_24(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 // 484 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused__to_copy_25(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 40 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.48717948717948717 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_26(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 40 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.48717948717948717 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 19, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_27(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 40 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.48717948717948717 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = 1.0 tmp11 = triton_helpers.minimum(tmp9, tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_28(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 40 % 40 x0 = xindex % 40 x6 = xindex // 1600 x2 = xindex // 1600 % 256 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp25 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp39 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 20, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 20 * tmp4 + 400 * x6), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp15 = tmp14 + tmp1 tmp16 = tmp14 < 0 tmp17 = tl.where(tmp16, tmp15, tmp14) tmp18 = tl.load(in_ptr2 + (tmp17 + 20 * tmp4 + 400 * x6), None, eviction_policy='evict_last') tmp19 = tmp18 + tmp10 tmp20 = triton_helpers.maximum(tmp12, tmp19) tmp21 = tmp20 - tmp13 tmp23 = tmp21 * tmp22 tmp24 = tmp13 + tmp23 tmp26 = tmp25 + tmp1 tmp27 = tmp25 < 0 tmp28 = tl.where(tmp27, tmp26, tmp25) tmp29 = tl.load(in_ptr2 + (tmp8 + 20 * tmp28 + 400 * x6), None, eviction_policy='evict_last') tmp30 = tmp29 + tmp10 tmp31 = triton_helpers.maximum(tmp12, tmp30) tmp32 = tl.load(in_ptr2 + (tmp17 + 20 * tmp28 + 400 * x6), None, eviction_policy='evict_last') tmp33 = tmp32 + tmp10 tmp34 = triton_helpers.maximum(tmp12, tmp33) tmp35 = tmp34 - tmp31 tmp36 = tmp35 * tmp22 tmp37 = tmp31 + tmp36 tmp38 = tmp37 - tmp24 tmp40 = tmp38 * tmp39 tmp41 = tmp24 + tmp40 tl.store(in_out_ptr0 + x4, tmp41, None) @triton.jit def triton_poi_fused_cat_29(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 1600 % 256 x3 = xindex // 409600 x4 = xindex % 1600 x0 = xindex % 40 x1 = xindex // 40 % 40 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 128, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 1600 * x2 + 204800 * x3), tmp4, other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tl.full([1], 256, tl.int64) tmp13 = tl.load(in_ptr2 + (5043 + x0 + 122 * x1 + 14884 * (-128 + x2) + 1905152 * x3), tmp10, other=0.0) tmp14 = tl.where(tmp4, tmp9, tmp13) tl.store(out_ptr0 + x5, tmp14, None) @triton.jit def triton_poi_fused_convolution_relu_30(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 // 1444 % 128 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused__to_copy_31(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 72 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.49295774647887325 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tl.store(out_ptr0 + x0, tmp6, xmask) @triton.jit def triton_poi_fused_add_clamp_32(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 72 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.49295774647887325 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tl.full([1], 1, tl.int64) tmp8 = tmp6 + tmp7 tmp9 = tl.full([1], 35, tl.int64) tmp10 = triton_helpers.minimum(tmp8, tmp9) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused__to_copy_arange_clamp_mul_sub_33(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 72 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.49295774647887325 tmp3 = tmp1 * tmp2 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = tmp5.to(tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 - tmp7 tmp9 = triton_helpers.maximum(tmp8, tmp4) tmp10 = 1.0 tmp11 = triton_helpers.minimum(tmp9, tmp10) tl.store(out_ptr0 + x0, tmp11, xmask) @triton.jit def triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_34(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x1 = xindex // 72 % 72 x0 = xindex % 72 x6 = xindex // 5184 x2 = xindex // 5184 % 128 x4 = xindex tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp5 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last') tmp10 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last') tmp14 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last') tmp22 = tl.load(in_ptr5 + x0, None, eviction_policy='evict_last') tmp25 = tl.load(in_ptr6 + x1, None, eviction_policy='evict_last') tmp39 = tl.load(in_ptr7 + x1, None, eviction_policy='evict_last') tmp1 = tl.full([XBLOCK], 36, tl.int32) tmp2 = tmp0 + tmp1 tmp3 = tmp0 < 0 tmp4 = tl.where(tmp3, tmp2, tmp0) tmp6 = tmp5 + tmp1 tmp7 = tmp5 < 0 tmp8 = tl.where(tmp7, tmp6, tmp5) tmp9 = tl.load(in_ptr2 + (tmp8 + 36 * tmp4 + 1296 * x6), None, eviction_policy='evict_last') tmp11 = tmp9 + tmp10 tmp12 = tl.full([1], 0, tl.int32) tmp13 = triton_helpers.maximum(tmp12, tmp11) tmp15 = tmp14 + tmp1 tmp16 = tmp14 < 0 tmp17 = tl.where(tmp16, tmp15, tmp14) tmp18 = tl.load(in_ptr2 + (tmp17 + 36 * tmp4 + 1296 * x6), None, eviction_policy='evict_last') tmp19 = tmp18 + tmp10 tmp20 = triton_helpers.maximum(tmp12, tmp19) tmp21 = tmp20 - tmp13 tmp23 = tmp21 * tmp22 tmp24 = tmp13 + tmp23 tmp26 = tmp25 + tmp1 tmp27 = tmp25 < 0 tmp28 = tl.where(tmp27, tmp26, tmp25) tmp29 = tl.load(in_ptr2 + (tmp8 + 36 * tmp28 + 1296 * x6), None, eviction_policy='evict_last') tmp30 = tmp29 + tmp10 tmp31 = triton_helpers.maximum(tmp12, tmp30) tmp32 = tl.load(in_ptr2 + (tmp17 + 36 * tmp28 + 1296 * x6), None, eviction_policy='evict_last') tmp33 = tmp32 + tmp10 tmp34 = triton_helpers.maximum(tmp12, tmp33) tmp35 = tmp34 - tmp31 tmp36 = tmp35 * tmp22 tmp37 = tmp31 + tmp36 tmp38 = tmp37 - tmp24 tmp40 = tmp38 * tmp39 tmp41 = tmp24 + tmp40 tl.store(in_out_ptr0 + x4, tmp41, None) @triton.jit def triton_poi_fused_cat_35(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex // 5184 % 128 x3 = xindex // 663552 x4 = xindex % 5184 x0 = xindex % 72 x1 = xindex // 72 % 72 x5 = xindex tmp0 = x2 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x4 + 5184 * x2 + 331776 * x3), tmp4, other=0.0) tmp6 = tl.load(in_ptr1 + x2, tmp4, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype) tmp9 = tl.where(tmp4, tmp7, tmp8) tmp10 = tmp0 >= tmp3 tl.full([1], 128, tl.int64) tmp13 = tl.load(in_ptr2 + (22770 + x0 + 252 * x1 + 63504 * (-64 + x2) + 4064256 * x3), tmp10, other=0.0) tmp14 = tl.where(tmp4, tmp9, tmp13) tl.store(out_ptr0 + x5, tmp14, None) @triton.jit def triton_poi_fused_convolution_relu_36(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1254400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4900 % 64 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_37(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 // 4624 % 64 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_38(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18496 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tl.store(in_out_ptr0 + x0, tmp3, xmask) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_39(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 1296 % 128 x0 = xindex % 1296 x4 = xindex // 1296 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + (x0 + 1408 * x4), tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_40(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 400 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_41(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 144 % 512 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_42(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 64 % 1024 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47) = args args.clear() assert_size_stride(primals_1, (64, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 1, 256, 256), (65536, 65536, 256, 1)) assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_5, (64,), (1,)) assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_7, (128,), (1,)) assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_11, (256,), (1,)) assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_13, (256,), (1,)) assert_size_stride(primals_14, (512, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_15, (512,), (1,)) assert_size_stride(primals_16, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_17, (512,), (1,)) assert_size_stride(primals_18, (1024, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_19, (1024,), (1,)) assert_size_stride(primals_20, (1024, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_21, (1024,), (1,)) assert_size_stride(primals_22, (512, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_23, (512,), (1,)) assert_size_stride(primals_24, (512, 1024, 3, 3), (9216, 9, 3, 1)) assert_size_stride(primals_25, (512,), (1,)) assert_size_stride(primals_26, (512, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_27, (512,), (1,)) assert_size_stride(primals_28, (256, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_29, (256,), (1,)) assert_size_stride(primals_30, (256, 512, 3, 3), (4608, 9, 3, 1)) assert_size_stride(primals_31, (256,), (1,)) assert_size_stride(primals_32, (256, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_33, (256,), (1,)) assert_size_stride(primals_34, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_35, (128,), (1,)) assert_size_stride(primals_36, (128, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_37, (128,), (1,)) assert_size_stride(primals_38, (128, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_39, (128,), (1,)) assert_size_stride(primals_40, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_41, (64,), (1,)) assert_size_stride(primals_42, (64, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_43, (64,), (1,)) assert_size_stride(primals_44, (64, 64, 3, 3), (576, 9, 3, 1)) assert_size_stride(primals_45, (64,), (1,)) assert_size_stride(primals_46, (1, 64, 1, 1), (64, 1, 1, 1)) assert_size_stride(primals_47, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 64, 254, 254), (4129024, 64516, 254, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(16516096)](buf1, primals_2, 16516096, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 64, 252, 252), (4064256, 63504, 252, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_1[grid(16257024)](buf3, primals_5, 16257024, XBLOCK=512, num_warps=8, num_stages=1) del primals_5 buf4 = empty_strided_cuda((4, 64, 126, 126), (1017856, 15904, 126, 1), torch.float32) buf5 = empty_strided_cuda((4, 64, 126, 126), (1024000, 16000, 126, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_2[grid(4064256)](buf3, buf4, buf5, 4064256, XBLOCK=512, num_warps=8, num_stages=1) buf6 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 128, 124, 124), (1968128, 15376, 124, 1)) buf7 = buf6 del buf6 triton_poi_fused_convolution_relu_3[grid(7872512)](buf7, primals_7, 7872512, XBLOCK=512, num_warps=8, num_stages=1) del primals_7 buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf8, (4, 128, 122, 122), (1905152, 14884, 122, 1)) buf9 = buf8 del buf8 triton_poi_fused_convolution_relu_4[grid(7620608)](buf9, primals_9, 7620608, XBLOCK=1024, num_warps=4, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 128, 61, 61), (479232, 3744, 61, 1), torch.float32) buf11 = empty_strided_cuda((4, 128, 61, 61), (491520, 3840, 61, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_5[grid(1905152)](buf9, buf10, buf11, 1905152, XBLOCK=512, num_warps=8, num_stages=1) buf12 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf12, (4, 256, 59, 59), (891136, 3481, 59, 1)) buf13 = buf12 del buf12 triton_poi_fused_convolution_relu_6[grid(3564544)](buf13, primals_11, 3564544, XBLOCK=1024, num_warps=4, num_stages=1) del primals_11 buf14 = extern_kernels.convolution(buf13, primals_12, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf14, (4, 256, 57, 57), (831744, 3249, 57, 1)) buf15 = buf14 del buf14 triton_poi_fused_convolution_relu_7[grid(3326976)](buf15, primals_13, 3326976, XBLOCK=1024, num_warps=4, num_stages=1) del primals_13 buf16 = empty_strided_cuda((4, 256, 28, 28), (200704, 784, 28, 1), torch.float32) buf17 = empty_strided_cuda((4, 256, 28, 28), (200704, 784, 28, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_8[grid(802816)](buf15, buf16, buf17, 802816, XBLOCK=512, num_warps=8, num_stages=1) buf18 = extern_kernels.convolution(buf16, primals_14, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 512, 26, 26), (346112, 676, 26, 1)) buf19 = buf18 del buf18 triton_poi_fused_convolution_relu_9[grid(1384448)](buf19, primals_15, 1384448, XBLOCK=1024, num_warps=4, num_stages=1) del primals_15 buf20 = extern_kernels.convolution(buf19, primals_16, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 512, 24, 24), (294912, 576, 24, 1)) buf21 = buf20 del buf20 triton_poi_fused_convolution_relu_10[grid(1179648)](buf21, primals_17, 1179648, XBLOCK=1024, num_warps=4, num_stages=1) del primals_17 buf22 = empty_strided_cuda((4, 512, 12, 12), (73728, 144, 12, 1), torch.float32) buf23 = empty_strided_cuda((4, 512, 12, 12), (73728, 144, 12, 1), torch.int8) triton_poi_fused_max_pool2d_with_indices_11[grid(294912)](buf21, buf22, buf23, 294912, XBLOCK=512, num_warps=8, num_stages=1) buf24 = extern_kernels.convolution(buf22, primals_18, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 1024, 10, 10), (102400, 100, 10, 1)) buf25 = buf24 del buf24 triton_poi_fused_convolution_relu_12[grid(409600)](buf25, primals_19, 409600, XBLOCK=1024, num_warps=4, num_stages=1) del primals_19 buf26 = extern_kernels.convolution(buf25, primals_20, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 1024, 8, 8), (65536, 64, 8, 1)) buf27 = empty_strided_cuda((16, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_13[grid(16)](buf27, 16, XBLOCK=16, num_warps=1, num_stages=1) buf28 = empty_strided_cuda((16, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_14[grid(16)](buf28, 16, XBLOCK=16, num_warps=1, num_stages=1) buf29 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused__to_copy_13[grid(16)](buf29, 16, XBLOCK=16, num_warps=1, num_stages=1) buf30 = empty_strided_cuda((16,), (1,), torch.int64) triton_poi_fused_add_clamp_14[grid(16)](buf30, 16, XBLOCK=16, num_warps=1, num_stages=1) buf31 = empty_strided_cuda((16,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_15[grid(16)](buf31, 16, XBLOCK=16, num_warps=1, num_stages=1) buf33 = empty_strided_cuda((16, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_15[grid(16)](buf33, 16, XBLOCK=16, num_warps=1, num_stages=1) buf34 = empty_strided_cuda((4, 1024, 16, 16), (262144, 256, 16, 1), torch.float32) buf35 = buf34 del buf34 triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_16[grid (1048576)](buf35, buf27, buf29, buf26, primals_21, buf30, buf31, buf28, buf33, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) buf36 = extern_kernels.convolution(buf35, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf36, (4, 512, 16, 16), (131072, 256, 16, 1)) buf37 = empty_strided_cuda((4, 1024, 16, 16), (262144, 256, 16, 1), torch.float32) triton_poi_fused_cat_17[grid(1048576)](buf36, primals_23, buf21, buf37, 1048576, XBLOCK=1024, num_warps=4, num_stages=1) del buf36 del primals_23 buf38 = extern_kernels.convolution(buf37, primals_24, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf38, (4, 512, 14, 14), (100352, 196, 14, 1)) buf39 = buf38 del buf38 triton_poi_fused_convolution_relu_18[grid(401408)](buf39, primals_25, 401408, XBLOCK=512, num_warps=8, num_stages=1) del primals_25 buf40 = extern_kernels.convolution(buf39, primals_26, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf40, (4, 512, 12, 12), (73728, 144, 12, 1)) buf41 = empty_strided_cuda((24, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_19[grid(24)](buf41, 24, XBLOCK=32, num_warps=1, num_stages=1) buf42 = empty_strided_cuda((24, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_20[grid(24)](buf42, 24, XBLOCK=32, num_warps=1, num_stages=1) buf43 = empty_strided_cuda((24,), (1,), torch.int64) triton_poi_fused__to_copy_19[grid(24)](buf43, 24, XBLOCK=32, num_warps=1, num_stages=1) buf44 = empty_strided_cuda((24,), (1,), torch.int64) triton_poi_fused_add_clamp_20[grid(24)](buf44, 24, XBLOCK=32, num_warps=1, num_stages=1) buf45 = empty_strided_cuda((24,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_21[grid(24)](buf45, 24, XBLOCK=32, num_warps=1, num_stages=1) buf47 = empty_strided_cuda((24, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_21[grid(24)](buf47, 24, XBLOCK=32, num_warps=1, num_stages=1) buf48 = empty_strided_cuda((4, 512, 24, 24), (294912, 576, 24, 1), torch.float32) buf49 = buf48 del buf48 triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_22[grid (1179648)](buf49, buf41, buf43, buf40, primals_27, buf44, buf45, buf42, buf47, 1179648, XBLOCK=1024, num_warps=4, num_stages=1) buf50 = extern_kernels.convolution(buf49, primals_28, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf50, (4, 256, 24, 24), (147456, 576, 24, 1)) buf51 = empty_strided_cuda((4, 512, 24, 24), (294912, 576, 24, 1), torch.float32) triton_poi_fused_cat_23[grid(1179648)](buf50, primals_29, buf15, buf51, 1179648, XBLOCK=1024, num_warps=4, num_stages=1) del buf50 del primals_29 buf52 = extern_kernels.convolution(buf51, primals_30, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf52, (4, 256, 22, 22), (123904, 484, 22, 1)) buf53 = buf52 del buf52 triton_poi_fused_convolution_relu_24[grid(495616)](buf53, primals_31, 495616, XBLOCK=1024, num_warps=4, num_stages=1) del primals_31 buf54 = extern_kernels.convolution(buf53, primals_32, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf54, (4, 256, 20, 20), (102400, 400, 20, 1)) buf55 = empty_strided_cuda((40, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_25[grid(40)](buf55, 40, XBLOCK=64, num_warps=1, num_stages=1) buf56 = empty_strided_cuda((40, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_26[grid(40)](buf56, 40, XBLOCK=64, num_warps=1, num_stages=1) buf57 = empty_strided_cuda((40,), (1,), torch.int64) triton_poi_fused__to_copy_25[grid(40)](buf57, 40, XBLOCK=64, num_warps=1, num_stages=1) buf58 = empty_strided_cuda((40,), (1,), torch.int64) triton_poi_fused_add_clamp_26[grid(40)](buf58, 40, XBLOCK=64, num_warps=1, num_stages=1) buf59 = empty_strided_cuda((40,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_27[grid(40)](buf59, 40, XBLOCK=64, num_warps=1, num_stages=1) buf61 = empty_strided_cuda((40, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_27[grid(40)](buf61, 40, XBLOCK=64, num_warps=1, num_stages=1) buf62 = empty_strided_cuda((4, 256, 40, 40), (409600, 1600, 40, 1), torch.float32) buf63 = buf62 del buf62 triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_28[grid (1638400)](buf63, buf55, buf57, buf54, primals_33, buf58, buf59, buf56, buf61, 1638400, XBLOCK=1024, num_warps=4, num_stages=1) buf64 = extern_kernels.convolution(buf63, primals_34, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf64, (4, 128, 40, 40), (204800, 1600, 40, 1)) buf65 = empty_strided_cuda((4, 256, 40, 40), (409600, 1600, 40, 1), torch.float32) triton_poi_fused_cat_29[grid(1638400)](buf64, primals_35, buf9, buf65, 1638400, XBLOCK=512, num_warps=8, num_stages=1) del buf64 del primals_35 buf66 = extern_kernels.convolution(buf65, primals_36, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf66, (4, 128, 38, 38), (184832, 1444, 38, 1)) buf67 = buf66 del buf66 triton_poi_fused_convolution_relu_30[grid(739328)](buf67, primals_37, 739328, XBLOCK=1024, num_warps=4, num_stages=1) del primals_37 buf68 = extern_kernels.convolution(buf67, primals_38, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf68, (4, 128, 36, 36), (165888, 1296, 36, 1)) buf69 = empty_strided_cuda((72, 1), (1, 1), torch.int64) triton_poi_fused__to_copy_31[grid(72)](buf69, 72, XBLOCK=128, num_warps=4, num_stages=1) buf70 = empty_strided_cuda((72, 1), (1, 1), torch.int64) triton_poi_fused_add_clamp_32[grid(72)](buf70, 72, XBLOCK=128, num_warps=4, num_stages=1) buf71 = empty_strided_cuda((72,), (1,), torch.int64) triton_poi_fused__to_copy_31[grid(72)](buf71, 72, XBLOCK=128, num_warps=4, num_stages=1) buf72 = empty_strided_cuda((72,), (1,), torch.int64) triton_poi_fused_add_clamp_32[grid(72)](buf72, 72, XBLOCK=128, num_warps=4, num_stages=1) buf73 = empty_strided_cuda((72,), (1,), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_33[grid(72)](buf73, 72, XBLOCK=128, num_warps=4, num_stages=1) buf75 = empty_strided_cuda((72, 1), (1, 1), torch.float32) triton_poi_fused__to_copy_arange_clamp_mul_sub_33[grid(72)](buf75, 72, XBLOCK=128, num_warps=4, num_stages=1) buf76 = empty_strided_cuda((4, 128, 72, 72), (663552, 5184, 72, 1), torch.float32) buf77 = buf76 del buf76 triton_poi_fused__unsafe_index_add_convolution_mul_relu_sub_34[grid (2654208)](buf77, buf69, buf71, buf68, primals_39, buf72, buf73, buf70, buf75, 2654208, XBLOCK=1024, num_warps=4, num_stages=1) buf78 = extern_kernels.convolution(buf77, primals_40, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf78, (4, 64, 72, 72), (331776, 5184, 72, 1)) buf79 = empty_strided_cuda((4, 128, 72, 72), (663552, 5184, 72, 1), torch.float32) triton_poi_fused_cat_35[grid(2654208)](buf78, primals_41, buf3, buf79, 2654208, XBLOCK=1024, num_warps=4, num_stages=1) del buf78 del primals_41 buf80 = extern_kernels.convolution(buf79, primals_42, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf80, (4, 64, 70, 70), (313600, 4900, 70, 1)) buf81 = buf80 del buf80 triton_poi_fused_convolution_relu_36[grid(1254400)](buf81, primals_43, 1254400, XBLOCK=1024, num_warps=4, num_stages=1) del primals_43 buf82 = extern_kernels.convolution(buf81, primals_44, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf82, (4, 64, 68, 68), (295936, 4624, 68, 1)) buf83 = buf82 del buf82 triton_poi_fused_convolution_relu_37[grid(1183744)](buf83, primals_45, 1183744, XBLOCK=1024, num_warps=4, num_stages=1) del primals_45 buf84 = extern_kernels.convolution(buf83, primals_46, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf84, (4, 1, 68, 68), (4624, 4624, 68, 1)) buf85 = buf84 del buf84 triton_poi_fused_convolution_38[grid(18496)](buf85, primals_47, 18496, XBLOCK=256, num_warps=4, num_stages=1) del primals_47 buf86 = empty_strided_cuda((4, 128, 36, 36), (180224, 1408, 36, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_39[grid(663552)]( buf68, primals_39, buf86, 663552, XBLOCK=1024, num_warps=4, num_stages=1) del buf68 del primals_39 buf87 = empty_strided_cuda((4, 256, 20, 20), (102400, 400, 20, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_40[grid(409600)]( buf54, primals_33, buf87, 409600, XBLOCK=1024, num_warps=4, num_stages=1) del buf54 del primals_33 buf88 = empty_strided_cuda((4, 512, 12, 12), (73728, 144, 12, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_41[grid(294912)]( buf40, primals_27, buf88, 294912, XBLOCK=1024, num_warps=4, num_stages=1) del buf40 del primals_27 buf89 = empty_strided_cuda((4, 1024, 8, 8), (65536, 64, 8, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_42[grid(262144)]( buf26, primals_21, buf89, 262144, XBLOCK=512, num_warps=8, num_stages=1) del buf26 del primals_21 return (buf85, primals_1, primals_3, primals_4, primals_6, primals_8, primals_10, primals_12, primals_14, primals_16, primals_18, primals_20, primals_22, primals_24, primals_26, primals_28, primals_30, primals_32, primals_34, primals_36, primals_38, primals_40, primals_42, primals_44, primals_46, buf1, buf3, buf4, buf5, buf7, buf9, buf10, buf11, buf13, buf15, buf16, buf17, buf19, buf21, buf22, buf23, buf25, buf27, buf28, buf29, buf30, buf31, buf33, buf35, buf37, buf39, buf41, buf42, buf43, buf44, buf45, buf47, buf49, buf51, buf53, buf55, buf56, buf57, buf58, buf59, buf61, buf63, buf65, buf67, buf69, buf70, buf71, buf72, buf73, buf75, buf77, buf79, buf81, buf83, buf86, buf87, buf88, buf89) class ContractingBlock(nn.Module): """ ContractingBlock Class Performs two convolutions followed by a max pool operation. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, in_channels, out_channels): super().__init__() self.conv3x3_0 = nn.Conv2d(in_channels, out_channels, kernel_size=3) self.conv3x3_1 = nn.Conv2d(out_channels, out_channels, kernel_size=3) def forward(self, x): """ Function for completing a forward pass of ContractingBlock: Given an image tensor, completes a contracting block and returns the transformed tensor. Parameters: x: image tensor of shape (batch size, channels, height, width) """ fx = F.relu(self.conv3x3_0(x)) fx = F.relu(self.conv3x3_1(fx)) return fx class ExpandingBlock(nn.Module): """ ExpandingBlock Performs an upsampling, a convolution, a concatenation of its two inputs, followed by two more convolutions. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, hid_channels): super(ExpandingBlock, self).__init__() self.upsample = nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True) self.conv = nn.Conv2d(hid_channels, hid_channels // 2, kernel_size= 3, stride=1, padding=1) self.conv3x3_0 = nn.Conv2d(hid_channels, hid_channels // 2, kernel_size=3, stride=1) self.conv3x3_1 = nn.Conv2d(hid_channels // 2, hid_channels // 2, kernel_size=3, stride=1) @staticmethod def crop(x, shape=None): """ Function for cropping an image tensor: Given an image tensor and the new shape, crops to the center pixels (assumes that the input's size and the new size are even numbers). Parameters: image: image tensor of shape (batch size, channels, height, width) new_shape: a torch.Size object with the shape you want x to have """ _, _, h, w = x.shape _, _, h_new, w_new = shape ch, cw = h // 2, w // 2 ch_new, cw_new = h_new // 2, w_new // 2 x1 = int(cw - cw_new) y1 = int(ch - ch_new) x2 = int(x1 + w_new) y2 = int(y1 + h_new) return x[:, :, y1:y2, x1:x2] def forward(self, x, skip): """ Function for completing a forward pass of ExpandingBlock: Given an image tensor, completes an expanding block and returns the transformed tensor. Parameters: x: image tensor of shape (batch size, channels, height, width) skip_con_x: the image tensor from the contracting path (from the opposing block of x) for the skip connection """ up = self.upsample(x) upconv = self.conv(up) skip = self.crop(skip, upconv.shape) fx = torch.cat([upconv, skip], dim=1) fx = F.relu(self.conv3x3_0(fx)) fx = F.relu(self.conv3x3_1(fx)) return fx class FeatureMapBlock(nn.Module): """ FeatureMapBlock The final layer of a UNet - maps each pixel to a pixel with the correct number of output dimensions using a 1x1 convolution. Values: input_channels: the number of channels to expect from a given input """ def __init__(self, in_channels, out_channels): super(FeatureMapBlock, self).__init__() self.conv1x1 = nn.Conv2d(in_channels, out_channels, kernel_size=1) def forward(self, x): """ Function for completing a forward pass of FeatureMapBlock: Given an image tensor, returns it mapped to the desired number of channels. Parameters: x: image tensor of shape (batch size, channels, height, width) """ fx = self.conv1x1(x) return fx class UnetNew(nn.Module): """ UNet Class A series of 4 contracting blocks followed by 4 expanding blocks to transform an input image into the corresponding paired image, with an upfeature layer at the start and a downfeature layer at the end Values: input_channels: the number of channels to expect from a given input output_channels: the number of channels to expect for a given output """ def __init__(self, in_channels=1, hid_channels=64, out_channels=1): super(UnetNew, self).__init__() self.contract1 = ContractingBlock(1, hid_channels) self.contract2 = ContractingBlock(hid_channels, hid_channels * 2) self.contract3 = ContractingBlock(hid_channels * 2, hid_channels * 4) self.contract4 = ContractingBlock(hid_channels * 4, hid_channels * 8) self.bottleneck = ContractingBlock(hid_channels * 8, hid_channels * 16) self.expand1 = ExpandingBlock(hid_channels * 16) self.expand2 = ExpandingBlock(hid_channels * 8) self.expand3 = ExpandingBlock(hid_channels * 4) self.expand4 = ExpandingBlock(hid_channels * 2) self.downfeature = FeatureMapBlock(hid_channels, out_channels) self.pool = nn.MaxPool2d(kernel_size=2, stride=2) def forward(self, input_0): primals_1 = self.contract1.conv3x3_0.weight primals_2 = self.contract1.conv3x3_0.bias primals_4 = self.contract1.conv3x3_1.weight primals_5 = self.contract1.conv3x3_1.bias primals_6 = self.contract2.conv3x3_0.weight primals_7 = self.contract2.conv3x3_0.bias primals_8 = self.contract2.conv3x3_1.weight primals_9 = self.contract2.conv3x3_1.bias primals_10 = self.contract3.conv3x3_0.weight primals_11 = self.contract3.conv3x3_0.bias primals_12 = self.contract3.conv3x3_1.weight primals_13 = self.contract3.conv3x3_1.bias primals_14 = self.contract4.conv3x3_0.weight primals_15 = self.contract4.conv3x3_0.bias primals_16 = self.contract4.conv3x3_1.weight primals_17 = self.contract4.conv3x3_1.bias primals_18 = self.bottleneck.conv3x3_0.weight primals_19 = self.bottleneck.conv3x3_0.bias primals_20 = self.bottleneck.conv3x3_1.weight primals_21 = self.bottleneck.conv3x3_1.bias primals_22 = self.expand1.conv.weight primals_23 = self.expand1.conv.bias primals_24 = self.expand1.conv3x3_0.weight primals_25 = self.expand1.conv3x3_0.bias primals_26 = self.expand1.conv3x3_1.weight primals_27 = self.expand1.conv3x3_1.bias primals_28 = self.expand2.conv.weight primals_29 = self.expand2.conv.bias primals_30 = self.expand2.conv3x3_0.weight primals_31 = self.expand2.conv3x3_0.bias primals_32 = self.expand2.conv3x3_1.weight primals_33 = self.expand2.conv3x3_1.bias primals_34 = self.expand3.conv.weight primals_35 = self.expand3.conv.bias primals_36 = self.expand3.conv3x3_0.weight primals_37 = self.expand3.conv3x3_0.bias primals_38 = self.expand3.conv3x3_1.weight primals_39 = self.expand3.conv3x3_1.bias primals_40 = self.expand4.conv.weight primals_41 = self.expand4.conv.bias primals_42 = self.expand4.conv3x3_0.weight primals_43 = self.expand4.conv3x3_0.bias primals_44 = self.expand4.conv3x3_1.weight primals_45 = self.expand4.conv3x3_1.bias primals_46 = self.downfeature.conv1x1.weight primals_47 = self.downfeature.conv1x1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22, primals_23, primals_24, primals_25, primals_26, primals_27, primals_28, primals_29, primals_30, primals_31, primals_32, primals_33, primals_34, primals_35, primals_36, primals_37, primals_38, primals_39, primals_40, primals_41, primals_42, primals_43, primals_44, primals_45, primals_46, primals_47]) return output[0]
akanametov/unet-pytorch
Unet
false
3,190
[ "MIT" ]
0
6cf0f70674958356ea4ac36fe61b0415921f72ae
https://github.com/akanametov/unet-pytorch/tree/6cf0f70674958356ea4ac36fe61b0415921f72ae
SortNet
import torch import torch.nn as nn import torch.nn.functional as F class SortNet(nn.Module): def __init__(self, input_size, hidden_size): super(SortNet, self).__init__() self.input_size = input_size self.hidden_size = hidden_size self.fc1 = nn.Linear(input_size, hidden_size, bias=None) self.fc2 = nn.Linear(hidden_size, input_size) def forward(self, x): x = F.tanh(self.fc1(x)) x = self.fc2(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(256)](buf1, 256, XBLOCK=128, num_warps =4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_4, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_4 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_2, (64, 4), (4, 1), 0), buf1, primals_3 class SortNetNew(nn.Module): def __init__(self, input_size, hidden_size): super(SortNetNew, self).__init__() self.input_size = input_size self.hidden_size = hidden_size self.fc1 = nn.Linear(input_size, hidden_size, bias=None) self.fc2 = nn.Linear(hidden_size, input_size) def forward(self, input_0): primals_1 = self.fc1.weight primals_3 = self.fc2.weight primals_4 = self.fc2.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
bashish101/sort
SortNet
false
3,191
[ "MIT" ]
0
c8f3e4875c039e6eb935c34ed8403c5d439bf8ad
https://github.com/bashish101/sort/tree/c8f3e4875c039e6eb935c34ed8403c5d439bf8ad
Lambda
import torch import torch.nn as nn class Lambda(nn.Module): def forward(self, t, y): t = t.unsqueeze(0) equation = -1000 * y + 3000 - 2000 * torch.exp(-t) return equation def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_exp_mul_neg_sub_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) tmp5 = tl.load(in_ptr1 + x0, xmask) tmp1 = -1000.0 tmp2 = tmp0 * tmp1 tmp3 = 3000.0 tmp4 = tmp2 + tmp3 tmp6 = -tmp5 tmp7 = tl_math.exp(tmp6) tmp8 = 2000.0 tmp9 = tmp7 * tmp8 tmp10 = tmp4 - tmp9 tl.store(out_ptr0 + x0, tmp10, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_exp_mul_neg_sub_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class LambdaNew(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]
arnabgho/torchdiffeq
Lambda
false
3,192
[ "MIT" ]
0
d4f73440d0e714b87ea133610e61eefbd673e5f5
https://github.com/arnabgho/torchdiffeq/tree/d4f73440d0e714b87ea133610e61eefbd673e5f5
SineODE
import math import torch class SineODE(torch.nn.Module): def __init__(self, device): super(SineODE, self).__init__() def forward(self, t, y): return 2 * y / t + t ** 4 * torch.sin(2 * t) - t ** 2 + 4 * t ** 3 def y_exact(self, t): return -0.5 * t ** 4 * torch.cos(2 * t) + 0.5 * t ** 3 * torch.sin( 2 * t) + 0.25 * t ** 2 * torch.cos(2 * t) - t ** 3 + 2 * t ** 4 + ( math.pi - 0.25) * t ** 2 def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'device': 0}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import math assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_div_mul_pow_sin_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr1 + x0, xmask) tmp1 = 2.0 tmp2 = tmp0 * tmp1 tmp4 = tmp2 / tmp3 tmp5 = tmp3 * tmp3 tmp6 = tmp5 * tmp5 tmp7 = tmp3 * tmp1 tmp8 = tl_math.sin(tmp7) tmp9 = tmp6 * tmp8 tmp10 = tmp4 + tmp9 tmp11 = tmp10 - tmp5 tmp12 = tmp5 * tmp3 tmp13 = 4.0 tmp14 = tmp12 * tmp13 tmp15 = tmp11 + tmp14 tl.store(out_ptr0 + x0, tmp15, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_mul_pow_sin_sub_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 SineODENew(torch.nn.Module): def __init__(self, device): super(SineODENew, self).__init__() def y_exact(self, t): return -0.5 * t ** 4 * torch.cos(2 * t) + 0.5 * t ** 3 * torch.sin( 2 * t) + 0.25 * t ** 2 * torch.cos(2 * t) - t ** 3 + 2 * t ** 4 + ( math.pi - 0.25) * t ** 2 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
arnabgho/torchdiffeq
SineODE
false
3,193
[ "MIT" ]
0
d4f73440d0e714b87ea133610e61eefbd673e5f5
https://github.com/arnabgho/torchdiffeq/tree/d4f73440d0e714b87ea133610e61eefbd673e5f5
generator
import torch import torch.nn as nn import torch.nn.functional as F class generator(nn.Module): def __init__(self, z_dim, point_dim, gf_dim): super(generator, self).__init__() self.z_dim = z_dim self.point_dim = point_dim self.gf_dim = gf_dim self.linear_1 = nn.Linear(self.z_dim + self.point_dim, self.gf_dim * 8, bias=True) self.linear_2 = nn.Linear(self.gf_dim * 8, self.gf_dim * 8, bias=True) self.linear_3 = nn.Linear(self.gf_dim * 8, self.gf_dim * 8, bias=True) self.linear_4 = nn.Linear(self.gf_dim * 8, self.gf_dim * 4, bias=True) self.linear_5 = nn.Linear(self.gf_dim * 4, self.gf_dim * 2, bias=True) self.linear_6 = nn.Linear(self.gf_dim * 2, self.gf_dim * 1, bias=True) self.linear_7 = nn.Linear(self.gf_dim * 1, 1, bias=True) nn.init.normal_(self.linear_1.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_1.bias, 0) nn.init.normal_(self.linear_2.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_2.bias, 0) nn.init.normal_(self.linear_3.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_3.bias, 0) nn.init.normal_(self.linear_4.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_4.bias, 0) nn.init.normal_(self.linear_5.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_5.bias, 0) nn.init.normal_(self.linear_6.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_6.bias, 0) nn.init.normal_(self.linear_7.weight, mean=1e-05, std=0.02) nn.init.constant_(self.linear_7.bias, 0) def forward(self, points, z, is_training=False): zs = z.view(-1, 1, self.z_dim).repeat(1, points.size()[1], 1) pointz = torch.cat([points, zs], 2) l1 = self.linear_1(pointz) l1 = F.leaky_relu(l1, negative_slope=0.02, inplace=True) l2 = self.linear_2(l1) l2 = F.leaky_relu(l2, negative_slope=0.02, inplace=True) l3 = self.linear_3(l2) l3 = F.leaky_relu(l3, negative_slope=0.02, inplace=True) l4 = self.linear_4(l3) l4 = F.leaky_relu(l4, negative_slope=0.02, inplace=True) l5 = self.linear_5(l4) l5 = F.leaky_relu(l5, negative_slope=0.02, inplace=True) l6 = self.linear_6(l5) l6 = F.leaky_relu(l6, negative_slope=0.02, inplace=True) l7 = self.linear_7(l6) l7 = torch.max(torch.min(l7, l7 * 0.01 + 0.99), l7 * 0.01) return l7 def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'z_dim': 4, 'point_dim': 4, 'gf_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x3 = xindex // 8 x2 = xindex // 32 x4 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (4 * x3 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = tl.load(in_ptr1 + (4 * x2 + (-4 + x0)), tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tl.where(tmp4, tmp5, tmp9) tl.store(out_ptr0 + x4, tmp10, xmask) @triton.jit def triton_poi_fused_leaky_relu_leaky_relu_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 % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.02 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_view_2(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 x0 = xindex % 32 x1 = xindex // 32 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 32 * x1 + 128 * (x1 % 4 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_leaky_relu_leaky_relu_backward_3(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.02 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_view_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * (x1 % 4 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_leaky_relu_leaky_relu_backward_5(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.02 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_view_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 8 x1 = xindex // 8 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1 + 32 * (x1 % 4 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_leaky_relu_leaky_relu_backward_7(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.02 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tmp7 > tmp3 tl.store(in_out_ptr0 + x2, tmp7, xmask) tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_view_8(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * (x1 % 4 // 4)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_maximum_minimum_mul_9(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.01 tmp2 = tmp0 * tmp1 tmp3 = 0.99 tmp4 = tmp2 + tmp3 tmp5 = triton_helpers.minimum(tmp0, tmp4) tmp6 = triton_helpers.maximum(tmp5, tmp2) tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_3, (32, 8), (8, 1)) assert_size_stride(primals_4, (32,), (1,)) assert_size_stride(primals_5, (32, 32), (32, 1)) assert_size_stride(primals_6, (32,), (1,)) assert_size_stride(primals_7, (32, 32), (32, 1)) assert_size_stride(primals_8, (32,), (1,)) assert_size_stride(primals_9, (16, 32), (32, 1)) assert_size_stride(primals_10, (16,), (1,)) assert_size_stride(primals_11, (8, 16), (16, 1)) assert_size_stride(primals_12, (8,), (1,)) assert_size_stride(primals_13, (4, 8), (8, 1)) assert_size_stride(primals_14, (4,), (1,)) assert_size_stride(primals_15, (1, 4), (4, 1)) assert_size_stride(primals_16, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(128)](primals_2, primals_1, buf0, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((16, 32), (32, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 8), (8, 1), 0), reinterpret_tensor(primals_3, (8, 32), (1, 8), 0), out=buf1) del primals_3 buf2 = reinterpret_tensor(buf1, (4, 4, 32), (128, 32, 1), 0) del buf1 buf27 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_1[grid(512)](buf2, primals_4, buf27, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_4 buf3 = empty_strided_cuda((16, 32), (32, 1), torch.float32) triton_poi_fused_view_2[grid(512)](buf2, buf3, 512, XBLOCK=256, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (16, 32), (32, 1), 0) del buf2 extern_kernels.mm(buf3, reinterpret_tensor(primals_5, (32, 32), (1, 32), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 32), (128, 32, 1), 0) del buf4 buf26 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_1[grid(512)](buf5, primals_6, buf26, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_6 buf6 = empty_strided_cuda((16, 32), (32, 1), torch.float32) triton_poi_fused_view_2[grid(512)](buf5, buf6, 512, XBLOCK=256, num_warps=4, num_stages=1) buf7 = reinterpret_tensor(buf5, (16, 32), (32, 1), 0) del buf5 extern_kernels.mm(buf6, reinterpret_tensor(primals_7, (32, 32), (1, 32), 0), out=buf7) buf8 = reinterpret_tensor(buf7, (4, 4, 32), (128, 32, 1), 0) del buf7 buf25 = empty_strided_cuda((4, 4, 32), (128, 32, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_1[grid(512)](buf8, primals_8, buf25, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_8 buf9 = empty_strided_cuda((16, 32), (32, 1), torch.float32) triton_poi_fused_view_2[grid(512)](buf8, buf9, 512, XBLOCK=256, num_warps=4, num_stages=1) del buf8 buf10 = empty_strided_cuda((16, 16), (16, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_9, (32, 16), (1, 32), 0), out=buf10) buf11 = reinterpret_tensor(buf10, (4, 4, 16), (64, 16, 1), 0) del buf10 buf24 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_3[grid(256)](buf11, primals_10, buf24, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_10 buf12 = empty_strided_cuda((16, 16), (16, 1), torch.float32) triton_poi_fused_view_4[grid(256)](buf11, buf12, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf11 buf13 = empty_strided_cuda((16, 8), (8, 1), torch.float32) extern_kernels.mm(buf12, reinterpret_tensor(primals_11, (16, 8), (1, 16), 0), out=buf13) buf14 = reinterpret_tensor(buf13, (4, 4, 8), (32, 8, 1), 0) del buf13 buf23 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_5[grid(128)](buf14, primals_12, buf23, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_12 buf15 = empty_strided_cuda((16, 8), (8, 1), torch.float32) triton_poi_fused_view_6[grid(128)](buf14, buf15, 128, XBLOCK=128, num_warps=4, num_stages=1) del buf14 buf16 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(buf15, reinterpret_tensor(primals_13, (8, 4), (1, 8), 0), out=buf16) buf17 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0) del buf16 buf22 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.bool) triton_poi_fused_leaky_relu_leaky_relu_backward_7[grid(64)](buf17, primals_14, buf22, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_14 buf18 = empty_strided_cuda((16, 4), (4, 1), torch.float32) triton_poi_fused_view_8[grid(64)](buf17, buf18, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf17 buf20 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_16, buf18, reinterpret_tensor( primals_15, (4, 1), (1, 4), 0), alpha=1, beta=1, out=buf20) del primals_16 buf21 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32) triton_poi_fused_add_maximum_minimum_mul_9[grid(16)](buf20, buf21, 16, XBLOCK=16, num_warps=1, num_stages=1) return (buf21, reinterpret_tensor(buf0, (16, 8), (8, 1), 0), buf3, buf6, buf9, buf12, buf15, buf18, buf20, primals_15, buf22, primals_13, buf23, primals_11, buf24, primals_9, buf25, primals_7, buf26, primals_5, buf27) class generatorNew(nn.Module): def __init__(self, z_dim, point_dim, gf_dim): super(generatorNew, self).__init__() self.z_dim = z_dim self.point_dim = point_dim self.gf_dim = gf_dim self.linear_1 = nn.Linear(self.z_dim + self.point_dim, self.gf_dim * 8, bias=True) self.linear_2 = nn.Linear(self.gf_dim * 8, self.gf_dim * 8, bias=True) self.linear_3 = nn.Linear(self.gf_dim * 8, self.gf_dim * 8, bias=True) self.linear_4 = nn.Linear(self.gf_dim * 8, self.gf_dim * 4, bias=True) self.linear_5 = nn.Linear(self.gf_dim * 4, self.gf_dim * 2, bias=True) self.linear_6 = nn.Linear(self.gf_dim * 2, self.gf_dim * 1, bias=True) self.linear_7 = nn.Linear(self.gf_dim * 1, 1, bias=True) nn.init.normal_(self.linear_1.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_1.bias, 0) nn.init.normal_(self.linear_2.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_2.bias, 0) nn.init.normal_(self.linear_3.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_3.bias, 0) nn.init.normal_(self.linear_4.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_4.bias, 0) nn.init.normal_(self.linear_5.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_5.bias, 0) nn.init.normal_(self.linear_6.weight, mean=0.0, std=0.02) nn.init.constant_(self.linear_6.bias, 0) nn.init.normal_(self.linear_7.weight, mean=1e-05, std=0.02) nn.init.constant_(self.linear_7.bias, 0) def forward(self, input_0, input_1): primals_3 = self.linear_1.weight primals_4 = self.linear_1.bias primals_5 = self.linear_2.weight primals_6 = self.linear_2.bias primals_7 = self.linear_3.weight primals_8 = self.linear_3.bias primals_9 = self.linear_4.weight primals_10 = self.linear_4.bias primals_11 = self.linear_5.weight primals_12 = self.linear_5.bias primals_13 = self.linear_6.weight primals_14 = self.linear_6.bias primals_15 = self.linear_7.weight primals_16 = self.linear_7.bias primals_2 = input_0 primals_1 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16]) return output[0]
bblinn2017/IM-NET-pytorch
generator
false
3,194
[ "MIT" ]
0
82ff646aaf2f93ae1560debb40fe05f1420ff655
https://github.com/bblinn2017/IM-NET-pytorch/tree/82ff646aaf2f93ae1560debb40fe05f1420ff655
encoder
import torch import torch.nn as nn import torch.nn.functional as F class encoder(nn.Module): def __init__(self, ef_dim, z_dim): super(encoder, self).__init__() self.ef_dim = ef_dim self.z_dim = z_dim self.conv_1 = nn.Conv3d(1, self.ef_dim, 4, stride=2, padding=1, bias=False) self.in_1 = nn.InstanceNorm3d(self.ef_dim) self.conv_2 = nn.Conv3d(self.ef_dim, self.ef_dim * 2, 4, stride=2, padding=1, bias=False) self.in_2 = nn.InstanceNorm3d(self.ef_dim * 2) self.conv_3 = nn.Conv3d(self.ef_dim * 2, self.ef_dim * 4, 4, stride =2, padding=1, bias=False) self.in_3 = nn.InstanceNorm3d(self.ef_dim * 4) self.conv_4 = nn.Conv3d(self.ef_dim * 4, self.ef_dim * 8, 4, stride =2, padding=1, bias=False) self.in_4 = nn.InstanceNorm3d(self.ef_dim * 8) self.conv_5 = nn.Conv3d(self.ef_dim * 8, self.z_dim, 4, stride=1, padding=0, bias=True) nn.init.xavier_uniform_(self.conv_1.weight) nn.init.xavier_uniform_(self.conv_2.weight) nn.init.xavier_uniform_(self.conv_3.weight) nn.init.xavier_uniform_(self.conv_4.weight) nn.init.xavier_uniform_(self.conv_5.weight) nn.init.constant_(self.conv_5.bias, 0) def forward(self, inputs, is_training=False): d_1 = self.in_1(self.conv_1(inputs)) d_1 = F.leaky_relu(d_1, negative_slope=0.02, inplace=True) d_2 = self.in_2(self.conv_2(d_1)) d_2 = F.leaky_relu(d_2, negative_slope=0.02, inplace=True) d_3 = self.in_3(self.conv_3(d_2)) d_3 = F.leaky_relu(d_3, negative_slope=0.02, inplace=True) d_4 = self.in_4(self.conv_4(d_3)) d_4 = F.leaky_relu(d_4, negative_slope=0.02, inplace=True) d_5 = self.conv_5(d_4) d_5 = F.leaky_relu(d_5, negative_slope=0.02, inplace=True) d_5 = d_5.view(-1, self.z_dim) d_5 = torch.sigmoid(d_5) return d_5 """ # VAE d_5 = d_5.view(-1, 2, self.z_dim) mu = d_5[:,0] log_var = d_5[:,1] std = torch.exp(0.5 * log_var) eps = torch.randn_like(std) sample = mu + (eps * std) sample = torch.sigmoid(sample) return sample, mu, log_var """ def get_inputs(): return [torch.rand([4, 1, 64, 64, 64])] def get_init_inputs(): return [[], {'ef_dim': 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 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_red_fused__native_batch_norm_legit_0(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 64 rnumel = 8192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4 = tmp4_tmp[:, None] tl.store(out_ptr0 + x0, tmp2, xmask) tl.store(out_ptr1 + x0, tmp3, xmask) tl.store(out_ptr2 + x0, tmp4, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 16 RBLOCK: tl.constexpr = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 4 * x0), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r1 + 4 * x0), xmask, other=0.0) tmp2 = tl.load(in_ptr2 + (r1 + 4 * x0), xmask, other=0.0) tmp3 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tmp7 = tl.where(xmask, tmp3, 0) tmp8 = tl.where(xmask, tmp4, 0) tmp9 = tl.where(xmask, tmp5, 0) tmp10, tmp11, tmp12 = triton_helpers.welford(tmp7, tmp8, tmp9, 1) tmp13 = tmp10[:, None] tmp14 = tmp11[:, None] tmp12[:, None] tmp16 = 32768.0 tmp17 = tmp14 / tmp16 tmp18 = 1e-05 tmp19 = tmp17 + tmp18 tmp20 = libdevice.rsqrt(tmp19) tl.store(out_ptr2 + x0, tmp20, xmask) tl.store(out_ptr0 + x0, tmp13, xmask) tl.store(out_ptr1 + x0, tmp14, xmask) @triton.jit def triton_poi_fused_leaky_relu_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x1 = xindex // 32768 tmp0 = tl.load(in_ptr0 + x2, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 32768.0 tmp5 = tmp3 / tmp4 tmp6 = 1e-05 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp2 * tmp8 tmp10 = 0.0 tmp11 = tmp9 > tmp10 tmp12 = 0.02 tmp13 = tmp9 * tmp12 tmp14 = tl.where(tmp11, tmp9, tmp13) tl.store(out_ptr0 + x2, tmp14, None) @triton.jit def triton_red_fused__native_batch_norm_legit_leaky_relu_3(in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr): xnumel = 32 rnumel = 4096 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rbase = tl.arange(0, RBLOCK)[None, :] x0 = xindex tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32) tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp0 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_last', other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers. welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0) ) tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean) tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2) tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight) tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean, tmp2_m2, tmp2_weight, 1) tmp2 = tmp2_tmp[:, None] tmp3 = tmp3_tmp[:, None] tmp4_tmp[:, None] tl.store(out_ptr0 + x0, tmp2, xmask) for roffset in range(0, rnumel, RBLOCK): rindex = roffset + rbase rmask = rindex < rnumel r1 = rindex tmp5 = tl.load(in_ptr0 + (r1 + 4096 * x0), rmask & xmask, eviction_policy='evict_first', other=0.0) tmp6 = tmp5 - tmp2 tmp7 = 4096.0 tmp8 = tmp3 / tmp7 tmp9 = 1e-05 tmp10 = tmp8 + tmp9 tmp11 = libdevice.rsqrt(tmp10) tmp12 = tmp6 * tmp11 tmp13 = 0.0 tmp14 = tmp12 > tmp13 tmp15 = 0.02 tmp16 = tmp12 * tmp15 tmp17 = tl.where(tmp14, tmp12, tmp16) tl.store(out_ptr2 + (r1 + 4096 * x0), tmp17, rmask & xmask) tmp18 = 4096.0 tmp19 = tmp3 / tmp18 tmp20 = 1e-05 tmp21 = tmp19 + tmp20 tmp22 = libdevice.rsqrt(tmp21) tl.store(out_ptr3 + x0, tmp22, xmask) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_4(in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 512 xoffset = tl.program_id(0) * XBLOCK xindex = tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 512 * x0), None) tmp1 = tl.broadcast_to(tmp0, [RBLOCK]) tmp3 = tl.broadcast_to(tmp1, [RBLOCK]) tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0)) tmp6 = tl.full([1], 512, tl.int32) tmp7 = tmp6.to(tl.float32) tmp8 = tmp5 / tmp7 tmp9 = tmp1 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tl.broadcast_to(tmp10, [RBLOCK]) tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0)) tmp14 = tmp0 - tmp8 tmp15 = 512.0 tmp16 = tmp13 / tmp15 tmp17 = 1e-05 tmp18 = tmp16 + tmp17 tmp19 = libdevice.rsqrt(tmp18) tmp20 = tmp14 * tmp19 tmp21 = 0.0 tmp22 = tmp20 > tmp21 tmp23 = 0.02 tmp24 = tmp20 * tmp23 tmp25 = tl.where(tmp22, tmp20, tmp24) tl.store(out_ptr2 + (r1 + 512 * x0), tmp25, None) tl.store(out_ptr3 + x0, tmp19, None) tl.store(out_ptr0 + x0, tmp8, None) @triton.jit def triton_per_fused__native_batch_norm_legit_leaky_relu_5(in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 128 RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) 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 = tmp0 - tmp10 tmp18 = 64.0 tmp19 = tmp16 / tmp18 tmp20 = 1e-05 tmp21 = tmp19 + tmp20 tmp22 = libdevice.rsqrt(tmp21) tmp23 = tmp17 * tmp22 tmp24 = 0.0 tmp25 = tmp23 > tmp24 tmp26 = 0.02 tmp27 = tmp23 * tmp26 tmp28 = tl.where(tmp25, tmp23, tmp27) tl.store(out_ptr2 + (r1 + 64 * x0), tmp28, xmask) tl.store(out_ptr3 + x0, tmp22, xmask) tl.store(out_ptr0 + x0, tmp10, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_sigmoid_6( in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tmp5 = 0.02 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tmp8 = tl.sigmoid(tmp7) tmp9 = tmp7 > tmp3 tl.store(out_ptr0 + x2, tmp8, xmask) tl.store(out_ptr1 + x2, tmp9, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 1, 4, 4, 4), (64, 64, 16, 4, 1)) assert_size_stride(primals_2, (4, 1, 64, 64, 64), (262144, 262144, 4096, 64, 1)) assert_size_stride(primals_3, (8, 4, 4, 4, 4), (256, 64, 16, 4, 1)) assert_size_stride(primals_4, (16, 8, 4, 4, 4), (512, 64, 16, 4, 1)) assert_size_stride(primals_5, (32, 16, 4, 4, 4), (1024, 64, 16, 4, 1)) assert_size_stride(primals_6, (4, 32, 4, 4, 4), (2048, 64, 16, 4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(2, 2, 2), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 32, 32, 32), (131072, 32768, 1024, 32, 1)) buf1 = empty_strided_cuda((1, 16, 1, 1, 1, 4), (64, 4, 64, 64, 64, 1), torch.float32) buf2 = empty_strided_cuda((1, 16, 1, 1, 1, 4), (64, 4, 64, 64, 64, 1), torch.float32) buf3 = empty_strided_cuda((1, 16, 1, 1, 1, 4), (64, 4, 64, 64, 64, 1), torch.float32) get_raw_stream(0) triton_red_fused__native_batch_norm_legit_0[grid(64)](buf0, buf1, buf2, buf3, 64, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1) buf4 = empty_strided_cuda((1, 16, 1, 1, 1), (16, 1, 16, 16, 16), torch.float32) buf5 = empty_strided_cuda((1, 16, 1, 1, 1), (16, 1, 16, 16, 16), torch.float32) buf7 = empty_strided_cuda((1, 16, 1, 1, 1), (16, 1, 16, 16, 16), torch.float32) triton_per_fused__native_batch_norm_legit_1[grid(16)](buf1, buf2, buf3, buf4, buf5, buf7, 16, 4, XBLOCK=1, num_warps=2, num_stages=1) del buf1 buf8 = empty_strided_cuda((4, 4, 32, 32, 32), (131072, 32768, 1024, 32, 1), torch.float32) triton_poi_fused_leaky_relu_2[grid(524288)](buf0, buf4, buf5, buf8, 524288, XBLOCK=1024, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf8, primals_3, stride=(2, 2, 2), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 8, 16, 16, 16), (32768, 4096, 256, 16, 1)) buf10 = empty_strided_cuda((1, 32, 1, 1, 1), (32, 1, 32, 32, 32), torch.float32) buf14 = empty_strided_cuda((4, 8, 16, 16, 16), (32768, 4096, 256, 16, 1), torch.float32) buf13 = empty_strided_cuda((1, 32, 1, 1, 1), (32, 1, 32, 32, 32), torch.float32) triton_red_fused__native_batch_norm_legit_leaky_relu_3[grid(32)](buf9, buf10, buf14, buf13, 32, 4096, XBLOCK=1, RBLOCK=2048, num_warps =16, num_stages=1) buf15 = extern_kernels.convolution(buf14, primals_4, stride=(2, 2, 2), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf15, (4, 16, 8, 8, 8), (8192, 512, 64, 8, 1)) buf16 = reinterpret_tensor(buf3, (1, 64, 1, 1, 1), (64, 1, 64, 64, 64), 0) del buf3 buf20 = empty_strided_cuda((4, 16, 8, 8, 8), (8192, 512, 64, 8, 1), torch.float32) buf19 = reinterpret_tensor(buf2, (1, 64, 1, 1, 1), (64, 1, 64, 64, 64), 0) del buf2 triton_per_fused__native_batch_norm_legit_leaky_relu_4[grid(64)](buf15, buf16, buf20, buf19, 64, 512, num_warps=4, num_stages=1) buf21 = extern_kernels.convolution(buf20, primals_5, stride=(2, 2, 2), padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf21, (4, 32, 4, 4, 4), (2048, 64, 16, 4, 1)) buf22 = empty_strided_cuda((1, 128, 1, 1, 1), (128, 1, 128, 128, 128), torch.float32) buf26 = empty_strided_cuda((4, 32, 4, 4, 4), (2048, 64, 16, 4, 1), torch.float32) buf25 = empty_strided_cuda((1, 128, 1, 1, 1), (128, 1, 128, 128, 128), torch.float32) triton_per_fused__native_batch_norm_legit_leaky_relu_5[grid(128)](buf21 , buf22, buf26, buf25, 128, 64, XBLOCK=32, num_warps=8, num_stages=1) buf27 = extern_kernels.convolution(buf26, primals_6, stride=(1, 1, 1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False, output_padding=(0, 0, 0), groups=1, bias=None) assert_size_stride(buf27, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1)) buf28 = reinterpret_tensor(buf5, (4, 4), (4, 1), 0) del buf5 buf29 = empty_strided_cuda((4, 4, 1, 1, 1), (4, 1, 1, 1, 1), torch.bool ) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_sigmoid_6[ grid(16)](buf27, primals_7, buf28, buf29, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf27 del primals_7 return (buf28, primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, buf0, reinterpret_tensor(buf7, (16,), (1,), 0), buf8, buf9, reinterpret_tensor(buf13, (32,), (1,), 0), buf14, buf15, reinterpret_tensor(buf19, (64,), (1,), 0), buf20, buf21, reinterpret_tensor(buf25, (128,), (1,), 0), buf26, buf28, buf29, reinterpret_tensor(buf22, (1, 128, 1, 1, 1), (128, 1, 1, 1, 1), 0), reinterpret_tensor(buf16, (1, 64, 1, 1, 1), (64, 1, 1, 1, 1), 0), reinterpret_tensor(buf10, (1, 32, 1, 1, 1), (32, 1, 1, 1, 1), 0), reinterpret_tensor(buf4, (1, 16, 1, 1, 1), (16, 1, 1, 1, 1), 0)) class encoderNew(nn.Module): def __init__(self, ef_dim, z_dim): super(encoderNew, self).__init__() self.ef_dim = ef_dim self.z_dim = z_dim self.conv_1 = nn.Conv3d(1, self.ef_dim, 4, stride=2, padding=1, bias=False) self.in_1 = nn.InstanceNorm3d(self.ef_dim) self.conv_2 = nn.Conv3d(self.ef_dim, self.ef_dim * 2, 4, stride=2, padding=1, bias=False) self.in_2 = nn.InstanceNorm3d(self.ef_dim * 2) self.conv_3 = nn.Conv3d(self.ef_dim * 2, self.ef_dim * 4, 4, stride =2, padding=1, bias=False) self.in_3 = nn.InstanceNorm3d(self.ef_dim * 4) self.conv_4 = nn.Conv3d(self.ef_dim * 4, self.ef_dim * 8, 4, stride =2, padding=1, bias=False) self.in_4 = nn.InstanceNorm3d(self.ef_dim * 8) self.conv_5 = nn.Conv3d(self.ef_dim * 8, self.z_dim, 4, stride=1, padding=0, bias=True) nn.init.xavier_uniform_(self.conv_1.weight) nn.init.xavier_uniform_(self.conv_2.weight) nn.init.xavier_uniform_(self.conv_3.weight) nn.init.xavier_uniform_(self.conv_4.weight) nn.init.xavier_uniform_(self.conv_5.weight) nn.init.constant_(self.conv_5.bias, 0) def forward(self, input_0): primals_1 = self.conv_1.weight primals_3 = self.conv_2.weight primals_4 = self.conv_3.weight primals_5 = self.conv_4.weight primals_6 = self.conv_5.weight primals_7 = self.conv_5.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
bblinn2017/IM-NET-pytorch
encoder
false
3,195
[ "MIT" ]
0
82ff646aaf2f93ae1560debb40fe05f1420ff655
https://github.com/bblinn2017/IM-NET-pytorch/tree/82ff646aaf2f93ae1560debb40fe05f1420ff655
Permute
import torch import torch.nn as nn class Permute(nn.Module): def __init__(self, permutation=[2, 1, 0]): super().__init__() self.permutation = permutation def forward(self, input): return input[:, self.permutation] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 192 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 3 x0 = xindex % 16 x2 = xindex // 48 x3 = xindex tmp0 = x1 tmp1 = tl.full([1], 1, tl.int64) tmp2 = tmp0 < tmp1 tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.full([1], 0, tl.int64) tmp6 = tl.where(tmp4, tmp1, tmp5) tmp7 = tl.where(tmp2, tmp3, tmp6) tmp8 = tl.load(in_ptr0 + (x0 + 16 * tmp7 + 64 * x2), xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 3, 4, 4), (48, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_index_0[grid(192)](arg0_1, buf0, 192, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class PermuteNew(nn.Module): def __init__(self, permutation=[2, 1, 0]): super().__init__() self.permutation = permutation def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
beibuwandeluori/Attack-ImageNet-tianchi
Permute
false
3,196
[ "MIT" ]
0
85294952ac1a190c26bba5e8f141b1c68e72668a
https://github.com/beibuwandeluori/Attack-ImageNet-tianchi/tree/85294952ac1a190c26bba5e8f141b1c68e72668a
FastBlock
import torch import torch.nn as nn def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FastBlock(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FastBlock, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel, kernel_size=3, stride= self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=1, stride=1, padding=0, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) self._conv3 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm3 = get_operator_from_cfg(temp_norm_cfg) def forward(self, x): identity = x out = self._conv1(x) if self._norm_cfg is not None: out = self._norm1(out) out = self._activation(out) out = self._conv2(out) if self._norm_cfg is not None: out = self._norm2(out) out = self._activation(out) out = self._conv3(out) if self._norm_cfg is not None: out = self._norm3(out) if self._downsample is not None: identity = self._downsample(x) out += identity out = self._activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_input_channels': 4, 'num_block_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = 0.0 tmp8 = tmp6 <= tmp7 tl.store(in_out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (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, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_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 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(256)](buf1, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 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, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_relu_0[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=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(256)]( buf5, primals_7, primals_1, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 return buf5, primals_1, primals_2, primals_4, primals_6, buf1, buf3, buf6 def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FastBlockNew(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FastBlockNew, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel, kernel_size=3, stride= self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=1, stride=1, padding=0, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) self._conv3 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm3 = get_operator_from_cfg(temp_norm_cfg) def forward(self, input_0): primals_2 = self._conv1.weight primals_3 = self._conv1.bias primals_4 = self._conv2.weight primals_5 = self._conv2.bias primals_6 = self._conv3.weight primals_7 = self._conv3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
becauseofAI/DemoHub
FastBlock
false
3,197
[ "Apache-2.0" ]
0
2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
https://github.com/becauseofAI/DemoHub/tree/2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
DepthWiseSeparableConv2d
import torch import torch.nn as nn import torch.jit import torch.nn class DepthWiseSeparableConv2d(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True): """Depthwise separable 2D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv2d` for details. """ super(DepthWiseSeparableConv2d, self).__init__() self.depth_conv = nn.Conv2d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv2d(in_channels, out_channels, 1) def forward(self, input): return self.point_conv(self.depth_conv(input)) 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.jit import torch.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, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, 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 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, 3, 3), (36, 9, 3, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_0[grid(144)](buf3, primals_5, 144, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1 class DepthWiseSeparableConv2dNew(nn.Module): def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=1, dilation=1, bias=True): """Depthwise separable 2D convolution. Args: in_channels (int): number of input channels. out_channels (int): number of output channels. kernel_size (int or (int, int)): kernel size. kwargs: additional keyword arguments. See `Conv2d` for details. """ super(DepthWiseSeparableConv2dNew, self).__init__() self.depth_conv = nn.Conv2d(in_channels, in_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, bias=bias) self.point_conv = nn.Conv2d(in_channels, out_channels, 1) def forward(self, input_0): primals_1 = self.depth_conv.weight primals_2 = self.depth_conv.bias primals_4 = self.point_conv.weight primals_5 = self.point_conv.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
ankmathur96/torchsupport
DepthWiseSeparableConv2d
false
3,198
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
Decoder
import torch import torch.nn as nn class Decoder(nn.Module): def __init__(self, latent_dim=4, obs_dim=2, nhidden=20): super(Decoder, self).__init__() self.relu = nn.ReLU(inplace=True) self.fc1 = nn.Linear(latent_dim, nhidden) self.fc2 = nn.Linear(nhidden, obs_dim) def forward(self, z): out = self.fc1(z) out = self.relu(out) out = self.fc2(out) return out 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 = 1280 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x0 = xindex % 20 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x4, tmp4, xmask) tl.store(out_ptr0 + x4, tmp6, xmask) @triton.jit def triton_poi_fused_view_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1280 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 20 x1 = xindex // 20 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 20 * x1 + 80 * (x1 % 4 // 4) + 320 * ((4 * (x1 // 4 % 4) + x1 % 4) // 16)), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (20, 4), (4, 1)) assert_size_stride(primals_2, (20,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (2, 20), (20, 1)) assert_size_stride(primals_5, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 20), (20, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 20), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 20), (320, 80, 20, 1), 0) del buf0 buf4 = empty_strided_cuda((4, 4, 4, 20), (320, 80, 20, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(1280)](buf1, primals_2, buf4, 1280, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 20), (20, 1), torch.float32) triton_poi_fused_view_1[grid(1280)](buf1, buf2, 1280, XBLOCK=128, num_warps=4, num_stages=1) del buf1 buf3 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_5, buf2, reinterpret_tensor(primals_4, (20, 2), (1, 20), 0), alpha=1, beta=1, out=buf3) del primals_5 return reinterpret_tensor(buf3, (4, 4, 4, 2), (32, 8, 2, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf2, primals_4, buf4 class DecoderNew(nn.Module): def __init__(self, latent_dim=4, obs_dim=2, nhidden=20): super(DecoderNew, self).__init__() self.relu = nn.ReLU(inplace=True) self.fc1 = nn.Linear(latent_dim, nhidden) self.fc2 = nn.Linear(nhidden, obs_dim) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
arnabgho/torchdiffeq
Decoder
false
3,199
[ "MIT" ]
0
d4f73440d0e714b87ea133610e61eefbd673e5f5
https://github.com/arnabgho/torchdiffeq/tree/d4f73440d0e714b87ea133610e61eefbd673e5f5
FilterResponseNorm
import torch import torch.nn as nn import torch.nn.functional as func import torch.jit import torch.nn class FilterResponseNorm(nn.Module): def __init__(self, in_size, eps=1e-16): super().__init__() self.eps = eps self.in_size = in_size self.register_parameter('scale', nn.Parameter(torch.ones(in_size, dtype=torch.float))) self.register_parameter('bias', nn.Parameter(torch.zeros(in_size, dtype=torch.float))) self.register_parameter('threshold', nn.Parameter(torch.zeros( in_size, dtype=torch.float))) def forward(self, inputs): out = inputs.view(inputs.size(0), inputs.size(1), -1) nu2 = (out ** 2).mean(dim=-1) extension = [1] * (inputs.dim() - 2) denominator = torch.sqrt(nu2 + self.eps) denominator = denominator.view(inputs.size(0), inputs.size(1), * extension) scale = self.scale.view(1, self.scale.size(0), *extension) bias = self.bias.view(1, self.bias.size(0), *extension) threshold = self.threshold.view(1, self.threshold.size(0), *extension) out = inputs / denominator.detach() out = func.relu(scale * out + bias - threshold) + threshold return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_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 from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.jit import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_per_fused_add_div_mean_mul_pow_relu_sqrt_sub_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) tmp11 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last') tmp14 = 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 tmp8 = 1e-16 tmp9 = tmp7 + tmp8 tmp10 = libdevice.sqrt(tmp9) tmp12 = tmp0 / tmp10 tmp13 = tmp11 * tmp12 tmp15 = tmp13 + tmp14 tmp17 = tmp15 - tmp16 tmp18 = tl.full([1, 1], 0, tl.int32) tmp19 = triton_helpers.maximum(tmp18, tmp17) tmp20 = tmp19 + tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + x0, tmp10, xmask) tl.store(out_ptr0 + (r1 + 16 * x0), tmp20, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_mul_pow_relu_sqrt_sub_0[grid(16)](buf1, primals_1, primals_2, primals_3, primals_4, buf2, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) return (buf2, primals_1, primals_2, primals_3, primals_4, reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0)) class FilterResponseNormNew(nn.Module): def __init__(self, in_size, eps=1e-16): super().__init__() self.eps = eps self.in_size = in_size self.register_parameter('scale', nn.Parameter(torch.ones(in_size, dtype=torch.float))) self.register_parameter('bias', nn.Parameter(torch.zeros(in_size, dtype=torch.float))) self.register_parameter('threshold', nn.Parameter(torch.zeros( in_size, dtype=torch.float))) def forward(self, input_0): primals_2 = self.scale primals_3 = self.bias primals_4 = self.threshold primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
ankmathur96/torchsupport
FilterResponseNorm
false
3,200
[ "MIT" ]
0
77bf4a90b8770a408665e2604428808c3ed2f979
https://github.com/ankmathur96/torchsupport/tree/77bf4a90b8770a408665e2604428808c3ed2f979
ConstantODE
import torch class ConstantODE(torch.nn.Module): def __init__(self, device): super(ConstantODE, self).__init__() self.a = torch.nn.Parameter(torch.tensor(0.2)) self.b = torch.nn.Parameter(torch.tensor(3.0)) def forward(self, t, y): return self.a + (y - (self.a * t + self.b)) ** 5 def y_exact(self, t): return self.a * t + self.b def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'device': 0}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_mul_pow_sub_0(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 x0 = xindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp3 = tl.load(in_ptr2 + x0, xmask) tmp5 = tl.load(in_ptr3 + 0) tmp6 = tl.broadcast_to(tmp5, [XBLOCK]) tmp4 = tmp1 * tmp3 tmp7 = tmp4 + tmp6 tmp8 = tmp2 - tmp7 tmp9 = tmp8 * tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp10 * tmp8 tmp12 = tmp1 + tmp11 tl.store(out_ptr0 + x0, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (), ()) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (), ()) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_mul_pow_sub_0[grid(256)](primals_1, primals_4, primals_2, primals_3, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) return buf0, primals_1, primals_2, primals_3, primals_4 class ConstantODENew(torch.nn.Module): def __init__(self, device): super(ConstantODENew, self).__init__() self.a = torch.nn.Parameter(torch.tensor(0.2)) self.b = torch.nn.Parameter(torch.tensor(3.0)) def y_exact(self, t): return self.a * t + self.b def forward(self, input_0, input_1): primals_1 = self.a primals_3 = self.b primals_2 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
arnabgho/torchdiffeq
ConstantODE
false
3,201
[ "MIT" ]
0
d4f73440d0e714b87ea133610e61eefbd673e5f5
https://github.com/arnabgho/torchdiffeq/tree/d4f73440d0e714b87ea133610e61eefbd673e5f5
FasterBlock
import torch import torch.nn as nn def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FasterBlock(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FasterBlock, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel, kernel_size=3, stride= self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) def forward(self, x): identity = x out = self._conv1(x) if self._norm_cfg is not None: out = self._norm1(out) out = self._activation(out) out = self._conv2(out) if self._norm_cfg is not None: out = self._norm2(out) if self._downsample is not None: identity = self._downsample(x) out += identity out = self._activation(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_input_channels': 4, 'num_block_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_1(in_out_ptr0, in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = 0.0 tmp8 = tmp6 <= tmp7 tl.store(in_out_ptr0 + x3, tmp6, xmask) tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = 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 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(256)](buf1, primals_3, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1)) buf3 = buf2 del buf2 buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_1[grid(256)]( buf3, primals_5, primals_1, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_2, primals_4, buf1, buf4 def get_operator_from_cfg(operator_cfg): operator_cfg_copy = operator_cfg.copy() construct_str = 'nn.' construct_str += operator_cfg_copy.pop('type') + '(' for k, v in operator_cfg_copy.items(): construct_str += k + '=' + str(v) + ',' construct_str += ')' return eval(construct_str) class FasterBlockNew(nn.Module): def __init__(self, num_input_channels, num_block_channels, stride=1, downsample=None, activation_cfg=dict(type='ReLU', inplace=True), norm_cfg=None): super(FasterBlockNew, self).__init__() if downsample is not None: assert stride == 2 if norm_cfg is not None: assert norm_cfg['type'] in ['BatchNorm2d', 'GroupNorm'] self._num_input_channel = num_input_channels self._num_block_channel = num_block_channels self._stride = stride self._activation_cfg = activation_cfg self._norm_cfg = norm_cfg self._downsample = downsample self._conv1 = nn.Conv2d(in_channels=self._num_input_channel, out_channels=self._num_block_channel, kernel_size=3, stride= self._stride, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm1 = get_operator_from_cfg(temp_norm_cfg) self._activation = get_operator_from_cfg(self._activation_cfg) self._conv2 = nn.Conv2d(in_channels=self._num_block_channel, out_channels=self._num_block_channel, kernel_size=3, stride=1, padding=1, bias=True if self._norm_cfg is None else False) if self._norm_cfg is not None: temp_norm_cfg = self._norm_cfg.copy() if temp_norm_cfg['type'] == 'BatchNorm2d': temp_norm_cfg['num_features'] = self._num_block_channel else: temp_norm_cfg['num_channels'] = self._num_block_channel self._norm2 = get_operator_from_cfg(temp_norm_cfg) 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]
becauseofAI/DemoHub
FasterBlock
false
3,202
[ "Apache-2.0" ]
0
2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
https://github.com/becauseofAI/DemoHub/tree/2b7fdd1f1c6f229ba326e8c1b78c4e7f5982f3da
LinearProximal
import math import torch import torch.nn.functional as functional from torch import nn class LinearProximal(nn.Module): """Applies a linear transformation to the incoming data: :math:`y = xA^T + b` Args: in_features: size of each input sample out_features: size of each output sample bias: If set to ``False``, the layer will not learn an additive bias. Default: ``True`` Shape: - Input: :math:`(N, *, H_{in})` where :math:`*` means any number of additional dimensions and :math:`H_{in} = \\text{in\\_features}` - Output: :math:`(N, *, H_{out})` where all but the last dimension are the same shape as the input and :math:`H_{out} = \\text{out\\_features}`. Attributes: weight: the learnable weights of the module of shape :math:`(\\text{out\\_features}, \\text{in\\_features})`. The values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})`, where :math:`k = \\frac{1}{\\text{in\\_features}}` bias: the learnable bias of the module of shape :math:`(\\text{out\\_features})`. If :attr:`bias` is ``True``, the values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where :math:`k = \\frac{1}{\\text{in\\_features}}` Examples:: >>> m = nn.Linear(20, 30) >>> input = torch.randn(128, 20) >>> output = m(input) >>> print(output.size()) torch.Size([128, 30]) """ __constants__ = ['bias', 'in_features', 'out_features'] def __init__(self, in_features, out_features, bias=True): super(LinearProximal, self).__init__() self.in_features = in_features self.out_features = out_features self.weight_u = nn.Parameter(torch.Tensor(out_features, in_features)) self.weight_v = nn.Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = nn.Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): nn.init.kaiming_uniform_(self.weight_u, a=math.sqrt(5)) nn.init.kaiming_uniform_(self.weight_v, a=math.sqrt(5)) self.weight_u.data.abs_() self.weight_v.data.abs_() if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight_u) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def forward(self, input): return functional.linear(input, self.weight_u - self.weight_v, self .bias) def extra_repr(self): return 'in_features={}, out_features={}, bias={}'.format(self. in_features, self.out_features, self.bias is not None) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'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 assert_size_stride = torch._C._dynamo.guards.assert_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, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 - tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4 = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_sub_0[grid(16)](primals_1, primals_2, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, reinterpret_tensor(primals_4, (64, 4), (4, 1), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf1) del buf0 del primals_3 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_4, (64, 4), (4, 1), 0) class LinearProximalNew(nn.Module): """Applies a linear transformation to the incoming data: :math:`y = xA^T + b` Args: in_features: size of each input sample out_features: size of each output sample bias: If set to ``False``, the layer will not learn an additive bias. Default: ``True`` Shape: - Input: :math:`(N, *, H_{in})` where :math:`*` means any number of additional dimensions and :math:`H_{in} = \\text{in\\_features}` - Output: :math:`(N, *, H_{out})` where all but the last dimension are the same shape as the input and :math:`H_{out} = \\text{out\\_features}`. Attributes: weight: the learnable weights of the module of shape :math:`(\\text{out\\_features}, \\text{in\\_features})`. The values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})`, where :math:`k = \\frac{1}{\\text{in\\_features}}` bias: the learnable bias of the module of shape :math:`(\\text{out\\_features})`. If :attr:`bias` is ``True``, the values are initialized from :math:`\\mathcal{U}(-\\sqrt{k}, \\sqrt{k})` where :math:`k = \\frac{1}{\\text{in\\_features}}` Examples:: >>> m = nn.Linear(20, 30) >>> input = torch.randn(128, 20) >>> output = m(input) >>> print(output.size()) torch.Size([128, 30]) """ __constants__ = ['bias', 'in_features', 'out_features'] def __init__(self, in_features, out_features, bias=True): super(LinearProximalNew, self).__init__() self.in_features = in_features self.out_features = out_features self.weight_u = nn.Parameter(torch.Tensor(out_features, in_features)) self.weight_v = nn.Parameter(torch.Tensor(out_features, in_features)) if bias: self.bias = nn.Parameter(torch.Tensor(out_features)) else: self.register_parameter('bias', None) self.reset_parameters() def reset_parameters(self): nn.init.kaiming_uniform_(self.weight_u, a=math.sqrt(5)) nn.init.kaiming_uniform_(self.weight_v, a=math.sqrt(5)) self.weight_u.data.abs_() self.weight_v.data.abs_() if self.bias is not None: fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight_u) bound = 1 / math.sqrt(fan_in) nn.init.uniform_(self.bias, -bound, bound) def extra_repr(self): return 'in_features={}, out_features={}, bias={}'.format(self. in_features, self.out_features, self.bias is not None) def forward(self, input_0): primals_1 = self.weight_u primals_2 = self.weight_v primals_3 = self.bias primals_4 = input_0 output = call([primals_1, primals_2, primals_3, primals_4]) return output[0]
belbahrim/twin-causal-net
LinearProximal
false
3,203
[ "MIT" ]
0
f45d5a61ed9039ae7d0cd615d95212f11a5a2086
https://github.com/belbahrim/twin-causal-net/tree/f45d5a61ed9039ae7d0cd615d95212f11a5a2086
TwoLayerNet
import torch class TwoLayerNet(torch.nn.Module): """ This class is copied from PyTorch's documentation and is meant to be the simplest, non-trivial custom NN we can use for testing provenance. See [here](https://pytorch.org/tutorials/beginner/examples_nn/two_layer_net_module.html#sphx-glr-beginner-examples-nn-two-layer-net-module-py) """ def __init__(self, D_in, H, D_out): """ In the constructor we instantiate two nn.Linear modules and assign them as member variables. """ super(TwoLayerNet, self).__init__() self.linear1 = torch.nn.Linear(D_in, H) self.linear2 = torch.nn.Linear(H, D_out) def forward(self, x): """ In the forward function we accept a Tensor of input data and we must return a Tensor of output data. We can use Modules defined in the constructor as well as arbitrary operators on Tensors. """ h_relu = self.linear1(x).clamp(min=0) y_pred = self.linear2(h_relu) return y_pred def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'D_in': 4, 'H': 4, 'D_out': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime 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_clamp_ge_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = tmp2 >= tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp5, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4), (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 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_clamp_ge_0[grid(256)](buf0, primals_2, buf1, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = buf0 del buf0 extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_4, buf3 class TwoLayerNetNew(torch.nn.Module): """ This class is copied from PyTorch's documentation and is meant to be the simplest, non-trivial custom NN we can use for testing provenance. See [here](https://pytorch.org/tutorials/beginner/examples_nn/two_layer_net_module.html#sphx-glr-beginner-examples-nn-two-layer-net-module-py) """ def __init__(self, D_in, H, D_out): """ In the constructor we instantiate two nn.Linear modules and assign them as member variables. """ super(TwoLayerNetNew, self).__init__() self.linear1 = torch.nn.Linear(D_in, H) self.linear2 = torch.nn.Linear(H, D_out) def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
benfogelson/provenance
TwoLayerNet
false
3,204
[ "MIT" ]
0
e61095e767e8786943ea76bef9b5dd6dd9575041
https://github.com/benfogelson/provenance/tree/e61095e767e8786943ea76bef9b5dd6dd9575041
Conv2dBlock
import torch import torch.nn.functional as F from torch import nn class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_dim': 4, 'out_dim': 4, 'ks': 4, 'st': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn.functional as F from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(4, 4), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 1, 1), (4, 1, 1, 1)) buf1 = buf0 del buf0 buf2 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.bool) get_raw_stream(0) triton_poi_fused_convolution_relu_threshold_backward_0[grid(16)](buf1, primals_3, buf2, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_3 return buf1, primals_1, primals_2, buf2 class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlockNew(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlockNew, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, input_0): primals_1 = self.conv.weight primals_3 = self.conv.bias primals_2 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
belphegor2211/KLTN_GANwriting
Conv2dBlock
false
3,205
[ "MIT" ]
0
67d4d5c286ec45ef704b49c5abf9774d38bf65eb
https://github.com/belphegor2211/KLTN_GANwriting/tree/67d4d5c286ec45ef704b49c5abf9774d38bf65eb
Biaffine
import torch import torch.nn as nn import torch.utils.checkpoint class Biaffine(nn.Module): def __init__(self, n_in, n_out=1, bias_x=True, bias_y=True): super(Biaffine, self).__init__() self.n_in = n_in self.n_out = n_out self.bias_x = bias_x self.bias_y = bias_y self.weight = nn.Parameter(torch.Tensor(n_out, n_in + bias_x, n_in + bias_y)) self.reset_parameters() def extra_repr(self): info = f'n_in={self.n_in}, n_out={self.n_out}' if self.bias_x: info += f', bias_x={self.bias_x}' if self.bias_y: info += f', bias_y={self.bias_y}' return info def reset_parameters(self): nn.init.zeros_(self.weight) def forward(self, x, y): if self.bias_x: x = torch.cat([x, x.new_ones(x.shape[:-1]).unsqueeze(-1)], -1) if self.bias_y: y = torch.cat([y, y.new_ones(y.shape[:-1]).unsqueeze(-1)], -1) x = x.unsqueeze(1) y = y.unsqueeze(1) s = x @ self.weight @ y.transpose(-1, -2) s = s.squeeze(1) return s def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_in': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils.checkpoint assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 320 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = x0 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], 5, tl.int64) tmp9 = 1.0 tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp6, tmp9, tmp10) tmp12 = tl.where(tmp4, tmp5, tmp11) tl.store(out_ptr0 + x2, tmp12, 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, (1, 5, 5), (25, 5, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 5), (80, 20, 5, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(320)](primals_1, buf0, 320, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4, 5), (20, 5, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 5), (20, 5, 1), 0), reinterpret_tensor(primals_3, (16, 5, 5), (0, 5, 1), 0), out=buf1) del primals_3 buf2 = empty_strided_cuda((4, 4, 4, 5), (80, 20, 5, 1), torch.float32) triton_poi_fused_cat_0[grid(320)](primals_2, buf2, 320, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf1, reinterpret_tensor(buf2, (16, 5, 4), (20, 1, 5), 0), out=buf3) del buf1 return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf2, (16, 4, 5), (20, 5, 1), 0 ), reinterpret_tensor(buf0, (16, 5, 4), (20, 1, 5), 0) class BiaffineNew(nn.Module): def __init__(self, n_in, n_out=1, bias_x=True, bias_y=True): super(BiaffineNew, self).__init__() self.n_in = n_in self.n_out = n_out self.bias_x = bias_x self.bias_y = bias_y self.weight = nn.Parameter(torch.Tensor(n_out, n_in + bias_x, n_in + bias_y)) self.reset_parameters() def extra_repr(self): info = f'n_in={self.n_in}, n_out={self.n_out}' if self.bias_x: info += f', bias_x={self.bias_x}' if self.bias_y: info += f', bias_y={self.bias_y}' return info def reset_parameters(self): nn.init.zeros_(self.weight) def forward(self, input_0, input_1): primals_3 = self.weight primals_1 = input_0 primals_2 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
benjamin-mlr/lightning-language-modeling
Biaffine
false
3,206
[ "Apache-2.0" ]
0
62b497cc2a01bdae0451ebe0f314f7fcb0f7eef3
https://github.com/benjamin-mlr/lightning-language-modeling/tree/62b497cc2a01bdae0451ebe0f314f7fcb0f7eef3
ActFirstResBlock
import torch import torch.nn.functional as F from torch import nn class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class ActFirstResBlock(nn.Module): def __init__(self, fin, fout, fhid=None, activation='lrelu', norm='none'): super().__init__() self.learned_shortcut = fin != fout self.fin = fin self.fout = fout self.fhid = min(fin, fout) if fhid is None else fhid self.conv_0 = Conv2dBlock(self.fin, self.fhid, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) self.conv_1 = Conv2dBlock(self.fhid, self.fout, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) if self.learned_shortcut: self.conv_s = Conv2dBlock(self.fin, self.fout, 1, 1, activation ='none', use_bias=False) def forward(self, x): x_s = self.conv_s(x) if self.learned_shortcut else x dx = self.conv_0(x) dx = self.conv_1(dx) out = x_s + dx return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'fin': 4, 'fout': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn.functional as F from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_leaky_relu_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x2 = xindex // 36 x3 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2), xmask, eviction_policy='evict_last') tmp1 = 0.0 tmp2 = tmp0 > tmp1 tmp3 = 0.2 tmp4 = tmp0 * tmp3 tmp5 = tl.where(tmp2, tmp0, tmp4) tl.store(out_ptr0 + x3, tmp5, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 0.0 tmp4 = tmp2 > tmp3 tl.store(out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 6 x1 = xindex // 6 % 6 x4 = xindex // 36 x2 = xindex // 36 % 4 x5 = xindex tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4), xmask, eviction_policy='evict_last').to(tl.int1) tmp1 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 + x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4), xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = 0.2 tmp5 = tmp3 * tmp4 tmp6 = tl.where(tmp0, tmp3, tmp5) tl.store(out_ptr0 + x5, tmp6, xmask) @triton.jit def triton_poi_fused_add_convolution_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_out_ptr0 + x3, xmask) tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp4 = tmp0 + tmp3 tl.store(in_out_ptr0 + x3, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (4,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_reflection_pad2d_0[grid(576)](primals_1, buf0, 576, XBLOCK=256, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1)) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf1, primals_3, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2[grid(576)]( buf2, buf1, primals_3, buf3, 576, XBLOCK=128, num_warps=4, num_stages=1) del buf1 del primals_3 buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 triton_poi_fused_add_convolution_3[grid(256)](buf5, primals_1, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_1 del primals_5 return buf5, primals_2, primals_4, buf0, buf2, buf3 class AdaptiveInstanceNorm2d(nn.Module): def __init__(self, num_features, eps=1e-05, momentum=0.1): super(AdaptiveInstanceNorm2d, self).__init__() self.num_features = num_features self.eps = eps self.momentum = momentum self.weight = None self.bias = None self.register_buffer('running_mean', torch.zeros(num_features)) self.register_buffer('running_var', torch.ones(num_features)) def forward(self, x): assert self.weight is not None and self.bias is not None, 'Please assign AdaIN weight first' b, c = x.size(0), x.size(1) running_mean = self.running_mean.repeat(b) running_var = self.running_var.repeat(b) x_reshaped = x.contiguous().view(1, b * c, *x.size()[2:]) out = F.batch_norm(x_reshaped, running_mean, running_var, self. weight, self.bias, True, self.momentum, self.eps) return out.view(b, c, *x.size()[2:]) def __repr__(self): return self.__class__.__name__ + '(' + str(self.num_features) + ')' class Conv2dBlock(nn.Module): def __init__(self, in_dim, out_dim, ks, st, padding=0, norm='none', activation='relu', pad_type='zero', use_bias=True, activation_first =False): super(Conv2dBlock, self).__init__() self.use_bias = use_bias self.activation_first = activation_first if pad_type == 'reflect': self.pad = nn.ReflectionPad2d(padding) elif pad_type == 'replicate': self.pad = nn.ReplicationPad2d(padding) elif pad_type == 'zero': self.pad = nn.ZeroPad2d(padding) else: assert 0, 'Unsupported padding type: {}'.format(pad_type) norm_dim = out_dim if norm == 'bn': self.norm = nn.BatchNorm2d(norm_dim) elif norm == 'in': self.norm = nn.InstanceNorm2d(norm_dim) elif norm == 'adain': self.norm = AdaptiveInstanceNorm2d(norm_dim) elif norm == 'none': self.norm = None else: assert 0, 'Unsupported normalization: {}'.format(norm) if activation == 'relu': self.activation = nn.ReLU(inplace=False) elif activation == 'lrelu': self.activation = nn.LeakyReLU(0.2, inplace=False) elif activation == 'tanh': self.activation = nn.Tanh() elif activation == 'none': self.activation = None else: assert 0, 'Unsupported activation: {}'.format(activation) self.conv = nn.Conv2d(in_dim, out_dim, ks, st, bias=self.use_bias) def forward(self, x): if self.activation_first: if self.activation: x = self.activation(x) x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) else: x = self.conv(self.pad(x)) if self.norm: x = self.norm(x) if self.activation: x = self.activation(x) return x class ActFirstResBlockNew(nn.Module): def __init__(self, fin, fout, fhid=None, activation='lrelu', norm='none'): super().__init__() self.learned_shortcut = fin != fout self.fin = fin self.fout = fout self.fhid = min(fin, fout) if fhid is None else fhid self.conv_0 = Conv2dBlock(self.fin, self.fhid, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) self.conv_1 = Conv2dBlock(self.fhid, self.fout, 3, 1, padding=1, pad_type='reflect', norm=norm, activation=activation, activation_first=True) if self.learned_shortcut: self.conv_s = Conv2dBlock(self.fin, self.fout, 1, 1, activation ='none', use_bias=False) def forward(self, input_0): primals_2 = self.conv_0.conv.weight primals_3 = self.conv_0.conv.bias primals_4 = self.conv_1.conv.weight primals_5 = self.conv_1.conv.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
belphegor2211/KLTN_GANwriting
ActFirstResBlock
false
3,207
[ "MIT" ]
0
67d4d5c286ec45ef704b49c5abf9774d38bf65eb
https://github.com/belphegor2211/KLTN_GANwriting/tree/67d4d5c286ec45ef704b49c5abf9774d38bf65eb
PrimaryCapsLayer
import torch import torch.nn as nn def squash(x): lengths2 = x.pow(2).sum(dim=2) lengths = lengths2.sqrt() x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1) return x class PrimaryCapsLayer(nn.Module): def __init__(self, input_channels, output_caps, output_dim, kernel_size, stride): super(PrimaryCapsLayer, self).__init__() self.conv = nn.Conv2d(input_channels, output_caps * output_dim, kernel_size=kernel_size, stride=stride) self.input_channels = input_channels self.output_caps = output_caps self.output_dim = output_dim def forward(self, input): out = self.conv(input) N, _C, H, W = out.size() out = out.view(N, self.output_caps, self.output_dim, H, W) out = out.permute(0, 1, 3, 4, 2).contiguous() out = out.view(out.size(0), -1, out.size(4)) out = squash(out) return out def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_channels': 4, 'output_caps': 4, 'output_dim': 4, 'kernel_size': 4, 'stride': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 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_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 * tmp1 tmp4 = tmp3 * tmp3 tmp5 = tmp2 + tmp4 tmp7 = tmp6 * tmp6 tmp8 = tmp5 + tmp7 tmp10 = tmp9 * tmp9 tmp11 = tmp8 + tmp10 tmp12 = 1.0 tmp13 = tmp11 + tmp12 tmp14 = tmp11 / tmp13 tmp15 = libdevice.sqrt(tmp11) tmp16 = tmp14 / tmp15 tmp17 = tmp0 * tmp16 tl.store(out_ptr0 + x2, tmp17, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (16, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 16, 1, 1), (16, 1, 1, 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 buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_mul_1[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) return buf2, primals_1, primals_3, buf1 def squash(x): lengths2 = x.pow(2).sum(dim=2) lengths = lengths2.sqrt() x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1) return x class PrimaryCapsLayerNew(nn.Module): def __init__(self, input_channels, output_caps, output_dim, kernel_size, stride): super(PrimaryCapsLayerNew, self).__init__() self.conv = nn.Conv2d(input_channels, output_caps * output_dim, kernel_size=kernel_size, stride=stride) self.input_channels = input_channels self.output_caps = output_caps self.output_dim = output_dim 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]
bentrevett/capsules
PrimaryCapsLayer
false
3,208
[ "MIT" ]
0
239273de25c607d7a7504e8c6900772fddd15cd3
https://github.com/bentrevett/capsules/tree/239273de25c607d7a7504e8c6900772fddd15cd3
policy_net
import torch import torch.nn.functional as F import torch.nn as nn class policy_net(nn.Module): def __init__(self, n_states, n_actions, n_hidden=128): super(policy_net, self).__init__() self.affine1 = nn.Linear(n_states, n_hidden) self.affine2 = nn.Linear(n_hidden, n_actions) def forward(self, x): x = F.relu(self.affine1(x)) action_scores = self.affine2(x) return F.softmax(action_scores, dim=1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_states': 4, 'n_actions': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x3, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 16 x2 = xindex // 64 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x3, tmp8, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (128, 4), (4, 1)) assert_size_stride(primals_2, (128,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 128), (128, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf0 buf5 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1, primals_2, buf5, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128), (128, 1), 0), reinterpret_tensor(primals_4, (128, 4), (1, 128), 0), alpha=1, beta=1, out=buf2) del primals_5 buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(256)](buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf2 triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf3 return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 128), (128, 1), 0 ), buf4, primals_4, buf5 class policy_netNew(nn.Module): def __init__(self, n_states, n_actions, n_hidden=128): super(policy_netNew, self).__init__() self.affine1 = nn.Linear(n_states, n_hidden) self.affine2 = nn.Linear(n_hidden, n_actions) def forward(self, input_0): primals_1 = self.affine1.weight primals_2 = self.affine1.bias primals_4 = self.affine2.weight primals_5 = self.affine2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
bigtreeljc/force_learning
policy_net
false
3,209
[ "MIT" ]
0
183a7c96c411e282966604e3cb375ba49e91a88c
https://github.com/bigtreeljc/force_learning/tree/183a7c96c411e282966604e3cb375ba49e91a88c
spectral_model
import torch import torch.nn as nn import torch.nn.functional as F class spectral_model(nn.Module): def __init__(self, num_classes): super(spectral_model, self).__init__() self.mlp1 = nn.Conv1d(6, 64, 1) self.mlp2 = nn.Conv1d(64, 128, 1) self.mlp3 = nn.Conv1d(128, 256, 1) self.flatten = nn.Flatten() self.fc1 = nn.Linear(256, 128) self.fc2 = nn.Linear(128, 64) self.fc3 = nn.Linear(64, num_classes) def forward(self, x): x = x.permute(0, 2, 1) x = F.relu(self.mlp1(x)) x = F.relu(self.mlp2(x)) x = F.relu(self.mlp3(x)) x = torch.max(x, 2, keepdim=True)[0] x = self.flatten(x) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) return x def get_inputs(): return [torch.rand([4, 6, 6])] def get_init_inputs(): return [[], {'num_classes': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 24 xnumel = 6 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 6 y1 = yindex // 6 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 6 * x2 + 36 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 6 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1536 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 6 % 64 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3072 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 6 % 128 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_max_relu_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 256 tmp0 = tl.load(in_ptr0 + 6 * x2, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (1 + 6 * x2), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr0 + (2 + 6 * x2), xmask, eviction_policy='evict_last' ) tmp40 = tl.load(in_ptr0 + (3 + 6 * x2), xmask, eviction_policy='evict_last' ) tmp57 = tl.load(in_ptr0 + (4 + 6 * x2), xmask, eviction_policy='evict_last' ) tmp74 = tl.load(in_ptr0 + (5 + 6 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = tmp5 + tmp1 tmp7 = triton_helpers.maximum(tmp3, tmp6) tmp8 = tmp4 > tmp7 tmp9 = tmp4 == tmp7 tmp10 = tmp4 != tmp4 tmp11 = tmp7 != tmp7 tmp12 = tmp10 > tmp11 tmp13 = tmp8 | tmp12 tmp14 = tmp10 & tmp11 tmp15 = tmp9 | tmp14 tmp16 = tl.full([1], 0, tl.int64) tmp17 = tl.full([1], 1, tl.int64) tmp18 = tmp16 < tmp17 tmp19 = tmp15 & tmp18 tmp20 = tmp13 | tmp19 tmp21 = tl.where(tmp20, tmp4, tmp7) tmp22 = tl.where(tmp20, tmp16, tmp17) tmp24 = tmp23 + tmp1 tmp25 = triton_helpers.maximum(tmp3, tmp24) tmp26 = tmp21 > tmp25 tmp27 = tmp21 == tmp25 tmp28 = tmp21 != tmp21 tmp29 = tmp25 != tmp25 tmp30 = tmp28 > tmp29 tmp31 = tmp26 | tmp30 tmp32 = tmp28 & tmp29 tmp33 = tmp27 | tmp32 tmp34 = tl.full([1], 2, tl.int64) tmp35 = tmp22 < tmp34 tmp36 = tmp33 & tmp35 tmp37 = tmp31 | tmp36 tmp38 = tl.where(tmp37, tmp21, tmp25) tmp39 = tl.where(tmp37, tmp22, tmp34) tmp41 = tmp40 + tmp1 tmp42 = triton_helpers.maximum(tmp3, tmp41) tmp43 = tmp38 > tmp42 tmp44 = tmp38 == tmp42 tmp45 = tmp38 != tmp38 tmp46 = tmp42 != tmp42 tmp47 = tmp45 > tmp46 tmp48 = tmp43 | tmp47 tmp49 = tmp45 & tmp46 tmp50 = tmp44 | tmp49 tmp51 = tl.full([1], 3, tl.int64) tmp52 = tmp39 < tmp51 tmp53 = tmp50 & tmp52 tmp54 = tmp48 | tmp53 tmp55 = tl.where(tmp54, tmp38, tmp42) tmp56 = tl.where(tmp54, tmp39, tmp51) tmp58 = tmp57 + tmp1 tmp59 = triton_helpers.maximum(tmp3, tmp58) tmp60 = tmp55 > tmp59 tmp61 = tmp55 == tmp59 tmp62 = tmp55 != tmp55 tmp63 = tmp59 != tmp59 tmp64 = tmp62 > tmp63 tmp65 = tmp60 | tmp64 tmp66 = tmp62 & tmp63 tmp67 = tmp61 | tmp66 tmp68 = tl.full([1], 4, tl.int64) tmp69 = tmp56 < tmp68 tmp70 = tmp67 & tmp69 tmp71 = tmp65 | tmp70 tmp72 = tl.where(tmp71, tmp55, tmp59) tmp73 = tl.where(tmp71, tmp56, tmp68) tmp75 = tmp74 + tmp1 tmp76 = triton_helpers.maximum(tmp3, tmp75) tmp77 = tmp72 > tmp76 tmp78 = tmp72 == tmp76 tmp79 = tmp72 != tmp72 tmp80 = tmp76 != tmp76 tmp81 = tmp79 > tmp80 tmp82 = tmp77 | tmp81 tmp83 = tmp79 & tmp80 tmp84 = tmp78 | tmp83 tmp85 = tl.full([1], 5, tl.int64) tmp86 = tmp73 < tmp85 tmp87 = tmp84 & tmp86 tmp88 = tmp82 | tmp87 tl.where(tmp88, tmp72, tmp76) tmp90 = tl.where(tmp88, tmp73, tmp85) tmp91 = triton_helpers.maximum(tmp4, tmp7) tmp92 = triton_helpers.maximum(tmp91, tmp25) tmp93 = triton_helpers.maximum(tmp92, tmp42) tmp94 = triton_helpers.maximum(tmp93, tmp59) tmp95 = triton_helpers.maximum(tmp94, tmp76) tl.store(out_ptr0 + x2, tmp90, xmask) tl.store(out_ptr1 + x2, tmp95, xmask) @triton.jit def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 128 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 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_relu_threshold_backward_6(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 6 % 256 tmp0 = tl.load(in_ptr0 + x3, None) tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(out_ptr0 + x3, tmp6, None) 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, 6, 6), (36, 6, 1)) assert_size_stride(primals_2, (64, 6, 1), (6, 1, 1)) assert_size_stride(primals_3, (64,), (1,)) assert_size_stride(primals_4, (128, 64, 1), (64, 1, 1)) assert_size_stride(primals_5, (128,), (1,)) assert_size_stride(primals_6, (256, 128, 1), (128, 1, 1)) assert_size_stride(primals_7, (256,), (1,)) assert_size_stride(primals_8, (128, 256), (256, 1)) assert_size_stride(primals_9, (128,), (1,)) assert_size_stride(primals_10, (64, 128), (128, 1)) assert_size_stride(primals_11, (64,), (1,)) assert_size_stride(primals_12, (4, 64), (64, 1)) assert_size_stride(primals_13, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 6, 6), (36, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(24, 6)](primals_1, buf0, 24, 6, XBLOCK=8, YBLOCK=32, num_warps=4, num_stages=1) buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf1, (4, 64, 6), (384, 6, 1)) del buf0 buf2 = buf1 del buf1 triton_poi_fused_convolution_relu_1[grid(1536)](buf2, primals_3, 1536, XBLOCK=128, num_warps=4, num_stages=1) del primals_3 buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf3, (4, 128, 6), (768, 6, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_relu_2[grid(3072)](buf4, primals_5, 3072, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf5 = extern_kernels.convolution(buf4, primals_6, stride=(1,), padding=(0,), dilation=(1,), transposed=False, output_padding=( 0,), groups=1, bias=None) assert_size_stride(buf5, (4, 256, 6), (1536, 6, 1)) buf6 = empty_strided_cuda((4, 256, 1), (256, 1, 1), torch.int64) buf7 = empty_strided_cuda((4, 256, 1), (256, 1, 1), torch.float32) triton_poi_fused_convolution_max_relu_3[grid(1024)](buf5, primals_7, buf6, buf7, 1024, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (4, 256), (256, 1), 0), reinterpret_tensor(primals_8, (256, 128), (1, 256), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_4[grid(512)](buf9, primals_9, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 buf10 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_10, (128, 64), ( 1, 128), 0), out=buf10) buf11 = buf10 del buf10 triton_poi_fused_relu_5[grid(256)](buf11, primals_11, 256, XBLOCK= 256, num_warps=4, num_stages=1) del primals_11 buf12 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_13, buf11, reinterpret_tensor( primals_12, (64, 4), (1, 64), 0), alpha=1, beta=1, out=buf12) del primals_13 buf13 = empty_strided_cuda((4, 256, 6), (1536, 6, 1), torch.bool) triton_poi_fused_convolution_relu_threshold_backward_6[grid(6144)](buf5 , primals_7, buf13, 6144, XBLOCK=256, num_warps=4, num_stages=1) del buf5 del primals_7 return buf12, primals_2, primals_4, primals_6, reinterpret_tensor(primals_1 , (4, 6, 6), (36, 1, 6), 0), buf2, buf4, buf6, reinterpret_tensor(buf7, (4, 256), (256, 1), 0 ), buf9, buf11, primals_12, primals_10, primals_8, buf13 class spectral_modelNew(nn.Module): def __init__(self, num_classes): super(spectral_modelNew, self).__init__() self.mlp1 = nn.Conv1d(6, 64, 1) self.mlp2 = nn.Conv1d(64, 128, 1) self.mlp3 = nn.Conv1d(128, 256, 1) self.flatten = nn.Flatten() self.fc1 = nn.Linear(256, 128) self.fc2 = nn.Linear(128, 64) self.fc3 = nn.Linear(64, num_classes) def forward(self, input_0): primals_2 = self.mlp1.weight primals_3 = self.mlp1.bias primals_4 = self.mlp2.weight primals_5 = self.mlp2.bias primals_6 = self.mlp3.weight primals_7 = self.mlp3.bias primals_8 = self.fc1.weight primals_9 = self.fc1.bias primals_10 = self.fc2.weight primals_11 = self.fc2.bias primals_12 = self.fc3.weight primals_13 = self.fc3.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]
berkbilir/point-cloud-classification
spectral_model
false
3,210
[ "MIT" ]
0
4188b317acc8efccb694831b26a3a8564dee5530
https://github.com/berkbilir/point-cloud-classification/tree/4188b317acc8efccb694831b26a3a8564dee5530