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
SimpleASinModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleASinModule(torch.nn.Module): def __init__(self): super(SimpleASinModule, self).__init__() def forward(self, a): return torch.asin(a + a) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_asin_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = libdevice.asin(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_asin_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleASinModuleNew(torch.nn.Module): def __init__(self): super(SimpleASinModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleASinModule
false
7,378
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleAvgPool1dModule
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleAvgPool1dModule(torch.nn.Module): def __init__(self, kernel_size, stride=None, padding=0): super(SimpleAvgPool1dModule, self).__init__() self.kernel_size = kernel_size self.padding = padding self.stride = stride def forward(self, inputs): return F.avg_pool1d(inputs, self.kernel_size, padding=self.padding, stride=self.stride) def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp1 + tmp0 tmp4 = tmp3 + tmp2 tmp6 = tmp5 + tmp4 tmp7 = 0.25 tmp8 = tmp6 * tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_avg_pool2d_0[grid(4)](arg0_1, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 1), (1, 1), 0), class SimpleAvgPool1dModuleNew(torch.nn.Module): def __init__(self, kernel_size, stride=None, padding=0): super(SimpleAvgPool1dModuleNew, self).__init__() self.kernel_size = kernel_size self.padding = padding self.stride = stride def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleAvgPool1dModule
false
7,379
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
MixtureDensityHead
from _paritybench_helpers import _mock_config import torch import torch.nn as nn from torch.autograd import Variable from torch.distributions import Categorical class MixtureDensityHead(nn.Module): def __init__(self, config: 'DictConfig', **kwargs): self.hparams = config super().__init__() self._build_network() def _build_network(self): self.pi = nn.Linear(self.hparams.input_dim, self.hparams.num_gaussian) nn.init.normal_(self.pi.weight) self.sigma = nn.Linear(self.hparams.input_dim, self.hparams. num_gaussian, bias=self.hparams.sigma_bias_flag) self.mu = nn.Linear(self.hparams.input_dim, self.hparams.num_gaussian) nn.init.normal_(self.mu.weight) if self.hparams.mu_bias_init is not None: for i, bias in enumerate(self.hparams.mu_bias_init): nn.init.constant_(self.mu.bias[i], bias) def forward(self, x): pi = self.pi(x) sigma = self.sigma(x) sigma = nn.ELU()(sigma) + 1 + 1e-15 mu = self.mu(x) return pi, sigma, mu def gaussian_probability(self, sigma, mu, target, log=False): """Returns the probability of `target` given MoG parameters `sigma` and `mu`. Arguments: sigma (BxGxO): The standard deviation of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian. mu (BxGxO): The means of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian. target (BxI): A batch of target. B is the batch size and I is the number of input dimensions. Returns: probabilities (BxG): The probability of each point in the probability of the distribution in the corresponding sigma/mu index. """ target = target.expand_as(sigma) if log: ret = -torch.log(sigma) - 0.5 * LOG2PI - 0.5 * torch.pow(( target - mu) / sigma, 2) else: ret = ONEOVERSQRT2PI / sigma * torch.exp(-0.5 * ((target - mu) / sigma) ** 2) return ret def log_prob(self, pi, sigma, mu, y): log_component_prob = self.gaussian_probability(sigma, mu, y, log=True) log_mix_prob = torch.log(nn.functional.gumbel_softmax(pi, tau=self. hparams.softmax_temperature, dim=-1) + 1e-15) return torch.logsumexp(log_component_prob + log_mix_prob, dim=-1) def sample(self, pi, sigma, mu): """Draw samples from a MoG.""" categorical = Categorical(pi) pis = categorical.sample().unsqueeze(1) sample = Variable(sigma.data.new(sigma.size(0), 1).normal_()) sample = sample * sigma.gather(1, pis) + mu.gather(1, pis) return sample def generate_samples(self, pi, sigma, mu, n_samples=None): if n_samples is None: n_samples = self.hparams.n_samples samples = [] softmax_pi = nn.functional.gumbel_softmax(pi, tau=self.hparams. softmax_temperature, dim=-1) assert (softmax_pi < 0).sum().item( ) == 0, 'pi parameter should not have negative' for _ in range(n_samples): samples.append(self.sample(softmax_pi, sigma, mu)) samples = torch.cat(samples, dim=1) return samples def generate_point_predictions(self, pi, sigma, mu, n_samples=None): samples = self.generate_samples(pi, sigma, mu, n_samples) if self.hparams.central_tendency == 'mean': y_hat = torch.mean(samples, dim=-1) elif self.hparams.central_tendency == 'median': y_hat = torch.median(samples, dim=-1).values return y_hat.unsqueeze(1) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(input_dim=4, num_gaussian=4, sigma_bias_flag=4, mu_bias_init=[4, 4])}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn from torch.autograd import Variable from torch.distributions import Categorical assert_size_stride = torch._C._dynamo.guards.assert_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_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) tmp8 = tmp7 + tmp3 tmp9 = 1e-15 tmp10 = tmp8 + tmp9 tl.store(out_ptr0 + x0, tmp10, 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, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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_elu_0[grid(256)](buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0 ), alpha=1, beta=1, out=buf3) del primals_6 del primals_7 return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), buf2, reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1 class MixtureDensityHeadNew(nn.Module): def __init__(self, config: 'DictConfig', **kwargs): self.hparams = config super().__init__() self._build_network() def _build_network(self): self.pi = nn.Linear(self.hparams.input_dim, self.hparams.num_gaussian) nn.init.normal_(self.pi.weight) self.sigma = nn.Linear(self.hparams.input_dim, self.hparams. num_gaussian, bias=self.hparams.sigma_bias_flag) self.mu = nn.Linear(self.hparams.input_dim, self.hparams.num_gaussian) nn.init.normal_(self.mu.weight) if self.hparams.mu_bias_init is not None: for i, bias in enumerate(self.hparams.mu_bias_init): nn.init.constant_(self.mu.bias[i], bias) def gaussian_probability(self, sigma, mu, target, log=False): """Returns the probability of `target` given MoG parameters `sigma` and `mu`. Arguments: sigma (BxGxO): The standard deviation of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian. mu (BxGxO): The means of the Gaussians. B is the batch size, G is the number of Gaussians, and O is the number of dimensions per Gaussian. target (BxI): A batch of target. B is the batch size and I is the number of input dimensions. Returns: probabilities (BxG): The probability of each point in the probability of the distribution in the corresponding sigma/mu index. """ target = target.expand_as(sigma) if log: ret = -torch.log(sigma) - 0.5 * LOG2PI - 0.5 * torch.pow(( target - mu) / sigma, 2) else: ret = ONEOVERSQRT2PI / sigma * torch.exp(-0.5 * ((target - mu) / sigma) ** 2) return ret def log_prob(self, pi, sigma, mu, y): log_component_prob = self.gaussian_probability(sigma, mu, y, log=True) log_mix_prob = torch.log(nn.functional.gumbel_softmax(pi, tau=self. hparams.softmax_temperature, dim=-1) + 1e-15) return torch.logsumexp(log_component_prob + log_mix_prob, dim=-1) def sample(self, pi, sigma, mu): """Draw samples from a MoG.""" categorical = Categorical(pi) pis = categorical.sample().unsqueeze(1) sample = Variable(sigma.data.new(sigma.size(0), 1).normal_()) sample = sample * sigma.gather(1, pis) + mu.gather(1, pis) return sample def generate_samples(self, pi, sigma, mu, n_samples=None): if n_samples is None: n_samples = self.hparams.n_samples samples = [] softmax_pi = nn.functional.gumbel_softmax(pi, tau=self.hparams. softmax_temperature, dim=-1) assert (softmax_pi < 0).sum().item( ) == 0, 'pi parameter should not have negative' for _ in range(n_samples): samples.append(self.sample(softmax_pi, sigma, mu)) samples = torch.cat(samples, dim=1) return samples def generate_point_predictions(self, pi, sigma, mu, n_samples=None): samples = self.generate_samples(pi, sigma, mu, n_samples) if self.hparams.central_tendency == 'mean': y_hat = torch.mean(samples, dim=-1) elif self.hparams.central_tendency == 'median': y_hat = torch.median(samples, dim=-1).values return y_hat.unsqueeze(1) def forward(self, input_0): primals_1 = self.pi.weight primals_2 = self.pi.bias primals_4 = self.sigma.weight primals_5 = self.sigma.bias primals_6 = self.mu.weight primals_7 = self.mu.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0], output[1], output[2]
Actis92/pytorch_tabular
MixtureDensityHead
false
7,380
[ "MIT" ]
1
78dabf5e7b97d8ff24db4bc83d9d0a2273941bbe
https://github.com/Actis92/pytorch_tabular/tree/78dabf5e7b97d8ff24db4bc83d9d0a2273941bbe
SimpleACosModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleACosModule(torch.nn.Module): def __init__(self): super(SimpleACosModule, self).__init__() def forward(self, a): return torch.acos(a + a) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_acos_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = libdevice.acos(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_acos_add_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleACosModuleNew(torch.nn.Module): def __init__(self): super(SimpleACosModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleACosModule
false
7,381
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleATanModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleATanModule(torch.nn.Module): def __init__(self): super(SimpleATanModule, self).__init__() def forward(self, a): return torch.atan(a + a) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_atan_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = libdevice.atan(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_atan_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleATanModuleNew(torch.nn.Module): def __init__(self): super(SimpleATanModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleATanModule
false
7,382
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleAddMmModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleAddMmModule(torch.nn.Module): def __init__(self, alpha=1, beta=1): super(SimpleAddMmModule, self).__init__() self.alpha = alpha self.beta = beta def forward(self, a, b, c): return (a + a).addmm(b, c) def get_inputs(): return [torch.rand([4, 4]), 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 import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) 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((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(buf0, arg1_1, arg2_1, alpha=1, beta=1, out=buf1) del arg1_1 del arg2_1 del buf0 return buf1, class SimpleAddMmModuleNew(torch.nn.Module): def __init__(self, alpha=1, beta=1): super(SimpleAddMmModuleNew, self).__init__() self.alpha = alpha self.beta = beta 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]
opti-mix/glow
SimpleAddMmModule
false
7,383
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleAbsModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleAbsModule(torch.nn.Module): def __init__(self): super(SimpleAbsModule, self).__init__() def forward(self, a): return torch.abs(a + a) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = tl_math.abs(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_abs_add_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleAbsModuleNew(torch.nn.Module): def __init__(self): super(SimpleAbsModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleAbsModule
false
7,384
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleCeilModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleCeilModule(torch.nn.Module): def forward(self, a, b): c = a + b return torch.ceil(c) 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 libdevice import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_ceil_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 + tmp1 tmp3 = libdevice.ceil(tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_ceil_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleCeilModuleNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleCeilModule
false
7,385
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
OneTupleModule
import torch import torch.jit import torch.onnx import torch.nn class OneTupleModule(torch.nn.Module): def __init__(self): super(OneTupleModule, self).__init__() def forward(self, x): y = 2 * x return y, 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 2.0 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class OneTupleModuleNew(torch.nn.Module): def __init__(self): super(OneTupleModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
OneTupleModule
false
7,386
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleBmmModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleBmmModule(torch.nn.Module): def forward(self, a, b): return (a + a).bmm(b) def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(buf0, arg1_1, out=buf1) del arg1_1 del buf0 return buf1, class SimpleBmmModuleNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleBmmModule
false
7,387
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
ConvGRUCell
import torch from torch import nn as nn import torch.nn.functional as F def one_param(m): """First parameter in `m`""" return next(m.parameters()) class ConvGRUCell(nn.Module): def __init__(self, input_dim, hidden_dim, kernel_size=(3, 3), bias=True, activation=F.tanh, batchnorm=False): """ Initialize ConvGRU cell. Parameters ---------- input_dim: int Number of channels of input tensor. hidden_dim: int Number of channels of hidden state. kernel_size: (int, int) Size of the convolutional kernel. bias: bool Whether or not to add the bias. """ super().__init__() self.input_dim = input_dim self.hidden_dim = hidden_dim self.kernel_size = kernel_size if isinstance(kernel_size, (tuple, list) ) else [kernel_size] * 2 self.padding = self.kernel_size[0] // 2, self.kernel_size[1] // 2 self.bias = bias self.activation = activation self.batchnorm = batchnorm self.conv_zr = nn.Conv2d(in_channels=self.input_dim + self. hidden_dim, out_channels=2 * self.hidden_dim, kernel_size=self. kernel_size, padding=self.padding, bias=self.bias) self.conv_h1 = nn.Conv2d(in_channels=self.input_dim, out_channels= self.hidden_dim, kernel_size=self.kernel_size, padding=self. padding, bias=self.bias) self.conv_h2 = nn.Conv2d(in_channels=self.hidden_dim, out_channels= self.hidden_dim, kernel_size=self.kernel_size, padding=self. padding, bias=self.bias) self.reset_parameters() def forward(self, input, h_prev=None): if h_prev is None: h_prev = self.init_hidden(input) combined = torch.cat((input, h_prev), dim=1) combined_conv = F.sigmoid(self.conv_zr(combined)) z, r = torch.split(combined_conv, self.hidden_dim, dim=1) h_ = self.activation(self.conv_h1(input) + r * self.conv_h2(h_prev)) h_cur = (1 - z) * h_ + z * h_prev return h_cur def init_hidden(self, input): bs, _ch, h, w = input.shape return one_param(self).new_zeros(bs, self.hidden_dim, h, w) def reset_parameters(self): nn.init.xavier_uniform_(self.conv_zr.weight, gain=nn.init. calculate_gain('tanh')) self.conv_zr.bias.data.zero_() nn.init.xavier_uniform_(self.conv_h1.weight, gain=nn.init. calculate_gain('tanh')) self.conv_h1.bias.data.zero_() nn.init.xavier_uniform_(self.conv_h2.weight, gain=nn.init. calculate_gain('tanh')) self.conv_h2.bias.data.zero_() if self.batchnorm: self.bn1.reset_parameters() self.bn2.reset_parameters() def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_dim': 4, 'hidden_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice from torch import 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_new_zeros_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 16 % 8 x0 = xindex % 16 x2 = xindex // 128 x3 = xindex tmp0 = x1 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp9 = 0.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 + x3, tmp12, xmask) @triton.jit def triton_poi_fused_convolution_sigmoid_2(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 x3 = xindex x1 = xindex // 16 % 8 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tl.store(in_out_ptr0 + x3, tmp3, xmask) @triton.jit def triton_poi_fused_add_convolution_mul_rsub_tanh_3(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x4 = xindex x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex % 64 tmp0 = tl.load(in_out_ptr0 + x4, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_out_ptr1 + x4, xmask) tmp4 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr2 + (x3 + 128 * x2), xmask) tmp9 = tl.load(in_ptr2 + (64 + x3 + 128 * x2), xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = 1.0 tmp8 = tmp7 - tmp6 tmp10 = tmp9 * tmp5 tmp11 = tmp2 + tmp10 tmp12 = libdevice.tanh(tmp11) tmp13 = tmp8 * tmp12 tmp14 = 0.0 tmp15 = tmp6 * tmp14 tmp16 = tmp13 + tmp15 tl.store(in_out_ptr0 + x4, tmp2, xmask) tl.store(in_out_ptr1 + x4, tmp5, xmask) tl.store(out_ptr0 + x4, tmp8, xmask) tl.store(out_ptr1 + x4, 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, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (8, 8, 3, 3), (72, 9, 3, 1)) assert_size_stride(primals_3, (8,), (1,)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_new_zeros_0[grid(256)](buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) buf1 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32) triton_poi_fused_cat_1[grid(512)](primals_1, buf1, 512, XBLOCK=256, num_warps=4, num_stages=1) buf2 = extern_kernels.convolution(buf1, primals_2, 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 = buf2 del buf2 triton_poi_fused_convolution_sigmoid_2[grid(512)](buf3, primals_3, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_3 buf4 = extern_kernels.convolution(primals_1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1)) buf6 = extern_kernels.convolution(buf0, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1)) buf5 = buf4 del buf4 buf7 = buf6 del buf6 buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_add_convolution_mul_rsub_tanh_3[grid(256)](buf5, buf7, primals_5, primals_7, buf3, buf8, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 del primals_7 return (buf9, primals_1, primals_2, primals_4, primals_6, buf0, buf1, buf3, reinterpret_tensor(buf3, (4, 4, 4, 4), (128, 16, 4, 1), 64), buf5, buf7, buf8) def one_param(m): """First parameter in `m`""" return next(m.parameters()) class ConvGRUCellNew(nn.Module): def __init__(self, input_dim, hidden_dim, kernel_size=(3, 3), bias=True, activation=F.tanh, batchnorm=False): """ Initialize ConvGRU cell. Parameters ---------- input_dim: int Number of channels of input tensor. hidden_dim: int Number of channels of hidden state. kernel_size: (int, int) Size of the convolutional kernel. bias: bool Whether or not to add the bias. """ super().__init__() self.input_dim = input_dim self.hidden_dim = hidden_dim self.kernel_size = kernel_size if isinstance(kernel_size, (tuple, list) ) else [kernel_size] * 2 self.padding = self.kernel_size[0] // 2, self.kernel_size[1] // 2 self.bias = bias self.activation = activation self.batchnorm = batchnorm self.conv_zr = nn.Conv2d(in_channels=self.input_dim + self. hidden_dim, out_channels=2 * self.hidden_dim, kernel_size=self. kernel_size, padding=self.padding, bias=self.bias) self.conv_h1 = nn.Conv2d(in_channels=self.input_dim, out_channels= self.hidden_dim, kernel_size=self.kernel_size, padding=self. padding, bias=self.bias) self.conv_h2 = nn.Conv2d(in_channels=self.hidden_dim, out_channels= self.hidden_dim, kernel_size=self.kernel_size, padding=self. padding, bias=self.bias) self.reset_parameters() def init_hidden(self, input): bs, _ch, h, w = input.shape return one_param(self).new_zeros(bs, self.hidden_dim, h, w) def reset_parameters(self): nn.init.xavier_uniform_(self.conv_zr.weight, gain=nn.init. calculate_gain('tanh')) self.conv_zr.bias.data.zero_() nn.init.xavier_uniform_(self.conv_h1.weight, gain=nn.init. calculate_gain('tanh')) self.conv_h1.bias.data.zero_() nn.init.xavier_uniform_(self.conv_h2.weight, gain=nn.init. calculate_gain('tanh')) self.conv_h2.bias.data.zero_() if self.batchnorm: self.bn1.reset_parameters() self.bn2.reset_parameters() def forward(self, input_0): primals_2 = self.conv_zr.weight primals_3 = self.conv_zr.bias primals_4 = self.conv_h1.weight primals_5 = self.conv_h1.bias primals_6 = self.conv_h2.weight primals_7 = self.conv_h2.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
openclimatefix/MetNet
ConvGRUCell
false
7,388
[ "MIT" ]
1
06eed550e93da6325641958b0d36c15adde1d928
https://github.com/openclimatefix/MetNet/tree/06eed550e93da6325641958b0d36c15adde1d928
SimpleAndModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleAndModule(torch.nn.Module): def __init__(self): super(SimpleAndModule, self).__init__() def forward(self, a, b): c = torch.logical_and(a, b) return torch.logical_and(c, c) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_logical_and_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) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tmp0 != 0 tmp3 = tmp2 != 0 tmp4 = tmp1 & tmp3 tmp5 = tmp4 & tmp4 tl.store(out_ptr0 + x0, tmp5, 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.bool) get_raw_stream(0) triton_poi_fused_logical_and_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 SimpleAndModuleNew(torch.nn.Module): def __init__(self): super(SimpleAndModuleNew, 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]
opti-mix/glow
SimpleAndModule
false
7,389
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleClampMinModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleClampMinModel(torch.nn.Module): def __init__(self, min): super(SimpleClampMinModel, self).__init__() self.min = min def forward(self, input): return torch.clamp_min(input, self.min) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'min': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clamp_min_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 4.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_min_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleClampMinModelNew(torch.nn.Module): def __init__(self, min): super(SimpleClampMinModelNew, self).__init__() self.min = min def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleClampMinModel
false
7,390
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
EnsembleModel
import math import torch import numpy as np import torch.nn.functional as F def truncated_standardized_normal(shape, a=-2.0, b=2.0): a = torch.Tensor([a]) b = torch.Tensor([b]) U = torch.distributions.uniform.Uniform(0, 1) u = U.sample(shape) Fa = 0.5 * (1 + torch.erf(a / math.sqrt(2))) Fb = 0.5 * (1 + torch.erf(b / math.sqrt(2))) return math.sqrt(2) * torch.erfinv(2 * ((Fb - Fa) * u + Fa) - 1) def get_affine_params(ensemble_size, in_features, out_features): w = truncated_standardized_normal(shape=(ensemble_size, in_features, out_features)) / (2.0 * math.sqrt(in_features)) w = torch.nn.Parameter(w) b = torch.nn.Parameter(torch.zeros(ensemble_size, 1, out_features, dtype=torch.float32)) return w, b class EnsembleModel(torch.nn.Module): def __init__(self, ensemble_size, input_num, output_num, hidden_num=200): super().__init__() self.num_nets = ensemble_size self.input_num = input_num self.output_num = output_num self.lin0_w, self.lin0_b = get_affine_params(ensemble_size, input_num, hidden_num) self.lin1_w, self.lin1_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin2_w, self.lin2_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin3_w, self.lin3_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin4_w, self.lin4_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin5_w, self.lin5_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin6_w, self.lin6_b = get_affine_params(ensemble_size, hidden_num, 2 * output_num) self.inputs_mu = torch.nn.Parameter(torch.zeros(input_num), requires_grad=False) self.inputs_sigma = torch.nn.Parameter(torch.zeros(input_num), requires_grad=False) self.max_logvar = torch.nn.Parameter(torch.ones(1, output_num, dtype=torch.float32) / 2.0) self.min_logvar = torch.nn.Parameter(-torch.ones(1, output_num, dtype=torch.float32) * 10.0) def compute_decays(self): loss = 0.0 loss += 1.0 * (self.lin0_w ** 2).sum() loss += 1.0 * (self.lin1_w ** 2).sum() loss += 1.0 * (self.lin2_w ** 2).sum() loss += 1.0 * (self.lin3_w ** 2).sum() loss += 1.0 * (self.lin4_w ** 2).sum() loss += 1.0 * (self.lin5_w ** 2).sum() loss += 1.0 * (self.lin6_w ** 2).sum() return 1e-05 * loss / 2.0 def fit_input_stats(self, data): mu = np.mean(data, axis=0, keepdims=True) sigma = np.std(data, axis=0, keepdims=True) sigma[sigma < 1e-12] = 1.0 self.inputs_mu.data = torch.from_numpy(mu).float() self.inputs_sigma.data = torch.from_numpy(sigma).float() def forward(self, inputs): inputs = (inputs - self.inputs_mu) / self.inputs_sigma inputs = inputs.matmul(self.lin0_w) + self.lin0_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin1_w) + self.lin1_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin2_w) + self.lin2_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin3_w) + self.lin3_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin4_w) + self.lin4_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin5_w) + self.lin5_b inputs = F.silu(inputs) inputs = inputs.matmul(self.lin6_w) + self.lin6_b mean = inputs[:, :, :self.output_num] logvar = inputs[:, :, self.output_num:] logvar = self.max_logvar - F.softplus(self.max_logvar - logvar) logvar = self.min_logvar + F.softplus(logvar - self.min_logvar) return mean, logvar def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'ensemble_size': 4, 'input_num': 4, 'output_num': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language 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 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 reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_div_sub_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 / tmp3 tl.store(out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_add_silu_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3200 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x0 = xindex % 200 x2 = xindex // 800 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + (x0 + 200 * x2), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.sigmoid(tmp2) tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_add_2(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 x0 = xindex % 8 x2 = xindex // 32 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + (x0 + 8 * x2), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_add_softplus_sub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + (4 + x0 + 8 * x1), xmask) tmp3 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 20.0 tmp5 = tmp2 > tmp4 tmp6 = tl_math.exp(tmp2) tmp7 = libdevice.log1p(tmp6) tmp8 = tl.where(tmp5, tmp2, tmp7) tmp9 = tmp0 - tmp8 tmp10 = tmp9 - tmp3 tmp11 = tmp10 > tmp4 tmp12 = tl_math.exp(tmp10) tmp13 = libdevice.log1p(tmp12) tmp14 = tl.where(tmp11, tmp10, tmp13) tmp15 = tmp3 + tmp14 tl.store(out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr1 + x2, tmp15, 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) = args args.clear() assert_size_stride(primals_1, (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, 200), (800, 200, 1)) assert_size_stride(primals_5, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_6, (4, 200, 200), (40000, 200, 1)) assert_size_stride(primals_7, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_8, (4, 200, 200), (40000, 200, 1)) assert_size_stride(primals_9, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_10, (4, 200, 200), (40000, 200, 1)) assert_size_stride(primals_11, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_12, (4, 200, 200), (40000, 200, 1)) assert_size_stride(primals_13, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_14, (4, 200, 200), (40000, 200, 1)) assert_size_stride(primals_15, (4, 1, 200), (200, 200, 1)) assert_size_stride(primals_16, (4, 200, 8), (1600, 8, 1)) assert_size_stride(primals_17, (4, 1, 8), (8, 8, 1)) assert_size_stride(primals_18, (1, 4), (4, 1)) assert_size_stride(primals_19, (1, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_div_sub_0[grid(16)](primals_2, primals_1, primals_3, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del primals_1 del primals_2 del primals_3 buf1 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (0, 4, 1), 0 ), primals_4, out=buf1) del primals_4 buf2 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf1, primals_5, buf2, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf3 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(buf2, primals_6, out=buf3) buf4 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf3, primals_7, buf4, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf5 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(buf4, primals_8, out=buf5) buf6 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf5, primals_9, buf6, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf7 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(buf6, primals_10, out=buf7) buf8 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf7, primals_11, buf8, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf9 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(buf8, primals_12, out=buf9) buf10 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf9, primals_13, buf10, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf11 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) extern_kernels.bmm(buf10, primals_14, out=buf11) buf12 = empty_strided_cuda((4, 4, 200), (800, 200, 1), torch.float32) triton_poi_fused_add_silu_1[grid(3200)](buf11, primals_15, buf12, 3200, XBLOCK=128, num_warps=4, num_stages=1) buf13 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32) extern_kernels.bmm(buf12, primals_16, out=buf13) buf14 = buf13 del buf13 triton_poi_fused_add_2[grid(128)](buf14, primals_17, 128, XBLOCK= 128, num_warps=4, num_stages=1) del primals_17 buf15 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) buf16 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_softplus_sub_3[grid(64)](primals_18, buf14, primals_19, buf15, buf16, 64, XBLOCK=64, num_warps=1, num_stages=1) return (reinterpret_tensor(buf14, (4, 4, 4), (32, 8, 1), 0), buf16, primals_5, primals_7, primals_9, primals_11, primals_13, primals_15, primals_18, primals_19, buf0, buf1, buf3, buf5, buf7, buf9, buf11, buf15, reinterpret_tensor(buf12, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_16, (4, 8, 200), (1600, 1, 8), 0), reinterpret_tensor(buf10, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_14, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf8, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_12, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf6, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_10, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf4, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_8, (4, 200, 200), (40000, 1, 200), 0), reinterpret_tensor(buf2, (4, 200, 4), (800, 1, 200), 0), reinterpret_tensor(primals_6, (4, 200, 200), (40000, 1, 200), 0)) def truncated_standardized_normal(shape, a=-2.0, b=2.0): a = torch.Tensor([a]) b = torch.Tensor([b]) U = torch.distributions.uniform.Uniform(0, 1) u = U.sample(shape) Fa = 0.5 * (1 + torch.erf(a / math.sqrt(2))) Fb = 0.5 * (1 + torch.erf(b / math.sqrt(2))) return math.sqrt(2) * torch.erfinv(2 * ((Fb - Fa) * u + Fa) - 1) def get_affine_params(ensemble_size, in_features, out_features): w = truncated_standardized_normal(shape=(ensemble_size, in_features, out_features)) / (2.0 * math.sqrt(in_features)) w = torch.nn.Parameter(w) b = torch.nn.Parameter(torch.zeros(ensemble_size, 1, out_features, dtype=torch.float32)) return w, b class EnsembleModelNew(torch.nn.Module): def __init__(self, ensemble_size, input_num, output_num, hidden_num=200): super().__init__() self.num_nets = ensemble_size self.input_num = input_num self.output_num = output_num self.lin0_w, self.lin0_b = get_affine_params(ensemble_size, input_num, hidden_num) self.lin1_w, self.lin1_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin2_w, self.lin2_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin3_w, self.lin3_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin4_w, self.lin4_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin5_w, self.lin5_b = get_affine_params(ensemble_size, hidden_num, hidden_num) self.lin6_w, self.lin6_b = get_affine_params(ensemble_size, hidden_num, 2 * output_num) self.inputs_mu = torch.nn.Parameter(torch.zeros(input_num), requires_grad=False) self.inputs_sigma = torch.nn.Parameter(torch.zeros(input_num), requires_grad=False) self.max_logvar = torch.nn.Parameter(torch.ones(1, output_num, dtype=torch.float32) / 2.0) self.min_logvar = torch.nn.Parameter(-torch.ones(1, output_num, dtype=torch.float32) * 10.0) def compute_decays(self): loss = 0.0 loss += 1.0 * (self.lin0_w ** 2).sum() loss += 1.0 * (self.lin1_w ** 2).sum() loss += 1.0 * (self.lin2_w ** 2).sum() loss += 1.0 * (self.lin3_w ** 2).sum() loss += 1.0 * (self.lin4_w ** 2).sum() loss += 1.0 * (self.lin5_w ** 2).sum() loss += 1.0 * (self.lin6_w ** 2).sum() return 1e-05 * loss / 2.0 def fit_input_stats(self, data): mu = np.mean(data, axis=0, keepdims=True) sigma = np.std(data, axis=0, keepdims=True) sigma[sigma < 1e-12] = 1.0 self.inputs_mu.data = torch.from_numpy(mu).float() self.inputs_sigma.data = torch.from_numpy(sigma).float() def forward(self, input_0): primals_4 = self.lin0_w primals_5 = self.lin0_b primals_6 = self.lin1_w primals_7 = self.lin1_b primals_8 = self.lin2_w primals_9 = self.lin2_b primals_10 = self.lin3_w primals_11 = self.lin3_b primals_12 = self.lin4_w primals_13 = self.lin4_b primals_14 = self.lin5_w primals_15 = self.lin5_b primals_16 = self.lin6_w primals_17 = self.lin6_b primals_1 = self.inputs_mu primals_3 = self.inputs_sigma primals_18 = self.max_logvar primals_19 = self.min_logvar primals_2 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17, primals_18, primals_19]) return output[0], output[1]
numahha/wmopo
EnsembleModel
false
7,391
[ "MIT" ]
1
1557dab2e8168c1f2e53ffbc435b4000680f1d28
https://github.com/numahha/wmopo/tree/1557dab2e8168c1f2e53ffbc435b4000680f1d28
SimpleClampModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleClampModel(torch.nn.Module): def __init__(self, min, max): super(SimpleClampModel, self).__init__() self.min = min self.max = max def forward(self, input): return torch.clamp(input, self.min, self.max) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'min': 4, 'max': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clamp_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 4.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = triton_helpers.minimum(tmp2, tmp1) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clamp_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleClampModelNew(torch.nn.Module): def __init__(self, min, max): super(SimpleClampModelNew, self).__init__() self.min = min self.max = max def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleClampModel
false
7,392
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleExpModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleExpModule(torch.nn.Module): def forward(self, input): other = torch.exp(input) return torch.exp(other) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_exp_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl_math.exp(tmp0) tmp2 = tl_math.exp(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_exp_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleExpModuleNew(torch.nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleExpModule
false
7,393
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleGeluModule
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleGeluModule(torch.nn.Module): def forward(self, tensor): return F.gelu(tensor + tensor) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_gelu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp4 = 0.7071067811865476 tmp5 = tmp1 * tmp4 tmp6 = libdevice.erf(tmp5) tmp7 = 1.0 tmp8 = tmp6 + tmp7 tmp9 = tmp3 * tmp8 tl.store(out_ptr0 + x0, tmp9, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_gelu_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleGeluModuleNew(torch.nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleGeluModule
false
7,394
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleCosModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleCosModule(torch.nn.Module): def __init__(self): super(SimpleCosModule, self).__init__() def forward(self, a): return torch.cos(a + a) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_cos_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = tl_math.cos(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_cos_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleCosModuleNew(torch.nn.Module): def __init__(self): super(SimpleCosModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleCosModule
false
7,395
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleMaxModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleMaxModule(torch.nn.Module): def __init__(self): super(SimpleMaxModule, self).__init__() def forward(self, a, b): return torch.max(a + a, b + b) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_maximum_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) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tmp0 + tmp0 tmp3 = tmp2 + tmp2 tmp4 = triton_helpers.maximum(tmp1, tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_maximum_0[grid(256)](arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleMaxModuleNew(torch.nn.Module): def __init__(self): super(SimpleMaxModuleNew, 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]
opti-mix/glow
SimpleMaxModule
false
7,396
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleFloorModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleFloorModule(torch.nn.Module): def forward(self, a, b): c = a + b return torch.floor(c) 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 libdevice import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_floor_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 + tmp1 tmp3 = libdevice.floor(tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_floor_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 SimpleFloorModuleNew(torch.nn.Module): def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleFloorModule
false
7,397
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleConv2dModule
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleConv2dModule(torch.nn.Module): def __init__(self, stride=1, padding=0, dilation=1, groups=1): super(SimpleConv2dModule, self).__init__() self.stride = stride self.padding = padding self.dilation = dilation self.groups = groups def forward(self, inputs, filters, bias=None): conv = F.conv2d(inputs, filters, bias=bias, stride=self.stride, padding=self.padding, dilation=self.dilation, groups=self.groups) return F.relu(conv) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda 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 = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask) tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(in_out_ptr0 + x0, tmp2, xmask) 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, 1, 16, 4), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(16, 16)](arg1_1, buf0, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_convolution_0[grid(16, 16)](arg0_1, buf1, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del arg0_1 buf2 = extern_kernels.convolution(buf0, buf1, 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, 4, 4)) del buf0 del buf1 buf3 = reinterpret_tensor(buf2, (4, 4, 1, 1), (4, 1, 1, 1), 0) del buf2 triton_poi_fused_relu_1[grid(16)](buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf3, class SimpleConv2dModuleNew(torch.nn.Module): def __init__(self, stride=1, padding=0, dilation=1, groups=1): super(SimpleConv2dModuleNew, self).__init__() self.stride = stride self.padding = padding self.dilation = dilation self.groups = groups def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleConv2dModule
false
7,398
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleConvTranspose2dModule
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleConvTranspose2dModule(torch.nn.Module): def __init__(self, stride=1, padding=0, output_padding=0, dilation=1, groups=1): super(SimpleConvTranspose2dModule, self).__init__() self.stride = stride self.padding = padding self.output_padding = output_padding self.groups = groups self.dilation = dilation def forward(self, inputs, filters, bias=None): convTranspose = F.conv_transpose2d(inputs, filters, bias=bias, stride=self.stride, padding=self.padding, output_padding=self. output_padding, groups=self.groups, dilation=self.dilation) return F.relu(convTranspose) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y3 = yindex y0 = yindex % 4 y1 = yindex // 4 tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask) tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_relu_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 49 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 196 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.full([1, 1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tl.store(out_ptr0 + (x2 + 49 * y3), tmp2, xmask & ymask) 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, 1, 16, 4), torch.float32) get_raw_stream(0) triton_poi_fused_convolution_0[grid(16, 16)](arg1_1, buf0, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32) triton_poi_fused_convolution_0[grid(16, 16)](arg0_1, buf1, 16, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1) del arg0_1 buf2 = extern_kernels.convolution(buf0, buf1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 4, 7, 7), (196, 1, 28, 4)) del buf0 del buf1 buf3 = empty_strided_cuda((4, 4, 7, 7), (196, 49, 7, 1), torch.float32) triton_poi_fused_relu_1[grid(16, 49)](buf2, buf3, 16, 49, XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1) del buf2 return buf3, class SimpleConvTranspose2dModuleNew(torch.nn.Module): def __init__(self, stride=1, padding=0, output_padding=0, dilation=1, groups=1): super(SimpleConvTranspose2dModuleNew, self).__init__() self.stride = stride self.padding = padding self.output_padding = output_padding self.groups = groups self.dilation = dilation def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleConvTranspose2dModule
false
7,399
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleCumSumModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleCumSumModule(torch.nn.Module): def __init__(self, dim): super(SimpleCumSumModule, self).__init__() self.dim = dim def forward(self, tensor): return torch.cumsum(tensor, self.dim) def get_inputs(): return [torch.rand([4, 4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def _triton_helper_fn_add0(arg0_0, arg1_0): tmp0 = arg0_0 + arg1_0 return tmp0 @triton.jit def triton_per_fused_cumsum_0(in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl .constexpr): xnumel = 256 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 = tmp0.to(tl.float32) tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK]) tmp3, = tl.associative_scan((tmp2,), 1, _triton_helper_fn_add0) tl.store(out_ptr0 + (r1 + 4 * x0), tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_cumsum_0[grid(256)](arg0_1, buf0, 256, 4, XBLOCK= 32, num_warps=2, num_stages=1) del arg0_1 return buf0, class SimpleCumSumModuleNew(torch.nn.Module): def __init__(self, dim): super(SimpleCumSumModuleNew, self).__init__() self.dim = dim def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleCumSumModule
false
7,400
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleLogModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleLogModule(torch.nn.Module): def __init__(self, *dimensions): super(SimpleLogModule, self).__init__() def forward(self, a): b = torch.log(a) return torch.log(b) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_log_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl_math.log(tmp0) tmp2 = tl_math.log(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_log_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleLogModuleNew(torch.nn.Module): def __init__(self, *dimensions): super(SimpleLogModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleLogModule
false
7,401
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleFmodModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleFmodModule(torch.nn.Module): def __init__(self): super(SimpleFmodModule, self).__init__() def forward(self, a, b): if b.size() == torch.Size([]): c = a.fmod(b.item()) else: c = a.fmod(b) return c.fmod(1.0) 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 libdevice import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_fmod_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = libdevice.fmod(tmp0, tmp1) tmp3 = 1.0 tmp4 = libdevice.fmod(tmp2, tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_fmod_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleFmodModuleNew(torch.nn.Module): def __init__(self): super(SimpleFmodModuleNew, 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]
opti-mix/glow
SimpleFmodModule
false
7,402
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
Foo
import torch import torch.jit import torch.onnx import torch.nn class Foo(torch.nn.Module): def __init__(self): super(Foo, self).__init__() self.conv1 = torch.nn.Conv2d(3, 6, 3) self.relu = torch.nn.ReLU() self.conv2 = torch.nn.Conv2d(6, 16, 3) def forward(self, x): x = self.conv1(x) x = self.relu(x) y = self.conv2(x) return y 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 92256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3844 % 6 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 230400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3600 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (6, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (6,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) assert_size_stride(primals_4, (16, 6, 3, 3), (54, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 6, 62, 62), (23064, 3844, 62, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(92256)](buf1, primals_2, 92256, 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, 16, 60, 60), (57600, 3600, 60, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_1[grid(230400)](buf3, primals_5, 230400, XBLOCK=1024, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1 class FooNew(torch.nn.Module): def __init__(self): super(FooNew, self).__init__() self.conv1 = torch.nn.Conv2d(3, 6, 3) self.relu = torch.nn.ReLU() self.conv2 = torch.nn.Conv2d(6, 16, 3) 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]
opti-mix/glow
Foo
false
7,403
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleNotModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleNotModule(torch.nn.Module): def __init__(self): super(SimpleNotModule, self).__init__() def forward(self, a): b = torch.logical_not(a) return torch.logical_not(b) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_logical_not_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 != 0 tmp2 = tmp1 == 0 tmp3 = tmp2 == 0 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool) get_raw_stream(0) triton_poi_fused_logical_not_0[grid(256)](arg0_1, buf0, 256, XBLOCK =128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleNotModuleNew(torch.nn.Module): def __init__(self): super(SimpleNotModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleNotModule
false
7,404
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleMatmulModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleMatmulModule(torch.nn.Module): def __init__(self): super(SimpleMatmulModule, self).__init__() def forward(self, a, b): return a.matmul(b + b) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg1_1 buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg0_1, (16, 4, 4), (16, 4, 1 ), 0), reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1), 0), out =buf1) del arg0_1 del buf0 return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0), class SimpleMatmulModuleNew(torch.nn.Module): def __init__(self): super(SimpleMatmulModuleNew, 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]
opti-mix/glow
SimpleMatmulModule
false
7,405
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleLinearModule
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleLinearModule(torch.nn.Module): def __init__(self): super(SimpleLinearModule, self).__init__() def forward(self, input, weight, bias=None): return F.linear(input + input, weight, bias) 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 import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4), (4, 1)) assert_size_stride(arg1_1, (4, 4), (4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(buf0, reinterpret_tensor(arg1_1, (4, 4), (1, 4), 0), out=buf1) del arg1_1 del buf0 return buf1, class SimpleLinearModuleNew(torch.nn.Module): def __init__(self): super(SimpleLinearModuleNew, 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]
opti-mix/glow
SimpleLinearModule
false
7,406
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleOrModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleOrModule(torch.nn.Module): def __init__(self): super(SimpleOrModule, self).__init__() def forward(self, a, b): c = torch.logical_or(a, b) return torch.logical_or(c, c) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_logical_or_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) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tmp0 != 0 tmp3 = tmp2 != 0 tmp4 = tmp1 | tmp3 tmp5 = tmp4 | tmp4 tl.store(out_ptr0 + x0, tmp5, 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.bool) get_raw_stream(0) triton_poi_fused_logical_or_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 SimpleOrModuleNew(torch.nn.Module): def __init__(self): super(SimpleOrModuleNew, 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]
opti-mix/glow
SimpleOrModule
false
7,407
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleMulModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleMulModule(torch.nn.Module): def __init__(self): super(SimpleMulModule, self).__init__() def forward(self, left, right): other = left.mul(right.item() if right.size() == torch.Size([]) else right) return other.mul(other) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 * tmp1 tmp3 = tmp2 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_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 SimpleMulModuleNew(torch.nn.Module): def __init__(self): super(SimpleMulModuleNew, 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]
opti-mix/glow
SimpleMulModule
false
7,408
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleMinModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleMinModule(torch.nn.Module): def __init__(self): super(SimpleMinModule, self).__init__() def forward(self, a, b): return torch.min(a + a, b + b) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_minimum_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) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tmp0 + tmp0 tmp3 = tmp2 + tmp2 tmp4 = triton_helpers.minimum(tmp1, tmp3) tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_minimum_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 SimpleMinModuleNew(torch.nn.Module): def __init__(self): super(SimpleMinModuleNew, 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]
opti-mix/glow
SimpleMinModule
false
7,409
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleReciprocalModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleReciprocalModel(torch.nn.Module): def __init__(self, inplace=False): super(SimpleReciprocalModel, self).__init__() self.inplace = inplace def forward(self, tensor): other = tensor + tensor return other.reciprocal_() if self.inplace else torch.reciprocal(other) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_reciprocal_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = tl.full([1], 1, tl.int32) tmp3 = tmp2 / tmp1 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_reciprocal_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleReciprocalModelNew(torch.nn.Module): def __init__(self, inplace=False): super(SimpleReciprocalModelNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleReciprocalModel
false
7,410
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleReluModel
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleReluModel(torch.nn.Module): def __init__(self, inplace=False): super(SimpleReluModel, self).__init__() self.inplace = inplace def forward(self, tensor): other = F.relu(tensor, inplace=self.inplace) return F.relu(other, 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.full([1], 0, tl.int32) tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp3 = triton_helpers.maximum(tmp1, tmp2) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_relu_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleReluModelNew(torch.nn.Module): def __init__(self, inplace=False): super(SimpleReluModelNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleReluModel
false
7,411
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleTypeasModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleTypeasModel(torch.nn.Module): def __init__(self): super(SimpleTypeasModel, self).__init__() def forward(self, tensor, other=None): other = tensor if other is None else other if tensor.dtype != torch.bool: tensor = tensor + tensor typed = tensor.type_as(other) return typed + typed 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = tmp1 + tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleTypeasModelNew(torch.nn.Module): def __init__(self): super(SimpleTypeasModelNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleTypeasModel
false
7,412
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleLogSoftmaxModel
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleLogSoftmaxModel(torch.nn.Module): def __init__(self, dimension): super(SimpleLogSoftmaxModel, self).__init__() self.dimension = dimension def forward(self, tensor): return F.log_softmax(tensor, self.dimension) def get_inputs(): return [torch.rand([4, 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 import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__log_softmax_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 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_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 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): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__log_softmax_0[grid(1024)](arg0_1, buf0, 1024, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) triton_poi_fused__log_softmax_1[grid(1024)](buf0, buf1, 1024, XBLOCK=128, num_warps=4, num_stages=1) del buf0 return buf1, class SimpleLogSoftmaxModelNew(torch.nn.Module): def __init__(self, dimension): super(SimpleLogSoftmaxModelNew, self).__init__() self.dimension = dimension def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleLogSoftmaxModel
false
7,413
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleReshapeModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleReshapeModel(torch.nn.Module): def __init__(self, shape): super(SimpleReshapeModel, self).__init__() self.shape = shape def forward(self, tensor): combined = tensor + tensor return combined.reshape(self.shape) def get_inputs(): return [torch.rand([4])] def get_init_inputs(): return [[], {'shape': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 4 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tl.store(out_ptr0 + x0, tmp1, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) get_raw_stream(0) triton_poi_fused_add_0[grid(4)](arg0_1, buf0, 4, XBLOCK=4, num_warps=1, num_stages=1) del arg0_1 return buf0, class SimpleReshapeModelNew(torch.nn.Module): def __init__(self, shape): super(SimpleReshapeModelNew, self).__init__() self.shape = shape def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleReshapeModel
false
7,414
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleSumModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleSumModule(torch.nn.Module): def __init__(self, dtype=None): super(SimpleSumModule, self).__init__() self.dtype = dtype def forward(self, a): b = a + a return torch.sum(b, dtype=self.dtype) 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_sum_0(in_ptr0, out_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tmp0 + tmp0 tmp2 = tl.broadcast_to(tmp1, [RBLOCK]) tmp4 = triton_helpers.promote_to_tensor(tl.sum(tmp2, 0)) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp4, None) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_add_sum_0[grid(1)](arg0_1, buf0, 1, 256, num_warps =2, num_stages=1) del arg0_1 return buf0, class SimpleSumModuleNew(torch.nn.Module): def __init__(self, dtype=None): super(SimpleSumModuleNew, self).__init__() self.dtype = dtype def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleSumModule
false
7,415
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleXorModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleXorModule(torch.nn.Module): def __init__(self): super(SimpleXorModule, self).__init__() def forward(self, a, b): c = torch.logical_xor(a, b) return torch.logical_xor(c, c) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_logical_xor_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) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp1 = tmp0 != 0 tmp3 = tmp2 != 0 tmp4 = tmp1 ^ tmp3 tmp5 = tmp4 ^ tmp4 tl.store(out_ptr0 + x0, tmp5, 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.bool) get_raw_stream(0) triton_poi_fused_logical_xor_0[grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleXorModuleNew(torch.nn.Module): def __init__(self): super(SimpleXorModuleNew, 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]
opti-mix/glow
SimpleXorModule
false
7,416
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimplePowModule
import torch import torch.jit import torch.onnx import torch.nn class SimplePowModule(torch.nn.Module): def __init__(self, power): super(SimplePowModule, self).__init__() self.power = power def forward(self, tensor): return torch.pow(tensor, self.power) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'power': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_pow_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 * tmp0 tmp2 = tmp1 * tmp1 tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_pow_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimplePowModuleNew(torch.nn.Module): def __init__(self, power): super(SimplePowModuleNew, self).__init__() self.power = power def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimplePowModule
false
7,417
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleSinModule
import torch import torch.jit import torch.onnx import torch.nn class SimpleSinModule(torch.nn.Module): def __init__(self): super(SimpleSinModule, self).__init__() def forward(self, a): return torch.sin(a + a) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_sin_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tmp0 + tmp0 tmp2 = tl_math.sin(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_sin_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleSinModuleNew(torch.nn.Module): def __init__(self): super(SimpleSinModuleNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleSinModule
false
7,418
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleStackModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleStackModel(torch.nn.Module): def __init__(self, dim): super(SimpleStackModel, self).__init__() self.dim = dim def forward(self, a, b): c = b + b return torch.stack((a, c), dim=self.dim) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_stack_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 512 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 2 x1 = xindex // 2 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 1, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp6 = tmp0 >= tmp3 tl.full([1], 2, tl.int64) tmp9 = tl.load(in_ptr1 + x1, tmp6 & xmask, eviction_policy='evict_last', other=0.0) tmp10 = tmp9 + tmp9 tmp11 = tl.full(tmp10.shape, 0.0, tmp10.dtype) tmp12 = tl.where(tmp6, tmp10, tmp11) tmp13 = tl.where(tmp4, tmp5, tmp12) tl.store(out_ptr0 + x2, tmp13, 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, 2), (128, 32, 8, 2, 1), torch.float32) get_raw_stream(0) triton_poi_fused_stack_0[grid(512)](arg1_1, arg0_1, buf0, 512, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class SimpleStackModelNew(torch.nn.Module): def __init__(self, dim): super(SimpleStackModelNew, self).__init__() self.dim = dim def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
opti-mix/glow
SimpleStackModel
false
7,419
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleTanhModel
import torch import torch.jit import torch.onnx import torch.nn class SimpleTanhModel(torch.nn.Module): def __init__(self, inplace=False): super(SimpleTanhModel, self).__init__() self.inplace = inplace def forward(self, tensor): tensor = tensor + tensor return tensor.tanh_() if self.inplace else tensor.tanh() 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.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_add_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 = tmp0 + tmp0 tmp2 = libdevice.tanh(tmp1) tl.store(out_ptr0 + x0, tmp2, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_tanh_0[grid(256)](arg0_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 return buf0, class SimpleTanhModelNew(torch.nn.Module): def __init__(self, inplace=False): super(SimpleTanhModelNew, self).__init__() self.inplace = inplace def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleTanhModel
false
7,420
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
SimpleSoftmaxModel
import torch import torch.nn.functional as F import torch.jit import torch.onnx import torch.nn class SimpleSoftmaxModel(torch.nn.Module): def __init__(self, dimension): super(SimpleSoftmaxModel, self).__init__() self.dimension = dimension def forward(self, tensor): return F.softmax(tensor, self.dimension) def get_inputs(): return [torch.rand([4, 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 import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.jit import torch.onnx import torch.nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused__softmax_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 x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4, 4), (256, 64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__softmax_0[grid(1024)](arg0_1, buf0, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del arg0_1 buf1 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) triton_poi_fused__softmax_1[grid(1024)](buf0, buf1, 1024, XBLOCK= 256, num_warps=4, num_stages=1) del buf0 return buf1, class SimpleSoftmaxModelNew(torch.nn.Module): def __init__(self, dimension): super(SimpleSoftmaxModelNew, self).__init__() self.dimension = dimension def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
opti-mix/glow
SimpleSoftmaxModel
false
7,421
[ "Apache-2.0" ]
1
4ba074df5da9822986a23a6679ab592c22660f6d
https://github.com/opti-mix/glow/tree/4ba074df5da9822986a23a6679ab592c22660f6d
HardKumaBinarizer
import torch import torch.nn as nn import torch.optim def kuma_reparametrization(a, b): u = torch.rand_like(a) k = (1 - (1 - u) ** (1 / (b + 1e-08))) ** (1 / (a + 1e-08)) return k class Rectifier(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.l = l self.r = r self.eps = 1e-07 def forward(self, x, l=None, r=None): l = l if l is not None else self.l r = r if r is not None else self.r t = l + (r - l) * x t = torch.nn.functional.hardtanh(t, 0, 1) return t class HardKumaBinarizer(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.rectifier = Rectifier(l, r) def forward(self, a, b, l=None, r=None): k = kuma_reparametrization(torch.exp(a), torch.exp(b)) t = self.rectifier(k, l, r) return t def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch from torch 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 import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride @triton.jit def triton_poi_fused_add_exp_hardtanh_mul_pow_reciprocal_rsub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp3 = tl.load(in_ptr0 + x0, xmask) tmp12 = tl.load(in_ptr1 + x0, xmask) tmp1 = 1.0 tmp2 = tmp1 - tmp0 tmp4 = tl_math.exp(tmp3) tmp5 = 1e-08 tmp6 = tmp4 + tmp5 tmp7 = tl.full([1], 1, tl.int32) tmp8 = tmp7 / tmp6 tmp9 = tmp8 * tmp1 tmp10 = libdevice.pow(tmp2, tmp9) tmp11 = tmp1 - tmp10 tmp13 = tl_math.exp(tmp12) tmp14 = tmp13 + tmp5 tmp15 = tmp7 / tmp14 tmp16 = tmp15 * tmp1 tmp17 = libdevice.pow(tmp11, tmp16) tmp18 = 1.2000000000000002 tmp19 = tmp17 * tmp18 tmp20 = -0.1 tmp21 = tmp19 + tmp20 tmp22 = 0.0 tmp23 = triton_helpers.maximum(tmp21, tmp22) tmp24 = triton_helpers.minimum(tmp23, tmp1) tl.store(in_out_ptr0 + x0, tmp24, 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 = torch.ops.aten.rand.default([4, 4, 4, 4], dtype=torch. float32, device=device(type='cuda', index=0), pin_memory=False) buf1 = buf0 del buf0 buf2 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_add_exp_hardtanh_mul_pow_reciprocal_rsub_0[grid(256)]( buf2, arg1_1, arg0_1, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf2, def kuma_reparametrization(a, b): u = torch.rand_like(a) k = (1 - (1 - u) ** (1 / (b + 1e-08))) ** (1 / (a + 1e-08)) return k class Rectifier(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.l = l self.r = r self.eps = 1e-07 def forward(self, x, l=None, r=None): l = l if l is not None else self.l r = r if r is not None else self.r t = l + (r - l) * x t = torch.nn.functional.hardtanh(t, 0, 1) return t class HardKumaBinarizerNew(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.rectifier = Rectifier(l, r) def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
ovechkinVT/SkipRNN
HardKumaBinarizer
false
7,422
[ "MIT" ]
1
7c1f37349d464b1b6bf8835520abad22b199f1ad
https://github.com/ovechkinVT/SkipRNN/tree/7c1f37349d464b1b6bf8835520abad22b199f1ad
L1Loss
import torch from torch import nn from torch import torch class L1Loss(nn.Module): def __init__(self): super().__init__() def forward(self, Yp, Yt): num = Yt.size(0) Yp = Yp.view(num, -1) Yt = Yt.view(num, -1) loss = nn.functional.l1_loss(Yp, Yt) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn from torch import torch assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_mean_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tl.broadcast_to(tmp3, [RBLOCK]) tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0)) tmp7 = 256.0 tmp8 = tmp6 / tmp7 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp8, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_abs_mean_sub_0[grid(1)](buf1, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class L1LossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
oskarnatan/RGBDVS-fusion
L1Loss
false
7,423
[ "MIT" ]
1
5e560f54442d387a86e3a469107cf65859693987
https://github.com/oskarnatan/RGBDVS-fusion/tree/5e560f54442d387a86e3a469107cf65859693987
HuberLoss
import torch from torch import nn from torch import torch class HuberLoss(nn.Module): def __init__(self): super().__init__() def forward(self, Yp, Yt): num = Yt.size(0) Yp = Yp.view(num, -1) Yt = Yt.view(num, -1) loss = nn.functional.smooth_l1_loss(Yp, Yt, beta=0.5) return loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math from torch import nn from torch import torch 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_smooth_l1_loss_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 0.5 tmp5 = tmp3 < tmp4 tmp6 = tmp3 * tmp3 tmp7 = tmp6 * tmp4 tmp8 = 2.0 tmp9 = tmp7 * tmp8 tmp10 = 0.25 tmp11 = tmp3 - tmp10 tmp12 = tl.where(tmp5, tmp9, tmp11) tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tmp16 = 256.0 tmp17 = tmp15 / tmp16 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp17, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf1 = buf0 del buf0 get_raw_stream(0) triton_per_fused_smooth_l1_loss_0[grid(1)](buf1, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf1, class HuberLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
oskarnatan/RGBDVS-fusion
HuberLoss
false
7,424
[ "MIT" ]
1
5e560f54442d387a86e3a469107cf65859693987
https://github.com/oskarnatan/RGBDVS-fusion/tree/5e560f54442d387a86e3a469107cf65859693987
BCEDiceLoss
import torch from torch import nn from torch import torch class BCEDiceLoss(nn.Module): def __init__(self): super().__init__() def forward(self, Yp, Yt, smooth=1e-07): num = Yt.size(0) Yp = Yp.view(num, -1) Yt = Yt.view(num, -1) bce = nn.functional.binary_cross_entropy(Yp, Yt) intersection = (Yp * Yt).sum() dice_loss = 1 - (2.0 * intersection + smooth) / (Yp.sum() + Yt.sum( ) + smooth) bce_dice_loss = bce + dice_loss return bce_dice_loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math from torch import nn from torch import torch assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_binary_cross_entropy_div_mul_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 = tmp0 - tmp1 tmp4 = -tmp3 tmp5 = libdevice.log1p(tmp4) tmp6 = -100.0 tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp2 * tmp7 tmp9 = tl_math.log(tmp3) tmp10 = triton_helpers.maximum(tmp9, tmp6) tmp11 = tmp0 * tmp10 tmp12 = tmp8 - tmp11 tmp13 = tl.broadcast_to(tmp12, [RBLOCK]) tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0)) tmp16 = tmp3 * tmp0 tmp17 = tl.broadcast_to(tmp16, [RBLOCK]) tmp19 = triton_helpers.promote_to_tensor(tl.sum(tmp17, 0)) tmp20 = tl.broadcast_to(tmp3, [RBLOCK]) tmp22 = triton_helpers.promote_to_tensor(tl.sum(tmp20, 0)) tmp23 = tl.broadcast_to(tmp0, [RBLOCK]) tmp25 = triton_helpers.promote_to_tensor(tl.sum(tmp23, 0)) tmp26 = 256.0 tmp27 = tmp15 / tmp26 tmp28 = 2.0 tmp29 = tmp19 * tmp28 tmp30 = 1e-07 tmp31 = tmp29 + tmp30 tmp32 = tmp22 + tmp25 tmp33 = tmp32 + tmp30 tmp34 = tmp31 / tmp33 tmp35 = tmp1 - tmp34 tmp36 = tmp27 + tmp35 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp36, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf4 = buf0 del buf0 get_raw_stream(0) triton_per_fused_add_binary_cross_entropy_div_mul_rsub_sum_0[grid(1)]( buf4, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf4, class BCEDiceLossNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
oskarnatan/RGBDVS-fusion
BCEDiceLoss
false
7,425
[ "MIT" ]
1
5e560f54442d387a86e3a469107cf65859693987
https://github.com/oskarnatan/RGBDVS-fusion/tree/5e560f54442d387a86e3a469107cf65859693987
UnpoolAvgEquiangular
import torch from torch.nn import functional as F def equiangular_dimension_unpack(nodes, ratio): """Calculate the two underlying dimensions from the total number of nodes Args: nodes (int): combined dimensions ratio (float): ratio between the two dimensions Returns: int, int: separated dimensions """ dim1 = int((nodes / ratio) ** 0.5) dim2 = int((nodes * ratio) ** 0.5) if dim1 * dim2 != nodes: if nodes % dim1 == 0: dim2 = nodes // dim1 if nodes % dim2 == 0: dim1 = nodes // dim2 assert dim1 * dim2 == nodes, f'Unable to unpack nodes: {nodes}, ratio: {ratio}' return dim1, dim2 def equiangular_calculator(tensor, ratio): N, M, F = tensor.size() dim1, dim2 = equiangular_dimension_unpack(M, ratio) tensor = tensor.view(N, dim1, dim2, F) return tensor def reformat(x): """Reformat the input from a 4D tensor to a 3D tensor Args: x (:obj:`torch.tensor`): a 4D tensor Returns: :obj:`torch.tensor`: a 3D tensor """ x = x.permute(0, 2, 3, 1) N, D1, D2, Feat = x.size() x = x.view(N, D1 * D2, Feat) return x class UnpoolAvgEquiangular(torch.nn.Module): """EquiAngular average unpooling Parameters ---------- ratio : float Parameter for equiangular sampling -> width/height """ def __init__(self, ratio, kernel_size, *args, **kwargs): self.ratio = ratio self.kernel_size = int(kernel_size ** 0.5) super().__init__() def forward(self, inputs, *args): """calls pytorch's interpolate function to create the values while unpooling based on the nearby values Parameters ---------- inputs : torch.tensor of shape batch x pixels x features Input data Returns ------- x : torch.tensor of shape batch x unpooled pixels x features Layer output """ x = equiangular_calculator(inputs, self.ratio) x = x.permute(0, 3, 1, 2) x = F.interpolate(x, scale_factor=(self.kernel_size, self. kernel_size), mode='nearest') x = reformat(x) return x def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'ratio': 4, 'kernel_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__unsafe_index_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex // 32 % 2 x1 = xindex // 4 % 8 x0 = xindex % 4 x3 = xindex // 64 x5 = xindex tmp0 = x2 tmp1 = tmp0.to(tl.float32) tmp2 = 0.5 tmp3 = tmp1 * tmp2 tmp3.to(tl.int32) tmp5 = x1 tmp6 = tmp5.to(tl.float32) tmp7 = tmp6 * tmp2 tmp8 = tmp7.to(tl.int32) tmp9 = tl.load(in_ptr0 + (x0 + 4 * tmp8 + 16 * x3), xmask) tl.store(out_ptr0 + x5, tmp9, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 2, 8), (64, 1, 32, 4), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_clone_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 16, 4), (64, 4, 1), 0), def equiangular_dimension_unpack(nodes, ratio): """Calculate the two underlying dimensions from the total number of nodes Args: nodes (int): combined dimensions ratio (float): ratio between the two dimensions Returns: int, int: separated dimensions """ dim1 = int((nodes / ratio) ** 0.5) dim2 = int((nodes * ratio) ** 0.5) if dim1 * dim2 != nodes: if nodes % dim1 == 0: dim2 = nodes // dim1 if nodes % dim2 == 0: dim1 = nodes // dim2 assert dim1 * dim2 == nodes, f'Unable to unpack nodes: {nodes}, ratio: {ratio}' return dim1, dim2 def equiangular_calculator(tensor, ratio): N, M, F = tensor.size() dim1, dim2 = equiangular_dimension_unpack(M, ratio) tensor = tensor.view(N, dim1, dim2, F) return tensor def reformat(x): """Reformat the input from a 4D tensor to a 3D tensor Args: x (:obj:`torch.tensor`): a 4D tensor Returns: :obj:`torch.tensor`: a 3D tensor """ x = x.permute(0, 2, 3, 1) N, D1, D2, Feat = x.size() x = x.view(N, D1 * D2, Feat) return x class UnpoolAvgEquiangularNew(torch.nn.Module): """EquiAngular average unpooling Parameters ---------- ratio : float Parameter for equiangular sampling -> width/height """ def __init__(self, ratio, kernel_size, *args, **kwargs): self.ratio = ratio self.kernel_size = int(kernel_size ** 0.5) super().__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ownzonefeng/weather_prediction
UnpoolAvgEquiangular
false
7,426
[ "MIT" ]
1
723c02b6b3c0a40751d87572b66c7a4e040dec92
https://github.com/ownzonefeng/weather_prediction/tree/723c02b6b3c0a40751d87572b66c7a4e040dec92
UnpoolAvgHealpix
import torch class UnpoolAvgHealpix(torch.nn.Module): """Healpix Average Unpooling module Parameters ---------- kernel_size : int Pooling kernel width """ def __init__(self, kernel_size, *args, **kwargs): """kernel_size should be 4, 16, 64, etc.""" super().__init__() self.kernel_size = kernel_size def extra_repr(self): return 'kernel_size={kernel_size}'.format(**self.__dict__) def forward(self, x, *args): """x has shape (batch, pixels, channels) and is in nested ordering""" x = x.permute(0, 2, 1) x = torch.nn.functional.interpolate(x, scale_factor=self. kernel_size, mode='nearest') return x.permute(0, 2, 1) def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'kernel_size': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex tmp0 = x0 tmp1 = tmp0.to(tl.float32) tmp2 = 0.25 tmp3 = tmp1 * tmp2 tmp4 = tmp3.to(tl.int32) tmp5 = tl.load(in_ptr0 + (x1 + 4 * tmp4 + 16 * x2), xmask, eviction_policy='evict_last') tl.store(out_ptr0 + x3, tmp5, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32) get_raw_stream(0) triton_poi_fused__unsafe_index_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 return reinterpret_tensor(buf0, (4, 16, 4), (64, 1, 16), 0), class UnpoolAvgHealpixNew(torch.nn.Module): """Healpix Average Unpooling module Parameters ---------- kernel_size : int Pooling kernel width """ def __init__(self, kernel_size, *args, **kwargs): """kernel_size should be 4, 16, 64, etc.""" super().__init__() self.kernel_size = kernel_size def extra_repr(self): return 'kernel_size={kernel_size}'.format(**self.__dict__) def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ownzonefeng/weather_prediction
UnpoolAvgHealpix
false
7,427
[ "MIT" ]
1
723c02b6b3c0a40751d87572b66c7a4e040dec92
https://github.com/ownzonefeng/weather_prediction/tree/723c02b6b3c0a40751d87572b66c7a4e040dec92
IOUScore
import torch from torch import nn from torch import torch class IOUScore(nn.Module): def __init__(self): super().__init__() def forward(self, Yp, Yt): output_ = Yp > 0.5 target_ = Yt > 0.5 intersection = (output_ & target_).sum() union = (output_ | target_).sum() iou = intersection / union return iou def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn from torch import torch 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_bitwise_and_bitwise_or_div_gt_sum_0(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp3 = tl.load(in_ptr1 + r0, None) tmp1 = 0.5 tmp2 = tmp0 > tmp1 tmp4 = tmp3 > tmp1 tmp5 = tmp2 & tmp4 tmp6 = tmp5.to(tl.int64) tmp7 = tl.broadcast_to(tmp6, [RBLOCK]) tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0)) tmp10 = tmp2 | tmp4 tmp11 = tmp10.to(tl.int64) tmp12 = tl.broadcast_to(tmp11, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = tmp9.to(tl.float32) tmp16 = tmp14.to(tl.float32) tmp17 = tmp15 / tmp16 tl.store(out_ptr2 + tl.full([1], 0, tl.int32), tmp17, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf2 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_bitwise_and_bitwise_or_div_gt_sum_0[grid(1)](arg0_1, arg1_1, buf2, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class IOUScoreNew(nn.Module): def __init__(self): super().__init__() def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
oskarnatan/RGBDVS-fusion
IOUScore
false
7,428
[ "MIT" ]
1
5e560f54442d387a86e3a469107cf65859693987
https://github.com/oskarnatan/RGBDVS-fusion/tree/5e560f54442d387a86e3a469107cf65859693987
Critic
import torch import numpy as np from torch import nn import torch.autograd def fanin_(size): fan_in = size[0] weight = 1.0 / np.sqrt(fan_in) return torch.Tensor(size).uniform_(-weight, weight) class Critic(nn.Module): def __init__(self, state_dim, action_dim, h1=64, h2=32, init_w=0.003): super(Critic, self).__init__() self.linear1 = nn.Linear(state_dim, h1) self.linear1.weight.data = fanin_(self.linear1.weight.data.size()) self.linear2 = nn.Linear(h1 + action_dim, h2) self.linear2.weight.data = fanin_(self.linear2.weight.data.size()) self.linear3 = nn.Linear(h2, 1) self.linear3.weight.data.uniform_(-init_w, init_w) self.relu = nn.ReLU() def forward(self, state, action): x = self.linear1(state) x = self.relu(x) x = self.linear2(torch.cat([x, action], 1)) x = self.relu(x) x = self.linear3(x) return x def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'action_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import numpy as np from torch import nn import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 272 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 68 x1 = xindex // 68 x2 = xindex tmp0 = x0 tl.full([1], 0, tl.int64) tmp3 = tl.full([1], 64, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tl.load(in_ptr0 + (64 * x1 + x0), tmp4 & xmask, eviction_policy= 'evict_last', other=0.0) tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last', other=0.0) tmp7 = tmp5 + tmp6 tmp8 = tl.full([1], 0, tl.int32) tmp9 = triton_helpers.maximum(tmp8, tmp7) tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype) tmp11 = tl.where(tmp4, tmp9, tmp10) tmp12 = tmp0 >= tmp3 tl.full([1], 68, tl.int64) tmp15 = tl.load(in_ptr2 + (4 * x1 + (-64 + x0)), tmp12 & xmask, eviction_policy='evict_last', other=0.0) tmp16 = tl.where(tmp4, tmp11, tmp15) tl.store(out_ptr0 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 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) = args args.clear() assert_size_stride(primals_1, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (32, 68), (68, 1)) assert_size_stride(primals_6, (32,), (1,)) assert_size_stride(primals_7, (1, 32), (32, 1)) assert_size_stride(primals_8, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 64), (64, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 68), (68, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(272)](buf0, primals_2, primals_4, buf1, 272, XBLOCK=128, num_warps=4, num_stages=1) del primals_4 buf2 = empty_strided_cuda((4, 32), (32, 1), torch.float32) extern_kernels.mm(buf1, reinterpret_tensor(primals_5, (68, 32), (1, 68), 0), out=buf2) buf3 = buf2 del buf2 triton_poi_fused_relu_1[grid(128)](buf3, primals_6, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_6 buf5 = empty_strided_cuda((4, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_8, buf3, reinterpret_tensor(primals_7, (32, 1), (1, 32), 0), alpha=1, beta=1, out=buf5) del primals_8 buf6 = empty_strided_cuda((4, 64), (64, 1), torch.bool) triton_poi_fused_relu_threshold_backward_2[grid(256)](buf0, primals_2, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del buf0 del primals_2 return buf5, primals_3, buf1, buf3, primals_7, primals_5, buf6 def fanin_(size): fan_in = size[0] weight = 1.0 / np.sqrt(fan_in) return torch.Tensor(size).uniform_(-weight, weight) class CriticNew(nn.Module): def __init__(self, state_dim, action_dim, h1=64, h2=32, init_w=0.003): super(CriticNew, self).__init__() self.linear1 = nn.Linear(state_dim, h1) self.linear1.weight.data = fanin_(self.linear1.weight.data.size()) self.linear2 = nn.Linear(h1 + action_dim, h2) self.linear2.weight.data = fanin_(self.linear2.weight.data.size()) self.linear3 = nn.Linear(h2, 1) self.linear3.weight.data.uniform_(-init_w, init_w) self.relu = nn.ReLU() def forward(self, input_0, input_1): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_5 = self.linear2.weight primals_6 = self.linear2.bias primals_7 = self.linear3.weight primals_8 = self.linear3.bias primals_3 = input_0 primals_4 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8]) return output[0]
ori-goals/lfd-min-human-effort
Critic
false
7,429
[ "MIT" ]
1
f9fd70cdeb661151e5f81ac538ceb865531146b9
https://github.com/ori-goals/lfd-min-human-effort/tree/f9fd70cdeb661151e5f81ac538ceb865531146b9
HintonBinarizer
import torch import torch.nn as nn import torch.optim class hinton_binarize(torch.autograd.Function): """ Binarize function from the paper 'SKIP RNN: LEARNING TO SKIP STATE UPDATES IN RECURRENT NEURAL NETWORKS' https://openreview.net/forum?id=HkwVAXyCW Works as round function but has a unit gradient: Binarize(x) := (x > 0.5).float() d Binarize(x) / dx := 1 """ @staticmethod def forward(ctx, x, threshold=0.5): return (x > threshold).float() @staticmethod def backward(ctx, grad_output): return grad_output, None class HintonBinarizer(nn.Module): """ Binarize function from the paper 'SKIP RNN: LEARNING TO SKIP STATE UPDATES IN RECURRENT NEURAL NETWORKS' https://openreview.net/forum?id=HkwVAXyCW Works as round function but has a unit gradient: Binarize(x) := (x > 0.5).float() d Binarize(x) / dx := 1 """ def __init__(self, threshold=0.5): super().__init__() self.threshold = threshold def forward(self, x, threshold=None): threshold = threshold if threshold is not None else self.threshold return hinton_binarize.apply(x, threshold) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.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__to_copy_gt_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 0.5 tmp2 = tmp0 > tmp1 tmp3 = tmp2.to(tl.float32) tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused__to_copy_gt_0[grid(256)](arg0_1, buf0, 256, XBLOCK =256, num_warps=4, num_stages=1) del arg0_1 return buf0, class hinton_binarize(torch.autograd.Function): """ Binarize function from the paper 'SKIP RNN: LEARNING TO SKIP STATE UPDATES IN RECURRENT NEURAL NETWORKS' https://openreview.net/forum?id=HkwVAXyCW Works as round function but has a unit gradient: Binarize(x) := (x > 0.5).float() d Binarize(x) / dx := 1 """ @staticmethod def forward(ctx, x, threshold=0.5): return (x > threshold).float() @staticmethod def backward(ctx, grad_output): return grad_output, None class HintonBinarizerNew(nn.Module): """ Binarize function from the paper 'SKIP RNN: LEARNING TO SKIP STATE UPDATES IN RECURRENT NEURAL NETWORKS' https://openreview.net/forum?id=HkwVAXyCW Works as round function but has a unit gradient: Binarize(x) := (x > 0.5).float() d Binarize(x) / dx := 1 """ def __init__(self, threshold=0.5): super().__init__() self.threshold = threshold def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ovechkinVT/SkipRNN
HintonBinarizer
false
7,430
[ "MIT" ]
1
7c1f37349d464b1b6bf8835520abad22b199f1ad
https://github.com/ovechkinVT/SkipRNN/tree/7c1f37349d464b1b6bf8835520abad22b199f1ad
torch_return_int8_argmax
import torch class torch_return_int8_argmax(torch.nn.Module): def __init__(self): super(torch_return_int8_argmax, self).__init__() def forward(self, x): x0 = x.squeeze(0) _, x1 = torch.max(x0, 0) return x1 def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_max_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + (64 + x0), xmask) tmp17 = tl.load(in_ptr0 + (128 + x0), xmask) tmp32 = tl.load(in_ptr0 + (192 + x0), xmask) tmp2 = tmp0 > tmp1 tmp3 = tmp0 == tmp1 tmp4 = tmp0 != tmp0 tmp5 = tmp1 != tmp1 tmp6 = tmp4 > tmp5 tmp7 = tmp2 | tmp6 tmp8 = tmp4 & tmp5 tmp9 = tmp3 | tmp8 tmp10 = tl.full([1], 0, tl.int64) tmp11 = tl.full([1], 1, tl.int64) tmp12 = tmp10 < tmp11 tmp13 = tmp9 & tmp12 tmp14 = tmp7 | tmp13 tmp15 = tl.where(tmp14, tmp0, tmp1) tmp16 = tl.where(tmp14, tmp10, tmp11) tmp18 = tmp15 > tmp17 tmp19 = tmp15 == tmp17 tmp20 = tmp15 != tmp15 tmp21 = tmp17 != tmp17 tmp22 = tmp20 > tmp21 tmp23 = tmp18 | tmp22 tmp24 = tmp20 & tmp21 tmp25 = tmp19 | tmp24 tmp26 = tl.full([1], 2, tl.int64) tmp27 = tmp16 < tmp26 tmp28 = tmp25 & tmp27 tmp29 = tmp23 | tmp28 tmp30 = tl.where(tmp29, tmp15, tmp17) tmp31 = tl.where(tmp29, tmp16, tmp26) tmp33 = tmp30 > tmp32 tmp34 = tmp30 == tmp32 tmp35 = tmp30 != tmp30 tmp36 = tmp32 != tmp32 tmp37 = tmp35 > tmp36 tmp38 = tmp33 | tmp37 tmp39 = tmp35 & tmp36 tmp40 = tmp34 | tmp39 tmp41 = tl.full([1], 3, tl.int64) tmp42 = tmp31 < tmp41 tmp43 = tmp40 & tmp42 tmp44 = tmp38 | tmp43 tl.where(tmp44, tmp30, tmp32) tmp46 = tl.where(tmp44, tmp31, tmp41) tl.store(out_ptr0 + x0, tmp46, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64) get_raw_stream(0) triton_poi_fused_max_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf0, class torch_return_int8_argmaxNew(torch.nn.Module): def __init__(self): super(torch_return_int8_argmaxNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ozendelait/pytorch-semseg
torch_return_int8_argmax
false
7,431
[ "MIT" ]
1
200491febd653bd26befcd5b3d52c614aa832b7e
https://github.com/ozendelait/pytorch-semseg/tree/200491febd653bd26befcd5b3d52c614aa832b7e
Actor
import torch import numpy as np from torch import nn import torch.autograd def fanin_(size): fan_in = size[0] weight = 1.0 / np.sqrt(fan_in) return torch.Tensor(size).uniform_(-weight, weight) class Actor(nn.Module): def __init__(self, state_dim, action_dim, h1=64, h2=32, init_w=0.003): super(Actor, self).__init__() self.linear1 = nn.Linear(state_dim, h1) self.linear1.weight.data = fanin_(self.linear1.weight.data.size()) self.linear2 = nn.Linear(h1, h2) self.linear2.weight.data = fanin_(self.linear2.weight.data.size()) self.linear3 = nn.Linear(h2, action_dim) self.linear3.weight.data.uniform_(-init_w, init_w) self.relu = nn.ReLU() self.tanh = nn.Tanh() cuda = torch.cuda.is_available() self.device = torch.device('cuda' if cuda else 'cpu') def forward(self, state): x = self.linear1(state) x = self.relu(x) x = self.linear2(x) x = self.relu(x) x = self.linear3(x) x = self.tanh(x) return x def get_action(self, state): state = torch.FloatTensor(state).unsqueeze(0) action = self.forward(state) return action.detach().cpu().numpy()[0] def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_dim': 4, 'action_dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice import numpy as np from torch import nn import torch.autograd assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda 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_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (64, 4), (4, 1)) assert_size_stride(primals_2, (64,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (32, 64), (64, 1)) assert_size_stride(primals_5, (32,), (1,)) assert_size_stride(primals_6, (4, 32), (32, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 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 buf7 = 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, buf7, 4096, XBLOCK=128, 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 buf6 = 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, buf6, 2048, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 32), (32, 1), 0), reinterpret_tensor(primals_6, (32, 4), (1, 32), 0), out=buf4) buf5 = reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf4 triton_poi_fused_tanh_2[grid(256)](buf5, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 64), (64, 1), 0), reinterpret_tensor( buf3, (64, 32), (32, 1), 0), buf5, primals_6, buf6, primals_4, buf7 def fanin_(size): fan_in = size[0] weight = 1.0 / np.sqrt(fan_in) return torch.Tensor(size).uniform_(-weight, weight) class ActorNew(nn.Module): def __init__(self, state_dim, action_dim, h1=64, h2=32, init_w=0.003): super(ActorNew, self).__init__() self.linear1 = nn.Linear(state_dim, h1) self.linear1.weight.data = fanin_(self.linear1.weight.data.size()) self.linear2 = nn.Linear(h1, h2) self.linear2.weight.data = fanin_(self.linear2.weight.data.size()) self.linear3 = nn.Linear(h2, action_dim) self.linear3.weight.data.uniform_(-init_w, init_w) self.relu = nn.ReLU() self.tanh = nn.Tanh() cuda = torch.cuda.is_available() self.device = torch.device('cuda' if cuda else 'cpu') def get_action(self, state): state = torch.FloatTensor(state).unsqueeze(0) action = self.forward(state) return action.detach().cpu().numpy()[0] def forward(self, input_0): primals_1 = self.linear1.weight primals_2 = self.linear1.bias primals_4 = self.linear2.weight primals_5 = self.linear2.bias primals_6 = self.linear3.weight primals_7 = self.linear3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
ori-goals/lfd-min-human-effort
Actor
false
7,432
[ "MIT" ]
1
f9fd70cdeb661151e5f81ac538ceb865531146b9
https://github.com/ori-goals/lfd-min-human-effort/tree/f9fd70cdeb661151e5f81ac538ceb865531146b9
Rectifier
import torch import torch.nn as nn import torch.optim class Rectifier(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.l = l self.r = r self.eps = 1e-07 def forward(self, x, l=None, r=None): l = l if l is not None else self.l r = r if r is not None else self.r t = l + (r - l) * x t = torch.nn.functional.hardtanh(t, 0, 1) return t def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn import torch.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_hardtanh_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = 1.2000000000000002 tmp2 = tmp0 * tmp1 tmp3 = -0.1 tmp4 = tmp2 + tmp3 tmp5 = 0.0 tmp6 = triton_helpers.maximum(tmp4, tmp5) tmp7 = 1.0 tmp8 = triton_helpers.minimum(tmp6, tmp7) tl.store(out_ptr0 + x0, tmp8, xmask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_hardtanh_mul_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 return buf0, class RectifierNew(nn.Module): def __init__(self, l=-0.1, r=1.1): super().__init__() self.l = l self.r = r self.eps = 1e-07 def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ovechkinVT/SkipRNN
Rectifier
false
7,433
[ "MIT" ]
1
7c1f37349d464b1b6bf8835520abad22b199f1ad
https://github.com/ovechkinVT/SkipRNN/tree/7c1f37349d464b1b6bf8835520abad22b199f1ad
torch_fakeint8_to_float
import torch class torch_fakeint8_to_float(torch.nn.Module): def __init__(self): super(torch_fakeint8_to_float, self).__init__() def forward(self, x): x0 = x.permute(2, 0, 1) x0 += torch.clamp(x0, -1, 0) * -256.0 return x0.unsqueeze(0).contiguous() def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, out_ptr1, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (x1 + 4 * y0), xmask & ymask, eviction_policy= 'evict_last') tmp1 = -1.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 0.0 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp5 = -256.0 tmp6 = tmp4 * tmp5 tmp7 = tmp0 + tmp6 tl.store(out_ptr0 + (y0 + 16 * x1), tmp7, xmask & ymask) tl.store(out_ptr1 + (x1 + 4 * y0), tmp7, xmask & ymask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(16, 4)](arg0_1, buf0, arg0_1, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1) del arg0_1 return buf0, class torch_fakeint8_to_floatNew(torch.nn.Module): def __init__(self): super(torch_fakeint8_to_floatNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ozendelait/pytorch-semseg
torch_fakeint8_to_float
false
7,434
[ "MIT" ]
1
200491febd653bd26befcd5b3d52c614aa832b7e
https://github.com/ozendelait/pytorch-semseg/tree/200491febd653bd26befcd5b3d52c614aa832b7e
torch_uint8_to_float_normed
import torch class torch_uint8_to_float_normed(torch.nn.Module): def __init__(self): super(torch_uint8_to_float_normed, self).__init__() def forward(self, x): return (x.permute(2, 0, 1) / 255.0).unsqueeze(0).contiguous() def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask, eviction_policy= 'evict_last') tmp1 = 0.00392156862745098 tmp2 = tmp0 * tmp1 tl.store(out_ptr0 + (x1 + 16 * y0), tmp2, xmask & ymask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(4, 16)](arg0_1, buf0, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) del arg0_1 return buf0, class torch_uint8_to_float_normedNew(torch.nn.Module): def __init__(self): super(torch_uint8_to_float_normedNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ozendelait/pytorch-semseg
torch_uint8_to_float_normed
false
7,435
[ "MIT" ]
1
200491febd653bd26befcd5b3d52c614aa832b7e
https://github.com/ozendelait/pytorch-semseg/tree/200491febd653bd26befcd5b3d52c614aa832b7e
Attention
import math import torch import torch.nn as nn import torch.optim import torch.nn.functional as F class Attention(nn.Module): """Attention layer - Custom layer to perform weighted average over the second axis (axis=1) Transforming a tensor of size [N, W, H] to [N, 1, H]. N: batch size W: number of words, different sentence length will need to be padded to have the same size for each mini-batch H: hidden state dimension or word embedding dimension Args: dim: The dimension of the word embedding Attributes: w: learnable weight matrix of size [dim, dim] v: learnable weight vector of size [dim] Examples:: >>> m = models_pytorch.Attention(300) >>> input = Variable(torch.randn(4, 128, 300)) >>> output = m(input) >>> print(output.size()) """ def __init__(self, dim): super(Attention, self).__init__() self.dim = dim self.att_weights = None self.w = nn.Parameter(torch.Tensor(dim, dim)) self.v = nn.Parameter(torch.Tensor(dim)) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.w.size(1)) self.w.data.uniform_(-stdv, stdv) self.v.data.uniform_(-stdv, stdv) def forward(self, input): wplus = torch.mm(input.contiguous().view(-1, input.size()[2]), self.w) wplus = wplus.contiguous().view(-1, input.size()[1], self.w.size()[1]) wplus = torch.tanh(wplus) att_w = torch.mm(wplus.contiguous().view(-1, wplus.size()[2]), self .v.contiguous().view(self.v.size()[0], 1)) att_w = att_w.contiguous().view(-1, wplus.size()[1]) att_w = F.softmax(att_w, dim=1) self.att_weights = att_w after_attention = torch.bmm(att_w.unsqueeze(1), input) return after_attention def __repr__(self): return self.__class__.__name__ + ' (' + '1' + ', ' + str(self.dim ) + ')' def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'dim': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math import torch.nn as nn import torch.optim assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_tanh_0(in_out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = libdevice.tanh(tmp0) tl.store(in_out_ptr0 + x0, tmp1, xmask) @triton.jit def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused__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') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = tmp1 + tmp2 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp0 / tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0), primals_2, out=buf0) del primals_2 buf1 = reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_tanh_0[grid(64)](buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((16, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf1, (16, 4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 1), (1, 1), 0), out=buf2) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused__softmax_1[grid(16)](buf2, buf3, 16, XBLOCK=16, num_warps=1, num_stages=1) buf4 = reinterpret_tensor(buf2, (4, 4), (4, 1), 0) del buf2 triton_poi_fused__softmax_2[grid(16)](buf3, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1) buf5 = reinterpret_tensor(buf3, (4, 1, 4), (4, 4, 1), 0) del buf3 extern_kernels.bmm(reinterpret_tensor(buf4, (4, 1, 4), (4, 4, 1), 0 ), primals_1, out=buf5) return buf5, buf4, primals_1, buf1, buf4, reinterpret_tensor(primals_3, (1, 4), (1, 1), 0) class AttentionNew(nn.Module): """Attention layer - Custom layer to perform weighted average over the second axis (axis=1) Transforming a tensor of size [N, W, H] to [N, 1, H]. N: batch size W: number of words, different sentence length will need to be padded to have the same size for each mini-batch H: hidden state dimension or word embedding dimension Args: dim: The dimension of the word embedding Attributes: w: learnable weight matrix of size [dim, dim] v: learnable weight vector of size [dim] Examples:: >>> m = models_pytorch.Attention(300) >>> input = Variable(torch.randn(4, 128, 300)) >>> output = m(input) >>> print(output.size()) """ def __init__(self, dim): super(AttentionNew, self).__init__() self.dim = dim self.att_weights = None self.w = nn.Parameter(torch.Tensor(dim, dim)) self.v = nn.Parameter(torch.Tensor(dim)) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.w.size(1)) self.w.data.uniform_(-stdv, stdv) self.v.data.uniform_(-stdv, stdv) def __repr__(self): return self.__class__.__name__ + ' (' + '1' + ', ' + str(self.dim ) + ')' def forward(self, input_0): primals_2 = self.w primals_3 = self.v primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
ovechkinVT/SkipRNN
Attention
false
7,436
[ "MIT" ]
1
7c1f37349d464b1b6bf8835520abad22b199f1ad
https://github.com/ovechkinVT/SkipRNN/tree/7c1f37349d464b1b6bf8835520abad22b199f1ad
AvgLayer
import torch import torch.nn as nn import torch.utils.data class AvgLayer(nn.Module): def forward(self, input): return input.mean(3, keepdim=True) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn import torch.utils.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_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tl.store(out_ptr0 + x0, tmp8, xmask) 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), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mean_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del arg0_1 return buf0, class AvgLayerNew(nn.Module): def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
pYtoner/EasyOCR
AvgLayer
false
7,437
[ "Apache-2.0" ]
1
cbb2df77ae789dd4c7807541e0357d9a698ba801
https://github.com/pYtoner/EasyOCR/tree/cbb2df77ae789dd4c7807541e0357d9a698ba801
LearnedUtility
import torch import torch.nn as nn class LearnedUtility(nn.Module): def __init__(self, slope=0): super().__init__() self.theta_tt = torch.nn.Parameter(slope * torch.ones(1)) self.theta_tt.requiresGrad = True def forward(self, x): return torch.multiply(self.theta_tt, x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK]) tmp2 = tl.load(in_ptr1 + x0, xmask) tmp3 = tmp1 * tmp2 tl.store(out_ptr0 + x0, tmp3, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (1,), (1,)) assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_0[grid(256)](primals_1, primals_2, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del primals_1 return buf0, primals_2 class LearnedUtilityNew(nn.Module): def __init__(self, slope=0): super().__init__() self.theta_tt = torch.nn.Parameter(slope * torch.ones(1)) self.theta_tt.requiresGrad = True def forward(self, input_0): primals_1 = self.theta_tt primals_2 = input_0 output = call([primals_1, primals_2]) return output[0]
pabloguarda/NeuralTransportationNetworks
LearnedUtility
false
7,438
[ "MIT" ]
1
0461c26128b09488aff237b760068b43d131f8a9
https://github.com/pabloguarda/NeuralTransportationNetworks/tree/0461c26128b09488aff237b760068b43d131f8a9
PreNet
import torch from torch import nn import torch.nn.functional as F 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=True) x = self.fc2(x) x = F.relu(x) x = F.dropout(x, self.p, training=True) 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 from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): 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 buf11 = 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, buf11, 16384, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = torch.ops.aten.native_dropout.default(buf1, 0.5, True) del buf1 buf3 = buf2[0] buf4 = buf2[1] del buf2 buf5 = empty_strided_cuda((64, 128), (128, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf3, (64, 256), (256, 1), 0), reinterpret_tensor(primals_4, (256, 128), (1, 256), 0), out=buf5) buf6 = reinterpret_tensor(buf5, (4, 4, 4, 128), (2048, 512, 128, 1), 0) del buf5 buf10 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1), torch.bool) triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf6, primals_5, buf10, 8192, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf7 = torch.ops.aten.native_dropout.default(buf6, 0.5, True) del buf6 buf8 = buf7[0] buf9 = buf7[1] del buf7 return buf8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf4, reinterpret_tensor(buf3, (64, 256), (256, 1), 0 ), buf9, buf10, primals_4, buf11 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]
padmalcom/AISpeechAssistant
PreNet
false
7,439
[ "Apache-2.0" ]
1
b7501a23a8f513acb5043f3c7bb06df129bdc2cc
https://github.com/padmalcom/AISpeechAssistant/tree/b7501a23a8f513acb5043f3c7bb06df129bdc2cc
torch_uint8_to_float
import torch class torch_uint8_to_float(torch.nn.Module): def __init__(self): super(torch_uint8_to_float, self).__init__() def forward(self, x): return x.permute(2, 0, 1).unsqueeze(0).contiguous() def get_inputs(): return [torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream 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_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 4 xnumel = 16 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x1 = xindex y0 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask, eviction_policy= 'evict_last') tl.store(out_ptr0 + (x1 + 16 * y0), tmp0, xmask & ymask) def call(args): arg0_1, = args args.clear() assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((1, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(4, 16)](arg0_1, buf0, 4, 16, XBLOCK= 16, YBLOCK=4, num_warps=1, num_stages=1) del arg0_1 return buf0, class torch_uint8_to_floatNew(torch.nn.Module): def __init__(self): super(torch_uint8_to_floatNew, self).__init__() def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
ozendelait/pytorch-semseg
torch_uint8_to_float
false
7,440
[ "MIT" ]
1
200491febd653bd26befcd5b3d52c614aa832b7e
https://github.com/ozendelait/pytorch-semseg/tree/200491febd653bd26befcd5b3d52c614aa832b7e
LearnedSigmoid
import torch import torch.nn as nn class LearnedSigmoid(nn.Module): def __init__(self, slope=1): super().__init__() self.q = torch.nn.Parameter(torch.ones(slope)) self.q.requiresGrad = True def forward(self, x): return torch.multiply(torch.sigmoid(x), self.q) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp2 = tl.load(in_ptr1 + 0) tmp3 = tl.broadcast_to(tmp2, [XBLOCK]) tmp1 = tl.sigmoid(tmp0) tmp4 = tmp1 * tmp3 tl.store(out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sigmoid_0[grid(256)](primals_1, primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 return buf0, primals_1 class LearnedSigmoidNew(nn.Module): def __init__(self, slope=1): super().__init__() self.q = torch.nn.Parameter(torch.ones(slope)) self.q.requiresGrad = True def forward(self, input_0): primals_2 = self.q primals_1 = input_0 output = call([primals_1, primals_2]) return output[0]
pabloguarda/NeuralTransportationNetworks
LearnedSigmoid
false
7,441
[ "MIT" ]
1
0461c26128b09488aff237b760068b43d131f8a9
https://github.com/pabloguarda/NeuralTransportationNetworks/tree/0461c26128b09488aff237b760068b43d131f8a9
Lenet
import torch from torch import nn from torch.nn import Sequential from torch.nn import Conv2d import torch.nn import torch.optim class Lenet(nn.Module): def __init__(self): super(Lenet, self).__init__() layer1 = Sequential() layer1.add_module('conv1', Conv2d(3, 32, 3, 1, padding=1)) self.layer1 = layer1 def forward(self, x): rt = self.layer1(x) rt = rt.view(rt.size(0), -1) return rt 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 import nn from torch.nn import Sequential from torch.nn import Conv2d import torch.nn import torch.optim 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): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x3 = xindex x1 = xindex // 4096 % 32 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (32, 3, 3, 3), (27, 9, 3, 1)) assert_size_stride(primals_2, (32,), (1,)) assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 32, 64, 64), (131072, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(524288)](buf1, primals_2, 524288, XBLOCK=512, num_warps=8, num_stages=1) del primals_2 return reinterpret_tensor(buf1, (4, 131072), (131072, 1), 0 ), primals_1, primals_3 class LenetNew(nn.Module): def __init__(self): super(LenetNew, self).__init__() layer1 = Sequential() layer1.add_module('conv1', Conv2d(3, 32, 3, 1, padding=1)) self.layer1 = layer1 def forward(self, input_0): primals_1 = self.layer1.conv1.weight primals_2 = self.layer1.conv1.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
partnernetsoftware/openlab
Lenet
false
7,442
[ "MIT" ]
1
faa4e58486a7bc4140ad3d56545bfb736cb86696
https://github.com/partnernetsoftware/openlab/tree/faa4e58486a7bc4140ad3d56545bfb736cb86696
SilogLoss
import torch import torch.nn as nn class SilogLoss(nn.Module): def __init__(self, ratio=10, ratio2=0.85): super().__init__() self.ratio = ratio self.ratio2 = ratio2 def forward(self, pred, gt): log_diff = torch.log(pred * self.ratio) - torch.log(gt * self.ratio) silog1 = torch.mean(log_diff ** 2) silog2 = self.ratio2 * log_diff.mean() ** 2 silog_loss = torch.sqrt(silog1 - silog2) * self.ratio return silog_loss def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_log_mean_mul_pow_sqrt_sub_0(in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp4 = tl.load(in_ptr1 + r0, None) tmp1 = 10.0 tmp2 = tmp0 * tmp1 tmp3 = tl_math.log(tmp2) tmp5 = tmp4 * tmp1 tmp6 = tl_math.log(tmp5) tmp7 = tmp3 - tmp6 tmp8 = tmp7 * tmp7 tmp9 = tl.broadcast_to(tmp8, [RBLOCK]) tmp11 = triton_helpers.promote_to_tensor(tl.sum(tmp9, 0)) tmp12 = tl.broadcast_to(tmp7, [RBLOCK]) tmp14 = triton_helpers.promote_to_tensor(tl.sum(tmp12, 0)) tmp15 = 256.0 tmp16 = tmp11 / tmp15 tmp17 = tmp14 / tmp15 tmp18 = tmp17 * tmp17 tmp19 = 0.85 tmp20 = tmp18 * tmp19 tmp21 = tmp16 - tmp20 tmp22 = libdevice.sqrt(tmp21) tmp23 = tmp22 * tmp1 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp23, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) buf2 = buf0 del buf0 get_raw_stream(0) triton_per_fused_log_mean_mul_pow_sqrt_sub_0[grid(1)](buf2, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf2, class SilogLossNew(nn.Module): def __init__(self, ratio=10, ratio2=0.85): super().__init__() self.ratio = ratio self.ratio2 = ratio2 def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
pection/packnet-sfm
SilogLoss
false
7,443
[ "MIT" ]
1
d5673567b649e6bfda292c894cacdeb06aa80913
https://github.com/pection/packnet-sfm/tree/d5673567b649e6bfda292c894cacdeb06aa80913
BerHuLoss
import torch import torch.nn as nn class BerHuLoss(nn.Module): """Class implementing the BerHu loss.""" def __init__(self, threshold=0.2): """ Initializes the BerHuLoss class. Parameters ---------- threshold : float Mask parameter """ super().__init__() self.threshold = threshold def forward(self, pred, gt): """ Calculates the BerHu loss. Parameters ---------- pred : torch.Tensor [B,1,H,W] Predicted inverse depth map gt : torch.Tensor [B,1,H,W] Ground-truth inverse depth map Returns ------- loss : torch.Tensor [1] BerHu loss """ huber_c = torch.max(pred - gt) huber_c = self.threshold * huber_c diff = (pred - gt).abs() huber_mask = (diff > huber_c).detach() diff2 = diff[huber_mask] diff2 = diff2 ** 2 return torch.cat((diff, diff2)).mean() def get_inputs(): return [torch.rand([4]), torch.rand([4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_gt_max_mul_sub_0(in_ptr0, in_ptr1, out_ptr1, out_ptr2, 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 = triton_helpers.max2(tmp3, 1)[:, None] tmp6 = tl_math.abs(tmp2) tmp7 = 0.2 tmp8 = tmp5 * tmp7 tmp9 = tmp6 > tmp8 tl.store(out_ptr1 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp6, None) tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp9, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4,), (1,)) assert_size_stride(arg1_1, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4,), (1,), torch.float32) buf2 = empty_strided_cuda((4,), (1,), torch.bool) get_raw_stream(0) triton_per_fused_abs_gt_max_mul_sub_0[grid(1)](arg0_1, arg1_1, buf0, buf2, 1, 4, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf0, buf2 class BerHuLossNew(nn.Module): """Class implementing the BerHu loss.""" def __init__(self, threshold=0.2): """ Initializes the BerHuLoss class. Parameters ---------- threshold : float Mask parameter """ super().__init__() self.threshold = threshold def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
pection/packnet-sfm
BerHuLoss
false
7,444
[ "MIT" ]
1
d5673567b649e6bfda292c894cacdeb06aa80913
https://github.com/pection/packnet-sfm/tree/d5673567b649e6bfda292c894cacdeb06aa80913
_ImpalaCNN
import torch from typing import Tuple from torch import nn class _ImpalaResBlock(nn.Module): def __init__(self, n_channels: 'int'): super().__init__() self.n_channels = n_channels kernel_size = 3 padding = 1 self.relu = nn.ReLU() self.relu_inplace = nn.ReLU() self.conv1 = nn.Conv2d(n_channels, n_channels, kernel_size, padding =padding) self.conv2 = nn.Conv2d(n_channels, n_channels, kernel_size, padding =padding) def forward(self, inputs): x = self.relu(inputs) x = self.conv1(x) x = self.relu_inplace(x) x = self.conv2(x) x += inputs return x class _ImpalaBlock(nn.Module): def __init__(self, n_channels_in: 'int', n_channels_out: 'int'): super().__init__() self.n_channels_in = n_channels_in self.n_channels_out = n_channels_out kernel_size = 3 padding = 1 self.conv1 = nn.Conv2d(n_channels_in, n_channels_out, kernel_size, padding=padding) self.pool = nn.MaxPool2d(kernel_size, stride=2, padding=padding) self.res1 = _ImpalaResBlock(n_channels_out) self.res2 = _ImpalaResBlock(n_channels_out) def forward(self, x): x = self.conv1(x) x = self.pool(x) x = self.res1(x) x = self.res2(x) return x class _ImpalaCNN(nn.Module): def __init__(self, img_shape: 'Tuple[int, int, int]', n_extra_feats: 'int'=0, n_outputs: 'int'=256): super().__init__() self.n_outputs = n_outputs h, w, c = img_shape self.block1 = _ImpalaBlock(c, 16) self.block2 = _ImpalaBlock(16, 32) self.block3 = _ImpalaBlock(32, 32) self.relu = nn.ReLU() self.flatten = nn.Flatten() test_img = torch.empty(c, h, w)[None] n_feats = self.block3(self.block2(self.block1(test_img))).numel() self.linear = nn.Linear(n_feats + n_extra_feats, self.n_outputs) def forward(self, x, extra_obs=None): x = self.block1(x) x = self.block2(x) x = self.block3(x) x = self.relu(x) x = self.flatten(x) if extra_obs is not None: x = torch.cat((x, extra_obs), -1) x = self.linear(x) x = self.relu(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'img_shape': [4, 4, 4]}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from typing import Tuple from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl .constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 16 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_relu_1(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 2 % 2 x0 = xindex % 2 x4 = xindex // 2 x3 = xindex tmp0 = -1 + 2 * x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = -1 + 2 * x0 tmp7 = tmp6 >= tmp1 tmp8 = tmp6 < tmp3 tmp9 = tmp7 & tmp8 tmp10 = tmp5 & tmp9 tmp11 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x4), tmp10 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp12 = 2 * x0 tmp13 = tmp12 >= tmp1 tmp14 = tmp12 < tmp3 tmp15 = tmp13 & tmp14 tmp16 = tmp5 & tmp15 tmp17 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x4), tmp16 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp18 = triton_helpers.maximum(tmp17, tmp11) tmp19 = 1 + 2 * x0 tmp20 = tmp19 >= tmp1 tmp21 = tmp19 < tmp3 tmp22 = tmp20 & tmp21 tmp23 = tmp5 & tmp22 tmp24 = tl.load(in_ptr0 + (-3 + 2 * x0 + 8 * x4), tmp23 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp25 = triton_helpers.maximum(tmp24, tmp18) tmp26 = 2 * x1 tmp27 = tmp26 >= tmp1 tmp28 = tmp26 < tmp3 tmp29 = tmp27 & tmp28 tmp30 = tmp29 & tmp9 tmp31 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x4), tmp30 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp25) tmp33 = tmp29 & tmp15 tmp34 = tl.load(in_ptr0 + (2 * x0 + 8 * x4), tmp33 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp29 & tmp22 tmp37 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x4), tmp36 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = 1 + 2 * x1 tmp40 = tmp39 >= tmp1 tmp41 = tmp39 < tmp3 tmp42 = tmp40 & tmp41 tmp43 = tmp42 & tmp9 tmp44 = tl.load(in_ptr0 + (3 + 2 * x0 + 8 * x4), tmp43 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp45 = triton_helpers.maximum(tmp44, tmp38) tmp46 = tmp42 & tmp15 tmp47 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x4), tmp46 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp48 = triton_helpers.maximum(tmp47, tmp45) tmp49 = tmp42 & tmp22 tmp50 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x4), tmp49 & xmask, eviction_policy='evict_last', other=float('-inf')) tmp51 = triton_helpers.maximum(tmp50, tmp48) tmp52 = tmp17 > tmp11 tmp53 = tl.full([1], 1, tl.int8) tmp54 = tl.full([1], 0, tl.int8) tmp55 = tl.where(tmp52, tmp53, tmp54) tmp56 = tmp24 > tmp18 tmp57 = tl.full([1], 2, tl.int8) tmp58 = tl.where(tmp56, tmp57, tmp55) tmp59 = tmp31 > tmp25 tmp60 = tl.full([1], 3, tl.int8) tmp61 = tl.where(tmp59, tmp60, tmp58) tmp62 = tmp34 > tmp32 tmp63 = tl.full([1], 4, tl.int8) tmp64 = tl.where(tmp62, tmp63, tmp61) tmp65 = tmp37 > tmp35 tmp66 = tl.full([1], 5, tl.int8) tmp67 = tl.where(tmp65, tmp66, tmp64) tmp68 = tmp44 > tmp38 tmp69 = tl.full([1], 6, tl.int8) tmp70 = tl.where(tmp68, tmp69, tmp67) tmp71 = tmp47 > tmp45 tmp72 = tl.full([1], 7, tl.int8) tmp73 = tl.where(tmp71, tmp72, tmp70) tmp74 = tmp50 > tmp48 tmp75 = tl.full([1], 8, tl.int8) tmp76 = tl.where(tmp74, tmp75, tmp73) tmp77 = tl.full([1], 0, tl.int32) tmp78 = triton_helpers.maximum(tmp77, tmp51) tl.store(out_ptr0 + x3, tmp51, xmask) tl.store(out_ptr1 + x3, tmp76, xmask) tl.store(out_ptr2 + x3, tmp78, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 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_add_convolution_relu_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 16 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x3, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tl.store(out_ptr0 + x3, tmp6, xmask) @triton.jit def triton_poi_fused_add_convolution_4(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 4 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr1 + x3, xmask) tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr3 + x3, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp2 + tmp7 tl.store(in_out_ptr0 + x3, tmp8, xmask) @triton.jit def triton_poi_fused_convolution_5(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 x3 = xindex x1 = xindex // 4 % 32 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_max_pool2d_with_indices_relu_6(in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.full([1], -1, tl.int64) tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = tmp2 & tmp4 tmp6 = tmp5 & tmp5 tmp7 = tl.load(in_ptr0 + (-3 + 4 * x0), tmp6 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp8 = tmp1 >= tmp1 tmp9 = tmp1 < tmp3 tmp10 = tmp8 & tmp9 tmp11 = tmp5 & tmp10 tmp12 = tl.load(in_ptr0 + (-2 + 4 * x0), tmp11 & xmask, eviction_policy ='evict_last', other=float('-inf')) tmp13 = triton_helpers.maximum(tmp12, tmp7) tmp14 = tl.full([1], 1, tl.int64) tmp15 = tmp14 >= tmp1 tmp16 = tmp14 < tmp3 tmp17 = tmp15 & tmp16 tmp18 = tmp5 & tmp17 tmp19 = tl.load(in_ptr0 + (-1 + 4 * x0), tmp18 & xmask, eviction_policy ='evict_last', other=float('-inf')) tmp20 = triton_helpers.maximum(tmp19, tmp13) tmp21 = tmp10 & tmp5 tmp22 = tl.load(in_ptr0 + (-1 + 4 * x0), tmp21 & xmask, eviction_policy ='evict_last', other=float('-inf')) tmp23 = triton_helpers.maximum(tmp22, tmp20) tmp24 = tmp10 & tmp10 tmp25 = tl.load(in_ptr0 + 4 * x0, tmp24 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp26 = triton_helpers.maximum(tmp25, tmp23) tmp27 = tmp10 & tmp17 tmp28 = tl.load(in_ptr0 + (1 + 4 * x0), tmp27 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp29 = triton_helpers.maximum(tmp28, tmp26) tmp30 = tmp17 & tmp5 tmp31 = tl.load(in_ptr0 + (1 + 4 * x0), tmp30 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp32 = triton_helpers.maximum(tmp31, tmp29) tmp33 = tmp17 & tmp10 tmp34 = tl.load(in_ptr0 + (2 + 4 * x0), tmp33 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp35 = triton_helpers.maximum(tmp34, tmp32) tmp36 = tmp17 & tmp17 tmp37 = tl.load(in_ptr0 + (3 + 4 * x0), tmp36 & xmask, eviction_policy= 'evict_last', other=float('-inf')) tmp38 = triton_helpers.maximum(tmp37, tmp35) tmp39 = tmp12 > tmp7 tmp40 = tl.full([1], 1, tl.int8) tmp41 = tl.full([1], 0, tl.int8) tmp42 = tl.where(tmp39, tmp40, tmp41) tmp43 = tmp19 > tmp13 tmp44 = tl.full([1], 2, tl.int8) tmp45 = tl.where(tmp43, tmp44, tmp42) tmp46 = tmp22 > tmp20 tmp47 = tl.full([1], 3, tl.int8) tmp48 = tl.where(tmp46, tmp47, tmp45) tmp49 = tmp25 > tmp23 tmp50 = tl.full([1], 4, tl.int8) tmp51 = tl.where(tmp49, tmp50, tmp48) tmp52 = tmp28 > tmp26 tmp53 = tl.full([1], 5, tl.int8) tmp54 = tl.where(tmp52, tmp53, tmp51) tmp55 = tmp31 > tmp29 tmp56 = tl.full([1], 6, tl.int8) tmp57 = tl.where(tmp55, tmp56, tmp54) tmp58 = tmp34 > tmp32 tmp59 = tl.full([1], 7, tl.int8) tmp60 = tl.where(tmp58, tmp59, tmp57) tmp61 = tmp37 > tmp35 tmp62 = tl.full([1], 8, tl.int8) tmp63 = tl.where(tmp61, tmp62, tmp60) tmp64 = tl.full([1], 0, tl.int32) tmp65 = triton_helpers.maximum(tmp64, tmp38) tl.store(out_ptr0 + x0, tmp38, xmask) tl.store(out_ptr1 + x0, tmp63, xmask) tl.store(out_ptr2 + x0, tmp65, xmask) @triton.jit def triton_poi_fused_convolution_relu_7(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 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 = 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_convolution_relu_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = tl.full([1], 0, tl.int32) tmp6 = triton_helpers.maximum(tmp5, tmp4) tl.store(out_ptr0 + x2, tmp6, xmask) @triton.jit def triton_poi_fused_add_convolution_9(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr0 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp2 + tmp7 tl.store(in_out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_convolution_max_pool2d_with_indices_relu_10(in_out_ptr0, in_ptr0, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xnumel = 128 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 32 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], -1, tl.int64) tmp4 = tl.full([1], 0, tl.int64) tmp5 = tmp3 >= tmp4 tmp6 = tl.full([1], 1, tl.int64) tmp7 = tmp3 < tmp6 tmp8 = tmp5 & tmp7 tmp8 & tmp8 tmp10 = tmp4 >= tmp4 tmp11 = tmp4 < tmp6 tmp12 = tmp10 & tmp11 tmp8 & tmp12 tmp14 = triton_helpers.maximum(tmp2, tmp2) tmp15 = tmp6 >= tmp4 tmp16 = tmp6 < tmp6 tmp17 = tmp15 & tmp16 tmp8 & tmp17 tmp19 = triton_helpers.maximum(tmp2, tmp14) tmp12 & tmp8 tmp21 = triton_helpers.maximum(tmp2, tmp19) tmp12 & tmp12 tmp23 = triton_helpers.maximum(tmp2, tmp21) tmp12 & tmp17 tmp25 = triton_helpers.maximum(tmp2, tmp23) tmp17 & tmp8 tmp27 = triton_helpers.maximum(tmp2, tmp25) tmp17 & tmp12 tmp29 = triton_helpers.maximum(tmp2, tmp27) tmp17 & tmp17 tmp31 = triton_helpers.maximum(tmp2, tmp29) tmp32 = tmp2 > tmp2 tmp33 = tl.full([1], 1, tl.int8) tmp34 = tl.full([1], 0, tl.int8) tmp35 = tl.where(tmp32, tmp33, tmp34) tmp36 = tmp2 > tmp14 tmp37 = tl.full([1], 2, tl.int8) tmp38 = tl.where(tmp36, tmp37, tmp35) tmp39 = tmp2 > tmp19 tmp40 = tl.full([1], 3, tl.int8) tmp41 = tl.where(tmp39, tmp40, tmp38) tmp42 = tmp2 > tmp21 tmp43 = tl.full([1], 4, tl.int8) tmp44 = tl.where(tmp42, tmp43, tmp41) tmp45 = tmp2 > tmp23 tmp46 = tl.full([1], 5, tl.int8) tmp47 = tl.where(tmp45, tmp46, tmp44) tmp48 = tmp2 > tmp25 tmp49 = tl.full([1], 6, tl.int8) tmp50 = tl.where(tmp48, tmp49, tmp47) tmp51 = tmp2 > tmp27 tmp52 = tl.full([1], 7, tl.int8) tmp53 = tl.where(tmp51, tmp52, tmp50) tmp54 = tmp2 > tmp29 tmp55 = tl.full([1], 8, tl.int8) tmp56 = tl.where(tmp54, tmp55, tmp53) tmp57 = tl.full([1], 0, tl.int32) tmp58 = triton_helpers.maximum(tmp57, tmp31) tl.store(in_out_ptr0 + x2, tmp2, xmask) tl.store(out_ptr0 + x2, tmp31, xmask) tl.store(out_ptr1 + x2, tmp56, xmask) tl.store(out_ptr2 + x2, tmp58, xmask) @triton.jit def triton_poi_fused_add_convolution_relu_threshold_backward_11(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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 % 32 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x2, xmask) tmp4 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_out_ptr0 + x2, xmask) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp7 = tmp5 + tmp6 tmp8 = tmp2 + tmp7 tmp9 = tl.full([1], 0, tl.int32) tmp10 = triton_helpers.maximum(tmp9, tmp8) tmp11 = 0.0 tmp12 = tmp10 <= tmp11 tl.store(in_out_ptr0 + x2, tmp10, xmask) tl.store(out_ptr0 + x2, tmp12, xmask) @triton.jit def triton_poi_fused_relu_threshold_backward_12(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 % 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) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr0 + x2, tmp6, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, 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 ) = args args.clear() assert_size_stride(primals_1, (16, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (16,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_7, (16,), (1,)) assert_size_stride(primals_8, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_9, (16,), (1,)) assert_size_stride(primals_10, (16, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_11, (16,), (1,)) assert_size_stride(primals_12, (32, 16, 3, 3), (144, 9, 3, 1)) assert_size_stride(primals_13, (32,), (1,)) assert_size_stride(primals_14, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_15, (32,), (1,)) assert_size_stride(primals_16, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_17, (32,), (1,)) assert_size_stride(primals_18, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_19, (32,), (1,)) assert_size_stride(primals_20, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_21, (32,), (1,)) assert_size_stride(primals_22, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_23, (32,), (1,)) assert_size_stride(primals_24, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_25, (32,), (1,)) assert_size_stride(primals_26, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_27, (32,), (1,)) assert_size_stride(primals_28, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_29, (32,), (1,)) assert_size_stride(primals_30, (32, 32, 3, 3), (288, 9, 3, 1)) assert_size_stride(primals_31, (32,), (1,)) assert_size_stride(primals_32, (256, 32), (32, 1)) assert_size_stride(primals_33, (256,), (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, 16, 4, 4), (256, 16, 4, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_0[grid(1024)](buf1, primals_2, 1024, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 16, 2, 2), (64, 4, 2, 1), torch.float32) buf3 = empty_strided_cuda((4, 16, 2, 2), (64, 4, 2, 1), torch.int8) buf4 = empty_strided_cuda((4, 16, 2, 2), (64, 4, 2, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_relu_1[grid(256)](buf1, buf2, buf3, buf4, 256, XBLOCK=128, num_warps=4, num_stages=1) buf5 = extern_kernels.convolution(buf4, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 16, 2, 2), (64, 4, 2, 1)) buf6 = buf5 del buf5 triton_poi_fused_convolution_relu_2[grid(256)](buf6, primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf7 = extern_kernels.convolution(buf6, primals_6, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf7, (4, 16, 2, 2), (64, 4, 2, 1)) buf8 = empty_strided_cuda((4, 16, 2, 2), (64, 4, 2, 1), torch.float32) triton_poi_fused_add_convolution_relu_3[grid(256)](buf7, primals_7, buf2, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1) buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf9, (4, 16, 2, 2), (64, 4, 2, 1)) buf10 = buf9 del buf9 triton_poi_fused_convolution_relu_2[grid(256)](buf10, primals_9, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_9 buf11 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf11, (4, 16, 2, 2), (64, 4, 2, 1)) buf12 = buf11 del buf11 triton_poi_fused_add_convolution_4[grid(256)](buf12, primals_11, buf7, primals_7, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf2 del buf7 del primals_11 del primals_7 buf13 = extern_kernels.convolution(buf12, primals_12, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf13, (4, 32, 2, 2), (128, 4, 2, 1)) buf14 = buf13 del buf13 triton_poi_fused_convolution_5[grid(512)](buf14, primals_13, 512, XBLOCK=256, num_warps=4, num_stages=1) del primals_13 buf15 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch. float32) buf16 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.int8) buf17 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.float32) triton_poi_fused_max_pool2d_with_indices_relu_6[grid(128)](buf14, buf15, buf16, buf17, 128, XBLOCK=128, num_warps=4, num_stages=1) buf18 = extern_kernels.convolution(buf17, primals_14, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf18, (4, 32, 1, 1), (32, 1, 1, 1)) buf19 = buf18 del buf18 triton_poi_fused_convolution_relu_7[grid(128)](buf19, primals_15, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_15 buf20 = extern_kernels.convolution(buf19, primals_16, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf20, (4, 32, 1, 1), (32, 1, 1, 1)) buf21 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.float32) triton_poi_fused_add_convolution_relu_8[grid(128)](buf20, primals_17, buf15, buf21, 128, XBLOCK=128, num_warps=4, num_stages=1) buf22 = extern_kernels.convolution(buf21, primals_18, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf22, (4, 32, 1, 1), (32, 1, 1, 1)) buf23 = buf22 del buf22 triton_poi_fused_convolution_relu_7[grid(128)](buf23, primals_19, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_19 buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf24, (4, 32, 1, 1), (32, 1, 1, 1)) buf25 = reinterpret_tensor(buf15, (4, 32, 1, 1), (32, 1, 1, 1), 0) del buf15 triton_poi_fused_add_convolution_9[grid(128)](buf25, buf24, primals_21, buf20, primals_17, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_17 del primals_21 buf26 = extern_kernels.convolution(buf25, primals_22, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf26, (4, 32, 1, 1), (32, 1, 1, 1)) buf27 = buf26 del buf26 buf28 = reinterpret_tensor(buf24, (4, 32, 1, 1), (32, 1, 128, 128), 0) del buf24 buf29 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.int8) buf30 = buf20 del buf20 triton_poi_fused_convolution_max_pool2d_with_indices_relu_10[grid(128) ](buf27, primals_23, buf28, buf29, buf30, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_23 buf31 = extern_kernels.convolution(buf30, primals_24, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf31, (4, 32, 1, 1), (32, 1, 1, 1)) buf32 = buf31 del buf31 triton_poi_fused_convolution_relu_7[grid(128)](buf32, primals_25, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_25 buf33 = extern_kernels.convolution(buf32, primals_26, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf33, (4, 32, 1, 1), (32, 1, 1, 1)) buf34 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.float32) triton_poi_fused_add_convolution_relu_8[grid(128)](buf33, primals_27, buf28, buf34, 128, XBLOCK=128, num_warps=4, num_stages=1) buf35 = extern_kernels.convolution(buf34, primals_28, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf35, (4, 32, 1, 1), (32, 1, 1, 1)) buf36 = buf35 del buf35 triton_poi_fused_convolution_relu_7[grid(128)](buf36, primals_29, 128, XBLOCK=128, num_warps=4, num_stages=1) del primals_29 buf37 = extern_kernels.convolution(buf36, primals_30, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf37, (4, 32, 1, 1), (32, 1, 1, 1)) buf38 = reinterpret_tensor(buf28, (4, 32, 1, 1), (32, 1, 1, 1), 0) del buf28 buf42 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 1, 1), torch.bool) triton_poi_fused_add_convolution_relu_threshold_backward_11[grid(128)]( buf38, buf37, primals_31, buf33, primals_27, buf42, 128, XBLOCK =128, num_warps=4, num_stages=1) del buf33 del buf37 del primals_27 del primals_31 buf39 = empty_strided_cuda((4, 256), (256, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf38, (4, 32), (32, 1), 0), reinterpret_tensor(primals_32, (32, 256), (1, 32), 0), out=buf39) buf40 = buf39 del buf39 buf41 = empty_strided_cuda((4, 256), (256, 1), torch.bool) triton_poi_fused_relu_threshold_backward_12[grid(1024)](buf40, primals_33, buf41, 1024, XBLOCK=256, num_warps=4, num_stages=1) del primals_33 return (buf40, 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, buf1, buf3, buf4, buf6, buf8, buf10, buf12, buf14, buf16, buf17, buf19, buf21, buf23, buf25, buf27, buf29, buf30, buf32, buf34, buf36, reinterpret_tensor(buf38, (4, 32), (32, 1), 0), buf41, primals_32, buf42) class _ImpalaResBlock(nn.Module): def __init__(self, n_channels: 'int'): super().__init__() self.n_channels = n_channels kernel_size = 3 padding = 1 self.relu = nn.ReLU() self.relu_inplace = nn.ReLU() self.conv1 = nn.Conv2d(n_channels, n_channels, kernel_size, padding =padding) self.conv2 = nn.Conv2d(n_channels, n_channels, kernel_size, padding =padding) def forward(self, inputs): x = self.relu(inputs) x = self.conv1(x) x = self.relu_inplace(x) x = self.conv2(x) x += inputs return x class _ImpalaBlock(nn.Module): def __init__(self, n_channels_in: 'int', n_channels_out: 'int'): super().__init__() self.n_channels_in = n_channels_in self.n_channels_out = n_channels_out kernel_size = 3 padding = 1 self.conv1 = nn.Conv2d(n_channels_in, n_channels_out, kernel_size, padding=padding) self.pool = nn.MaxPool2d(kernel_size, stride=2, padding=padding) self.res1 = _ImpalaResBlock(n_channels_out) self.res2 = _ImpalaResBlock(n_channels_out) def forward(self, x): x = self.conv1(x) x = self.pool(x) x = self.res1(x) x = self.res2(x) return x class _ImpalaCNNNew(nn.Module): def __init__(self, img_shape: 'Tuple[int, int, int]', n_extra_feats: 'int'=0, n_outputs: 'int'=256): super().__init__() self.n_outputs = n_outputs h, w, c = img_shape self.block1 = _ImpalaBlock(c, 16) self.block2 = _ImpalaBlock(16, 32) self.block3 = _ImpalaBlock(32, 32) self.relu = nn.ReLU() self.flatten = nn.Flatten() test_img = torch.empty(c, h, w)[None] n_feats = self.block3(self.block2(self.block1(test_img))).numel() self.linear = nn.Linear(n_feats + n_extra_feats, self.n_outputs) def forward(self, input_0): primals_1 = self.block1.conv1.weight primals_2 = self.block1.conv1.bias primals_4 = self.block1.res1.conv1.weight primals_5 = self.block1.res1.conv1.bias primals_6 = self.block1.res1.conv2.weight primals_7 = self.block1.res1.conv2.bias primals_8 = self.block1.res2.conv1.weight primals_9 = self.block1.res2.conv1.bias primals_10 = self.block1.res2.conv2.weight primals_11 = self.block1.res2.conv2.bias primals_12 = self.block2.conv1.weight primals_13 = self.block2.conv1.bias primals_14 = self.block2.res1.conv1.weight primals_15 = self.block2.res1.conv1.bias primals_16 = self.block2.res1.conv2.weight primals_17 = self.block2.res1.conv2.bias primals_18 = self.block2.res2.conv1.weight primals_19 = self.block2.res2.conv1.bias primals_20 = self.block2.res2.conv2.weight primals_21 = self.block2.res2.conv2.bias primals_22 = self.block3.conv1.weight primals_23 = self.block3.conv1.bias primals_24 = self.block3.res1.conv1.weight primals_25 = self.block3.res1.conv1.bias primals_26 = self.block3.res1.conv2.weight primals_27 = self.block3.res1.conv2.bias primals_28 = self.block3.res2.conv1.weight primals_29 = self.block3.res2.conv1.bias primals_30 = self.block3.res2.conv2.weight primals_31 = self.block3.res2.conv2.bias primals_32 = self.linear.weight primals_33 = self.linear.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, 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]) return output[0]
nrfulton/vsrl-framework
_ImpalaCNN
false
7,445
[ "MIT" ]
1
c778824b3285e3e994a4c5846c7b1c2ac03c669b
https://github.com/nrfulton/vsrl-framework/tree/c778824b3285e3e994a4c5846c7b1c2ac03c669b
Decoder
import torch import torch.nn as nn class Decoder(nn.Module): def __init__(self, input_size): super(Decoder, self).__init__() self.fully = nn.Linear(input_size, 40) self.conv1 = nn.ConvTranspose2d(40, 20, kernel_size=5, stride=2) self.conv2 = nn.ConvTranspose2d(20, 10, kernel_size=5, stride=2) self.conv3 = nn.ConvTranspose2d(10, 1, kernel_size=5, stride=2) def forward(self, x): x = self.fully(x) x = x.view(x.data.shape[0], 40, 1, 1) x = torch.relu(self.conv1(x)) x = torch.relu(self.conv2(x)) x = torch.sigmoid(self.conv3(x)) return x def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers 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 = 2000 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 25 % 20 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6760 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 169 % 10 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_convolution_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 3364 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9) = args args.clear() assert_size_stride(primals_1, (40, 4), (4, 1)) assert_size_stride(primals_2, (40,), (1,)) assert_size_stride(primals_3, (4, 4), (4, 1)) assert_size_stride(primals_4, (40, 20, 5, 5), (500, 25, 5, 1)) assert_size_stride(primals_5, (20,), (1,)) assert_size_stride(primals_6, (20, 10, 5, 5), (250, 25, 5, 1)) assert_size_stride(primals_7, (10,), (1,)) assert_size_stride(primals_8, (10, 1, 5, 5), (25, 25, 5, 1)) assert_size_stride(primals_9, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 40), (40, 1), torch.float32) extern_kernels.addmm(primals_2, primals_3, reinterpret_tensor( primals_1, (4, 40), (1, 4), 0), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (4, 40, 1, 1), (40, 1, 1, 1), 0), primals_4, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 20, 5, 5), (500, 25, 5, 1)) buf2 = buf1 del buf1 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(2000)](buf2, primals_5, 2000, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf3 = extern_kernels.convolution(buf2, primals_6, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf3, (4, 10, 13, 13), (1690, 169, 13, 1)) buf4 = buf3 del buf3 triton_poi_fused_convolution_relu_1[grid(6760)](buf4, primals_7, 6760, XBLOCK=256, num_warps=4, num_stages=1) del primals_7 buf5 = extern_kernels.convolution(buf4, primals_8, stride=(2, 2), padding=(0, 0), dilation=(1, 1), transposed=True, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf5, (4, 1, 29, 29), (841, 841, 29, 1)) buf6 = buf5 del buf5 triton_poi_fused_convolution_sigmoid_2[grid(3364)](buf6, primals_9, 3364, XBLOCK=256, num_warps=4, num_stages=1) del primals_9 return (buf6, primals_3, primals_4, primals_6, primals_8, reinterpret_tensor(buf0, (4, 40, 1, 1), (40, 1, 1, 1), 0), buf2, buf4, buf6) class DecoderNew(nn.Module): def __init__(self, input_size): super(DecoderNew, self).__init__() self.fully = nn.Linear(input_size, 40) self.conv1 = nn.ConvTranspose2d(40, 20, kernel_size=5, stride=2) self.conv2 = nn.ConvTranspose2d(20, 10, kernel_size=5, stride=2) self.conv3 = nn.ConvTranspose2d(10, 1, kernel_size=5, stride=2) def forward(self, input_0): primals_1 = self.fully.weight primals_2 = self.fully.bias primals_4 = self.conv1.weight primals_5 = self.conv1.bias primals_6 = self.conv2.weight primals_7 = self.conv2.bias primals_8 = self.conv3.weight primals_9 = self.conv3.bias primals_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]
pacslab/serverless-ml-serving
Decoder
false
7,446
[ "MIT" ]
1
03a4cd5f1739aa4710ef886edd9332b3d755efbd
https://github.com/pacslab/serverless-ml-serving/tree/03a4cd5f1739aa4710ef886edd9332b3d755efbd
InvDepth
import torch import torch.nn as nn class InvDepth(nn.Module): """Inverse depth layer""" def __init__(self, in_channels, out_channels=1, min_depth=0.5): """ Initializes an InvDepth object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels min_depth : float Minimum depth value to calculate """ super().__init__() self.min_depth = min_depth self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1) self.pad = nn.ConstantPad2d([1] * 4, value=0) self.activ = nn.Sigmoid() def forward(self, x): """Runs the InvDepth layer.""" x = self.conv1(self.pad(x)) return self.activ(x) / self.min_depth def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 576 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 6 % 6 x0 = xindex % 6 x2 = xindex // 36 x4 = xindex tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp11, xmask) @triton.jit def triton_poi_fused_convolution_div_sigmoid_1(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tmp5 = 2.0 tmp6 = tmp4 * tmp5 tl.store(in_out_ptr0 + x0, tmp3, xmask) tl.store(out_ptr0 + x0, tmp6, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (1, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_3, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(576)](primals_1, buf0, 576, XBLOCK=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, 1, 4, 4), (16, 16, 4, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32) triton_poi_fused_convolution_div_sigmoid_1[grid(64)](buf2, primals_3, buf3, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_3 return buf3, primals_2, buf0, buf2 class InvDepthNew(nn.Module): """Inverse depth layer""" def __init__(self, in_channels, out_channels=1, min_depth=0.5): """ Initializes an InvDepth object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels min_depth : float Minimum depth value to calculate """ super().__init__() self.min_depth = min_depth self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1) self.pad = nn.ConstantPad2d([1] * 4, value=0) self.activ = nn.Sigmoid() def forward(self, input_0): primals_2 = self.conv1.weight primals_3 = self.conv1.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
pection/packnet-sfm
InvDepth
false
7,447
[ "MIT" ]
1
d5673567b649e6bfda292c894cacdeb06aa80913
https://github.com/pection/packnet-sfm/tree/d5673567b649e6bfda292c894cacdeb06aa80913
StackedAutoencoder
import torch import torch.nn as nn class StackedAutoencoder(nn.Module): """ 1-hidden layer AE trained with MSE loss """ def __init__(self, input_size, hidden_layer_size): super(StackedAutoencoder, self).__init__() self.encoder = nn.Linear(input_size, hidden_layer_size) self.decoder = nn.Linear(hidden_layer_size, input_size) def embedding(self, x): return self.encoder(x) def forward(self, x): x = self.encoder(x) x = torch.sigmoid(x) return self.decoder(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_layer_size': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 1), (1, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_sigmoid_0[grid(64)](buf1, primals_2, 64, XBLOCK=64, num_warps=1, 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, 1), ( 1, 1), 0), reinterpret_tensor(primals_4, (1, 4), (1, 1), 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 StackedAutoencoderNew(nn.Module): """ 1-hidden layer AE trained with MSE loss """ def __init__(self, input_size, hidden_layer_size): super(StackedAutoencoderNew, self).__init__() self.encoder = nn.Linear(input_size, hidden_layer_size) self.decoder = nn.Linear(hidden_layer_size, input_size) def embedding(self, x): return self.encoder(x) def forward(self, input_0): primals_1 = self.encoder.weight primals_2 = self.encoder.bias primals_4 = self.decoder.weight primals_5 = self.decoder.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pemami4911/ppi-with-stacked-autoencoders
StackedAutoencoder
false
7,448
[ "MIT" ]
1
c09aba827ac6991da3dbf1b2628ac5d0f5041548
https://github.com/pemami4911/ppi-with-stacked-autoencoders/tree/c09aba827ac6991da3dbf1b2628ac5d0f5041548
HardGRUCellNUAPT
import math import torch from torch import Tensor import torch.nn as nn import torch.nn.functional as F from typing import Optional import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardGRUCellNUAPT(torch.nn.RNNCellBase): """ This is a standard GRUCell by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. This module is not fully unary computing aware (NUA), i.e., not all intermediate data are bounded to the legal unary range. This module follows the PyTorch implementation style (PT). """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardGRUCellNUAPT, self).__init__(input_size, hidden_size, bias, num_chunks=3) self.hard = hard if hard is True: self.resetgate_sigmoid = ScaleHardsigmoid() self.updategate_sigmoid = ScaleHardsigmoid() self.newgate_tanh = nn.Hardtanh() else: self.resetgate_sigmoid = nn.Sigmoid() self.updategate_sigmoid = nn.Sigmoid() self.newgate_tanh = nn.Tanh() self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input: 'Tensor', hx: 'Optional[Tensor]'=None) ->Tensor: if hx is None: hx = torch.zeros(input.size()[0], self.hidden_size, dtype=input .dtype, device=input.device) gate_i = F.linear(input, self.weight_ih, self.bias_ih) gate_h = F.linear(hx, self.weight_hh, self.bias_hh) i_r, i_z, i_n = gate_i.chunk(3, 1) h_r, h_z, h_n = gate_h.chunk(3, 1) resetgate_in = i_r + h_r updategate_in = i_z + h_z resetgate = self.resetgate_sigmoid(resetgate_in) updategate = self.updategate_sigmoid(updategate_in) newgate_in = i_n + resetgate * h_n newgate = self.newgate_tanh(newgate_in) hy = (1 - updategate) * newgate + updategate * hx return hy def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import math import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_zeros_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_add_hardsigmoid_hardtanh_mul_rsub_1(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3, xnumel, XBLOCK: tl. constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (4 + x0 + 12 * x1), xmask) tmp1 = tl.load(in_ptr1 + (4 + x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + (4 + x0 + 12 * x1), xmask) tmp7 = tl.load(in_ptr0 + (x0 + 12 * x1), xmask) tmp8 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr2 + (x0 + 12 * x1), xmask) tmp13 = tl.load(in_ptr0 + (8 + x0 + 12 * x1), xmask) tmp14 = tl.load(in_ptr1 + (8 + x0), xmask, eviction_policy='evict_last') tmp23 = tl.load(in_ptr2 + (8 + x0 + 12 * x1), xmask) tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp5 = 3.0 tmp6 = tmp4 * tmp5 tmp9 = tmp7 + tmp8 tmp11 = tmp9 + tmp10 tmp12 = tmp11 * tmp5 tmp15 = tmp13 + tmp14 tmp16 = tmp12 + tmp5 tmp17 = 0.0 tmp18 = triton_helpers.maximum(tmp16, tmp17) tmp19 = 6.0 tmp20 = triton_helpers.minimum(tmp18, tmp19) tmp21 = 0.16666666666666666 tmp22 = tmp20 * tmp21 tmp24 = tmp22 * tmp23 tmp25 = tmp15 + tmp24 tmp26 = tmp6 + tmp5 tmp27 = triton_helpers.maximum(tmp26, tmp17) tmp28 = triton_helpers.minimum(tmp27, tmp19) tmp29 = tmp28 * tmp21 tmp30 = 1.0 tmp31 = tmp30 - tmp29 tmp32 = -1.0 tmp33 = triton_helpers.maximum(tmp25, tmp32) tmp34 = triton_helpers.minimum(tmp33, tmp30) tmp35 = tmp31 * tmp34 tmp36 = tmp29 * tmp17 tmp37 = tmp35 + tmp36 tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(out_ptr1 + x2, tmp12, xmask) tl.store(out_ptr2 + x2, tmp25, xmask) tl.store(out_ptr3 + x2, tmp37, 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, (12, 4), (4, 1)) assert_size_stride(primals_3, (12,), (1,)) assert_size_stride(primals_4, (12, 4), (4, 1)) assert_size_stride(primals_5, (12,), (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_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 12), (12, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 12), (1, 4), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 12), (12, 1), torch.float32) extern_kernels.addmm(primals_5, buf0, reinterpret_tensor(primals_4, (4, 12), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_4 del primals_5 buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) triton_poi_fused_add_hardsigmoid_hardtanh_mul_rsub_1[grid(16)](buf1, primals_3, buf2, buf4, buf3, buf5, buf6, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf1 del primals_3 return buf6, primals_1, buf0, reinterpret_tensor(buf2, (4, 4), (12, 1), 8 ), buf3, buf4, buf5 def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardGRUCellNUAPTNew(torch.nn.RNNCellBase): """ This is a standard GRUCell by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. This module is not fully unary computing aware (NUA), i.e., not all intermediate data are bounded to the legal unary range. This module follows the PyTorch implementation style (PT). """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardGRUCellNUAPTNew, self).__init__(input_size, hidden_size, bias, num_chunks=3) self.hard = hard if hard is True: self.resetgate_sigmoid = ScaleHardsigmoid() self.updategate_sigmoid = ScaleHardsigmoid() self.newgate_tanh = nn.Hardtanh() else: self.resetgate_sigmoid = nn.Sigmoid() self.updategate_sigmoid = nn.Sigmoid() self.newgate_tanh = nn.Tanh() self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input_0): primals_2 = self.weight_ih primals_4 = self.weight_hh primals_3 = self.bias_ih primals_5 = self.bias_hh primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pan185/UnarySim
HardGRUCellNUAPT
false
7,449
[ "MIT" ]
1
c03386efdbb8151f3c33f34b44d1d6a6fc960434
https://github.com/pan185/UnarySim/tree/c03386efdbb8151f3c33f34b44d1d6a6fc960434
InstanceNormLayer
import torch import torch.nn as nn class InstanceNormLayer(nn.Module): """Implements instance normalization layer.""" def __init__(self, epsilon=1e-08): super().__init__() self.epsilon = epsilon def forward(self, x): if len(x.shape) != 4: raise ValueError( f'The input tensor should be with shape [batch_size, num_channels, height, width], but {x.shape} received!' ) x = x - torch.mean(x, dim=[2, 3], keepdim=True) x = x / torch.sqrt(torch.mean(x ** 2, dim=[2, 3], keepdim=True) + self.epsilon) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_add_div_mean_pow_sqrt_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] tmp5 = 16.0 tmp6 = tmp4 / tmp5 tmp7 = tmp0 - tmp6 tmp8 = tmp7 * tmp7 tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK]) tmp11 = tl.where(xmask, tmp9, 0) tmp12 = tl.sum(tmp11, 1)[:, None] tmp13 = tmp12 / tmp5 tmp14 = 1e-08 tmp15 = tmp13 + tmp14 tmp16 = libdevice.sqrt(tmp15) tmp17 = tmp7 / tmp16 tl.store(out_ptr2 + (r1 + 16 * x0), tmp17, 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) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_per_fused_add_div_mean_pow_sqrt_sub_0[grid(16)](arg0_1, buf2, 16, 16, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 return buf2, class InstanceNormLayerNew(nn.Module): """Implements instance normalization layer.""" def __init__(self, epsilon=1e-08): super().__init__() self.epsilon = epsilon def forward(self, input_0): arg0_1 = input_0 output = call([arg0_1]) return output[0]
perladoubinsky/balanced_sampling_gan_controls
InstanceNormLayer
false
7,450
[ "MIT" ]
1
cbec7a38176406c0e19d4b6ebbc6c6b52d268036
https://github.com/perladoubinsky/balanced_sampling_gan_controls/tree/cbec7a38176406c0e19d4b6ebbc6c6b52d268036
ModelNet
import torch import torch.nn as nn class ModelNet(nn.Module): def __init__(self, input_size, num_hidden_layers=1, hidden_layer_size= 512, num_labels=2): super(ModelNet, self).__init__() self.model = nn.Sequential() for i in range(num_hidden_layers): self.model.add_module(f'ff_{i}', nn.Linear(input_size, hidden_layer_size)) self.model.add_module(f'relu{i}', nn.ReLU()) input_size = hidden_layer_size self.model.add_module('classification', nn.Linear(hidden_layer_size, num_labels)) def forward(self, x): return self.model(x) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'input_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x2 = xindex x0 = xindex % 512 tmp0 = tl.load(in_out_ptr0 + x2, None) tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp5 = 0.0 tmp6 = tmp4 <= tmp5 tl.store(in_out_ptr0 + x2, tmp4, None) tl.store(out_ptr0 + x2, tmp6, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (512, 4), (4, 1)) assert_size_stride(primals_2, (512,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (2, 512), (512, 1)) assert_size_stride(primals_5, (2,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 512), (512, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 512), (1, 4), 0), out=buf0) del primals_1 buf1 = reinterpret_tensor(buf0, (4, 4, 4, 512), (8192, 2048, 512, 1), 0 ) del buf0 buf3 = empty_strided_cuda((4, 4, 4, 512), (8192, 2048, 512, 1), torch.bool) get_raw_stream(0) triton_poi_fused_relu_threshold_backward_0[grid(32768)](buf1, primals_2, buf3, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 512), (512, 1), 0), reinterpret_tensor(primals_4, (512, 2), (1, 512), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 2), (32, 8, 2, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf1, (64, 512), (512, 1), 0), primals_4, buf3 class ModelNetNew(nn.Module): def __init__(self, input_size, num_hidden_layers=1, hidden_layer_size= 512, num_labels=2): super(ModelNetNew, self).__init__() self.model = nn.Sequential() for i in range(num_hidden_layers): self.model.add_module(f'ff_{i}', nn.Linear(input_size, hidden_layer_size)) self.model.add_module(f'relu{i}', nn.ReLU()) input_size = hidden_layer_size self.model.add_module('classification', nn.Linear(hidden_layer_size, num_labels)) def forward(self, input_0): primals_1 = self.model.ff_0.weight primals_2 = self.model.ff_0.bias primals_4 = self.model.classification.weight primals_5 = self.model.classification.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
patelrajnath/makeesy-deep-learning
ModelNet
false
7,451
[ "Apache-2.0" ]
1
172f8a4301d6b60927824a56648d60559ba3f14e
https://github.com/patelrajnath/makeesy-deep-learning/tree/172f8a4301d6b60927824a56648d60559ba3f14e
LocalDictionaryLoss
import torch import torch.nn class LocalDictionaryLoss(torch.nn.Module): def __init__(self, penalty): super(LocalDictionaryLoss, self).__init__() self.penalty = penalty def forward(self, A, y, x): return self.forward_detailed(A, y, x)[2] def forward_detailed(self, A, y, x): weight = (y.unsqueeze(1) - A.unsqueeze(0)).pow(2).sum(dim=2) a = 0.5 * (y - x @ A).pow(2).sum(dim=1).mean() b = (weight * x).sum(dim=1).mean() return a, b, a + b * self.penalty 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 [[], {'penalty': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_pow_sub_sum_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x2 = xindex // 64 x1 = xindex // 16 % 4 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp4 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp10 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp14 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy= 'evict_last') tmp15 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask, eviction_policy= 'evict_last') tmp19 = tl.load(in_ptr2 + x3, 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 tmp20 = tmp18 * tmp19 tl.store(out_ptr0 + x3, tmp20, xmask) @triton.jit def triton_per_fused_add_mean_mul_pow_sub_sum_1(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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_ptr1 + (r0 + 64 * r1), None) tmp4 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None) tmp5 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None) tmp9 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None) tmp10 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None) tmp14 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None) tmp15 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None) tmp22 = tl.load(in_ptr2 + (r0 + 64 * r1), None) tmp23 = tl.load(in_ptr2 + (16 + r0 + 64 * r1), None) tmp25 = tl.load(in_ptr2 + (32 + r0 + 64 * r1), None) tmp27 = tl.load(in_ptr2 + (48 + r0 + 64 * r1), None) 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 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK]) tmp21 = tl.sum(tmp19, 1)[:, None] tmp24 = tmp22 + tmp23 tmp26 = tmp24 + tmp25 tmp28 = tmp26 + tmp27 tmp29 = tl.broadcast_to(tmp28, [XBLOCK, RBLOCK]) tmp31 = tl.sum(tmp29, 1)[:, None] tmp32 = 64.0 tmp33 = tmp21 / tmp32 tmp34 = 0.5 tmp35 = tmp33 * tmp34 tmp36 = tmp31 / tmp32 tmp37 = 4.0 tmp38 = tmp36 * tmp37 tmp39 = tmp35 + tmp38 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp39, 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((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1 ), 0), reinterpret_tensor(arg1_1, (16, 4, 4), (16, 4, 1), 0), out=buf0) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_pow_sub_sum_0[grid(256)](arg0_1, arg1_1, arg2_1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 del arg2_1 buf1 = empty_strided_cuda((), (), torch.float32) buf4 = buf1 del buf1 triton_per_fused_add_mean_mul_pow_sub_sum_1[grid(1)](buf4, arg0_1, buf0, buf2, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del arg0_1 del buf0 del buf2 return buf4, class LocalDictionaryLossNew(torch.nn.Module): def __init__(self, penalty): super(LocalDictionaryLossNew, self).__init__() self.penalty = penalty def forward_detailed(self, A, y, x): weight = (y.unsqueeze(1) - A.unsqueeze(0)).pow(2).sum(dim=2) a = 0.5 * (y - x @ A).pow(2).sum(dim=1).mean() b = (weight * x).sum(dim=1).mean() return a, b, a + b * self.penalty 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]
pbt17/manifold-learning-with-simplex-constraints
LocalDictionaryLoss
false
7,452
[ "MIT" ]
1
36609e2d05600965ee1331823547a077ba7b5a51
https://github.com/pbt17/manifold-learning-with-simplex-constraints/tree/36609e2d05600965ee1331823547a077ba7b5a51
Discriminator
import math import torch import torch.nn as nn import torch.utils.data from collections import * class Discriminator(nn.Module): def __init__(self, n_hidden): super(Discriminator, self).__init__() self.weight = nn.Parameter(torch.Tensor(n_hidden, n_hidden)) self.reset_parameters() def uniform(self, size, tensor): bound = 1.0 / math.sqrt(size) if tensor is not None: tensor.data.uniform_(-bound, bound) def reset_parameters(self): size = self.weight.size(0) self.uniform(size, self.weight) def forward(self, features, summary): features = torch.matmul(features, torch.matmul(self.weight, summary)) return features def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'n_hidden': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import math import torch.nn as nn import torch.utils.data from collections 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_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 64 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) def call(args): primals_1, primals_2, primals_3 = 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, 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_clone_0[grid(64, 4)](primals_2, buf0, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) del primals_2 buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf1) del primals_1 buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_clone_0[grid(64, 4)](buf1, buf2, 64, 4, XBLOCK=4, YBLOCK=32, num_warps=4, num_stages=1) buf3 = reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0) del buf1 extern_kernels.bmm(reinterpret_tensor(primals_3, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf3) del buf2 return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor( primals_3, (16, 4, 4), (16, 1, 4), 0) class DiscriminatorNew(nn.Module): def __init__(self, n_hidden): super(DiscriminatorNew, self).__init__() self.weight = nn.Parameter(torch.Tensor(n_hidden, n_hidden)) self.reset_parameters() def uniform(self, size, tensor): bound = 1.0 / math.sqrt(size) if tensor is not None: tensor.data.uniform_(-bound, bound) def reset_parameters(self): size = self.weight.size(0) self.uniform(size, self.weight) def forward(self, input_0, input_1): primals_1 = self.weight primals_2 = input_0 primals_3 = input_1 output = call([primals_1, primals_2, primals_3]) return output[0]
pgplus1628/dgl
Discriminator
false
7,453
[ "Apache-2.0" ]
1
bf3994eea68b5841349f1616f41d0f70123a11ec
https://github.com/pgplus1628/dgl/tree/bf3994eea68b5841349f1616f41d0f70123a11ec
baseline
import torch import torch.nn.functional as F class baseline(torch.nn.Module): def __init__(self): super(baseline, self).__init__() self.conv1 = torch.nn.Conv2d(3, 6, 5) self.pool = torch.nn.MaxPool2d(2, 2) self.conv2 = torch.nn.Conv2d(6, 16, 5) self.fc1 = torch.nn.Linear(16 * 5 * 5, 120) self.fc2 = torch.nn.Linear(120, 84) self.fc3 = torch.nn.Linear(84, 10) def forward(self, x): x = self.pool(F.relu(self.conv1(x))) x = self.pool(F.relu(self.conv2(x))) x = x.view(-1, 16 * 5 * 5) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) x = F.softmax(x) return x def get_inputs(): return [torch.rand([4, 3, 32, 32])] 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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_convolution_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 18816 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 784 % 6 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 4704 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 14 x3 = xindex // 14 x2 = xindex // 1176 x4 = xindex % 1176 tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x3), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x3), xmask, eviction_policy ='evict_last') tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x3), xmask, eviction_policy='evict_last') tmp2 = triton_helpers.maximum(tmp1, tmp0) tmp4 = triton_helpers.maximum(tmp3, tmp2) tmp6 = triton_helpers.maximum(tmp5, tmp4) tmp7 = tmp1 > tmp0 tmp8 = tl.full([1], 1, tl.int8) tmp9 = tl.full([1], 0, tl.int8) tmp10 = tl.where(tmp7, tmp8, tmp9) tmp11 = tmp3 > tmp2 tmp12 = tl.full([1], 2, tl.int8) tmp13 = tl.where(tmp11, tmp12, tmp10) tmp14 = tmp5 > tmp4 tmp15 = tl.full([1], 3, tl.int8) tmp16 = tl.where(tmp14, tmp15, tmp13) tl.store(out_ptr0 + (x4 + 1184 * x2), tmp6, xmask) tl.store(out_ptr1 + (x4 + 1280 * x2), tmp16, xmask) @triton.jit def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 6400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 100 % 16 tmp0 = tl.load(in_out_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 1600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 5 x1 = xindex // 5 x2 = xindex tmp0 = tl.load(in_ptr0 + (2 * x0 + 20 * x1), xmask, eviction_policy= 'evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 20 * x1), xmask, eviction_policy ='evict_last') tmp7 = tl.load(in_ptr0 + (10 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (11 + 2 * x0 + 20 * x1), xmask, eviction_policy='evict_last') tmp2 = tmp1 > tmp0 tmp3 = tl.full([1], 1, tl.int8) tmp4 = tl.full([1], 0, tl.int8) tmp5 = tl.where(tmp2, tmp3, tmp4) tmp6 = triton_helpers.maximum(tmp1, tmp0) tmp8 = tmp7 > tmp6 tmp9 = tl.full([1], 2, tl.int8) tmp10 = tl.where(tmp8, tmp9, tmp5) tmp11 = triton_helpers.maximum(tmp7, tmp6) tmp13 = tmp12 > tmp11 tmp14 = tl.full([1], 3, tl.int8) tmp15 = tl.where(tmp13, tmp14, tmp10) tmp16 = triton_helpers.maximum(tmp12, tmp11) tl.store(out_ptr0 + x2, tmp15, xmask) tl.store(out_ptr1 + x2, tmp16, xmask) @triton.jit def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 480 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 120 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_poi_fused_relu_5(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 336 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 84 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x2, tmp4, xmask) @triton.jit def triton_per_fused__softmax_6(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 4 rnumel = 10 RBLOCK: tl.constexpr = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r1 = rindex x0 = xindex tmp0 = tl.load(in_ptr0 + (r1 + 10 * x0), rmask & xmask, other=0.0) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.where(rmask & xmask, tmp1, float('-inf')) tmp4 = triton_helpers.max2(tmp3, 1)[:, None] tmp5 = tmp0 - tmp4 tmp6 = tl_math.exp(tmp5) tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK]) tmp9 = tl.where(rmask & xmask, tmp7, 0) tmp10 = tl.sum(tmp9, 1)[:, None] tmp11 = tmp6 / tmp10 tl.store(out_ptr2 + (r1 + 10 * x0), tmp11, rmask & xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11) = args args.clear() assert_size_stride(primals_1, (6, 3, 5, 5), (75, 25, 5, 1)) assert_size_stride(primals_2, (6,), (1,)) assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1)) assert_size_stride(primals_4, (16, 6, 5, 5), (150, 25, 5, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (120, 400), (400, 1)) assert_size_stride(primals_7, (120,), (1,)) assert_size_stride(primals_8, (84, 120), (120, 1)) assert_size_stride(primals_9, (84,), (1,)) assert_size_stride(primals_10, (10, 84), (84, 1)) assert_size_stride(primals_11, (10,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 6, 28, 28), (4704, 784, 28, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(18816)](buf1, primals_2, 18816, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf2 = empty_strided_cuda((4, 6, 14, 14), (1184, 196, 14, 1), torch .float32) buf3 = empty_strided_cuda((4, 6, 14, 14), (1280, 196, 14, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_1[grid(4704)](buf1, buf2, buf3, 4704, XBLOCK=128, num_warps=4, num_stages=1) buf4 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf4, (4, 16, 10, 10), (1600, 100, 10, 1)) buf5 = buf4 del buf4 triton_poi_fused_convolution_relu_2[grid(6400)](buf5, primals_5, 6400, XBLOCK=256, num_warps=4, num_stages=1) del primals_5 buf6 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.int8) buf7 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.float32 ) triton_poi_fused_max_pool2d_with_indices_3[grid(1600)](buf5, buf6, buf7, 1600, XBLOCK=256, num_warps=4, num_stages=1) buf8 = empty_strided_cuda((4, 120), (120, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf7, (4, 400), (400, 1), 0), reinterpret_tensor(primals_6, (400, 120), (1, 400), 0), out=buf8) buf9 = buf8 del buf8 triton_poi_fused_relu_4[grid(480)](buf9, primals_7, 480, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 buf10 = empty_strided_cuda((4, 84), (84, 1), torch.float32) extern_kernels.mm(buf9, reinterpret_tensor(primals_8, (120, 84), (1, 120), 0), out=buf10) buf11 = buf10 del buf10 triton_poi_fused_relu_5[grid(336)](buf11, primals_9, 336, XBLOCK= 256, num_warps=4, num_stages=1) del primals_9 buf12 = empty_strided_cuda((4, 10), (10, 1), torch.float32) extern_kernels.addmm(primals_11, buf11, reinterpret_tensor( primals_10, (84, 10), (1, 84), 0), alpha=1, beta=1, out=buf12) del primals_11 buf15 = empty_strided_cuda((4, 10), (10, 1), torch.float32) triton_per_fused__softmax_6[grid(4)](buf12, buf15, 4, 10, XBLOCK=1, num_warps=2, num_stages=1) del buf12 return (buf15, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5, buf6, reinterpret_tensor(buf7, (4, 400), (400, 1), 0), buf9, buf11, buf15, primals_10, primals_8, primals_6) class baselineNew(torch.nn.Module): def __init__(self): super(baselineNew, self).__init__() self.conv1 = torch.nn.Conv2d(3, 6, 5) self.pool = torch.nn.MaxPool2d(2, 2) self.conv2 = torch.nn.Conv2d(6, 16, 5) self.fc1 = torch.nn.Linear(16 * 5 * 5, 120) self.fc2 = torch.nn.Linear(120, 84) self.fc3 = torch.nn.Linear(84, 10) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_6 = self.fc1.weight primals_7 = self.fc1.bias primals_8 = self.fc2.weight primals_9 = self.fc2.bias primals_10 = self.fc3.weight primals_11 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, primals_10, primals_11]) return output[0]
patrickjdarrow/unsupervised_augmentations
baseline
false
7,454
[ "MIT" ]
1
5a81fa45865f2537c4c73e9307f83a873928e5ae
https://github.com/patrickjdarrow/unsupervised_augmentations/tree/5a81fa45865f2537c4c73e9307f83a873928e5ae
HaltingUnit
import torch import torch.nn as nn import torch as th import torch.utils.data from collections import * import torch.nn.init as INIT from torch.nn import LayerNorm class HaltingUnit(nn.Module): halting_bias_init = 1.0 def __init__(self, dim_model): super(HaltingUnit, self).__init__() self.linear = nn.Linear(dim_model, 1) self.norm = LayerNorm(dim_model) INIT.constant_(self.linear.bias, self.halting_bias_init) def forward(self, x): return th.sigmoid(self.linear(self.norm(x))) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'dim_model': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn import torch.utils.data from collections import * import torch.nn.init as INIT from torch.nn import LayerNorm assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 + tmp3 tmp6 = tmp4 + tmp5 tmp7 = 4.0 tmp8 = tmp6 / tmp7 tmp9 = tmp0 - tmp8 tmp10 = tmp9 * tmp9 tmp11 = tmp1 - tmp8 tmp12 = tmp11 * tmp11 tmp13 = tmp10 + tmp12 tmp14 = tmp3 - tmp8 tmp15 = tmp14 * tmp14 tmp16 = tmp13 + tmp15 tmp17 = tmp5 - tmp8 tmp18 = tmp17 * tmp17 tmp19 = tmp16 + tmp18 tmp20 = tmp19 / tmp7 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tl.store(out_ptr0 + x0, tmp8, xmask) tl.store(out_ptr1 + x0, tmp23, xmask) @triton.jit def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = tmp2 * tmp3 tmp6 = tmp4 * tmp5 tmp8 = tmp6 + tmp7 tl.store(out_ptr0 + x2, tmp8, xmask) @triton.jit def triton_poi_fused_sigmoid_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_out_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr0 + 0) tmp2 = tl.broadcast_to(tmp1, [XBLOCK]) tmp3 = tmp0 + tmp2 tmp4 = tl.sigmoid(tmp3) tl.store(in_out_ptr0 + x0, tmp4, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (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, (1, 4), (4, 1)) assert_size_stride(primals_5, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32) get_raw_stream(0) triton_poi_fused_native_layer_norm_0[grid(64)](primals_3, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_native_layer_norm_1[grid(256)](primals_3, buf0, buf1, primals_1, primals_2, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf0 del primals_1 del primals_2 buf3 = reinterpret_tensor(buf1, (64, 1), (1, 1), 0) del buf1 extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 1), (1, 4), 0), out=buf3) buf4 = reinterpret_tensor(buf3, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf3 triton_poi_fused_sigmoid_2[grid(64)](buf4, primals_5, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_5 return buf4, primals_3, reinterpret_tensor(buf2, (64, 4), (4, 1), 0 ), buf4, primals_4 class HaltingUnitNew(nn.Module): halting_bias_init = 1.0 def __init__(self, dim_model): super(HaltingUnitNew, self).__init__() self.linear = nn.Linear(dim_model, 1) self.norm = LayerNorm(dim_model) INIT.constant_(self.linear.bias, self.halting_bias_init) def forward(self, input_0): primals_4 = self.linear.weight primals_5 = self.linear.bias primals_1 = self.norm.weight primals_2 = self.norm.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pgplus1628/dgl
HaltingUnit
false
7,455
[ "Apache-2.0" ]
1
bf3994eea68b5841349f1616f41d0f70123a11ec
https://github.com/pgplus1628/dgl/tree/bf3994eea68b5841349f1616f41d0f70123a11ec
EuclideanGMM
import math import torch import torch.nn as nn def gaussian_prob_density(x, mu, sigma, normalized=False): if normalized: k = mu.shape[-1] scaler = (2 * math.pi) ** (-k / 2) sigma_det = torch.prod(sigma, dim=-1) ** -0.5 bias = (x - mu).unsqueeze(-2) sigma_inv = torch.diag_embed(1 / sigma) exp = torch.exp(-0.5 * bias @ sigma_inv @ bias.transpose(-1, -2)) if normalized: return (scaler * sigma_det * exp)[..., 0, 0] else: return exp[..., 0, 0] class EuclideanGMM(nn.Module): def __init__(self, reduction='mean'): super().__init__() self.reduction = reduction def forward(self, w1, mu1, sigma1, w2, mu2, sigma2): """Compute Euclidean distance between two mixtures of Gaussian Parameters ---------- w1/w2 : torch.Tensor (*, M, N) where * is one or more batch dimensions. The weight for the GMM mu1/mu2 : torch.Tensor (*, M, N) where * is one or more batch dimensions. The mean vectors for the GMM sigma1/sigma2: torch.Tensor (*, M, N) where * is one or more batch dimensions. The diagonal covariance matrix for the GMM Returns ---------- torch.Tensor """ density_1 = EuclideanGMM.gaussian_cross_product(mu1, sigma1, mu1, sigma1) density_2 = EuclideanGMM.gaussian_cross_product(mu2, sigma2, mu2, sigma2) density_x = EuclideanGMM.gaussian_cross_product(mu1, sigma1, mu2, sigma2) w1_w1_cross = w1.unsqueeze(-1) @ w1.unsqueeze(-2) w2_w2_cross = w2.unsqueeze(-1) @ w2.unsqueeze(-2) w1_w2_cross = w1.unsqueeze(-1) @ w2.unsqueeze(-2) L2 = (w1_w1_cross * density_1 + w2_w2_cross * density_2 - 2 * w1_w2_cross * density_x) L2 = torch.sum(L2, dim=[-2, -1]) if self.reduction == 'sum': L2 = torch.sum(L2) elif self.reduction == 'mean': L2 = torch.mean(L2) return L2 @staticmethod def gaussian_cross_product(mu1, sigma1, mu2, sigma2): n_gauss_1 = mu1.shape[-2] n_gauss_2 = mu2.shape[-2] batch_size = mu1.shape[:-2] mu1 = mu1.unsqueeze(-2).expand(*batch_size, -1, n_gauss_2, -1) mu2 = mu2.unsqueeze(-3).expand(*batch_size, n_gauss_1, -1, -1) sigma1 = sigma1.unsqueeze(-2).expand(*batch_size, -1, n_gauss_2, -1) sigma2 = sigma2.unsqueeze(-3).expand(*batch_size, n_gauss_1, -1, -1) return gaussian_prob_density(mu1, mu2, sigma1 + sigma2) 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]), 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.triton_helpers import math as tl_math import math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_mul_sub_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x4 = xindex // 16 x3 = xindex // 64 x5 = xindex % 16 x6 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp1 = tl.load(in_ptr0 + (x5 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp5 = tl.load(in_ptr1 + (x0 + 4 * x4), xmask, eviction_policy='evict_last' ) tmp6 = tl.load(in_ptr1 + (x5 + 16 * x3), xmask, eviction_policy= 'evict_last') tmp2 = tmp0 - tmp1 tmp3 = -0.5 tmp4 = tmp2 * tmp3 tmp7 = tmp5 - tmp6 tmp8 = tmp7 * tmp3 tmp9 = tmp0 - tmp6 tmp10 = tmp9 * tmp3 tl.store(out_ptr0 + x6, tmp4, xmask) tl.store(out_ptr1 + x6, tmp2, xmask) tl.store(out_ptr2 + x6, tmp8, xmask) tl.store(out_ptr3 + x6, tmp7, xmask) tl.store(out_ptr4 + x6, tmp10, xmask) tl.store(out_ptr5 + x6, tmp9, xmask) @triton.jit def triton_poi_fused_diag_embed_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, xnumel, XBLOCK: tl.constexpr): xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] tl.full([XBLOCK], True, tl.int1) x0 = xindex % 4 x1 = xindex // 4 % 4 x6 = xindex // 64 x2 = xindex // 16 % 4 x4 = xindex // 256 x7 = xindex tmp3 = tl.load(in_ptr0 + (x0 + 4 * x6), None, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x4), None, eviction_policy ='evict_last') tmp12 = tl.load(in_ptr1 + (x0 + 4 * x6), None, eviction_policy='evict_last' ) tmp13 = tl.load(in_ptr1 + (x0 + 4 * x2 + 16 * x4), None, eviction_policy='evict_last') tmp0 = x0 tmp1 = x1 tmp2 = tmp0 == tmp1 tmp5 = tmp3 + tmp4 tmp6 = tl.full([1], 1, tl.int32) tmp7 = tmp6 / tmp5 tmp8 = 1.0 tmp9 = tmp7 * tmp8 tmp10 = 0.0 tmp11 = tl.where(tmp2, tmp9, tmp10) tmp14 = tmp12 + tmp13 tmp15 = tmp6 / tmp14 tmp16 = tmp15 * tmp8 tmp17 = tl.where(tmp2, tmp16, tmp10) tmp18 = tmp3 + tmp13 tmp19 = tmp6 / tmp18 tmp20 = tmp19 * tmp8 tmp21 = tl.where(tmp2, tmp20, tmp10) tl.store(out_ptr0 + x7, tmp11, None) tl.store(out_ptr1 + x7, tmp17, None) tl.store(out_ptr2 + x7, tmp21, None) @triton.jit def triton_per_fused_add_mul_sub_sum_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, 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 x3 = xindex x0 = xindex % 16 tmp0 = tl.load(in_ptr0 + (r2 + 16 * x3), xmask, other=0.0) tmp1 = tl.load(in_ptr1 + (r2 + 16 * x0), xmask, eviction_policy= 'evict_last', other=0.0) tmp4 = tl.load(in_ptr2 + (r2 + 16 * x3), xmask, other=0.0) tmp5 = tl.load(in_ptr3 + (r2 + 16 * x0), xmask, eviction_policy= 'evict_last', other=0.0) tmp9 = tl.load(in_ptr4 + (r2 + 16 * x3), xmask, other=0.0) tmp12 = tl.load(in_ptr5 + (r2 + 16 * x0), xmask, eviction_policy= 'evict_last', other=0.0) tmp2 = tl_math.exp(tmp1) tmp3 = tmp0 * tmp2 tmp6 = tl_math.exp(tmp5) tmp7 = tmp4 * tmp6 tmp8 = tmp3 + tmp7 tmp10 = 2.0 tmp11 = tmp9 * tmp10 tmp13 = tl_math.exp(tmp12) tmp14 = tmp11 * tmp13 tmp15 = tmp8 - tmp14 tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK]) tmp18 = tl.where(xmask, tmp16, 0) tmp19 = tl.sum(tmp18, 1)[:, None] tl.store(out_ptr0 + x3, tmp19, xmask) @triton.jit def triton_per_fused_mean_3(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr): RBLOCK: tl.constexpr = 64 xoffset = tl.program_id(0) * XBLOCK xoffset + tl.arange(0, XBLOCK)[:, None] tl.full([XBLOCK, RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[None, :] tl.full([XBLOCK, RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK]) tmp3 = tl.sum(tmp1, 1)[:, None] tmp4 = 64.0 tmp5 = tmp3 / tmp4 tl.debug_barrier() tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None) def call(args): arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_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)) assert_size_stride(arg5_1, (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), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(arg4_1, (64, 4, 1), (4, 1, 1), 0), reinterpret_tensor(arg4_1, (64, 1, 4), (4, 4, 1), 0), out=buf0) buf1 = empty_strided_cuda((4, 4, 4, 4, 1, 4), (256, 64, 16, 4, 4, 1 ), torch.float32) buf4 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4, 4, 4, 1, 4), (256, 64, 16, 4, 4, 1 ), torch.float32) buf10 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) buf13 = empty_strided_cuda((4, 4, 4, 4, 1, 4), (256, 64, 16, 4, 4, 1), torch.float32) buf16 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_mul_sub_0[grid(1024)](arg0_1, arg2_1, buf1, buf4, buf7, buf10, buf13, buf16, 1024, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg2_1 buf2 = empty_strided_cuda((4, 4, 4, 4, 4, 4), (1024, 256, 64, 16, 4, 1), torch.float32) buf8 = empty_strided_cuda((4, 4, 4, 4, 4, 4), (1024, 256, 64, 16, 4, 1), torch.float32) buf14 = empty_strided_cuda((4, 4, 4, 4, 4, 4), (1024, 256, 64, 16, 4, 1), torch.float32) triton_poi_fused_diag_embed_1[grid(4096)](arg1_1, arg3_1, buf2, buf8, buf14, 4096, XBLOCK=128, num_warps=4, num_stages=1) del arg1_1 del arg3_1 buf3 = empty_strided_cuda((256, 1, 4), (4, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf1, (256, 1, 4), (4, 0, 1), 0), reinterpret_tensor(buf2, (256, 4, 4), (16, 4, 1), 0), out=buf3) del buf1 del buf2 buf5 = empty_strided_cuda((256, 1, 1), (1, 1, 1), torch.float32) extern_kernels.bmm(buf3, reinterpret_tensor(buf4, (256, 4, 1), (4, 1, 0), 0), out=buf5) buf6 = reinterpret_tensor(buf4, (64, 4, 4), (16, 4, 1), 0) del buf4 extern_kernels.bmm(reinterpret_tensor(arg5_1, (64, 4, 1), (4, 1, 1), 0), reinterpret_tensor(arg5_1, (64, 1, 4), (4, 4, 1), 0), out=buf6) buf9 = buf3 del buf3 extern_kernels.bmm(reinterpret_tensor(buf7, (256, 1, 4), (4, 0, 1), 0), reinterpret_tensor(buf8, (256, 4, 4), (16, 4, 1), 0), out=buf9) del buf7 del buf8 buf11 = empty_strided_cuda((256, 1, 1), (1, 1, 1), torch.float32) extern_kernels.bmm(buf9, reinterpret_tensor(buf10, (256, 4, 1), (4, 1, 0), 0), out=buf11) buf12 = reinterpret_tensor(buf9, (64, 4, 4), (16, 4, 1), 0) del buf9 extern_kernels.bmm(reinterpret_tensor(arg4_1, (64, 4, 1), (4, 1, 1), 0), reinterpret_tensor(arg5_1, (64, 1, 4), (4, 4, 1), 0), out=buf12 ) del arg4_1 del arg5_1 buf15 = reinterpret_tensor(buf10, (256, 1, 4), (4, 4, 1), 0) del buf10 extern_kernels.bmm(reinterpret_tensor(buf13, (256, 1, 4), (4, 0, 1), 0), reinterpret_tensor(buf14, (256, 4, 4), (16, 4, 1), 0), out= buf15) del buf13 del buf14 buf17 = empty_strided_cuda((256, 1, 1), (1, 1, 1), torch.float32) extern_kernels.bmm(buf15, reinterpret_tensor(buf16, (256, 4, 1), (4, 1, 0), 0), out=buf17) del buf15 del buf16 buf18 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_per_fused_add_mul_sub_sum_2[grid(64)](buf0, buf5, buf6, buf11, buf12, buf17, buf18, 64, 16, XBLOCK=1, num_warps=2, num_stages=1) del buf0 del buf11 del buf12 del buf17 del buf5 del buf6 buf19 = empty_strided_cuda((), (), torch.float32) buf20 = buf19 del buf19 triton_per_fused_mean_3[grid(1)](buf20, buf18, 1, 64, XBLOCK=1, num_warps=2, num_stages=1) del buf18 return buf20, def gaussian_prob_density(x, mu, sigma, normalized=False): if normalized: k = mu.shape[-1] scaler = (2 * math.pi) ** (-k / 2) sigma_det = torch.prod(sigma, dim=-1) ** -0.5 bias = (x - mu).unsqueeze(-2) sigma_inv = torch.diag_embed(1 / sigma) exp = torch.exp(-0.5 * bias @ sigma_inv @ bias.transpose(-1, -2)) if normalized: return (scaler * sigma_det * exp)[..., 0, 0] else: return exp[..., 0, 0] class EuclideanGMMNew(nn.Module): def __init__(self, reduction='mean'): super().__init__() self.reduction = reduction @staticmethod def gaussian_cross_product(mu1, sigma1, mu2, sigma2): n_gauss_1 = mu1.shape[-2] n_gauss_2 = mu2.shape[-2] batch_size = mu1.shape[:-2] mu1 = mu1.unsqueeze(-2).expand(*batch_size, -1, n_gauss_2, -1) mu2 = mu2.unsqueeze(-3).expand(*batch_size, n_gauss_1, -1, -1) sigma1 = sigma1.unsqueeze(-2).expand(*batch_size, -1, n_gauss_2, -1) sigma2 = sigma2.unsqueeze(-3).expand(*batch_size, n_gauss_1, -1, -1) return gaussian_prob_density(mu1, mu2, sigma1 + sigma2) def forward(self, input_0, input_1, input_2, input_3, input_4, input_5): arg0_1 = input_0 arg1_1 = input_1 arg2_1 = input_2 arg3_1 = input_3 arg4_1 = input_4 arg5_1 = input_5 output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1, arg5_1]) return output[0]
ownzonefeng/Graph-based-text-representations
EuclideanGMM
false
7,456
[ "MIT" ]
1
4ddac6980d2741284474778dae2c2afa0adb5cda
https://github.com/ownzonefeng/Graph-based-text-representations/tree/4ddac6980d2741284474778dae2c2afa0adb5cda
HardMGUCellNUA
import math import torch from torch import Tensor import torch.nn as nn import torch.nn.functional as F from typing import Optional import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardMGUCellNUA(torch.nn.Module): """ This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details. Hardtanh is to bound data to the legal unary range. This module follows the uBrain implementation style to maximize hardware reuse. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardMGUCellNUA, self).__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.hard = hard if hard is True: self.fg_sigmoid = ScaleHardsigmoid() self.ng_tanh = nn.Hardtanh() else: self.fg_sigmoid = nn.Sigmoid() self.ng_tanh = nn.Tanh() self.weight_f = nn.Parameter(torch.empty((hidden_size, hidden_size + input_size))) self.weight_n = nn.Parameter(torch.empty((hidden_size, hidden_size + input_size))) if bias: self.bias_f = nn.Parameter(torch.empty(hidden_size)) self.bias_n = nn.Parameter(torch.empty(hidden_size)) else: self.register_parameter('bias_f', None) self.register_parameter('bias_n', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input: 'Tensor', hx: 'Optional[Tensor]'=None) ->Tensor: if hx is None: hx = torch.zeros(input.size()[0], self.hidden_size, dtype=input .dtype, device=input.device) self.fg_ug_in = torch.cat((hx, input), 1) self.fg_in = F.linear(self.fg_ug_in, self.weight_f, self.bias_f) self.fg = self.fg_sigmoid(self.fg_in) self.fg_hx = self.fg * hx self.ng_ug_in = torch.cat((self.fg_hx, input), 1) self.ng_in = F.linear(self.ng_ug_in, self.weight_n, self.bias_n) self.ng = self.ng_tanh(self.ng_in) self.fg_ng_inv = (0 - self.fg) * self.ng hy = self.ng + self.fg_ng_inv + self.fg_hx return hy def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import math import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_cat_0(in_ptr0, 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 = 0.0 tmp6 = tl.full(tmp5.shape, 0.0, tmp5.dtype) tmp7 = tl.where(tmp4, tmp5, tmp6) tmp8 = tmp0 >= tmp3 tl.full([1], 8, tl.int64) tmp11 = tl.load(in_ptr0 + (4 * x1 + (-4 + x0)), tmp8 & xmask, eviction_policy='evict_last', other=0.0) tmp12 = tl.where(tmp4, tmp7, tmp11) tl.store(out_ptr0 + x2, tmp12, xmask) @triton.jit def triton_poi_fused_hardsigmoid_hardsigmoid_backward_mul_zeros_1(in_ptr0, out_ptr0, out_ptr1, out_ptr2, 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 = 3.0 tmp2 = tmp0 * tmp1 tmp3 = tmp2 + tmp1 tmp4 = 0.0 tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp6 = 6.0 tmp7 = triton_helpers.minimum(tmp5, tmp6) tmp8 = 0.16666666666666666 tmp9 = tmp7 * tmp8 tmp10 = tmp9 * tmp4 tmp11 = -3.0 tmp12 = tmp2 > tmp11 tmp13 = tmp2 < tmp1 tmp14 = tmp12 & tmp13 tl.store(out_ptr0 + x0, tmp9, xmask) tl.store(out_ptr1 + x0, tmp10, xmask) tl.store(out_ptr2 + x0, tmp14, xmask) @triton.jit def triton_poi_fused_cat_2(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_hardtanh_hardtanh_backward_mul_rsub_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, 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) tmp5 = tl.load(in_ptr1 + x0, xmask) tmp10 = tl.load(in_ptr2 + x0, xmask) tmp1 = -1.0 tmp2 = triton_helpers.maximum(tmp0, tmp1) tmp3 = 1.0 tmp4 = triton_helpers.minimum(tmp2, tmp3) tmp6 = 0.0 tmp7 = tmp6 - tmp5 tmp8 = tmp7 * tmp4 tmp9 = tmp4 + tmp8 tmp11 = tmp9 + tmp10 tmp12 = tmp0 <= tmp1 tmp13 = tmp0 >= tmp3 tmp14 = tmp12 | tmp13 tl.store(out_ptr0 + x0, tmp4, xmask) tl.store(out_ptr1 + x0, tmp7, xmask) tl.store(out_ptr2 + x0, tmp8, xmask) tl.store(out_ptr3 + x0, tmp11, xmask) tl.store(out_ptr4 + x0, 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, 1)) assert_size_stride(primals_2, (4, 8), (8, 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) buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_cat_0[grid(32)](primals_1, buf0, 32, XBLOCK=32, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_3, buf0, reinterpret_tensor(primals_2, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf1) del primals_2 del primals_3 buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf11 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_hardsigmoid_hardsigmoid_backward_mul_zeros_1[grid(16) ](buf1, buf2, buf3, buf11, 16, XBLOCK=16, num_warps=1, num_stages=1 ) buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32) triton_poi_fused_cat_2[grid(32)](buf3, primals_1, buf4, 32, XBLOCK= 32, num_warps=1, num_stages=1) del primals_1 buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, buf4, reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), alpha=1, beta=1, out=buf5) del primals_5 buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_add_hardtanh_hardtanh_backward_mul_rsub_3[grid(16)]( buf5, buf2, buf3, buf6, buf7, buf8, buf9, buf10, 16, XBLOCK=16, num_warps=1, num_stages=1) return (buf9, buf8, buf6, buf5, buf4, buf3, buf2, buf1, buf0, buf0, buf4, buf6, buf7, buf10, primals_4, buf11) def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardMGUCellNUANew(torch.nn.Module): """ This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details. Hardtanh is to bound data to the legal unary range. This module follows the uBrain implementation style to maximize hardware reuse. """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardMGUCellNUANew, self).__init__() self.input_size = input_size self.hidden_size = hidden_size self.bias = bias self.hard = hard if hard is True: self.fg_sigmoid = ScaleHardsigmoid() self.ng_tanh = nn.Hardtanh() else: self.fg_sigmoid = nn.Sigmoid() self.ng_tanh = nn.Tanh() self.weight_f = nn.Parameter(torch.empty((hidden_size, hidden_size + input_size))) self.weight_n = nn.Parameter(torch.empty((hidden_size, hidden_size + input_size))) if bias: self.bias_f = nn.Parameter(torch.empty(hidden_size)) self.bias_n = nn.Parameter(torch.empty(hidden_size)) else: self.register_parameter('bias_f', None) self.register_parameter('bias_n', None) self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input_0): primals_2 = self.weight_f primals_4 = self.weight_n primals_3 = self.bias_f primals_5 = self.bias_n primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pan185/UnarySim
HardMGUCellNUA
false
7,457
[ "MIT" ]
1
c03386efdbb8151f3c33f34b44d1d6a6fc960434
https://github.com/pan185/UnarySim/tree/c03386efdbb8151f3c33f34b44d1d6a6fc960434
UnpackLayerConv2d
import torch import torch.nn as nn class Conv2D(nn.Module): """ 2D convolution with GroupNorm and ELU Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size stride : int Stride """ def __init__(self, in_channels, out_channels, kernel_size, stride): super().__init__() self.kernel_size = kernel_size self.conv_base = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride) self.pad = nn.ConstantPad2d([kernel_size // 2] * 4, value=0) self.normalize = torch.nn.GroupNorm(16, out_channels) self.activ = nn.ELU(inplace=True) def forward(self, x): """Runs the Conv2D layer.""" x = self.conv_base(self.pad(x)) return self.activ(self.normalize(x)) class UnpackLayerConv2d(nn.Module): """ Unpacking layer with 2d convolutions. Takes a [B,C,H,W] tensor, convolves it to produce [B,(r^2)C,H,W] and then unpacks it to produce [B,C,rH,rW]. """ def __init__(self, in_channels, out_channels, kernel_size, r=2): """ Initializes a UnpackLayerConv2d object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size r : int Packing ratio """ super().__init__() self.conv = Conv2D(in_channels, out_channels * r ** 2, kernel_size, 1) self.unpack = nn.PixelShuffle(r) def forward(self, x): """Runs the UnpackLayerConv2d layer.""" x = self.conv(x) x = self.unpack(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 8 % 8 x0 = xindex % 8 x2 = xindex // 64 x4 = xindex tmp0 = -2 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 4, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -2 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-10 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask, other=0.0) tl.store(out_ptr0 + x4, tmp11, xmask) @triton.jit def triton_per_fused_convolution_native_group_norm_pixel_shuffle_1(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr): xnumel = 64 rnumel = 25 RBLOCK: tl.constexpr = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel rindex = tl.arange(0, RBLOCK)[None, :] rmask = rindex < rnumel r2 = rindex x3 = xindex x0 = xindex % 16 r7 = rindex % 5 r8 = rindex // 5 x4 = xindex % 2 x5 = xindex // 2 % 2 x6 = xindex // 4 tmp0 = tl.load(in_out_ptr0 + (r2 + 25 * x3), rmask & xmask, other=0.0) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp26 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp28 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK]) tl.where(rmask & xmask, tmp3, 0) tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK]) tmp8 = tl.where(rmask & xmask, tmp6, 0) tmp9 = tl.sum(tmp8, 1)[:, None] tmp10 = tl.full([XBLOCK, 1], 25, tl.int32) tmp11 = tmp10.to(tl.float32) tmp12 = tmp9 / tmp11 tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK]) tmp17 = tl.where(rmask & xmask, tmp15, 0) tmp18 = tl.sum(tmp17, 1)[:, None] tmp19 = 25.0 tmp20 = tmp18 / tmp19 tmp21 = 1e-05 tmp22 = tmp20 + tmp21 tmp23 = libdevice.rsqrt(tmp22) tmp24 = tmp2 - tmp12 tmp25 = tmp24 * tmp23 tmp27 = tmp25 * tmp26 tmp29 = tmp27 + tmp28 tmp30 = 0.0 tmp31 = tmp29 > tmp30 tmp32 = 1.0 tmp33 = tmp29 * tmp32 tmp34 = libdevice.expm1(tmp33) tmp35 = tmp34 * tmp32 tmp36 = tl.where(tmp31, tmp33, tmp35) tl.store(in_out_ptr0 + (r2 + 25 * x3), tmp2, rmask & xmask) tl.debug_barrier() tl.store(in_out_ptr1 + x3, tmp23, xmask) tl.store(out_ptr2 + (x4 + 2 * r7 + 10 * x5 + 20 * r8 + 100 * x6), tmp36, rmask & xmask) tl.store(out_ptr0 + x3, tmp12, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (16, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (16,), (1,)) assert_size_stride(primals_5, (16,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32) get_raw_stream(0) triton_poi_fused_constant_pad_nd_0[grid(1024)](primals_1, buf0, 1024, XBLOCK=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, 16, 5, 5), (400, 25, 5, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 1, 1), torch.float32) buf4 = empty_strided_cuda((4, 16, 1, 1), (16, 1, 64, 64), torch.float32 ) buf6 = reinterpret_tensor(buf4, (4, 16, 1, 1), (16, 1, 1, 1), 0) del buf4 buf8 = empty_strided_cuda((4, 4, 5, 2, 5, 2), (400, 100, 20, 10, 2, 1), torch.float32) triton_per_fused_convolution_native_group_norm_pixel_shuffle_1[grid(64) ](buf2, buf6, primals_3, primals_4, primals_5, buf3, buf8, 64, 25, XBLOCK=8, num_warps=2, num_stages=1) del primals_3 return reinterpret_tensor(buf8, (4, 4, 10, 10), (400, 100, 10, 1), 0 ), primals_2, primals_4, primals_5, buf0, buf2, buf3, buf6 class Conv2D(nn.Module): """ 2D convolution with GroupNorm and ELU Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size stride : int Stride """ def __init__(self, in_channels, out_channels, kernel_size, stride): super().__init__() self.kernel_size = kernel_size self.conv_base = nn.Conv2d(in_channels, out_channels, kernel_size= kernel_size, stride=stride) self.pad = nn.ConstantPad2d([kernel_size // 2] * 4, value=0) self.normalize = torch.nn.GroupNorm(16, out_channels) self.activ = nn.ELU(inplace=True) def forward(self, x): """Runs the Conv2D layer.""" x = self.conv_base(self.pad(x)) return self.activ(self.normalize(x)) class UnpackLayerConv2dNew(nn.Module): """ Unpacking layer with 2d convolutions. Takes a [B,C,H,W] tensor, convolves it to produce [B,(r^2)C,H,W] and then unpacks it to produce [B,C,rH,rW]. """ def __init__(self, in_channels, out_channels, kernel_size, r=2): """ Initializes a UnpackLayerConv2d object. Parameters ---------- in_channels : int Number of input channels out_channels : int Number of output channels kernel_size : int Kernel size r : int Packing ratio """ super().__init__() self.conv = Conv2D(in_channels, out_channels * r ** 2, kernel_size, 1) self.unpack = nn.PixelShuffle(r) def forward(self, input_0): primals_2 = self.conv.conv_base.weight primals_3 = self.conv.conv_base.bias primals_4 = self.conv.normalize.weight primals_5 = self.conv.normalize.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pection/packnet-sfm
UnpackLayerConv2d
false
7,459
[ "MIT" ]
1
d5673567b649e6bfda292c894cacdeb06aa80913
https://github.com/pection/packnet-sfm/tree/d5673567b649e6bfda292c894cacdeb06aa80913
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]
piggy2303/DeepFillv2_Pytorch
Conv2dLayer
false
7,460
[ "MIT" ]
1
dd35299f11704f878ed7a33e14ccd51a9d64baaf
https://github.com/piggy2303/DeepFillv2_Pytorch/tree/dd35299f11704f878ed7a33e14ccd51a9d64baaf
Contracting_Block
import torch import torch.nn as nn import torch.nn.functional as F class Contracting_Block(nn.Module): def __init__(self, in_channels, out_channels): super(Contracting_Block, self).__init__() self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3) self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3) self.max_pool = nn.MaxPool2d(kernel_size=2, stride=2) def forward(self, x): x = F.relu(self.conv1(x)) x = F.relu(self.conv2(x)) x = self.max_pool(x) return x def get_inputs(): return [torch.rand([4, 4, 64, 64])] 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.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 = 61504 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3844 % 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_1(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 57600 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x3 = xindex x1 = xindex // 3600 % 4 x0 = xindex % 3600 x4 = xindex // 3600 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 + 3616 * x4), tmp4, xmask) @triton.jit def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 14400 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 30 x1 = xindex // 30 % 30 x2 = xindex // 900 x5 = xindex x4 = xindex // 3600 x6 = xindex % 3600 tmp0 = tl.load(in_ptr0 + (2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (60 + 2 * x0 + 120 * x1 + 3616 * x2), xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr0 + (61 + 2 * x0 + 120 * x1 + 3616 * 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 + x5, tmp6, xmask) tl.store(out_ptr1 + (x6 + 3712 * x4), tmp16, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 64, 64), (16384, 4096, 64, 1)) assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf0, (4, 4, 62, 62), (15376, 3844, 62, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(61504)](buf1, primals_2, 61504, 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, 60, 60), (14400, 3600, 60, 1)) buf3 = empty_strided_cuda((4, 4, 60, 60), (14464, 3616, 60, 1), torch.float32) triton_poi_fused_convolution_relu_1[grid(57600)](buf2, primals_5, buf3, 57600, XBLOCK=256, num_warps=4, num_stages=1) del buf2 del primals_5 buf4 = empty_strided_cuda((4, 4, 30, 30), (3600, 900, 30, 1), torch .float32) buf5 = empty_strided_cuda((4, 4, 30, 30), (3712, 900, 30, 1), torch .int8) triton_poi_fused_max_pool2d_with_indices_2[grid(14400)](buf3, buf4, buf5, 14400, XBLOCK=256, num_warps=4, num_stages=1) return buf4, primals_1, primals_3, primals_4, buf1, buf3, buf5 class Contracting_BlockNew(nn.Module): def __init__(self, in_channels, out_channels): super(Contracting_BlockNew, self).__init__() self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3) self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3) self.max_pool = nn.MaxPool2d(kernel_size=2, stride=2) 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]
parth2035/U-Net-Implementation
Contracting_Block
false
7,461
[ "MIT" ]
1
36ed8d140ef8a0031f63f2d1f577dcef92c4dab6
https://github.com/parth2035/U-Net-Implementation/tree/36ed8d140ef8a0031f63f2d1f577dcef92c4dab6
Differencial_SMAPE
import torch import torch.nn as nn class Differencial_SMAPE(nn.Module): def __init__(self): super(Differencial_SMAPE, self).__init__() def forward(self, true, predicted): epsilon = 0.1 summ = torch.clamp(torch.abs(true) + torch.abs(predicted) + epsilon, min=0.5 + epsilon) smape = torch.abs(predicted - true) / summ * 2.0 return torch.sum(smape) def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import math as tl_math import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_per_fused_abs_add_clamp_div_mul_sub_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, rnumel): XBLOCK: tl.constexpr = 1 RBLOCK: tl.constexpr = 256 xoffset = tl.program_id(0) * XBLOCK tl.full([1], xoffset, tl.int32) tl.full([RBLOCK], True, tl.int1) rindex = tl.arange(0, RBLOCK)[:] tl.full([RBLOCK], True, tl.int1) r0 = rindex tmp0 = tl.load(in_ptr0 + r0, None) tmp1 = tl.load(in_ptr1 + r0, None) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = tl_math.abs(tmp1) tmp5 = tl_math.abs(tmp0) tmp6 = tmp4 + tmp5 tmp7 = 0.1 tmp8 = tmp6 + tmp7 tmp9 = 0.6 tmp10 = triton_helpers.maximum(tmp8, tmp9) tmp11 = tmp3 / tmp10 tmp12 = 2.0 tmp13 = tmp11 * tmp12 tmp14 = tl.broadcast_to(tmp13, [RBLOCK]) tmp16 = triton_helpers.promote_to_tensor(tl.sum(tmp14, 0)) tl.store(out_ptr0 + tl.full([1], 0, tl.int32), tmp16, None) def call(args): arg0_1, arg1_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((), (), torch.float32) get_raw_stream(0) triton_per_fused_abs_add_clamp_div_mul_sub_sum_0[grid(1)](arg1_1, arg0_1, buf0, 1, 256, num_warps=2, num_stages=1) del arg0_1 del arg1_1 return buf0, class Differencial_SMAPENew(nn.Module): def __init__(self): super(Differencial_SMAPENew, 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]
pixel-ports/PV_prod_predic
Differencial_SMAPE
false
7,462
[ "Apache-2.0" ]
1
2ceb4cf8218f43f3ea94c5520b1904663cfb0de1
https://github.com/pixel-ports/PV_prod_predic/tree/2ceb4cf8218f43f3ea94c5520b1904663cfb0de1
HardMGUCellPT
import math import torch from torch import Tensor import torch.nn as nn import torch.nn.functional as F from typing import Optional import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardMGUCellPT(torch.nn.RNNCellBase): """ This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details. Hardtanh is to bound data to the legal unary range. This module is fully unary computing aware, i.e., all intermediate data are bounded to the legal unary range. This module follows the PyTorch implementation style (PT). """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardMGUCellPT, self).__init__(input_size, hidden_size, bias, num_chunks=2) self.hard = hard if hard is True: self.forgetgate_sigmoid = ScaleHardsigmoid() self.newgate_tanh = nn.Hardtanh() else: self.forgetgate_sigmoid = nn.Sigmoid() self.newgate_tanh = nn.Tanh() self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input: 'Tensor', hx: 'Optional[Tensor]'=None) ->Tensor: if hx is None: hx = torch.zeros(input.size()[0], self.hidden_size, dtype=input .dtype, device=input.device) self.gate_i = nn.Hardtanh()(F.linear(input, self.weight_ih, self. bias_ih)) self.gate_h = nn.Hardtanh()(F.linear(hx, self.weight_hh, self.bias_hh)) self.i_f, self.i_n = self.gate_i.chunk(2, 1) self.h_f, self.h_n = self.gate_h.chunk(2, 1) self.forgetgate_in = nn.Hardtanh()(self.i_f + self.h_f) self.forgetgate = self.forgetgate_sigmoid(self.forgetgate_in) self.newgate_prod = self.forgetgate * self.h_n self.newgate = self.newgate_tanh(self.i_n + self.newgate_prod) self.forgetgate_inv_prod = (0 - self.forgetgate) * self.newgate self.forgetgate_prod = self.forgetgate * hx hy = nn.Hardtanh()(self.newgate + self.forgetgate_inv_prod + self. forgetgate_prod) return hy def get_inputs(): return [torch.rand([4, 4])] def get_init_inputs(): return [[], {'input_size': 4, 'hidden_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers import math import torch.nn as nn import torch.nn.parallel import torch.optim import torch.utils.data import torch.utils.data.distributed assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_zeros_0(out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = 0.0 tl.store(out_ptr0 + x0, tmp0, xmask) @triton.jit def triton_poi_fused_hardtanh_hardtanh_backward_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 32 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 8 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = -1.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 1.0 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = tmp2 <= tmp3 tmp8 = tmp2 >= tmp5 tmp9 = tmp7 | tmp8 tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(out_ptr1 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2( in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_ptr2, out_ptr3, out_ptr4, out_ptr5, out_ptr6, out_ptr7, out_ptr8, out_ptr9, out_ptr10, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr1 + (x0 + 8 * x1), xmask) tmp19 = tl.load(in_ptr1 + (4 + x0 + 8 * x1), xmask) tmp21 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp2 = tmp0 + tmp1 tmp3 = -1.0 tmp4 = triton_helpers.maximum(tmp2, tmp3) tmp5 = 1.0 tmp6 = triton_helpers.minimum(tmp4, tmp5) tmp7 = tmp2 <= tmp3 tmp8 = tmp2 >= tmp5 tmp9 = tmp7 | tmp8 tmp10 = 3.0 tmp11 = tmp6 * tmp10 tmp12 = tmp11 + tmp10 tmp13 = 0.0 tmp14 = triton_helpers.maximum(tmp12, tmp13) tmp15 = 6.0 tmp16 = triton_helpers.minimum(tmp14, tmp15) tmp17 = 0.16666666666666666 tmp18 = tmp16 * tmp17 tmp20 = tmp18 * tmp19 tmp22 = tmp21 + tmp20 tmp23 = triton_helpers.maximum(tmp22, tmp3) tmp24 = triton_helpers.minimum(tmp23, tmp5) tmp25 = tmp22 <= tmp3 tmp26 = tmp22 >= tmp5 tmp27 = tmp25 | tmp26 tmp28 = tmp18 * tmp13 tmp29 = tmp13 - tmp18 tmp30 = tmp29 * tmp24 tmp31 = tmp24 + tmp30 tmp32 = tmp31 + tmp28 tmp33 = triton_helpers.maximum(tmp32, tmp3) tmp34 = triton_helpers.minimum(tmp33, tmp5) tmp35 = tmp32 <= tmp3 tmp36 = tmp32 >= tmp5 tmp37 = tmp35 | tmp36 tmp38 = -3.0 tmp39 = tmp11 > tmp38 tmp40 = tmp11 < tmp10 tmp41 = tmp39 & tmp40 tl.store(out_ptr0 + x2, tmp6, xmask) tl.store(out_ptr1 + x2, tmp9, xmask) tl.store(out_ptr2 + x2, tmp18, xmask) tl.store(out_ptr3 + x2, tmp20, xmask) tl.store(out_ptr4 + x2, tmp24, xmask) tl.store(out_ptr5 + x2, tmp27, xmask) tl.store(out_ptr6 + x2, tmp28, xmask) tl.store(out_ptr7 + x2, tmp30, xmask) tl.store(out_ptr8 + x2, tmp34, xmask) tl.store(out_ptr9 + x2, tmp37, xmask) tl.store(out_ptr10 + x2, tmp41, 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, (8, 4), (4, 1)) assert_size_stride(primals_3, (8,), (1,)) assert_size_stride(primals_4, (8, 4), (4, 1)) assert_size_stride(primals_5, (8,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_zeros_0[grid(16)](buf0, 16, XBLOCK=16, num_warps=1, num_stages=1) buf1 = empty_strided_cuda((4, 8), (8, 1), torch.float32) extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 8), (1, 4), 0), out=buf1) del primals_2 buf2 = empty_strided_cuda((4, 8), (8, 1), torch.float32) buf17 = empty_strided_cuda((4, 8), (8, 1), torch.bool) triton_poi_fused_hardtanh_hardtanh_backward_1[grid(32)](buf1, primals_3, buf2, buf17, 32, XBLOCK=32, num_warps=1, num_stages=1) del primals_3 buf3 = buf1 del buf1 extern_kernels.mm(buf0, reinterpret_tensor(primals_4, (4, 8), (1, 4 ), 0), out=buf3) del primals_4 buf4 = empty_strided_cuda((4, 8), (8, 1), torch.float32) buf16 = empty_strided_cuda((4, 8), (8, 1), torch.bool) triton_poi_fused_hardtanh_hardtanh_backward_1[grid(32)](buf3, primals_5, buf4, buf16, 32, XBLOCK=32, num_warps=1, num_stages=1) del buf3 del primals_5 buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf15 = empty_strided_cuda((4, 4), (4, 1), torch.bool) buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf7 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf8 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf13 = empty_strided_cuda((4, 4), (4, 1), torch.bool) buf10 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf11 = empty_strided_cuda((4, 4), (4, 1), torch.float32) buf12 = empty_strided_cuda((4, 4), (4, 1), torch.bool) buf14 = empty_strided_cuda((4, 4), (4, 1), torch.bool) triton_poi_fused_add_hardsigmoid_hardsigmoid_backward_hardtanh_hardtanh_backward_mul_rsub_2[ grid(16)](buf2, buf4, buf5, buf15, buf6, buf7, buf8, buf13, buf10, buf9, buf11, buf12, buf14, 16, XBLOCK=16, num_warps=1, num_stages=1) return buf11, buf10, buf9, buf8, buf7, buf6, buf5, reinterpret_tensor(buf4, (4, 4), (8, 1), 4), reinterpret_tensor(buf4, (4, 4), (8, 1), 0 ), reinterpret_tensor(buf2, (4, 4), (8, 1), 4), reinterpret_tensor(buf2 , (4, 4), (8, 1), 0), buf4, buf2, primals_1, buf0, reinterpret_tensor( buf4, (4, 4), (8, 1), 4 ), buf6, buf8, buf12, buf13, buf14, buf15, buf16, buf17 def truncated_normal(t, mean=0.0, std=0.01): torch.nn.init.normal_(t, mean=mean, std=std) while True: cond = torch.logical_or(t < mean - 2 * std, t > mean + 2 * std) if torch.sum(cond): t = torch.where(cond, torch.nn.init.normal_(torch.ones_like(t), mean=mean, std=std), t) else: break return t class ScaleHardsigmoid(torch.nn.Module): """ This is a scaled addition (x+1)/2. """ def __init__(self, scale=3): super(ScaleHardsigmoid, self).__init__() self.scale = scale def forward(self, x) ->str: return torch.nn.Hardsigmoid()(x * self.scale) class HardMGUCellPTNew(torch.nn.RNNCellBase): """ This is a minimal gated unit by replacing sigmoid and tanh with scalehardsigmoid and hardtanh if hard is set to True. Batch is always the dim[0]. Refer to "Simplified Minimal Gated Unit Variations for Recurrent Neural Networks" and "Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks" for more details. Hardtanh is to bound data to the legal unary range. This module is fully unary computing aware, i.e., all intermediate data are bounded to the legal unary range. This module follows the PyTorch implementation style (PT). """ def __init__(self, input_size: 'int', hidden_size: 'int', bias: 'bool'= True, hard: 'bool'=True) ->None: super(HardMGUCellPTNew, self).__init__(input_size, hidden_size, bias, num_chunks=2) self.hard = hard if hard is True: self.forgetgate_sigmoid = ScaleHardsigmoid() self.newgate_tanh = nn.Hardtanh() else: self.forgetgate_sigmoid = nn.Sigmoid() self.newgate_tanh = nn.Tanh() self.reset_parameters() def reset_parameters(self): stdv = 1.0 / math.sqrt(self.hidden_size) for weight in self.parameters(): weight.data = truncated_normal(weight, mean=0, std=stdv) def forward(self, input_0): primals_2 = self.weight_ih primals_4 = self.weight_hh primals_3 = self.bias_ih primals_5 = self.bias_hh primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pan185/UnarySim
HardMGUCellPT
false
7,463
[ "MIT" ]
1
c03386efdbb8151f3c33f34b44d1d6a6fc960434
https://github.com/pan185/UnarySim/tree/c03386efdbb8151f3c33f34b44d1d6a6fc960434
BertMixedLayer
from _paritybench_helpers import _mock_config import math import torch import torch.nn import torch.nn as nn class BertAttention(nn.Module): """BERT attention layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, context): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(context) mixed_value_layer = self.value(context) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_probs = self.dropout(nn.Softmax(dim=-1)(attention_scores)) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) return context_layer class BertOutput(nn.Module): """BERT output layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = torch.nn.LayerNorm(config.hidden_size, eps=1e-12) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states class BertMixedLayer(nn.Module): """BERT cross attention layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.att_x = BertAttention(config) self.output_x = BertOutput(config) self.att_y = BertAttention(config) self.output_y = BertOutput(config) def forward(self, x, y): output_x = self.att_x(x, y) output_y = self.att_y(y, x) return self.output_x(output_x, x), self.output_y(output_y, y) def get_inputs(): return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(num_attention_heads=4, hidden_size= 4, attention_probs_dropout_prob=0.5, hidden_dropout_prob=0.5)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import math import torch.nn import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = 1.0 tmp4 = tmp2 * tmp3 tl.store(out_ptr0 + (x2 + 4 * y3), tmp4, xmask & ymask) @triton.jit def triton_poi_fused_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last') tmp3 = triton_helpers.maximum(tmp1, tmp2) tmp5 = triton_helpers.maximum(tmp3, tmp4) tmp7 = triton_helpers.maximum(tmp5, tmp6) tmp8 = tmp0 - tmp7 tmp9 = tl_math.exp(tmp8) tl.store(out_ptr0 + x2, tmp9, xmask) @triton.jit def triton_poi_fused_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last') tmp6 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp18 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp25 = tl.load(in_ptr1 + x2, xmask) tmp26 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last') tmp27 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp29 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp31 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last' ) tmp1 = float('-inf') tmp2 = tmp0 == tmp1 tmp3 = tmp2 == 0 tmp4 = tmp3.to(tl.int64) tmp5 = tmp4 != 0 tmp7 = tmp6 == tmp1 tmp8 = tmp7 == 0 tmp9 = tmp8.to(tl.int64) tmp10 = tmp9 != 0 tmp11 = tmp5 | tmp10 tmp13 = tmp12 == tmp1 tmp14 = tmp13 == 0 tmp15 = tmp14.to(tl.int64) tmp16 = tmp15 != 0 tmp17 = tmp11 | tmp16 tmp19 = tmp18 == tmp1 tmp20 = tmp19 == 0 tmp21 = tmp20.to(tl.int64) tmp22 = tmp21 != 0 tmp23 = tmp17 | tmp22 tmp24 = tmp23 == 0 tmp28 = tmp26 + tmp27 tmp30 = tmp28 + tmp29 tmp32 = tmp30 + tmp31 tmp33 = tmp25 / tmp32 tmp34 = 0.0 tmp35 = tl.where(tmp24, tmp34, tmp33) tl.store(out_ptr0 + x2, tmp35, xmask) @triton.jit def triton_poi_fused_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask) @triton.jit def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl. constexpr, XBLOCK: tl.constexpr): ynumel = 16 xnumel = 4 yoffset = tl.program_id(1) * YBLOCK yindex = yoffset + tl.arange(0, YBLOCK)[None, :] ymask = yindex < ynumel xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:, None] xmask = xindex < xnumel x2 = xindex y0 = yindex % 4 y1 = yindex // 4 y3 = yindex tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask, eviction_policy='evict_last') tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask) @triton.jit def triton_poi_fused_add_native_layer_norm_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 16 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last') tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last') tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last') tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last' ) tmp2 = tmp0 + tmp1 tmp5 = tmp3 + tmp4 tmp6 = tmp2 + tmp5 tmp9 = tmp7 + tmp8 tmp10 = tmp6 + tmp9 tmp13 = tmp11 + tmp12 tmp14 = tmp10 + tmp13 tmp15 = 4.0 tmp16 = tmp14 / tmp15 tmp17 = tmp2 - tmp16 tmp18 = tmp17 * tmp17 tmp19 = tmp5 - tmp16 tmp20 = tmp19 * tmp19 tmp21 = tmp18 + tmp20 tmp22 = tmp9 - tmp16 tmp23 = tmp22 * tmp22 tmp24 = tmp21 + tmp23 tmp25 = tmp13 - tmp16 tmp26 = tmp25 * tmp25 tmp27 = tmp24 + tmp26 tmp28 = tmp27 / tmp15 tl.store(out_ptr0 + x0, tmp16, xmask) tl.store(out_ptr1 + x0, tmp28, xmask) @triton.jit def triton_poi_fused_add_native_layer_norm_6(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x1 = xindex // 4 x0 = xindex % 4 tmp0 = tl.load(in_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr1 + x2, xmask) tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last') tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp4 = tmp2 - tmp3 tmp6 = 1e-12 tmp7 = tmp5 + tmp6 tmp8 = libdevice.rsqrt(tmp7) tmp9 = tmp4 * tmp8 tmp11 = tmp9 * tmp10 tmp13 = tmp11 + tmp12 tl.store(out_ptr0 + x2, tmp13, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7, primals_8, primals_9, 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) = args args.clear() assert_size_stride(primals_1, (4, 4), (4, 1)) assert_size_stride(primals_2, (4,), (1,)) assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) assert_size_stride(primals_6, (4, 4, 4), (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,)) assert_size_stride(primals_17, (4,), (1,)) assert_size_stride(primals_18, (4,), (1,)) assert_size_stride(primals_19, (4, 4), (4, 1)) assert_size_stride(primals_20, (4,), (1,)) assert_size_stride(primals_21, (4,), (1,)) assert_size_stride(primals_22, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (16, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (16, 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, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_0[grid(16, 4)](buf0, primals_2, buf3, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_2 buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf0 triton_poi_fused_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_5 buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32) extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5) buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_1[grid(256)](buf5, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1) buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_2[grid(256)](buf5, buf6, buf7, 256, XBLOCK=128, num_warps=4, num_stages=1) buf8 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf1 triton_poi_fused_3[grid(16, 4)](buf2, primals_8, buf8, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del primals_8 buf9 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0) del buf2 extern_kernels.bmm(reinterpret_tensor(buf7, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf8, (16, 4, 1), (4, 1, 0), 0), out=buf9) buf10 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_6, (16, 4), (4, 1), 0), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf10) del primals_9 buf11 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf11) del primals_11 buf12 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(primals_3, (16, 4), (4, 1), 0), reinterpret_tensor(primals_13, (4, 4), (1, 4), 0), out=buf12) del primals_13 buf13 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_0[grid(16, 4)](buf10, primals_10, buf13, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_10 buf14 = reinterpret_tensor(buf10, (4, 4, 1, 4), (16, 4, 4, 1), 0) del buf10 triton_poi_fused_0[grid(16, 4)](buf11, primals_12, buf14, 16, 4, XBLOCK=4, YBLOCK=8, num_warps=1, num_stages=1) del primals_12 buf15 = reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0) del buf6 extern_kernels.bmm(reinterpret_tensor(buf13, (16, 4, 1), (4, 1, 0), 0), reinterpret_tensor(buf14, (16, 1, 4), (4, 0, 1), 0), out=buf15) buf16 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0) del buf5 triton_poi_fused_1[grid(256)](buf15, buf16, 256, XBLOCK=128, num_warps=4, num_stages=1) buf17 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) triton_poi_fused_2[grid(256)](buf15, buf16, buf17, 256, XBLOCK=128, num_warps=4, num_stages=1) del buf15 del buf16 buf18 = reinterpret_tensor(buf11, (4, 4, 4, 1), (16, 4, 1, 1), 0) del buf11 triton_poi_fused_3[grid(16, 4)](buf12, primals_14, buf18, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) del primals_14 buf19 = reinterpret_tensor(buf12, (16, 4, 1), (4, 1, 1), 0) del buf12 extern_kernels.bmm(reinterpret_tensor(buf17, (16, 4, 4), (16, 4, 1), 0), reinterpret_tensor(buf18, (16, 4, 1), (4, 1, 0), 0), out=buf19) buf20 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_4[grid(16, 4)](buf9, buf20, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf21 = reinterpret_tensor(buf9, (16, 4), (4, 1), 0) del buf9 extern_kernels.addmm(primals_16, reinterpret_tensor(buf20, (16, 4), (4, 1), 0), reinterpret_tensor(primals_15, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf21) del primals_16 buf22 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) buf23 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32) triton_poi_fused_add_native_layer_norm_5[grid(16)](buf21, primals_3, buf22, buf23, 16, XBLOCK=16, num_warps=1, num_stages=1) buf24 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_6[grid(64)](buf21, primals_3, buf22, buf23, primals_17, primals_18, buf24, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_18 buf25 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_clone_4[grid(16, 4)](buf19, buf25, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1) buf26 = reinterpret_tensor(buf19, (16, 4), (4, 1), 0) del buf19 extern_kernels.addmm(primals_20, reinterpret_tensor(buf25, (16, 4), (4, 1), 0), reinterpret_tensor(primals_19, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf26) del primals_20 buf27 = buf23 del buf23 buf28 = buf22 del buf22 triton_poi_fused_add_native_layer_norm_5[grid(16)](buf26, primals_6, buf27, buf28, 16, XBLOCK=16, num_warps=1, num_stages=1) buf29 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) triton_poi_fused_add_native_layer_norm_6[grid(64)](buf26, primals_6, buf27, buf28, primals_21, primals_22, buf29, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf27 del buf28 del primals_22 return (buf24, buf29, primals_3, primals_6, primals_17, primals_21, buf7, reinterpret_tensor(buf8, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0), buf17, reinterpret_tensor(buf18, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf13, (16, 1, 4), (4, 1, 1), 0), reinterpret_tensor(buf14, (16, 4, 1), (4, 1, 4), 0), reinterpret_tensor(buf20, (16, 4), (4, 1), 0), buf21, reinterpret_tensor(buf25, (16, 4), (4, 1), 0), buf26, primals_19, primals_15) class BertAttention(nn.Module): """BERT attention layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.num_attention_heads = config.num_attention_heads self.attention_head_size = int(config.hidden_size / config. num_attention_heads) self.all_head_size = (self.num_attention_heads * self. attention_head_size) self.query = nn.Linear(config.hidden_size, self.all_head_size) self.key = nn.Linear(config.hidden_size, self.all_head_size) self.value = nn.Linear(config.hidden_size, self.all_head_size) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def transpose_for_scores(self, x): new_x_shape = x.size()[:-1] + (self.num_attention_heads, self. attention_head_size) x = x.view(*new_x_shape) return x.permute(0, 2, 1, 3) def forward(self, hidden_states, context): mixed_query_layer = self.query(hidden_states) mixed_key_layer = self.key(context) mixed_value_layer = self.value(context) query_layer = self.transpose_for_scores(mixed_query_layer) key_layer = self.transpose_for_scores(mixed_key_layer) value_layer = self.transpose_for_scores(mixed_value_layer) attention_scores = torch.matmul(query_layer, key_layer.transpose(-1, -2)) attention_scores = attention_scores / math.sqrt(self. attention_head_size) attention_probs = self.dropout(nn.Softmax(dim=-1)(attention_scores)) context_layer = torch.matmul(attention_probs, value_layer) context_layer = context_layer.permute(0, 2, 1, 3).contiguous() new_context_layer_shape = context_layer.size()[:-2] + (self. all_head_size,) context_layer = context_layer.view(*new_context_layer_shape) return context_layer class BertOutput(nn.Module): """BERT output layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = torch.nn.LayerNorm(config.hidden_size, eps=1e-12) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states, input_tensor): hidden_states = self.dense(hidden_states) hidden_states = self.dropout(hidden_states) hidden_states = self.LayerNorm(hidden_states + input_tensor) return hidden_states class BertMixedLayerNew(nn.Module): """BERT cross attention layer. Based on: BERT (pytorch-transformer) https://github.com/huggingface/transformers """ def __init__(self, config) ->None: super().__init__() self.att_x = BertAttention(config) self.output_x = BertOutput(config) self.att_y = BertAttention(config) self.output_y = BertOutput(config) def forward(self, input_0, input_1): primals_1 = self.att_x.query.weight primals_2 = self.att_x.query.bias primals_4 = self.att_x.key.weight primals_5 = self.att_x.key.bias primals_7 = self.att_x.value.weight primals_8 = self.att_x.value.bias primals_9 = self.output_x.dense.weight primals_10 = self.output_x.dense.bias primals_12 = self.output_x.LayerNorm.weight primals_14 = self.output_x.LayerNorm.bias primals_11 = self.att_y.query.weight primals_16 = self.att_y.query.bias primals_13 = self.att_y.key.weight primals_17 = self.att_y.key.bias primals_15 = self.att_y.value.weight primals_18 = self.att_y.value.bias primals_19 = self.output_y.dense.weight primals_20 = self.output_y.dense.bias primals_21 = self.output_y.LayerNorm.weight primals_22 = self.output_y.LayerNorm.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, primals_17, primals_18, primals_19, primals_20, primals_21, primals_22]) return output[0], output[1]
Jianrong-Lu/MONAI
BertMixedLayer
false
7,464
[ "Apache-2.0" ]
1
c319ca8ff31aa980a045f1b913fb2eb22aadb080
https://github.com/Jianrong-Lu/MONAI/tree/c319ca8ff31aa980a045f1b913fb2eb22aadb080
SmoothL1Loss
import torch import torch.nn as nn import torch.cuda import torch.distributed import torch.multiprocessing class SmoothL1Loss(nn.Module): """Smooth L1 Loss""" def __init__(self, beta=0.11): super().__init__() self.beta = beta def forward(self, pred, target): x = (pred - target).abs() l1 = x - 0.5 * self.beta l2 = 0.5 * x ** 2 / self.beta return torch.where(x >= self.beta, l1, l2) 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 import torch.cuda import torch.distributed import torch.multiprocessing assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda @triton.jit def triton_poi_fused_abs_div_ge_mul_pow_sub_where_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex tmp0 = tl.load(in_ptr0 + x0, xmask) tmp1 = tl.load(in_ptr1 + x0, xmask) tmp2 = tmp0 - tmp1 tmp3 = tl_math.abs(tmp2) tmp4 = 0.11 tmp5 = tmp3 >= tmp4 tmp6 = 0.055 tmp7 = tmp3 - tmp6 tmp8 = tmp3 * tmp3 tmp9 = 0.5 tmp10 = tmp8 * tmp9 tmp11 = 9.090909090909092 tmp12 = tmp10 * tmp11 tmp13 = tl.where(tmp5, tmp7, tmp12) tl.store(out_ptr0 + x0, tmp13, 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_abs_div_ge_mul_pow_sub_where_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 SmoothL1LossNew(nn.Module): """Smooth L1 Loss""" def __init__(self, beta=0.11): super().__init__() self.beta = beta def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
pkashinkunti/retinanet-examples
SmoothL1Loss
false
7,465
[ "BSD-3-Clause" ]
1
30466522c018d4d0bd921485024e871b32ec4e73
https://github.com/pkashinkunti/retinanet-examples/tree/30466522c018d4d0bd921485024e871b32ec4e73
ConvBatchNorm2d
import torch import torch.nn as nn class ConvBatchNorm2d(nn.BatchNorm2d): def __init__(self, num_features, momentum=0.9, epsilon=1e-05): """ input: assume 4D input (mini_batch_size, # channel, w, h) momentum: momentum for exponential average """ super(nn.BatchNorm2d, self).__init__(num_features) self.momentum = momentum self.insize = num_features self.epsilon = epsilon self.register_buffer('running_mean', torch.zeros(self.insize)) self.register_buffer('running_var', torch.ones(self.insize)) self.reset_parameters() def reset_parameters(self): self.running_mean.zero_() self.running_var.fill_(1) def forward(self, x, gamma=None, beta=None): if self.training is True: mean = x.mean([0, 2, 3]) var = x.var([0, 2, 3]) if self.track_running_stats is True: with torch.no_grad(): self.running_mean = self.momentum * self.running_mean + ( 1.0 - self.momentum) * mean self.running_var = self.momentum * self.running_var + ( 1.0 - self.momentum) * (x.shape[0] / (x.shape[0] - 1) * var) else: mean = self.running_mean var = self.running_var current_mean = mean.view([1, self.insize, 1, 1]).expand_as(x) current_var = var.view([1, self.insize, 1, 1]).expand_as(x) x = x - current_mean x = x / (current_var + self.eps) ** 0.5 return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_features': 4}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn 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_pow_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 x3 = xindex x1 = xindex // 16 % 4 tmp0 = tl.load(in_ptr0 + x3, xmask) tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last') tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last') tmp2 = tmp0 - tmp1 tmp4 = 1e-05 tmp5 = tmp3 + tmp4 tmp6 = libdevice.sqrt(tmp5) tmp7 = tmp2 / tmp6 tl.store(out_ptr0 + x3, tmp7, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4,), (1,)) assert_size_stride(arg1_1, (4,), (1,)) assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_add_div_pow_sub_0[grid(256)](arg2_1, arg0_1, arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 del arg1_1 del arg2_1 return buf0, class ConvBatchNorm2dNew(nn.BatchNorm2d): def __init__(self, num_features, momentum=0.9, epsilon=1e-05): """ input: assume 4D input (mini_batch_size, # channel, w, h) momentum: momentum for exponential average """ super(nn.BatchNorm2d, self).__init__(num_features) self.momentum = momentum self.insize = num_features self.epsilon = epsilon self.register_buffer('running_mean', torch.zeros(self.insize)) self.register_buffer('running_var', torch.ones(self.insize)) self.reset_parameters() def reset_parameters(self): self.running_mean.zero_() self.running_var.fill_(1) def forward(self, input_0): arg0_1 = self.weight arg1_1 = self.bias arg2_1 = input_0 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
pigunther/Self-Correction-Human-Parsing-Updated
ConvBatchNorm2d
false
7,466
[ "MIT" ]
1
17331eaa5d6586a1ebb633eb61ed810d00d30a2f
https://github.com/pigunther/Self-Correction-Human-Parsing-Updated/tree/17331eaa5d6586a1ebb633eb61ed810d00d30a2f
AdaIN
import torch class AdaIN(torch.nn.Module): def __init__(self, channels_in, channels_out, norm=True): super(AdaIN, self).__init__() self.channels_in = channels_in self.channels_out = channels_out self.norm = norm self.affine_scale = torch.nn.Linear(channels_in, channels_out, bias =True) self.affine_bias = torch.nn.Linear(channels_in, channels_out, bias=True ) def forward(self, x, w): ys = self.affine_scale(w) yb = self.affine_bias(w) ys = torch.unsqueeze(ys, -1) yb = torch.unsqueeze(yb, -1) xm = torch.reshape(x, shape=(x.shape[0], x.shape[1], -1)) if self.norm: xm_mean = torch.mean(xm, dim=2, keepdims=True) xm_centered = xm - xm_mean xm_std_rev = torch.rsqrt(torch.mean(torch.mul(xm_centered, xm_centered), dim=2, keepdims=True)) xm_norm = xm_centered - xm_std_rev else: xm_norm = xm xm_scaled = xm_norm * ys + yb return torch.reshape(xm_scaled, x.shape) def get_inputs(): return [torch.rand([4, 4]), torch.rand([4, 4])] def get_init_inputs(): return [[], {'channels_in': 4, 'channels_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 assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_add_mean_mul_rsqrt_sub_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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) tmp8 = tl.load(in_out_ptr0 + x2, xmask) tmp9 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last') tmp12 = tl.load(in_ptr2 + x2, xmask) tmp13 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last') tmp1 = 1.0 tmp2 = tmp0 / tmp1 tmp3 = tmp0 - tmp2 tmp4 = tmp3 * tmp3 tmp5 = tmp4 / tmp1 tmp6 = libdevice.rsqrt(tmp5) tmp7 = tmp3 - tmp6 tmp10 = tmp8 + tmp9 tmp11 = tmp7 * tmp10 tmp14 = tmp12 + tmp13 tmp15 = tmp11 + tmp14 tl.store(in_out_ptr0 + x2, tmp15, 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, 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)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0) del primals_1 buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32) extern_kernels.mm(primals_3, reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1) del primals_4 buf2 = reinterpret_tensor(buf0, (4, 4, 1), (4, 1, 1), 0) del buf0 get_raw_stream(0) triton_poi_fused_add_mean_mul_rsqrt_sub_0[grid(16)](buf2, primals_6, primals_2, buf1, primals_5, 16, XBLOCK=16, num_warps=1, num_stages=1) del buf1 del primals_2 del primals_5 return reinterpret_tensor(buf2, (4, 4), (4, 1), 0), primals_3, primals_6 class AdaINNew(torch.nn.Module): def __init__(self, channels_in, channels_out, norm=True): super(AdaINNew, self).__init__() self.channels_in = channels_in self.channels_out = channels_out self.norm = norm self.affine_scale = torch.nn.Linear(channels_in, channels_out, bias =True) self.affine_bias = torch.nn.Linear(channels_in, channels_out, bias=True ) def forward(self, input_0, input_1): primals_1 = self.affine_scale.weight primals_2 = self.affine_scale.bias primals_3 = self.affine_bias.weight primals_5 = self.affine_bias.bias primals_4 = input_0 primals_6 = input_1 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6]) return output[0]
pigunther/Self-Correction-Human-Parsing-Updated
AdaIN
false
7,467
[ "MIT" ]
1
17331eaa5d6586a1ebb633eb61ed810d00d30a2f
https://github.com/pigunther/Self-Correction-Human-Parsing-Updated/tree/17331eaa5d6586a1ebb633eb61ed810d00d30a2f
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=256, num_warps=4, num_stages=1) del primals_1 buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 4, 5, 5), (100, 25, 5, 1)) buf2 = buf1 del buf1 buf3 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.bool) triton_poi_fused_convolution_leaky_relu_leaky_relu_backward_1[grid(400) ](buf2, primals_3, buf3, 400, XBLOCK=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]
piggy2303/DeepFillv2_Pytorch
TransposeConv2dLayer
false
7,468
[ "MIT" ]
1
dd35299f11704f878ed7a33e14ccd51a9d64baaf
https://github.com/piggy2303/DeepFillv2_Pytorch/tree/dd35299f11704f878ed7a33e14ccd51a9d64baaf
FocalLoss
import torch import torch.nn as nn import torch.nn.functional as F import torch.cuda import torch.distributed import torch.multiprocessing class FocalLoss(nn.Module): """Focal Loss - https://arxiv.org/abs/1708.02002""" def __init__(self, alpha=0.25, gamma=2): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, pred_logits, target): pred = pred_logits.sigmoid() ce = F.binary_cross_entropy_with_logits(pred_logits, target, reduction='none') alpha = target * self.alpha + (1.0 - target) * (1.0 - self.alpha) pt = torch.where(target == 1, pred, 1 - pred) return alpha * (1.0 - pt) ** self.gamma * ce def get_inputs(): return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {}]
import torch import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math import torch.nn as nn import torch.cuda import torch.distributed import torch.multiprocessing 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_binary_cross_entropy_with_logits_eq_mul_pow_rsub_sigmoid_where_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) tmp9 = tl.load(in_ptr1 + x0, xmask) tmp1 = 0.25 tmp2 = tmp0 * tmp1 tmp3 = 1.0 tmp4 = tmp3 - tmp0 tmp5 = 0.75 tmp6 = tmp4 * tmp5 tmp7 = tmp2 + tmp6 tmp8 = tmp0 == tmp3 tmp10 = tl.sigmoid(tmp9) tmp11 = tmp3 - tmp10 tmp12 = tl.where(tmp8, tmp10, tmp11) tmp13 = tmp3 - tmp12 tmp14 = tmp13 * tmp13 tmp15 = tmp7 * tmp14 tmp16 = tmp4 * tmp9 tmp17 = 0.0 tmp18 = triton_helpers.minimum(tmp17, tmp9) tmp19 = tl_math.abs(tmp9) tmp20 = -tmp19 tmp21 = tl_math.exp(tmp20) tmp22 = libdevice.log1p(tmp21) tmp23 = tmp18 - tmp22 tmp24 = tmp16 - tmp23 tmp25 = tmp15 * tmp24 tl.store(out_ptr0 + x0, tmp25, 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_binary_cross_entropy_with_logits_eq_mul_pow_rsub_sigmoid_where_0[ grid(256)](arg1_1, arg0_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1) del arg0_1 del arg1_1 return buf0, class FocalLossNew(nn.Module): """Focal Loss - https://arxiv.org/abs/1708.02002""" def __init__(self, alpha=0.25, gamma=2): super().__init__() self.alpha = alpha self.gamma = gamma def forward(self, input_0, input_1): arg0_1 = input_0 arg1_1 = input_1 output = call([arg0_1, arg1_1]) return output[0]
pkashinkunti/retinanet-examples
FocalLoss
false
7,469
[ "BSD-3-Clause" ]
1
30466522c018d4d0bd921485024e871b32ec4e73
https://github.com/pkashinkunti/retinanet-examples/tree/30466522c018d4d0bd921485024e871b32ec4e73
sobel_net
import torch import numpy as np from torch import nn import torch.nn.functional as F class sobel_net(nn.Module): def __init__(self): super().__init__() self.conv_opx = nn.Conv2d(1, 1, 3, bias=False) self.conv_opy = nn.Conv2d(1, 1, 3, bias=False) sobel_kernelx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], dtype='float32').reshape((1, 1, 3, 3)) sobel_kernely = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]], dtype='float32').reshape((1, 1, 3, 3)) self.conv_opx.weight.data = torch.from_numpy(sobel_kernelx) self.conv_opy.weight.data = torch.from_numpy(sobel_kernely) for p in self.parameters(): p.requires_grad = False def forward(self, im): x = (0.299 * im[:, 0, :, :] + 0.587 * im[:, 1, :, :] + 0.114 * im[:, 2, :, :]).unsqueeze(1) gradx = self.conv_opx(x) grady = self.conv_opy(x) x = (gradx ** 2 + grady ** 2) ** 0.5 x = (x - x.min()) / (x.max() - x.min()) x = F.pad(x, (1, 1, 1, 1)) x = torch.cat([im, 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 libdevice import numpy as np 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_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask) tmp7 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask) tmp1 = 0.299 tmp2 = tmp0 * tmp1 tmp4 = 0.587 tmp5 = tmp3 * tmp4 tmp6 = tmp2 + tmp5 tmp8 = 0.114 tmp9 = tmp7 * tmp8 tmp10 = tmp6 + tmp9 tl.store(out_ptr0 + x2, tmp10, xmask) @triton.jit def triton_per_fused_add_max_min_pow_1(in_ptr0, in_ptr1, out_ptr0, out_ptr1, out_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 * tmp0 tmp3 = tmp2 * tmp2 tmp4 = tmp1 + tmp3 tmp5 = libdevice.sqrt(tmp4) tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK]) tmp8 = triton_helpers.min2(tmp6, 1)[:, None] tmp10 = triton_helpers.max2(tmp6, 1)[:, None] tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None) tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp10, None) tl.store(out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp8, None) @triton.jit def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 64 x1 = xindex // 64 tmp0 = tl.load(in_ptr0 + x2, xmask) tl.store(out_ptr0 + (x0 + 80 * x1), tmp0, xmask) @triton.jit def triton_poi_fused_add_constant_pad_nd_div_pow_sub_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x1 = xindex // 4 % 4 x0 = xindex % 4 x2 = xindex // 16 x4 = xindex % 16 tmp17 = tl.load(in_ptr2 + 0) tmp18 = tl.broadcast_to(tmp17, [XBLOCK]) tmp20 = tl.load(in_ptr3 + 0) tmp21 = tl.broadcast_to(tmp20, [XBLOCK]) tmp22 = tl.load(in_ptr4 + 0) tmp23 = tl.broadcast_to(tmp22, [XBLOCK]) tmp0 = -1 + x1 tmp1 = tl.full([1], 0, tl.int64) tmp2 = tmp0 >= tmp1 tmp3 = tl.full([1], 2, tl.int64) tmp4 = tmp0 < tmp3 tmp5 = -1 + x0 tmp6 = tmp5 >= tmp1 tmp7 = tmp5 < tmp3 tmp8 = tmp2 & tmp4 tmp9 = tmp8 & tmp6 tmp10 = tmp9 & tmp7 tmp11 = tl.load(in_ptr0 + (-3 + x0 + 2 * x1 + 4 * x2), tmp10 & xmask, other=0.0) tmp12 = tmp11 * tmp11 tmp13 = tl.load(in_ptr1 + (-3 + x0 + 2 * x1 + 4 * x2), tmp10 & xmask, other=0.0) tmp14 = tmp13 * tmp13 tmp15 = tmp12 + tmp14 tmp16 = libdevice.sqrt(tmp15) tmp19 = tmp16 - tmp18 tmp24 = tmp21 - tmp23 tmp25 = tmp19 / tmp24 tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype) tmp27 = tl.where(tmp10, tmp25, tmp26) tl.store(out_ptr0 + (x4 + 80 * x2), tmp27, xmask) def call(args): arg0_1, arg1_1, arg2_1 = args args.clear() assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(arg1_1, (1, 1, 3, 3), (9, 9, 3, 1)) assert_size_stride(arg2_1, (1, 1, 3, 3), (9, 9, 3, 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_mul_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) buf1 = extern_kernels.convolution(reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 0, 4, 1), 0), arg1_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf1, (4, 1, 2, 2), (4, 4, 2, 1)) del arg1_1 buf2 = extern_kernels.convolution(reinterpret_tensor(buf0, (4, 1, 4, 4), (16, 0, 4, 1), 0), arg2_1, stride=(1, 1), padding=(0, 0), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 1, 2, 2), (4, 4, 2, 1)) del arg2_1 del buf0 buf3 = empty_strided_cuda((), (), torch.float32) buf4 = empty_strided_cuda((), (), torch.float32) buf5 = empty_strided_cuda((), (), torch.float32) triton_per_fused_add_max_min_pow_1[grid(1)](buf1, buf2, buf3, buf4, buf5, 1, 16, XBLOCK=1, num_warps=2, num_stages=1) buf8 = empty_strided_cuda((4, 5, 4, 4), (80, 16, 4, 1), torch.float32) buf6 = reinterpret_tensor(buf8, (4, 4, 4, 4), (80, 16, 4, 1), 0) triton_poi_fused_cat_2[grid(256)](arg0_1, buf6, 256, XBLOCK=256, num_warps=4, num_stages=1) del arg0_1 buf7 = reinterpret_tensor(buf8, (4, 1, 4, 4), (80, 16, 4, 1), 64) triton_poi_fused_add_constant_pad_nd_div_pow_sub_3[grid(64)](buf1, buf2, buf3, buf4, buf5, buf7, 64, XBLOCK=64, num_warps=1, num_stages=1) del buf1 del buf2 del buf3 del buf4 del buf5 return buf8, class sobel_netNew(nn.Module): def __init__(self): super().__init__() self.conv_opx = nn.Conv2d(1, 1, 3, bias=False) self.conv_opy = nn.Conv2d(1, 1, 3, bias=False) sobel_kernelx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], dtype='float32').reshape((1, 1, 3, 3)) sobel_kernely = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]], dtype='float32').reshape((1, 1, 3, 3)) self.conv_opx.weight.data = torch.from_numpy(sobel_kernelx) self.conv_opy.weight.data = torch.from_numpy(sobel_kernely) for p in self.parameters(): p.requires_grad = False def forward(self, input_0): arg1_1 = self.conv_opx.weight arg2_1 = self.conv_opy.weight arg0_1 = input_0 output = call([arg0_1, arg1_1, arg2_1]) return output[0]
phonhay103/DocTr
sobel_net
false
7,470
[ "MIT" ]
1
f052703976e2558633027907af48ecb1dc7718ff
https://github.com/phonhay103/DocTr/tree/f052703976e2558633027907af48ecb1dc7718ff
TrendNet
import torch import torch.nn as nn class TrendNet(nn.Module): def __init__(self, feature_size): super(TrendNet, self).__init__() self.hidden_size1 = 16 self.hidden_size2 = 16 self.output_size = 1 self.fc1 = nn.Linear(feature_size, self.hidden_size1) self.fc2 = nn.Linear(self.hidden_size1, self.hidden_size2) self.fc3 = nn.Linear(self.hidden_size2, self.output_size) def forward(self, input_data): input_data = input_data.transpose(0, 1) xout = self.fc1(input_data) xout = self.fc2(xout) xout = self.fc3(xout) return xout def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'feature_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 % 4 x2 = xindex // 64 x3 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2 + 64 * x1), xmask) tl.store(out_ptr0 + x3, tmp0, xmask) @triton.jit def triton_poi_fused_add_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 1024 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 16 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x2, tmp2, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (16, 4), (4, 1)) assert_size_stride(primals_3, (16,), (1,)) assert_size_stride(primals_4, (16, 16), (16, 1)) assert_size_stride(primals_5, (16,), (1,)) assert_size_stride(primals_6, (1, 16), (16, 1)) assert_size_stride(primals_7, (1,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(256)](primals_1, buf0, 256, XBLOCK= 128, num_warps=4, num_stages=1) del primals_1 buf1 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4, 16), (256, 64, 16, 1), 0) del buf1 triton_poi_fused_add_1[grid(1024)](buf2, primals_3, 1024, XBLOCK= 128, num_warps=4, num_stages=1) del primals_3 buf3 = empty_strided_cuda((64, 16), (16, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 16), (16, 1), 0), reinterpret_tensor(primals_4, (16, 16), (1, 16), 0 ), alpha=1, beta=1, out=buf3) del primals_5 buf5 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_7, buf3, reinterpret_tensor(primals_6, (16, 1), (1, 16), 0), alpha=1, beta=1, out=buf5) del primals_7 return reinterpret_tensor(buf5, (4, 4, 4, 1), (16, 4, 1, 1), 0 ), reinterpret_tensor(buf0, (64, 4), (4, 1), 0), reinterpret_tensor( buf2, (64, 16), (16, 1), 0), buf3, primals_6, primals_4 class TrendNetNew(nn.Module): def __init__(self, feature_size): super(TrendNetNew, self).__init__() self.hidden_size1 = 16 self.hidden_size2 = 16 self.output_size = 1 self.fc1 = nn.Linear(feature_size, self.hidden_size1) self.fc2 = nn.Linear(self.hidden_size1, self.hidden_size2) self.fc3 = nn.Linear(self.hidden_size2, self.output_size) def forward(self, input_0): primals_2 = self.fc1.weight primals_3 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
pixel-ports/PV_prod_predic
TrendNet
false
7,471
[ "Apache-2.0" ]
1
2ceb4cf8218f43f3ea94c5520b1904663cfb0de1
https://github.com/pixel-ports/PV_prod_predic/tree/2ceb4cf8218f43f3ea94c5520b1904663cfb0de1
FlowHead
import torch from torch import nn class FlowHead(nn.Module): def __init__(self, input_dim=128, hidden_dim=256): super(FlowHead, self).__init__() self.conv1 = nn.Conv2d(input_dim, hidden_dim, 3, padding=1) self.conv2 = nn.Conv2d(hidden_dim, 2, 3, padding=1) self.relu = nn.ReLU(inplace=True) def forward(self, x): return self.conv2(self.relu(self.conv1(x))) def get_inputs(): return [torch.rand([4, 128, 64, 64])] def get_init_inputs(): return [[], {}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime import triton_helpers from torch import nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride @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 % 256 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = tl.full([1], 0, tl.int32) tmp4 = triton_helpers.maximum(tmp3, tmp2) tl.store(in_out_ptr0 + x3, tmp4, None) @triton.jit def triton_poi_fused_convolution_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 // 4096 % 2 tmp0 = tl.load(in_out_ptr0 + x3, None) tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tl.store(in_out_ptr0 + x3, tmp2, None) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (256, 128, 3, 3), (1152, 9, 3, 1)) assert_size_stride(primals_2, (256,), (1,)) assert_size_stride(primals_3, (4, 128, 64, 64), (524288, 4096, 64, 1)) assert_size_stride(primals_4, (2, 256, 3, 3), (2304, 9, 3, 1)) assert_size_stride(primals_5, (2,), (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, 256, 64, 64), (1048576, 4096, 64, 1)) buf1 = buf0 del buf0 get_raw_stream(0) triton_poi_fused_convolution_relu_0[grid(4194304)](buf1, primals_2, 4194304, XBLOCK=1024, num_warps=4, num_stages=1) del primals_2 buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1), padding=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0, 0), groups=1, bias=None) assert_size_stride(buf2, (4, 2, 64, 64), (8192, 4096, 64, 1)) buf3 = buf2 del buf2 triton_poi_fused_convolution_1[grid(32768)](buf3, primals_5, 32768, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 return buf3, primals_1, primals_3, primals_4, buf1 class FlowHeadNew(nn.Module): def __init__(self, input_dim=128, hidden_dim=256): super(FlowHeadNew, self).__init__() self.conv1 = nn.Conv2d(input_dim, hidden_dim, 3, padding=1) self.conv2 = nn.Conv2d(hidden_dim, 2, 3, padding=1) self.relu = nn.ReLU(inplace=True) def forward(self, input_0): primals_1 = self.conv1.weight primals_2 = self.conv1.bias primals_4 = self.conv2.weight primals_5 = self.conv2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
phonhay103/DocTr
FlowHead
false
7,472
[ "MIT" ]
1
f052703976e2558633027907af48ecb1dc7718ff
https://github.com/phonhay103/DocTr/tree/f052703976e2558633027907af48ecb1dc7718ff
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=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, 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]
piggy2303/DeepFillv2_Pytorch
GatedConv2d
false
7,473
[ "MIT" ]
1
dd35299f11704f878ed7a33e14ccd51a9d64baaf
https://github.com/piggy2303/DeepFillv2_Pytorch/tree/dd35299f11704f878ed7a33e14ccd51a9d64baaf
ContinuousActor
import torch import numpy as np import torch.nn as nn import torch.nn.functional as F def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class ContinuousActor(nn.Module): """ContinuousActor network :param state_size: the size of the state space :type state_size: int :param hidden1_size: the size of the first hidden network :type hidden1_size: int :param hidden2_size: the size of the second hidden network :type hidden2_size: int :param action_size: the size of the action space :type action_size: int """ def __init__(self, state_size, hidden1_size, hidden2_size, action_size): super(ContinuousActor, self).__init__() self.fc1 = nn.Linear(state_size, hidden1_size) self.fc2 = nn.Linear(hidden1_size, hidden2_size) self.fc3 = nn.Linear(hidden2_size, action_size) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, state): """Build an actor network that maps states to actions. :param state: the state :type state: :class:`torch.Tensor` :return: action tensor :rtype: :class:`torch.Tensor` """ x = F.leaky_relu(self.fc1(state)) x = F.leaky_relu(self.fc2(x)) return torch.tanh(self.fc3(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'state_size': 4, 'hidden1_size': 4, 'hidden2_size': 4, 'action_size': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import numpy as np import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr): xnumel = 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 = tmp2 > tmp3 tmp5 = 0.01 tmp6 = tmp2 * tmp5 tmp7 = tl.where(tmp4, tmp2, tmp6) tl.store(out_ptr0 + x2, tmp4, xmask) tl.store(out_ptr1 + x2, tmp7, xmask) @triton.jit def triton_poi_fused_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr ): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, 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, (4, 4), (4, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((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.bool) buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_leaky_relu_0[grid(256)](buf0, primals_2, buf1, buf2, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_2 buf3 = buf0 del buf0 extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf3) 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.float32) triton_poi_fused_leaky_relu_0[grid(256)](buf3, primals_5, buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_5 buf6 = buf3 del buf3 extern_kernels.mm(reinterpret_tensor(buf5, (64, 4), (4, 1), 0), reinterpret_tensor(primals_6, (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_1[grid(256)](buf7, primals_7, 256, XBLOCK=128, num_warps=4, num_stages=1) del primals_7 return buf7, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 4), (4, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 4), (4, 1), 0 ), buf7, primals_6, primals_4 def hidden_init(layer): fan_in = layer.weight.data.size()[0] lim = 1.0 / np.sqrt(fan_in) return -lim, lim class ContinuousActorNew(nn.Module): """ContinuousActor network :param state_size: the size of the state space :type state_size: int :param hidden1_size: the size of the first hidden network :type hidden1_size: int :param hidden2_size: the size of the second hidden network :type hidden2_size: int :param action_size: the size of the action space :type action_size: int """ def __init__(self, state_size, hidden1_size, hidden2_size, action_size): super(ContinuousActorNew, self).__init__() self.fc1 = nn.Linear(state_size, hidden1_size) self.fc2 = nn.Linear(hidden1_size, hidden2_size) self.fc3 = nn.Linear(hidden2_size, action_size) self.reset_parameters() def reset_parameters(self): self.fc1.weight.data.uniform_(*hidden_init(self.fc1)) self.fc2.weight.data.uniform_(*hidden_init(self.fc2)) self.fc3.weight.data.uniform_(-0.003, 0.003) def forward(self, input_0): primals_1 = self.fc1.weight primals_2 = self.fc1.bias primals_4 = self.fc2.weight primals_5 = self.fc2.bias primals_6 = self.fc3.weight primals_7 = self.fc3.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
pjordan/rlcc
ContinuousActor
false
7,474
[ "Apache-2.0" ]
1
e84b8b5c14680dbad2efae22756fb40606b2384a
https://github.com/pjordan/rlcc/tree/e84b8b5c14680dbad2efae22756fb40606b2384a
PositionwiseFeedForward
import torch import torch.nn as nn import torch.nn.functional as F class PositionwiseFeedForward(nn.Module): """Positionwise feed forward :param int idim: input dimenstion :param int hidden_units: number of hidden units :param float dropout_rate: dropout rate """ def __init__(self, idim, hidden_units, dropout_rate=0.0): super(PositionwiseFeedForward, self).__init__() self.w_1 = nn.Linear(idim, hidden_units * 2) self.w_2 = nn.Linear(hidden_units, idim) self.dropout = nn.Dropout(dropout_rate) def forward(self, x): x = self.w_1(x) x = F.glu(x) return self.w_2(self.dropout(x)) def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'idim': 4, 'hidden_units': 4}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_glu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 256 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 4 x1 = xindex // 4 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 8 * x1), xmask) tmp1 = tl.load(in_ptr0 + (4 + x0 + 8 * x1), xmask) tmp2 = tl.sigmoid(tmp1) tmp3 = tmp0 * tmp2 tl.store(out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3, primals_4, primals_5 = args args.clear() assert_size_stride(primals_1, (8, 4), (4, 1)) assert_size_stride(primals_2, (8,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (4, 4), (4, 1)) assert_size_stride(primals_5, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((64, 8), (8, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 8), (1, 4), 0 ), alpha=1, beta=1, out=buf0) del primals_1 del primals_2 buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_glu_0[grid(256)](buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1) buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), ( 4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf2) del primals_5 return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), reinterpret_tensor(buf0, (4, 4, 4, 8), (128, 32, 8, 1), 0 ), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_4 class PositionwiseFeedForwardNew(nn.Module): """Positionwise feed forward :param int idim: input dimenstion :param int hidden_units: number of hidden units :param float dropout_rate: dropout rate """ def __init__(self, idim, hidden_units, dropout_rate=0.0): super(PositionwiseFeedForwardNew, self).__init__() self.w_1 = nn.Linear(idim, hidden_units * 2) self.w_2 = nn.Linear(hidden_units, idim) self.dropout = nn.Dropout(dropout_rate) def forward(self, input_0): primals_1 = self.w_1.weight primals_2 = self.w_1.bias primals_4 = self.w_2.weight primals_5 = self.w_2.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5]) return output[0]
pkufool/DaVinci-Speech
PositionwiseFeedForward
false
7,475
[ "MIT" ]
1
98602363168476356d492852093adbe65c65ac95
https://github.com/pkufool/DaVinci-Speech/tree/98602363168476356d492852093adbe65c65ac95
BertPooler
from _paritybench_helpers import _mock_config import torch import torch.nn as nn class BertPooler(nn.Module): def __init__(self, config): super(BertPooler, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() def forward(self, hidden_states): first_token_tensor = hidden_states[:, 0] pooled_output = self.dense(first_token_tensor) pooled_output = self.activation(pooled_output) return pooled_output def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'config': _mock_config(hidden_size=4)}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.nn as nn assert_size_stride = torch._C._dynamo.guards.assert_size_stride empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor @triton.jit def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x0 = xindex % 16 x1 = xindex // 16 x2 = xindex tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask) tl.store(out_ptr0 + x2, tmp0, xmask) @triton.jit def triton_poi_fused_add_tanh_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl. constexpr): xnumel = 64 xoffset = tl.program_id(0) * XBLOCK xindex = xoffset + tl.arange(0, XBLOCK)[:] xmask = xindex < xnumel x2 = xindex x0 = xindex % 4 tmp0 = tl.load(in_out_ptr0 + x2, xmask) tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last') tmp2 = tmp0 + tmp1 tmp3 = libdevice.tanh(tmp2) tl.store(in_out_ptr0 + x2, tmp3, xmask) def call(args): primals_1, primals_2, primals_3 = args args.clear() assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_2, (4, 4), (4, 1)) assert_size_stride(primals_3, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32) get_raw_stream(0) triton_poi_fused_clone_0[grid(64)](primals_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1) del primals_1 buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32) extern_kernels.mm(reinterpret_tensor(buf0, (16, 4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1) del primals_2 buf2 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0) del buf1 triton_poi_fused_add_tanh_1[grid(64)](buf2, primals_3, 64, XBLOCK= 64, num_warps=1, num_stages=1) del primals_3 return buf2, reinterpret_tensor(buf0, (16, 4), (4, 1), 0), buf2 class BertPoolerNew(nn.Module): def __init__(self, config): super(BertPoolerNew, self).__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() def forward(self, input_0): primals_2 = self.dense.weight primals_3 = self.dense.bias primals_1 = input_0 output = call([primals_1, primals_2, primals_3]) return output[0]
AlanFokCo/bert-chinese-horovod-elastic
BertPooler
false
7,476
[ "Apache-2.0" ]
1
02317d0857e0e8e313dd63ead61ca9996b25548e
https://github.com/AlanFokCo/bert-chinese-horovod-elastic/tree/02317d0857e0e8e313dd63ead61ca9996b25548e
VariableBoxMLP
import torch import torch.optim import torch.jit import torch.nn as nn class VariableBoxMLP(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int', neurons_per_layer: 'int', hidden_layers: 'int'): super(VariableBoxMLP, self).__init__() self.hidden_layers = hidden_layers self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features= neurons_per_layer) for i in range(0, hidden_layers): layer = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) torch.nn.init.xavier_normal_(layer.weight) torch.nn.init.zeros_(layer.bias) setattr(self, 'l' + str(i), layer) self.l_out = nn.Linear(in_features=neurons_per_layer, out_features= num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, x): x = self.act(self.l_in(x)) for i in range(self.hidden_layers): x = self.act(getattr(self, 'l' + str(i)).__call__(x)) x = self.l_out(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in_features': 4, 'num_out_features': 4, 'neurons_per_layer': 1, 'hidden_layers': 1}]
import torch from torch._inductor.select_algorithm import extern_kernels import triton import triton.language as tl from torch._inductor.runtime.triton_heuristics import grid from torch._C import _cuda_getCurrentRawStream as get_raw_stream from torch._inductor.runtime.triton_helpers import libdevice import torch.optim import torch.jit 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 = 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 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) def call(args): (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7) = args args.clear() assert_size_stride(primals_1, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 1), (1, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (4, 1), (1, 1)) assert_size_stride(primals_7, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_1 del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 1), ( 1, 0), 0), primals_4, alpha=1, beta=1, out=buf4) del primals_5 buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf5, (64, 1), ( 1, 0), 0), reinterpret_tensor(primals_6, (1, 4), (1, 1), 0), alpha=1, beta=1, out=buf6) del primals_7 return reinterpret_tensor(buf6, (4, 4, 4, 4), (64, 16, 4, 1), 0 ), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0 ), buf1, reinterpret_tensor(buf2, (64, 1), (1, 1), 0 ), buf4, reinterpret_tensor(buf5, (64, 1), (1, 1), 0 ), primals_6, primals_4 class VariableBoxMLPNew(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int', neurons_per_layer: 'int', hidden_layers: 'int'): super(VariableBoxMLPNew, self).__init__() self.hidden_layers = hidden_layers self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features= neurons_per_layer) for i in range(0, hidden_layers): layer = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) torch.nn.init.xavier_normal_(layer.weight) torch.nn.init.zeros_(layer.bias) setattr(self, 'l' + str(i), layer) self.l_out = nn.Linear(in_features=neurons_per_layer, out_features= num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, input_0): primals_1 = self.l_in.weight primals_2 = self.l_in.bias primals_4 = self.l0.weight primals_5 = self.l0.bias primals_6 = self.l_out.weight primals_7 = self.l_out.bias primals_3 = input_0 output = call([primals_1, primals_2, primals_3, primals_4, primals_5, primals_6, primals_7]) return output[0]
plaveczlambert/deep_euler_tests
VariableBoxMLP
false
7,477
[ "MIT" ]
1
a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a
https://github.com/plaveczlambert/deep_euler_tests/tree/a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a
SimpleMLP
import torch import torch.optim import torch.jit import torch.nn as nn class SimpleMLP(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int', neurons_per_layer: 'int'): super(SimpleMLP, self).__init__() self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features= neurons_per_layer) self.l1 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l2 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l3 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l4 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l5 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l6 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l_out = nn.Linear(in_features=neurons_per_layer, out_features= num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l1.weight) torch.nn.init.zeros_(self.l1.bias) torch.nn.init.xavier_normal_(self.l2.weight) torch.nn.init.zeros_(self.l2.bias) torch.nn.init.xavier_normal_(self.l3.weight) torch.nn.init.zeros_(self.l3.bias) torch.nn.init.xavier_normal_(self.l4.weight) torch.nn.init.zeros_(self.l4.bias) torch.nn.init.xavier_normal_(self.l5.weight) torch.nn.init.zeros_(self.l5.bias) torch.nn.init.xavier_normal_(self.l6.weight) torch.nn.init.zeros_(self.l6.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, x): x = self.act(self.l_in(x)) x = self.act(self.l1(x)) x = self.act(self.l2(x)) x = self.act(self.l3(x)) x = self.act(self.l4(x)) x = self.act(self.l5(x)) x = self.act(self.l6(x)) x = self.l_out(x) return x def get_inputs(): return [torch.rand([4, 4, 4, 4])] def get_init_inputs(): return [[], {'num_in_features': 4, 'num_out_features': 4, 'neurons_per_layer': 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.optim import torch.jit 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 = 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 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) 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, (1, 4), (4, 1)) assert_size_stride(primals_2, (1,), (1,)) assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1)) assert_size_stride(primals_4, (1, 1), (1, 1)) assert_size_stride(primals_5, (1,), (1,)) assert_size_stride(primals_6, (1, 1), (1, 1)) assert_size_stride(primals_7, (1,), (1,)) assert_size_stride(primals_8, (1, 1), (1, 1)) assert_size_stride(primals_9, (1,), (1,)) assert_size_stride(primals_10, (1, 1), (1, 1)) assert_size_stride(primals_11, (1,), (1,)) assert_size_stride(primals_12, (1, 1), (1, 1)) assert_size_stride(primals_13, (1,), (1,)) assert_size_stride(primals_14, (1, 1), (1, 1)) assert_size_stride(primals_15, (1,), (1,)) assert_size_stride(primals_16, (4, 1), (1, 1)) assert_size_stride(primals_17, (4,), (1,)) with torch.cuda._DeviceGuard(0): torch.cuda.set_device(0) buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0 ), alpha=1, beta=1, out=buf1) del primals_1 del primals_2 buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) get_raw_stream(0) triton_poi_fused_elu_0[grid(64)](buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1) buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 1), ( 1, 0), 0), primals_4, alpha=1, beta=1, out=buf4) del primals_5 buf5 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf4, buf5, 64, XBLOCK=64, num_warps=1, num_stages=1) buf7 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_7, reinterpret_tensor(buf5, (64, 1), ( 1, 0), 0), primals_6, alpha=1, beta=1, out=buf7) del primals_7 buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1) buf10 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_9, reinterpret_tensor(buf8, (64, 1), ( 1, 0), 0), primals_8, alpha=1, beta=1, out=buf10) del primals_9 buf11 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf10, buf11, 64, XBLOCK=64, num_warps=1, num_stages=1) buf13 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_11, reinterpret_tensor(buf11, (64, 1), (1, 0), 0), primals_10, alpha=1, beta=1, out=buf13) del primals_11 buf14 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf13, buf14, 64, XBLOCK=64, num_warps=1, num_stages=1) buf16 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_13, reinterpret_tensor(buf14, (64, 1), (1, 0), 0), primals_12, alpha=1, beta=1, out=buf16) del primals_13 buf17 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf16, buf17, 64, XBLOCK=64, num_warps=1, num_stages=1) buf19 = empty_strided_cuda((64, 1), (1, 1), torch.float32) extern_kernels.addmm(primals_15, reinterpret_tensor(buf17, (64, 1), (1, 0), 0), primals_14, alpha=1, beta=1, out=buf19) del primals_15 buf20 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32) triton_poi_fused_elu_0[grid(64)](buf19, buf20, 64, XBLOCK=64, num_warps=1, num_stages=1) buf21 = empty_strided_cuda((64, 4), (4, 1), torch.float32) extern_kernels.addmm(primals_17, reinterpret_tensor(buf20, (64, 1), (1, 0), 0), reinterpret_tensor(primals_16, (1, 4), (1, 1), 0), alpha=1, beta=1, out=buf21) del primals_17 return (reinterpret_tensor(buf21, (4, 4, 4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf1, reinterpret_tensor(buf2, (64, 1), (1, 1), 0), buf4, reinterpret_tensor(buf5, (64, 1), (1, 1), 0), buf7, reinterpret_tensor(buf8, (64, 1), (1, 1), 0), buf10, reinterpret_tensor(buf11, (64, 1), (1, 1), 0), buf13, reinterpret_tensor(buf14, (64, 1), (1, 1), 0), buf16, reinterpret_tensor(buf17, (64, 1), (1, 1), 0), buf19, reinterpret_tensor(buf20, (64, 1), (1, 1), 0), primals_16, primals_14, primals_12, primals_10, primals_8, primals_6, primals_4) class SimpleMLPNew(nn.Module): def __init__(self, num_in_features: 'int', num_out_features: 'int', neurons_per_layer: 'int'): super(SimpleMLPNew, self).__init__() self.act = nn.ELU() self.l_in = nn.Linear(in_features=num_in_features, out_features= neurons_per_layer) self.l1 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l2 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l3 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l4 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l5 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l6 = nn.Linear(in_features=neurons_per_layer, out_features= neurons_per_layer) self.l_out = nn.Linear(in_features=neurons_per_layer, out_features= num_out_features) torch.nn.init.xavier_normal_(self.l_in.weight) torch.nn.init.zeros_(self.l_in.bias) torch.nn.init.xavier_normal_(self.l1.weight) torch.nn.init.zeros_(self.l1.bias) torch.nn.init.xavier_normal_(self.l2.weight) torch.nn.init.zeros_(self.l2.bias) torch.nn.init.xavier_normal_(self.l3.weight) torch.nn.init.zeros_(self.l3.bias) torch.nn.init.xavier_normal_(self.l4.weight) torch.nn.init.zeros_(self.l4.bias) torch.nn.init.xavier_normal_(self.l5.weight) torch.nn.init.zeros_(self.l5.bias) torch.nn.init.xavier_normal_(self.l6.weight) torch.nn.init.zeros_(self.l6.bias) torch.nn.init.xavier_normal_(self.l_out.weight) torch.nn.init.zeros_(self.l_out.bias) def forward(self, input_0): primals_1 = self.l_in.weight primals_2 = self.l_in.bias primals_4 = self.l1.weight primals_5 = self.l1.bias primals_6 = self.l2.weight primals_7 = self.l2.bias primals_8 = self.l3.weight primals_9 = self.l3.bias primals_10 = self.l4.weight primals_11 = self.l4.bias primals_12 = self.l5.weight primals_13 = self.l5.bias primals_14 = self.l6.weight primals_15 = self.l6.bias primals_16 = self.l_out.weight primals_17 = self.l_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, primals_10, primals_11, primals_12, primals_13, primals_14, primals_15, primals_16, primals_17]) return output[0]
plaveczlambert/deep_euler_tests
SimpleMLP
false
7,478
[ "MIT" ]
1
a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a
https://github.com/plaveczlambert/deep_euler_tests/tree/a3ceef98ba76bd7a00ccd3c773cd9850311b3b1a